Skip to content

Instantly share code, notes, and snippets.

@aaronksaunders
Last active August 29, 2015 14:18
Show Gist options
  • Save aaronksaunders/7428406127ac2819d15a to your computer and use it in GitHub Desktop.
Save aaronksaunders/7428406127ac2819d15a to your computer and use it in GitHub Desktop.
Create Event Sample for Howard U Cross-Platform Mobile App Class Using Titanium Appcelerator Alloy + Appcelerator Cloud Services

Create Event Sample for Howard U Cross-Platform Mobile App Class Using Titanium Appcelerator Alloy

  1. Create New Project and make sure you cloud-enable the application
  2. Download the starter template from the github repo https://github.com/aaronksaunders/acs-adapter-starter/archive/master.zip
  3. Copy the contents of the app directory from the starter-template to replace the files in the new project you just created
  4. Login to the appcelerator cloud service console - my.appcelerator.com
  5. create a new test user for the application
  6. add the event.js file to the app/models directory
  7. add the function to you application and that should create a new Event

###Extending Model Example We also show an example of extending the Event model object to return the formatted time in two different ways using the moment.js javascript library

//
// http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Cloud.Events
//
exports.definition = {
config : {
"columns" : {},
"defaults" : {},
"adapter" : {
"type" : "acs",
},
"settings" : {
"object_name" : "events",
"object_method" : "Events"
}
},
extendModel : function(Model) {
// http://momentjs.com/
var moment = require('alloy/moment');
_.extend(Model.prototype, {
/**
* returns the start_time using plain english relative to current
* time
*/
getFromNowStartTime : function() {
var _model = this;
return moment(_model.get("start_time")).fromNow();
},
/**
* returns the start_time formatted
* See moment documentation for more information on formats
* @param {Object} _format
*/
getFormattedStartTime : function(_format) {
var _model = this;
return moment(_model.get("start_time")).format(_format || 'LLL');
}
});
return Model;
},
extendCollection : function(Collection) {
_.extend(Collection.prototype, {});
return Collection;
}
};
function doCreateEvent() {
var anEvent = Alloy.createModel('Event');
anEvent.set({
name : 'Celebration',
start_time : new Date(),
duration : 3600,
recurring : 'monthly',
recurring_count : 5
});
anEvent.save().then(function(_model) {
console.log("anEvent.save " +JSON.stringify(_model,null,2));
var moment = require('alloy/moment');
console.log("start time-relative: " + _model.getFromNowStartTime());
console.log("start time-formatted: " + _model.getFormattedStartTime());
}, function(_error) {
alert(_error.message);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment