Skip to content

Instantly share code, notes, and snippets.

@forcementor
Created October 17, 2012 21:24
Show Gist options
  • Save forcementor/3908301 to your computer and use it in GitHub Desktop.
Save forcementor/3908301 to your computer and use it in GitHub Desktop.
Developing Mobile…Force.com and Sencha-Part 2, Step 6: Add Controller Event Handling Functions
onSyncLeadCommand: function () {
console.log("onSyncLeadCommand");
//Get a ref to the store and remove it.
var leadsStore = Ext.getStore("Leads");
//Resync the proxy, reload and activate the list.
leadsStore.sync();
leadsStore.load();
this.activateLeadsList();
},
onNewLeadCommand: function () {
console.log("onNewLeadCommand");
//Set a default value for the Status selectfield.
var newLead = Ext.create("PocketCRM.model.Lead", {
Status: "Open - Not Contacted"
});
this.activateLeadEditor(newLead);
},
onEditLeadCommand: function (list, record) {
console.log("onEditLeadCommand");
this.activateLeadEditor(record);
},
onSaveLeadCommand: function () {
console.log("onSaveLeadCommand");
//Update the field values in the record.
var leadEditorView = this.getLeadEditorView();
var currentLead = leadEditorView.getRecord();
var newValues = leadEditorView.getValues();
this.getLeadEditorView().updateRecord(currentLead);
//Check for validation errors.
var errors = currentLead.validate();
if (!errors.isValid()) {
var msg = '';
errors.each(function (error) {
msg += error.getMessage() + '<br/>';
});
console.log('Errors: ' + msg);
Ext.Msg.alert('Please correct errors!', msg, Ext.emptyFn);
currentLead.reject();
return;
}
//Get a ref to the store.
var leadsStore = Ext.getStore("Leads");
//Add new record to the store.
if (null == leadsStore.findRecord('id', currentLead.data.id)) {
leadsStore.add(currentLead);
}
//Resync the proxy and activate the list.
leadsStore.sync();
this.activateLeadsList();
},
onDeleteLeadCommand: function () {
console.log("onDeleteLeadCommand");
//Get a ref to the form and its record.
var leadEditorView = this.getLeadEditorView();
var currentLead = leadEditorView.getRecord();
//Get a ref to the store and remove it.
var leadsStore = Ext.getStore("Leads");
leadsStore.remove(currentLead);
//Resync the proxy and activate the list.
leadsStore.sync();
this.activateLeadsList();
},
onBackToHomeCommand: function () {
console.log("onBackToHomeCommand");
this.activateLeadsList();
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment