Permalink
Browse files

Use SObject instead of Map<String, String> for server responses.

Requires using case-sensitive field names, and javascript-style time values.
  • Loading branch information...
1 parent 7dd8d30 commit c5f2b3cc5d58ed811615fb53777191494cd15f0b @jefftrull committed Nov 27, 2011
Showing with 17 additions and 28 deletions.
  1. +8 −20 classes/ExtJSStoreRemotingCtrl.cls
  2. +9 −8 components/ExtJS4_Data_Grid_with_JSR.component
@@ -75,10 +75,10 @@ global with sharing class ExtJSStoreRemotingCtrl {
global class CRUDResponse {
public Boolean success;
public String errorMessage;
- public List<Map<String, String> > records;
+ public List<SObject> records;
public Integer total;
CRUDResponse() {
- records = new List<Map<String, String> >();
+ records = new List<SObject>();
success = true;
}
}
@@ -120,13 +120,7 @@ global with sharing class ExtJSStoreRemotingCtrl {
for (List<SObject> rlit : Database.query(qstr)) {
for (SObject rit : rlit) {
if ((current_result >= qobj.start) && (current_result < (qobj.start + qobj.recordCount))) {
- Map<String, String> objmap = new Map<String, String>();
- for (String field : fieldNames) {
- if (rit.get(field) != null) {
- objmap.put(field, String.valueOf(rit.get(field)));
- }
- }
- resp.records.add(objmap);
+ resp.records.add(rit);
}
current_result++;
}
@@ -162,13 +156,7 @@ global with sharing class ExtJSStoreRemotingCtrl {
for (List<SObject> rlit : Database.query('SELECT ' + fieldList + ' FROM ' + objName +
' WHERE Id IN :updatedIds')) {
for (SObject rit : rlit) {
- Map<String, String> objmap = new Map<String, String>();
- for (String field : fieldNames) {
- if (rit.get(field) != null) {
- objmap.put(field, String.valueOf(rit.get(field)));
- }
- }
- resp.records.add(objmap);
+ resp.records.add(rit);
}
}
return resp;
@@ -225,7 +213,7 @@ global with sharing class ExtJSStoreRemotingCtrl {
List<Map<String, String> > sobjs = crudData.records;
List<String> idlist = new List<String>();
for (Map<String, String> sobj : sobjs) {
- idlist.add(sobj.get('id'));
+ idlist.add(sobj.get('Id'));
}
try {
@@ -267,9 +255,9 @@ global with sharing class ExtJSStoreRemotingCtrl {
List<SObject> sobjs = new List<SObject>();
for (Map<String, String> recmap : records) {
SObject sobj;
- if (recmap.containsKey('id')) {
+ if (recmap.containsKey('Id')) {
// create SObject using supplied Id (setting it as a field will fail)
- sobj = sobjToken.newSObject(recmap.get('id'));
+ sobj = sobjToken.newSObject(recmap.get('Id'));
} else {
sobj = sobjToken.newSObject();
}
@@ -279,7 +267,7 @@ global with sharing class ExtJSStoreRemotingCtrl {
Boolean emptyValue = (recmap.get(k) == null) || (recmap.get(k) == '') ||
(fieldMap.get(k).getDescribe().getType() != Schema.DisplayType.string) &&
(recmap.get(k) == 'null');
- if ((k != 'id') && // never try to set Id this way (see above)
+ if ((k != 'Id') && // never try to set Id this way (see above)
((action == 'update') || // don't try to set an empty value unless this is an update
!emptyValue)) {
if (emptyValue) {
@@ -71,21 +71,21 @@ Copyright 2011 Jeff Trull <jetrull@sbcglobal.net>
}
return request;
}});
-
+
// use JS Remoting to get field metadata info
// TODO check for creatability/updatability of the chosen SObject type by this user
- ExtJSStoreRemotingCtrl.describeFields('{!object}', String('{!fields}').toLowerCase(),
+ ExtJSStoreRemotingCtrl.describeFields('{!object}', String('{!fields}'),
function(fieldData, e) {
if (!e.status) {
Ext.Msg.alert('Server error', e.message);
return;
}
// define a Model using the information returned from the SObject describe call
var extfields = [];
- var fieldlist = String('{!fields}').toLowerCase().split(',');
- if (fieldlist.indexOf('id') == -1) {
+ var fieldlist = String('{!fields}').split(',');
+ if (fieldlist.indexOf('Id') == -1) {
extfields.push({
- name: 'id',
+ name: 'Id',
// Workaround: in Ext 3 (nonexistent) id property was removed from phantom records
persist: false // make sure we don't try to output this on create.
}); // always include ID in the store
@@ -94,7 +94,7 @@ Copyright 2011 Jeff Trull <jetrull@sbcglobal.net>
var field = {name: fieldData[i].name, type: fieldData[i].fieldType};
if (fieldData[i].fieldType == "date") {
// having trouble with dates for some reason. Need to manually specify here.
- field.dateFormat = "Y-m-d H:i:s"; // as supplied by String.valueOf on the server
+ field.dateFormat = "time"; // Force.com date serialization uses javascript time value
field.type = "date";
}
else if (fieldData[i].fieldType == "double") {
@@ -106,7 +106,7 @@ Copyright 2011 Jeff Trull <jetrull@sbcglobal.net>
} else {
field.type = "string";
}
- if (field.name == 'id') {
+ if (field.name == 'Id') {
field.persist = false;
}
// TODO add validations (list of valid values, regex, min/max) if possible
@@ -116,10 +116,11 @@ Copyright 2011 Jeff Trull <jetrull@sbcglobal.net>
// TODO add associations to other models
var modelName = Ext.String.capitalize("{!object}");
var extraParams = {sobjname: '{!object}', // will be sent along with start, limit, etc.
- fields: String('{!fields}').toLowerCase()};
+ fields: String('{!fields}')};
Ext.define(modelName, {
extend: 'Ext.data.Model',
fields: extfields,
+ idProperty: 'Id',
proxy: {
type: 'direct',
api: {read: ExtJSStoreRemotingCtrl.query,

0 comments on commit c5f2b3c

Please sign in to comment.