Created
April 22, 2011 15:26
-
-
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
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
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