Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var win = Ti.UI.createWindow({
- title : "ABC",
- backgroundColor : '#fff',
- layout:"vertical"
- });
- var Create = Titanium.UI.createButton({
- title : 'Create',
- top : 10,
- width : 100,
- height : 50
- });
- Create.addEventListener('click', function(e) {
- (function() {
- var ACS = require('ti.cloud'), env = Ti.App.deployType.toLowerCase() === 'production' ? 'production'
- : 'development', username = Ti.App.Properties
- .getString('acs-username-' + env), password = Ti.App.Properties
- .getString('acs-password-' + env);
- if (!env || !username || !password) {
- return;
- }
- ACS.Users.login({
- login : username,
- password : password,
- }, function(result) {
- if (env === 'development') {
- Ti.API.info('ACS Login Results for environment `' + env + '`:');
- Ti.API.info(result);
- }
- if (result && result.success && result.users && result.users.length) {
- Ti.App.fireEvent('login.success', result.users[0], env);
- //----------------
- ACS.Objects.create({
- classname: 'cars',
- fields: {
- make: 'nissan',
- color: 'blue',
- year: 2005
- }
- }, function (e) {
- if (e.success) {
- var car = e.cars[0];
- alert('Success:\n' +
- 'id: ' + car.id + '\n' +
- 'make: ' + car.make + '\n' +
- 'color: ' + car.color + '\n' +
- 'year: ' + car.year + '\n' +
- 'created_at: ' + car.created_at);
- } else {
- alert('Error:\n' +
- ((e.error && e.message) || JSON.stringify(e)));
- }
- });
- //----------------
- } else {
- Ti.App.fireEvent('login.failed', result, env);
- }
- });
- })();
- });
- win.add(Create);
- //--------------------------------------------------------
- var drop = Titanium.UI.createButton({
- title : 'Drop',
- top : 10,
- width : 100,
- height : 50
- });
- drop.addEventListener('click', function(e) {
- (function() {
- var ACS = require('ti.cloud'), env = Ti.App.deployType.toLowerCase() === 'production' ? 'production'
- : 'development', username = Ti.App.Properties
- .getString('acs-username-' + env), password = Ti.App.Properties
- .getString('acs-password-' + env);
- if (!env || !username || !password) {
- return;
- }
- ACS.Users.login({
- login : username,
- password : password,
- }, function(result) {
- if (env === 'development') {
- Ti.API.info('ACS Login Results for environment `' + env + '`:');
- Ti.API.info(result);
- }
- if (result && result.success && result.users && result.users.length) {
- Ti.App.fireEvent('login.success', result.users[0], env);
- //----------
- ACS.sendRequest({
- url : "objects/cars/admin_drop_collection.json",
- method : "DELETE"
- }, function(e) {
- if (e.success) {
- alert("All Car objects have been deleted.");
- } else {
- alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e)));
- }
- });
- //---------------
- } else {
- Ti.App.fireEvent('login.failed', result, env);
- }
- });
- })();
- });
- win.add(drop);
- //----------------------------------------------
- var Create2 = Titanium.UI.createButton({
- title : 'Create Again',
- top : 10,
- width : 100,
- height : 50
- });
- Create2.addEventListener('click', function(e) {
- (function() {
- var ACS = require('ti.cloud'), env = Ti.App.deployType.toLowerCase() === 'production' ? 'production'
- : 'development', username = Ti.App.Properties
- .getString('acs-username-' + env), password = Ti.App.Properties
- .getString('acs-password-' + env);
- if (!env || !username || !password) {
- return;
- }
- ACS.Users.login({
- login : username,
- password : password,
- }, function(result) {
- if (env === 'development') {
- Ti.API.info('ACS Login Results for environment `' + env + '`:');
- Ti.API.info(result);
- }
- if (result && result.success && result.users && result.users.length) {
- Ti.App.fireEvent('login.success', result.users[0], env);
- //----------------
- ACS.Objects.create({
- classname: 'cars',
- fields: {
- make: 'nissan2',
- color: 'blue',
- year: 2007
- }
- }, function (e) {
- if (e.success) {
- var car = e.cars[0];
- alert('Success:\n' +
- 'id: ' + car.id + '\n' +
- 'make: ' + car.make + '\n' +
- 'color: ' + car.color + '\n' +
- 'year: ' + car.year + '\n' +
- 'created_at: ' + car.created_at);
- } else {
- alert('Error:\n' +
- ((e.error && e.message) || JSON.stringify(e)));
- }
- });
- //----------------
- } else {
- Ti.App.fireEvent('login.failed', result, env);
- }
- });
- })();
- });
- win.add(Create2);
- win.open();
Add Comment
Please, Sign In to add comment