Created
May 3, 2011 19:23
-
-
Save skizzybiz/954021 to your computer and use it in GitHub Desktop.
DataSource update methods
This file contains 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
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