Created
October 17, 2012 21:31
-
-
Save forcementor/3908361 to your computer and use it in GitHub Desktop.
Developing Mobile…Force.com and Sencha-Part 2, Step 8: Adjusting the Model and Adding a Data Proxy - Modify the Model
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
| //The Lead model will include whatever fields are necssary to manage. | |
| Ext.define("PocketCRM.model.Lead", { | |
| extend: "Ext.data.Model", | |
| config: { | |
| idProperty: 'Id', | |
| fields: [ | |
| { | |
| name: 'Id', | |
| type: 'string', | |
| persist: false | |
| }, | |
| { | |
| name: 'Name', | |
| type: 'string', | |
| persist: false | |
| }, | |
| { | |
| name: 'FirstName', | |
| type: 'string' | |
| }, | |
| { | |
| name: 'LastName', | |
| type: 'string' | |
| }, | |
| { | |
| name: 'Company', | |
| type: 'string' | |
| }, | |
| { | |
| name: 'Title', | |
| type: 'string' | |
| }, | |
| { | |
| name: 'Phone', | |
| type: 'string' | |
| }, | |
| { | |
| name: 'MobilePhone', | |
| type: 'string' | |
| }, | |
| { | |
| name: 'Email', | |
| type: 'string' | |
| }, | |
| { | |
| name: 'Status', | |
| type: 'string' | |
| } | |
| ], | |
| validations: [ | |
| { | |
| type: 'presence', | |
| field: 'LastName', | |
| message: 'Enter a last name.' | |
| }, | |
| { | |
| type: 'presence', | |
| field: 'Company', | |
| message: 'Enter a company.' | |
| }, | |
| { | |
| type: 'presence', | |
| field: 'Status', | |
| message: 'Select a status.' | |
| } | |
| ], | |
| //Bind each CRUD functions to a @RemoteAction method in the Apex controller | |
| proxy: { | |
| type: 'direct', | |
| api: { | |
| read: PocketCRMLeadController.Query, | |
| create: PocketCRMLeadController.Add, | |
| update: PocketCRMLeadController.Edit, | |
| destroy: PocketCRMLeadController.Destroy | |
| }, | |
| limitParam: 'recordCount', // because "limit" is an Apex keyword | |
| sortParam: 'sortParams', // because "sort" is a keyword too | |
| pageParam: false, // we don't use this in the controller, so don't send it | |
| reader: { | |
| type: 'json', | |
| rootProperty: 'records', | |
| messageProperty: 'errorMessage' | |
| }, | |
| writer: { | |
| type: 'json', | |
| root: 'records', | |
| writeAllFields: false, // otherwise empty fields will transmit | |
| // as empty strings, instead of "null"/not present | |
| allowSingle: false, // need to always be an array for code simplification | |
| encode: false // docs say "set this to false when using DirectProxy" | |
| } | |
| } | |
| }, | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Includes a fix to include the MobilePhone field in the model.