Skip to content

Instantly share code, notes, and snippets.

@erichocean
Created September 22, 2008 07:14
Show Gist options
  • Save erichocean/11956 to your computer and use it in GitHub Desktop.
Save erichocean/11956 to your computer and use it in GitHub Desktop.
// ..........................................
// REFRESH
refreshRecords: function(records) {
if (!records || records.length == 0) return ;
records = this._recordsByResource(records) ; // sort by resource.
for(var resource in records) {
if (resource == '*') continue ;
var curRecords = records[resource] ;
// collect resource ids, sort records into hash, and get cacheCode.
var cacheCode = null ; var ids = [] ; var context = {} ;
var primaryKey = curRecords[0].get('primaryKey') ; // assumes all the same
curRecords.each(function(r) {
cacheCode = cacheCode || r._cacheCode ;
var key = r.get(primaryKey);
if (key) { ids.push(key); context[key] = r; }
});
context._recordType = curRecords[0].recordType ; // default rec type.
params = {
requestContext: context,
cacheCode: ((cacheCode=='') ? null : cacheCode),
onSuccess: this._refreshSuccess.bind(this),
onFailure: this._refreshFailure.bind(this)
};
if (ids.length == 1 && curRecords[0].refreshURL) params['url'] = curRecords[0].refreshURL;
// issue request
this.request(resource, this._refreshAction, ids, params, this._refreshMethod) ;
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment