Skip to content

Instantly share code, notes, and snippets.

@skizzybiz
Created May 3, 2011 19:23
Show Gist options
  • Save skizzybiz/954021 to your computer and use it in GitHub Desktop.
Save skizzybiz/954021 to your computer and use it in GitHub Desktop.
DataSource update methods
updateRecord: function(store, storeKey) {
var data, id, recordType, request;
recordType = store.recordTypeFor(storeKey);
id = store.idFor(storeKey);
data = this.formatData(store.readDataHash(storeKey), recordType);
console.log("storeKey = " + storeKey);
console.log("store.readDataHash(" + storeKey + ") = ");
console.log(store.readDataHash(storeKey));
request = SC.Request.putUrl("" + recordType.RESOURCE_PATH + "/" + id);
request.notify(this, 'updateRecordDidComplete', store, storeKey, id);
request.header({
"Accept": "application/json"
});
request.json();
request.send(data);
return YES;
},
updateRecordDidComplete: function(response, store, storeKey, id) {
if (this.responseOk(response)) {
console.log(response.get('body'));
return store.dataSourceDidComplete(storeKey);
} else {
return store.dataSourceDidError(storeKey, response);
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment