-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Ti.include('common.js');
var data = [
{title:'row1'},
{title:'row2'}
];
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
var win1= Ti.UI.createWindow({
backgroundColor:'#e4e4e4',
title:'나의 과제 리스트',
navBarHidden:true
});
win1.addEventListener('open',function(){
Cloud.Users.login({
login:'striketm@gmail.com',
password:'1234'
},function(e){
if(e.success){
alert('login success');
}else{
alert('login failed');
}
});
getMyHomework();
});
var titleView = Ti.UI.createView({
backgroundColor:'#333333',
width:Ti.Platform.displayCaps.platformWidth, // 안드로이드 해상도상의 넓이
height:80,
left:0,top:0
});
var lbTitle = Ti.UI.createLabel({
text:'나의 과제',
color:'#fff',
font:{fontSize:35}
});
titleView.add(lbTitle);
var btnAdd = Ti.UI.createButton({
title:'추가',
width:90,height:50,
right:10
});
var ReloadBtnAdd = Ti.UI.createButton({
title:'reload',
width:90,height:50,
left:2
});
ReloadBtnAdd.addEventListener('click',function(){
getMyHomework();
})
btnAdd.addEventListener('click',function(){
var writeWin = Ti.UI.createWindow({
backgroundColor:'#e4e4e4',
modal:true,
navBarHidden:true
});
var titleView2 = Ti.UI.createView({
backgroundColor:'#333333',
width:Ti.Platform.displayCaps.platformWidth, // 안드로이드 해상도상의 넓이
height:80,
left:0,top:0
});
var lbTitle2 = Ti.UI.createLabel({
text:'과제 등록',
color:'#fff',
font:{fontSize:35}
});
titleView2.add(lbTitle2);
var btnWriteWinClose = Ti.UI.createButton({
title:'닫기',
width:90,height:55,
left:10
});
btnWriteWinClose.addEventListener('click',function(){
getMyHomework();
writeWin.close();
});
titleView2.add(btnWriteWinClose);
var btnWriteWinSend = Ti.UI.createButton({
title:'등록',
width:90,height:55,
right:10
});
btnWriteWinSend.addEventListener('click',function(){
if(!tfWorkTitle.value){
alert('과제명을 등록하시오');
return false;
}
if(!taWorkCont.value){
alert('과제내용을 등록하시오');
return false;
}
Cloud.Posts.create({
title:tfWorkTitle.value,
content:taWorkCont.value
},function(e){
if(e.success){
alert('과제등록완료');
taWorkCont.value = tfWorkTitle.value = '';
getMyHomework();
writeWin.close();
}else{
alert(e);
}
});
});
titleView2.add(btnWriteWinSend);
var tfWorkTitle = Ti.UI.createTextField({
width:450,height:70,
top:100,
hintText:'과제명',
paddingLeft:5,
backgroundColor:'#fff',
borderRadius:5,
borderColor:'#000'
});
writeWin.add(tfWorkTitle);
var taWorkCont = Ti.UI.createTextArea({
width:450,height:300,
top:190,
font:{fontSize:30},
backgroundColor:'#fff',
borderRadius:5,
borderColor:'#000',
returnKeyType:Ti.UI.RETURNKEY_SEND
});
writeWin.add(taWorkCont);
writeWin.add(titleView2);
writeWin.open();
});
var tblWork = Ti.UI.createTableView({
minRowHeight:60, //
top:80,left:0
});
tblWork.addEventListener('click',function(e){
var detailWin = Ti.UI.createWindow({
modal:true,
navBarHidden:true,
backgroundColor:'#e4e4e4'
});
var titleView3 = Ti.UI.createView({
backgroundColor:'#333333',
width:Ti.Platform.displayCaps.platformWidth, // 안드로이드 해상도상의 넓이
height:80,
left:0,top:0
});
var lbTitle3 = Ti.UI.createLabel({
text:e.rowData._title,
color:'#fff',
font:{fontSize:35}
});
titleView3.add(lbTitle3);
var btnWriteWinClose3 = Ti.UI.createButton({
title:'닫기',
width:90,height:55,
left:10
});
btnWriteWinClose3.addEventListener('click',function(){
detailWin.close();
});
titleView3.add(btnWriteWinClose3);
detailWin.add(titleView3);
var lbRegDate = Ti.UI.createLabel({
text:e.rowData.rdate.substring(0,10),
color:'#000000',
font:{fontSize:17},
right:10,top:90
});
detailWin.add(lbRegDate);
var lbContD = Ti.UI.createLabel({
text:e.rowData.cont,
color:'#000000',
font:{fontSize:20},
width:Ti.Platform.displayCaps.platformHeight-20, // 해상도의 값을 알아오는 부분
left:10,top:117,
wordWrap:true
});
detailWin.add(lbContD);
detailWin.open();
});
tblWork.addEventListener('longpress',function(e){
var udAlertDlg = Ti.UI.createAlertDialog({
buttonNames:['수정','삭제','닫기'],
message:'과제를 어떻게 할까요?',
cancel:2
});
udAlertDlg.addEventListener('click',function(e2){
if(e2.index == 0){ // 수정
var writeWin = Ti.UI.createWindow({
backgroundColor:'#e4e4e4',
modal:true,
navBarHidden:true
});
var titleView2 = Ti.UI.createView({
backgroundColor:'#333333',
width:Ti.Platform.displayCaps.platformWidth, // 안드로이드 해상도상의 넓이
height:80,
left:0,top:0
});
var lbTitle2 = Ti.UI.createLabel({
text:'과제 수정',
color:'#fff',
font:{fontSize:35}
});
titleView2.add(lbTitle2);
var btnWriteWinClose = Ti.UI.createButton({
title:'닫기',
width:90,height:55,
left:10
});
btnWriteWinClose.addEventListener('click',function(){
writeWin.close();
});
titleView2.add(btnWriteWinClose);
var btnWriteWinSend = Ti.UI.createButton({
title:'수정',
width:90,height:55,
right:10
});
btnWriteWinSend.addEventListener('click',function(){
if(!tfWorkTitle.value){
alert('과제명을 등록하시오');
return false;
}
if(!taWorkCont.value){
alert('과제내용을 등록하시오');
return false;
}
Cloud.Posts.update({
post_id:e.rowData.id,
title:tfWorkTitle.value,
content:taWorkCont.value
},function(e3){
if(e3.success){
alert('과제수정완료');
taWorkCont.value = tfWorkTitle.value = '';
writeWin.close();
}else{
alert(e3);
}
getMyHomework();
});
});
titleView2.add(btnWriteWinSend);
var tfWorkTitle = Ti.UI.createTextField({
width:450,height:70,
top:100,
hintText:'과제명',
paddingLeft:5,
backgroundColor:'#fff',
borderRadius:5,
borderColor:'#000',
value:e.rowData._title
});
writeWin.add(tfWorkTitle);
var taWorkCont = Ti.UI.createTextArea({
width:450,height:300,
top:190,
font:{fontSize:30},
backgroundColor:'#fff',
borderRadius:5,
borderColor:'#000',
returnKeyType:Ti.UI.RETURNKEY_SEND,
value:e.rowData.cont
});
writeWin.add(taWorkCont);
writeWin.add(titleView2);
writeWin.open();
}else if(e2.index == 1){ // 삭제
Cloud.Posts.remove({
post_id:e.rowData.id
},function(e){
if(e.success){
alert('삭제완료');
getMyHomework();
}else{
alert('삭제실패');
}
});
}
});
udAlertDlg.show();
});
var getMyHomework= function(){
var arrPost = [];
Cloud.Posts.query(function(e){
if(e.success){
if(e.posts.length==0){
var row = Ti.UI.createTableViewRow({
height:60
});
var lbEmptyTitle = Ti.UI.createLabel({
text:'등록된 글이 없습니다',
font:{
fontSize:20,
},
color:'#000000',
height:Ti.UI.SIZE,width:Ti.UI.SIZE,
left:10
});
row.add(lbEmptyTitle);
arrPost.push(row);
tblWork.setData(arrPost);
}else{
for(var i=0;i<e.posts.length;i++){
var row = Ti.UI.createTableViewRow({
height:60,
_title:e.posts[i].title,
id:e.posts[i].id,
cont:e.posts[i].content,
rdate:e.posts[i].created_at
});
var lbTitle = Ti.UI.createLabel({
text:e.posts[i].title,
font:{
fontSize:17,
},
color:'#000000',
height:Ti.UI.SIZE,width:Ti.UI.SIZE,
left:10
});
row.add(lbTitle);
var lbTime = Ti.UI.createLabel({
text:e.posts[i].created_at.substring(0,10), // substring 텍스트의 0부터 10자리만 가져오는 함수
font:{
fontSize:17,
},
color:'#000000',
height:Ti.UI.SIZE,width:Ti.UI.SIZE,
right:10
});
row.add(lbTime);
arrPost.push(row);
}
tblWork.setData(arrPost);
}
}else{
}
});
};
titleView.add(btnAdd);
titleView.add(ReloadBtnAdd);
win1.add(titleView);
win1.add(tblWork);
win1.open();