Created
November 28, 2013 18:46
-
-
Save MotiurRahman/7696573 to your computer and use it in GitHub Desktop.
Android and IOS: Generate list with ACS Custom Objects CommonJS Module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create acs query for save and retrieved data from acs | |
var Cloud = require('ti.cloud'); | |
exports.addData = function(titleValue) { | |
Cloud.Objects.create({ | |
classname : 'data', | |
fields : { | |
title : titleValue, | |
} | |
}, function(e) { | |
if (e.success) { | |
var data = e.data[0]; | |
} else { | |
alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e))); | |
} | |
}); | |
}; | |
exports.getInfo = function(callback) { | |
var dataValue = []; | |
Cloud.Objects.query({ | |
classname : 'data' | |
}, function(e) { | |
if (e.success) { | |
for (var i = 0; i < e.data.length; i++) { | |
var dataValue = e.data[i]; | |
dataValue.push({ | |
title : dataValue.title | |
}); | |
// alert('value='+dataValue.title); | |
} | |
callback(dataValue); | |
} else { | |
alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e))); | |
} | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Hi here create a custom object named title which save to the remote acs and show | |
this in a tableView list form the remote acs. | |
*/ | |
Cloud.Users.login({ | |
login : '[email protected]', | |
password : '1234' | |
}, function(e) { | |
if (e.success) { | |
//alert('success'); | |
var user = e.users[0]; | |
var mainView = require('ui/common/customListView'); | |
var masterView = new mainView(); | |
masterView.open(); | |
} else { | |
alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e))); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is the main view for showing data | |
function listView() { | |
var win = Ti.UI.createWindow({ | |
layout : 'vertical', | |
backgroundColor : '#000', | |
navBarHidden : false, | |
title : 'Custom Object List' | |
}); | |
var Cloud = require('ti.cloud'); | |
// Create a TextField. | |
var title = Ti.UI.createTextField({ | |
height : Ti.UI.SIZE, | |
top : 10, | |
left : 10, | |
width : Ti.UI.FILL, | |
hintText : 'add something', | |
keyboardType : Ti.UI.KEYBOARD_DEFAULT, | |
returnKeyType : Ti.UI.RETURNKEY_DEFAULT, | |
borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED | |
}); | |
// Add to the parent view. | |
win.add(title); | |
// Listen for return events. | |
title.addEventListener('return', function(e) { | |
var ACS = require('lib/acs'); | |
ACS.addData(title.value); | |
title.blur(); | |
Ti.App.fireEvent('tableUpdate'); | |
}); | |
var tableData = []; | |
var tableView = Ti.UI.createTableView({ | |
data : tableData, | |
top : 0, | |
}); | |
win.add(tableView); | |
Ti.App.addEventListener('tableUpdate', refresh); | |
refresh(); | |
function refresh() { | |
tableData = []; | |
var ACS = require('lib/acs'); | |
ACS.getInfo(function(callback) { | |
// alert(callback.length); | |
for (var i = 0; i < callback.length; i++) { | |
var row = Ti.UI.createTableViewRow({ | |
className : 'forumEvent', // used to improve table performance | |
selectedBackgroundColor : 'white', | |
rowIndex : i, // custom property, useful for determining the row during events | |
height : 'auto', | |
title : callback[i].title, | |
}); | |
var title = Ti.UI.createLabel({ | |
color : 'red', | |
font : { | |
fontFamily : 'Arial', | |
fontSize : 25, | |
fontWeight : 'normal' | |
}, | |
text : callback[i].title, | |
top : 30, | |
left : 10, | |
right : 75 | |
}); | |
row.add(title); | |
tableData.push(row); | |
} | |
tableView.setData(tableData); | |
}); | |
} | |
return win; | |
} | |
module.exports = listView; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment