Skip to content

Instantly share code, notes, and snippets.

@amwhalen
Created April 22, 2011 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amwhalen/936880 to your computer and use it in GitHub Desktop.
Save amwhalen/936880 to your computer and use it in GitHub Desktop.
SproutCore DataSource POST is redirecting automatically, so the response parameter of didCreateRecord is a GET response instead of a POST response
createRecord: function(store, storeKey) {
if (SC.kindOf(store.recordTypeFor(storeKey), Library.Slideshow)) {
SC.Request.postUrl('/api/slideshow').header({ 'Accept': 'application/json' }).json()
.notify(this, this.didCreateRecord, store, storeKey)
.send(store.readDataHash(storeKey));
return YES;
}
return NO;
},
/**
* Created a new record on the server
*/
didCreateRecord: function(response, store, storeKey) {
console.log('didCreateRecord');
if (SC.ok(response)) {
// Adapted from parseUri 1.2.2
// (c) Steven Levithan <stevenlevithan.com>
// MIT License
var parser = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
var url = parser.exec(response.header('Location'))[8];
store.dataSourceDidComplete(storeKey, null, url);
} else {
this.errorPane('Failed to add. Server error.');
store.dataSourceDidError(storeKey, response);
// get rid of this record since it doesn't exist on the server
store.destroyRecord(null, null, storeKey);
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment