Created
February 8, 2012 19:24
-
-
Save devth/1772520 to your computer and use it in GitHub Desktop.
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
ns("decide").ApplicationModel = Backbone.Model.extend({ | |
sync: function(method, model, options) { | |
// Our overriden sync supports these events: | |
// sync:start | |
// sync:success | |
// sync:error | |
// sync:complete | |
// | |
// Params dispatched with the event: | |
// method, model, status | |
// | |
this.trigger('sync:start', method, model); | |
this.isLoading = true; | |
options = options || {}; | |
var complete = function(status) { model.trigger('sync:complete', method, model, status); | |
model.isLoading = false; }; | |
var modifiedOpts = { | |
success: function(resp, status, xhr) { | |
model.trigger('sync:success', method, model, status); | |
complete(status); | |
if (_.has(options, 'success')) { options.success(resp, status, xhr); } | |
}, | |
error: function(resp, status, xhr) { | |
model.trigger('sync:error', method, model, status); | |
complete(status); | |
if (_.has(options, 'error')) { options.error(resp, status, xhr); } | |
} | |
}; | |
// Use Backbone's native sync to finish the job | |
Backbone.sync.call(this, method, model, modifiedOpts); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment