Backbone ProtectedModel, WIP

This commit is contained in:
Gregory Eremin
2012-09-19 02:40:46 +04:00
parent 7cef7bfc9c
commit 95ac3e6eef
12 changed files with 69 additions and 33 deletions
@@ -0,0 +1,12 @@
class BeatHaven.Modules.ProtectedModel extends Backbone.Model
fetch: (options) ->
options = options ? _.clone(options) : {}
model = this
success = options.success
options.success = (resp, status, xhr) ->
if (!model.set(model.parse(resp, xhr), options)) return false;
if (success) success(model, resp);
};
options.error = Backbone.wrapError(options.error, model, options);
return (this.sync || Backbone.sync).call(this, 'read', this, options);