Created
March 23, 2014 04:48
-
-
Save csemrm/9718983 to your computer and use it in GitHub Desktop.
Titanium ACS post Objects: How to post data in ACS server
This file contains hidden or 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
var Cloud = require('ti.cloud'); | |
Cloud.debug = true; | |
var win = Ti.UI.createWindow({ | |
backgroundColor : 'white', | |
layout : 'vertical', | |
}); | |
var aTableView = Ti.UI.createTableView(); | |
login(); | |
function login() { | |
Cloud.Users.login({ | |
login : 'username', | |
password : 'password' | |
}, function(e) { | |
if (e.success) { | |
currentUser = e.users[0]; | |
loggedIn = true; | |
loaddata(); | |
} else { | |
Ti.API.info('Error:\\n' + ((e.error && e.message) || JSON.stringify(e))); | |
loggedIn = false; | |
currentUser = null; | |
} | |
}); | |
} | |
var input = Ti.UI.createTextField({ | |
height : 35, | |
top : 10, | |
left : 40, | |
width : 240, | |
hintText : 'This is hint text', | |
keyboardType : Ti.UI.KEYBOARD_DEFAULT, | |
returnKeyType : Ti.UI.RETURNKEY_DEFAULT, | |
borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED | |
}); | |
win.add(input); | |
var post_data = Ti.UI.createButton({ | |
title : 'Create post', | |
top : 20, | |
}); | |
win.add(post_data); | |
post_data.addEventListener('click', function() { | |
Cloud.Posts.create({ | |
title : input.value, | |
content : input.value, | |
}, function(e) { | |
if (e.success) { | |
loaddata(); | |
} else { | |
alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e))); | |
} | |
}); | |
}); | |
var load_post = Ti.UI.createButton({ | |
title : 'Load post', | |
top : 20, | |
}); | |
load_post.addEventListener('click', function() { | |
loaddata(); | |
}); | |
win.add(load_post); | |
win.add(aTableView); | |
win.open(); | |
function loaddata() { | |
var data = []; | |
Cloud.Posts.query({ | |
page : 1, | |
}, function(e) { | |
if (e.success) { | |
Ti.API.info('Success:\n' + 'Count: ' + e.posts.length); | |
for (var i = 0; i < e.posts.length; i++) { | |
var post = e.posts[i]; | |
Ti.API.info('post' + JSON.stringify(post)); | |
data.push({ | |
title : post.title, | |
}); | |
} | |
aTableView.setData([]); | |
aTableView.setData(data); | |
} else { | |
alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e))); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment