o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1383740409.3411672: @value"¢{I" class:EFI"BundledAsset;FI"logical_path;FI"(iugu-ux/components/base_resource.js;TI" pathname;FI"j/Users/alezonez/Projetos/iugu-ux/vendor/assets/javascripts/iugu-ux/components/base_resource.js.coffee;TI"content_type;FI"application/javascript;FI" mtime;FI"2013-08-12T17:29:28-03:00;FI" length;Fi¤I" digest;F"%e16a11be373b073b538d24bfbe0d58a0I" 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() { _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(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.complete = function(jqXHR, textStatus) { if (textStatus !== "success") { return options.context.disableLoader(); } if (options.elastic_delay === true) { return setTimeout(function() { options.context.disableLoader(); if (!options.callbackView) { return options.context.redirectBack(); } }, 1000); } else { options.context.disableLoader(); if (!options.callbackView) { return options.context.redirectBack(); } } }; 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) } }); }; BaseResource.prototype.appendLocaleInfo = function(uri) { return uri + (uri.indexOf('?') ? '?' : '&') + 'hl=' + encodeURIComponent(i18n.locale); }; BaseResource.prototype.request = function(type, url, options) { this.configureAjax(); options = _.extend(options, { type: type }); return app.ajax(url, options); }; return BaseResource; })(Backbone.AssociatedModel); }).call(this); ;FI"required_assets_digest;F"%9dcce54fc14f7f3aeeb2b77d6bc4ecdaI" _version;F"%6776f581a4329e299531e1d52aa59832