sandbox/tmp/cache/assets/D6D/AA0/sprockets%2F1cb4a75912d38d0bdde6ee6770644d0f in iugu-ux-0.9.5 vs sandbox/tmp/cache/assets/D6D/AA0/sprockets%2F1cb4a75912d38d0bdde6ee6770644d0f in iugu-ux-0.9.8

- old
+ new

@@ -1,36 +1,113 @@ -o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1357730061.9196579Û­: @value"U {I" -class:EFI"ProcessedAsset;FI"logical_path;FI"(iugu-ux/components/base_resource.js;FI" pathname;FI"u/Users/patricknegri/Desenvolvimento/iugu-ux/vendor/assets/javascripts/iugu-ux/components/base_resource.js.coffee;FI"content_type;FI"application/javascript;FI" -mtime;FI"2013-01-08T20:27:33-02:00;FI" length;FiÉI" digest;F"%20b49b2c8b8cb57af63937e26d8cdfa2I" source;FI"É(function() { - var __hasProp = {}.hasOwnProperty, +o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1372441617.113429: @value"·{I" +class:EFI"ProcessedAsset;FI"logical_path;F"(iugu-ux/components/base_resource.jsI" pathname;F"u/Users/patricknegri/Desenvolvimento/iugu-ux/vendor/assets/javascripts/iugu-ux/components/base_resource.js.coffeeI"content_type;FI"application/javascript;FI" +mtime;FI"2013-06-27T10:44:24-03:00;FI" length;Fi?I" digest;F"%514077a88a2a8325211a3d41157373bdI" source;FI"?(function() { + var _ref, + __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; window.app.BaseResource = (function(_super) { - __extends(BaseResource, _super); function BaseResource() { - return BaseResource.__super__.constructor.apply(this, arguments); + _ref = BaseResource.__super__.constructor.apply(this, arguments); + return _ref; } BaseResource.prototype.virtual_attributes = []; + BaseResource.prototype.initialize = function() { + _.each(this.relations, function(relation) { + if (relation.type === "Many") { + this.generateDefaults(relation); + this.generateTriggers(relation); + this.generateAddFunction(relation); + return this.generateRemoveFunction(relation); + } + }, this); + BaseResource.__super__.initialize.apply(this, arguments); + return this; + }; + + BaseResource.prototype.generateDefaults = function(relation) { + if (!this.get("" + relation.key)) { + return this.set("" + relation.key, []); + } + }; + + BaseResource.prototype.generateEvent = function(on_event, key, context) { + return this.get(key).on(on_event, function() { + return this.trigger("change:" + key); + }, context); + }; + + BaseResource.prototype.generateTriggers = function(relation) { + this.generateEvent('add', relation.key, this); + this.generateEvent('remove', relation.key, this); + return this.on('sync', function() { + this.generateEvent('add', relation.key, this); + return this.generateEvent('remove', relation.key, this); + }, this); + }; + + BaseResource.prototype.properCasedRelationName = function(key) { + return key.substr(0, 1).toUpperCase() + key.substr(1).toLowerCase(); + }; + + BaseResource.prototype.generateAddFunction = function(relation) { + return this["addTo" + (this.properCasedRelationName(relation.key))] = function() { + return this.get(relation.key).push(new relation.relatedModel); + }; + }; + + BaseResource.prototype.generateRemoveFunction = function(relation) { + return this["removeFrom" + (this.properCasedRelationName(relation.key))] = function(object) { + return this.get(relation.key).destroy(object); + }; + }; + BaseResource.prototype.sync = function(method, model, options) { this.configureAjax(); return Backbone.sync(method, model, options); }; BaseResource.prototype.toJSON = function(options) { - return _.omit(_.clone(this.attributes), this.virtual_attributes); + return _.omit(_.clone(BaseResource.__super__.toJSON.call(this, options)), this.virtual_attributes); }; BaseResource.prototype.url = function() { var base; + base = BaseResource.__super__.url.apply(this, arguments); return base = this.appendLocaleInfo(base); }; + BaseResource.prototype.save = function(attributes, options) { + if (this.isValid(true)) { + return BaseResource.__super__.save.call(this, null, this.handleViewContext(options)); + } + }; + + BaseResource.prototype.handleViewContext = function(options) { + if (!options.context) { + return options; + } + options.context.enableLoader(); + options.wait = true; + options.success = function() { + return options.context.redirectBack(); + }; + options.complete = function() { + return options.context.disableLoader(); + }; + return options; + }; + + BaseResource.prototype.destroy = function(options) { + return BaseResource.__super__.destroy.call(this, this.handleViewContext(options)); + }; + BaseResource.prototype.configureAjax = function() { return app.ajaxSetup({ headers: { Authorization: $.base64.encode(api_token) } @@ -41,10 +118,10 @@ return uri + (uri.indexOf('?') ? '?' : '&') + 'hl=' + encodeURIComponent(i18n.locale); }; return BaseResource; - })(Backbone.Model); + })(Backbone.AssociatedModel); }).call(this); -;TI"dependency_digest;F"%af94c49ecd9bdd234cf2c532f98d9ee6I"required_paths;F[I"u/Users/patricknegri/Desenvolvimento/iugu-ux/vendor/assets/javascripts/iugu-ux/components/base_resource.js.coffee;FI"dependency_paths;F[{I" path;FI"u/Users/patricknegri/Desenvolvimento/iugu-ux/vendor/assets/javascripts/iugu-ux/components/base_resource.js.coffee;FI" -mtime;FI"2013-01-08T20:27:33-02:00;FI" digest;F"%e94c45a2634b7d9738b3129349bd821aI" _version;F"%9f3b95dd7ea3030dc35985c0a8020862 +;TI"dependency_digest;F"%681527267648a048c219621c85cd36e2I"required_paths;F["u/Users/patricknegri/Desenvolvimento/iugu-ux/vendor/assets/javascripts/iugu-ux/components/base_resource.js.coffeeI"dependency_paths;F[{I" path;F"u/Users/patricknegri/Desenvolvimento/iugu-ux/vendor/assets/javascripts/iugu-ux/components/base_resource.js.coffeeI" +mtime;FI"2013-06-27T10:44:24-03:00;FI" digest;F"%59d2fee49302354d09d590efce913637I" _version;F"%6776f581a4329e299531e1d52aa59832 \ No newline at end of file