vendor/components/indefinido-indemma/build/development.js in ende-0.3.13 vs vendor/components/indefinido-indemma/build/development.js in ende-0.4.0
- old
+ new
@@ -252,58 +252,61 @@
));
require.register("indemma/lib/record.js", Function("exports, require, module",
"var $, advisable, bind, extend, merge, observable, type,\n __slice = [].slice;\n\n$ = require('jquery');\n\ntype = require('type');\n\nbind = require('bind');\n\nobservable = require('observable').mixin;\n\nadvisable = require('advisable').mixin;\n\nextend = require('assimilate');\n\nmerge = require('assimilate').withStrategy('deep');\n\nthis.model = (function() {\n var initialize_record, mixer, modelable;\n\n modelable = {\n after_mix: [],\n record: {\n after_initialize: [],\n before_initialize: []\n },\n all: function() {\n return this.cache;\n },\n create: function() {\n var params;\n\n params = 1 <= arguments.length ? __slice.call(arguments, 0) : [];\n throw 'model.create not implemented yet, try using the restful.model.create method';\n },\n where: function(conditions, first) {\n var record, results, _i, _len, _ref;\n\n if (first == null) {\n first = false;\n }\n results = [];\n if (type(conditions.id) !== 'array') {\n conditions.id = [conditions.id];\n }\n _ref = this.cache;\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n record = _ref[_i];\n if (conditions.id.indexOf(record._id) !== -1) {\n if (first) {\n return record;\n } else {\n results.push(record);\n }\n }\n }\n if (first) {\n return null;\n } else {\n return results;\n }\n }\n };\n initialize_record = function(data) {\n var after_initialize, callback, creation, index, instance, _i, _j, _len, _len1, _ref, _ref1;\n\n if (data == null) {\n data = {\n resource: this.resource,\n parent_resource: this.parent_resource\n };\n }\n data.resource || (data.resource = this.resource);\n data.parent_resource || (data.parent_resource = this.resource.parent || this.parent_resource);\n data.route || (data.route = this.route);\n data.nested_attributes = this.nested_attributes || [];\n after_initialize = (data.after_initialize || []).concat(this.record.after_initialize);\n creation = extend(Object.create(data), this.record, creation, {\n after_initialize: after_initialize\n });\n _ref = this.record.before_initialize;\n for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {\n callback = _ref[index];\n callback.call(this, creation);\n }\n instance = record.call(creation);\n _ref1 = instance.after_initialize;\n for (index = _j = 0, _len1 = _ref1.length; _j < _len1; index = ++_j) {\n callback = _ref1[index];\n callback.call(instance, instance);\n }\n delete instance.after_initialize;\n return instance;\n };\n mixer = function(options) {\n var after_initialize, callback, instance, _i, _len, _ref;\n\n if (this === window) {\n throw 'Model mixin called incorrectly call with model.call {} instead of model({})';\n }\n if (!mixer.stale) {\n mixer.stale = true;\n }\n if (this.record && this.record.after_initialize) {\n after_initialize = this.record.after_initialize.splice(0);\n } else {\n after_initialize = [];\n }\n instance = bind(this, initialize_record);\n extend(instance, merge(this, modelable));\n this.record = instance.record = merge({}, instance.record, modelable.record);\n this.record.after_initialize = instance.record.after_initialize = instance.record.after_initialize.concat(after_initialize);\n this.record.before_initialize = instance.record.before_initialize.concat([]);\n _ref = modelable.after_mix;\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n callback = _ref[_i];\n callback.call(instance, instance);\n }\n return mixer[this.resource.name || this.resource.toString()] = instance;\n };\n mixer.mix = function(blender) {\n if (this.stale) {\n throw \"Trying to change model mixin with \" + object + \" but model already used.\\nCheck your configuration order\";\n }\n return blender(modelable);\n };\n return mixer;\n})();\n\nthis.record = (function() {\n var callbacks, recordable, that;\n\n callbacks = {\n dirtify: function() {}\n };\n recordable = {\n dirty: false,\n after_initialize: [callbacks.dirtify]\n };\n that = function(data) {\n var after_initialize;\n\n if (this === window) {\n throw \"Mixin called incorrectly, call mixin with call method: record.call(object, data)\";\n }\n data || (data = {});\n after_initialize = (this.after_initialize || []).concat(data.after_initialize || []).concat(recordable.after_initialize);\n return advisable(observable(extend(this, recordable, data, {\n after_initialize: after_initialize\n })));\n };\n that.mix = function(blender) {\n return blender(recordable);\n };\n return that;\n})();\n\nexports.record = this.record;\n\nexports.model = this.model;\n//@ sourceURL=indemma/lib/record.js"
));
require.register("indemma/lib/record/associable.js", Function("exports, require, module",
-"var $, associable, callbacks, extend, model, modifiers, plural, root, singular, subscribers,\n __slice = [].slice;\n\nroot = window;\n\n$ = require('jquery');\n\nextend = require('assimilate');\n\nrequire('./resource');\n\nplural = {\n add: function() {\n var attributes, params, _i, _len, _results;\n\n params = 1 <= arguments.length ? __slice.call(arguments, 0) : [];\n _results = [];\n for (_i = 0, _len = params.length; _i < _len; _i++) {\n attributes = params[_i];\n _results.push(this.push(this.build(attributes)));\n }\n return _results;\n },\n create: function() {\n var attributes, params, record, _i, _len, _results;\n\n params = 1 <= arguments.length ? __slice.call(arguments, 0) : [];\n _results = [];\n for (_i = 0, _len = params.length; _i < _len; _i++) {\n attributes = params[_i];\n record = this.build(attributes);\n this.push(record);\n _results.push(record.save());\n }\n return _results;\n },\n build: function(data) {\n var _name;\n\n if (data == null) {\n data = {};\n }\n data.parent_resource = this.parent_resource;\n if (this.parent != null) {\n data.route || (data.route = \"\" + this.parent.route + \"/\" + this.parent._id + \"/\" + (model.pluralize(this.resource.toString())));\n }\n if (this.route !== data.route && this.route) {\n throw \"associable.has_many: cannot redefine route of association \" + this.parent_resource + \".\" + this.resource + \" from \" + this.route + \" to \" + data.route;\n }\n data[_name = this.parent_resource] || (data[_name] = this.parent);\n return model[model.singularize(this.resource)](data);\n },\n push: function() {\n console.warn(\"\" + this.resource + \".push is deprecated and will be removed, please use add instead\");\n return Array.prototype.push.apply(this, arguments);\n },\n length: 0,\n json: function(methods, omissions) {\n var record, _i, _len, _results;\n\n _results = [];\n for (_i = 0, _len = this.length; _i < _len; _i++) {\n record = this[_i];\n _results.push(record.json(methods, omissions));\n }\n return _results;\n }\n};\n\nsingular = {\n create: function(data) {\n return model[this.resource].create(extend({}, this, data));\n },\n build: function(data) {\n return this.owner[this.resource.toString()] = model[this.resource.toString()](extend({}, this, data));\n }\n};\n\nsubscribers = {\n belongs_to: {\n foreign_key: function(resource_id) {\n var associated, association_name, current_resource_id, resource, _ref;\n\n association_name = this.resource.toString();\n if (resource_id === null || resource_id === void 0) {\n this.dirty = true;\n this.owner[association_name] = resource_id;\n return resource_id;\n }\n current_resource_id = (_ref = this.owner[association_name]) != null ? _ref._id : void 0;\n if (resource_id !== current_resource_id) {\n resource = model[association_name];\n if (!resource) {\n console.warn(\"subscribers.belongs_to.foreign_key: associated factory not found for model: \" + association_name);\n return resource_id;\n }\n associated = resource.find(resource_id);\n associated || (associated = resource({\n _id: resource_id\n }));\n this.owner.observed[association_name] = associated;\n }\n return resource_id;\n },\n associated_changed: function(associated) {\n return this.owner.observed[\"\" + (this.resource.toString()) + \"_id\"] = associated ? associated._id : null;\n }\n }\n};\n\nmodifiers = {\n belongs_to: {\n associated_loader: function() {\n var association_name,\n _this = this;\n\n association_name = this.resource.toString();\n return Object.defineProperty(this.owner, association_name, {\n set: function(associated) {\n return this.observed[association_name] = associated;\n },\n get: function() {\n var associated, associated_id, resource;\n\n associated = _this.owner.observed[association_name];\n associated_id = _this.owner.observed[association_name + '_id'];\n if (!(((associated != null ? associated._id : void 0) != null) || associated_id)) {\n return associated;\n }\n if (associated != null ? associated.sustained : void 0) {\n return associated;\n }\n resource = model[association_name];\n if (!resource) {\n console.warn(\"subscribers.belongs_to.foreign_key: associated factory not found for model: \" + association_name);\n return associated;\n }\n associated = resource.find(associated_id || associated._id);\n associated || (associated = resource({\n _id: associated_id\n }));\n resource.storage.store(associated._id, associated);\n associated.reload();\n return _this.owner.observed[association_name] = associated;\n },\n configurable: true,\n enumerable: true\n });\n }\n }\n};\n\ncallbacks = {\n has_many: {\n nest_attributes: function() {\n var association, association_name, association_names, associations_attributes, message, _i, _len, _results;\n\n association_names = model[this.resource].has_many;\n if (association_names) {\n _results = [];\n for (_i = 0, _len = association_names.length; _i < _len; _i++) {\n association_name = association_names[_i];\n associations_attributes = this[\"\" + association_name + \"_attributes\"];\n if (associations_attributes && associations_attributes.length) {\n association = this[model.pluralize(association_name)];\n if (!association) {\n message = \"has_many.nest_attributes: Association not found for \" + association_name + \". \\n\";\n message += \"did you set it on model declaration? \\n has_many: \" + association_name + \" \";\n throw message;\n }\n association.resource = model.singularize(association.resource);\n association.add.apply(association, associations_attributes);\n _results.push(association.resource = model.pluralize(association.resource));\n } else {\n _results.push(void 0);\n }\n }\n return _results;\n }\n },\n update_association: function(data) {\n var associated, association, association_name, id, pluralized_association, _i, _j, _len, _len1, _ref;\n\n id = this._id || data && (data._id || data.id);\n if (!id) {\n return;\n }\n _ref = model[this.resource.toString()].has_many;\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n association_name = _ref[_i];\n pluralized_association = model.pluralize(association_name);\n association = this[pluralized_association];\n if (!association.route) {\n association.route = \"/\" + (model.pluralize(this.resource.toString())) + \"/\" + id + \"/\" + (model.pluralize(association.resource));\n for (_j = 0, _len1 = association.length; _j < _len1; _j++) {\n associated = association[_j];\n if (!associated.route && (associated.parent != null)) {\n associated.route = \"/\" + (model.pluralize(this.resource.toString())) + \"/\" + id + \"/\" + (model.pluralize(association.resource));\n }\n }\n }\n }\n return true;\n },\n autosave: function() {\n throw 'Not implemented yet';\n }\n },\n has_one: {\n nest_attributes: function() {\n var association_name, association_names, associations_attributes, _i, _len, _results;\n\n association_names = model[this.resource].has_one;\n if (association_names) {\n _results = [];\n for (_i = 0, _len = association_names.length; _i < _len; _i++) {\n association_name = association_names[_i];\n associations_attributes = this[\"\" + association_name + \"_attributes\"];\n if (associations_attributes) {\n this[association_name] = this[\"build_\" + association_name](associations_attributes);\n _results.push(delete this[\"\" + association_name + \"_attributes\"]);\n } else {\n _results.push(void 0);\n }\n }\n return _results;\n }\n }\n }\n};\n\nassociable = {\n model: {\n blender: function(definition) {\n var model;\n\n model = associable.model;\n this.create_after_hooks = model.create_after_hooks;\n this.create_before_hooks = model.create_before_hooks;\n if (this.has_many && $.type(this.has_many) !== 'array') {\n this.has_many = [this.has_many];\n }\n if (this.has_one && $.type(this.has_one) !== 'array') {\n this.has_one = [this.has_one];\n }\n if (this.belongs_to && $.type(this.belongs_to) !== 'array') {\n this.belongs_to = [this.belongs_to];\n }\n this.has_many || (this.has_many = []);\n this.has_one || (this.has_one = []);\n this.belongs_to || (this.belongs_to = []);\n return true;\n },\n create_after_hooks: function(definition) {\n var association_name, association_proxy, old_resource_id, options, resource, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _results;\n\n options = model[this.resource.name || this.resource.toString()];\n if (options.has_many) {\n _ref = options.has_many;\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n resource = _ref[_i];\n association_proxy = {\n resource: resource,\n parent_resource: this.resource,\n parent: this\n };\n association_name = model.pluralize(resource);\n this[association_name] = $.extend(association_proxy, plural);\n }\n this.after('saved', callbacks.has_many.update_association);\n callbacks.has_many.nest_attributes.call(this);\n }\n if (options.has_one) {\n _ref1 = options.has_one;\n for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {\n resource = _ref1[_j];\n association_proxy = {\n resource: resource,\n parent_resource: this.resource,\n owner: this\n };\n association_proxy[this.resource.toString()] = this;\n this[\"build_\" + resource] = $.proxy(singular.build, association_proxy);\n this[\"create_\" + resource] = $.proxy(singular.create, association_proxy);\n }\n callbacks.has_one.nest_attributes.call(this);\n }\n if (options.belongs_to) {\n _ref2 = options.belongs_to;\n _results = [];\n for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {\n resource = _ref2[_k];\n association_proxy = {\n resource: resource,\n parent_resource: this.resource,\n parent: this,\n owner: this\n };\n association_proxy[this.resource.toString()] = this;\n this[\"build_\" + resource] = $.proxy(singular.build, association_proxy);\n this[\"create_\" + resource] = $.proxy(singular.create, association_proxy);\n old_resource_id = this[\"\" + resource + \"_id\"];\n this[\"\" + resource + \"_id\"] = null;\n this.subscribe(\"\" + resource + \"_id\", $.proxy(subscribers.belongs_to.foreign_key, association_proxy));\n this.subscribe(resource.toString(), $.proxy(subscribers.belongs_to.associated_changed, association_proxy));\n this.resource_id = old_resource_id;\n if (this[\"\" + resource + \"_id\"] && !this[resource]) {\n _results.push(this.publish(\"\" + resource + \"_id\", this[\"\" + resource + \"_id\"]));\n } else {\n _results.push(void 0);\n }\n }\n return _results;\n }\n },\n create_before_hooks: function(record) {\n var association_proxy, definition, resource, _i, _len, _ref, _results;\n\n definition = this;\n if (definition.belongs_to) {\n _ref = definition.belongs_to;\n _results = [];\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n resource = _ref[_i];\n association_proxy = {\n resource: resource,\n parent_resource: this.resource,\n owner: record\n };\n _results.push(modifiers.belongs_to.associated_loader.call(association_proxy));\n }\n return _results;\n }\n }\n },\n record: {\n after_initialize: function(attributes) {\n if (this.resource == null) {\n throw new Error('resource must be defined in order to associate');\n }\n return model[this.resource.name || this.resource.toString()].create_after_hooks.call(this);\n },\n before_initialize: function(creation) {\n if (!this.resource) {\n throw new Error('resource must be defined in order to associate');\n }\n return model[this.resource.name || this.resource.toString()].create_before_hooks(creation);\n }\n }\n};\n\nmodel = root.model;\n\nmodel.mix(function(modelable) {\n modelable.after_mix.push(associable.model.blender);\n modelable.record.before_initialize.push(associable.record.before_initialize);\n return modelable.record.after_initialize.push(associable.record.after_initialize);\n});\n\nmodel.associable = {\n mix: function(blender) {\n return blender(singular, plural);\n }\n};\n//@ sourceURL=indemma/lib/record/associable.js"
+"var $, associable, callbacks, extend, model, modifiers, plural, root, singular, subscribers,\n __slice = [].slice;\n\nroot = window;\n\n$ = require('jquery');\n\nextend = require('assimilate');\n\nrequire('./resource');\n\nplural = {\n add: function() {\n var attributes, params, _i, _len, _results;\n\n params = 1 <= arguments.length ? __slice.call(arguments, 0) : [];\n _results = [];\n for (_i = 0, _len = params.length; _i < _len; _i++) {\n attributes = params[_i];\n _results.push(this.push(this.build(attributes)));\n }\n return _results;\n },\n create: function() {\n var attributes, params, record, _i, _len, _results;\n\n params = 1 <= arguments.length ? __slice.call(arguments, 0) : [];\n _results = [];\n for (_i = 0, _len = params.length; _i < _len; _i++) {\n attributes = params[_i];\n record = this.build(attributes);\n this.push(record);\n _results.push(record.save());\n }\n return _results;\n },\n build: function(data) {\n var _name;\n\n if (data == null) {\n data = {};\n }\n data.parent_resource = this.parent_resource;\n if (this.parent != null) {\n data.route || (data.route = \"\" + this.parent.route + \"/\" + this.parent._id + \"/\" + (model.pluralize(this.resource.toString())));\n }\n if (this.route !== data.route && this.route) {\n throw \"associable.has_many: cannot redefine route of association \" + this.parent_resource + \".\" + this.resource + \" from \" + this.route + \" to \" + data.route;\n }\n data[_name = this.parent_resource] || (data[_name] = this.parent);\n return model[model.singularize(this.resource)](data);\n },\n push: function() {\n console.warn(\"\" + this.resource + \".push is deprecated and will be removed, please use add instead\");\n return Array.prototype.push.apply(this, arguments);\n },\n length: 0,\n json: function(methods, omissions) {\n var record, _i, _len, _results;\n\n _results = [];\n for (_i = 0, _len = this.length; _i < _len; _i++) {\n record = this[_i];\n _results.push(record.json(methods, omissions));\n }\n return _results;\n }\n};\n\nsingular = {\n create: function(data) {\n return model[this.resource].create(extend({}, this, data));\n },\n build: function(data) {\n return this.owner[this.resource.toString()] = model[this.resource.toString()](extend({}, this, data));\n }\n};\n\nsubscribers = {\n belongs_to: {\n foreign_key: function(resource_id) {\n var association_name, current_resource_id, resource, _ref;\n\n association_name = this.resource.toString();\n if (!resource_id) {\n this.dirty = true;\n this.owner[association_name] = resource_id;\n return resource_id;\n }\n current_resource_id = (_ref = this.owner.observed[association_name]) != null ? _ref._id : void 0;\n if (resource_id !== current_resource_id) {\n resource = model[association_name];\n if (!resource) {\n console.warn(\"subscribers.belongs_to.foreign_key: associated factory not found for model: \" + association_name);\n return resource_id;\n }\n this.owner.observed[association_name] = null;\n }\n return resource_id;\n },\n associated_changed: function(associated) {\n return this.owner.observed[\"\" + (this.resource.toString()) + \"_id\"] = associated ? associated._id : null;\n }\n }\n};\n\nmodifiers = {\n belongs_to: {\n associated_loader: function() {\n var association_name,\n _this = this;\n\n association_name = this.resource.toString();\n return Object.defineProperty(this.owner, association_name, {\n set: function(associated) {\n return this.observed[association_name] = associated;\n },\n get: function() {\n var associated, associated_id, resource;\n\n associated = _this.owner.observed[association_name];\n associated_id = _this.owner.observed[association_name + '_id'];\n if (!(((associated != null ? associated._id : void 0) != null) || associated_id)) {\n return associated;\n }\n if (associated != null ? associated.sustained : void 0) {\n return associated;\n }\n resource = model[association_name];\n if (!resource) {\n console.warn(\"subscribers.belongs_to.foreign_key: associated factory not found for model: \" + association_name);\n return associated;\n }\n associated = resource.find(associated_id || associated._id);\n if (associated) {\n return _this.owner.observed[association_name] = associated;\n }\n associated || (associated = resource({\n _id: associated_id\n }));\n associated.reload();\n return _this.owner.observed[association_name] = associated;\n },\n configurable: true,\n enumerable: true\n });\n }\n }\n};\n\ncallbacks = {\n has_many: {\n nest_attributes: function() {\n var association, association_name, association_names, associations_attributes, message, _i, _len, _results;\n\n association_names = model[this.resource].has_many;\n if (association_names) {\n _results = [];\n for (_i = 0, _len = association_names.length; _i < _len; _i++) {\n association_name = association_names[_i];\n associations_attributes = this[\"\" + association_name + \"_attributes\"];\n association = this[model.pluralize(association_name)];\n if (associations_attributes && associations_attributes.length) {\n if (!association) {\n message = \"has_many.nest_attributes: Association not found for \" + association_name + \". \\n\";\n message += \"did you set it on model declaration? \\n has_many: \" + association_name + \" \";\n throw message;\n }\n association.resource = model.singularize(association.resource);\n association.add.apply(association, associations_attributes);\n _results.push(association.resource = model.pluralize(association.resource));\n } else {\n _results.push(void 0);\n }\n }\n return _results;\n }\n },\n update_association: function(data) {\n var associated, association, association_name, id, pluralized_association, _i, _j, _len, _len1, _ref;\n\n id = this._id || data && (data._id || data.id);\n if (!id) {\n return;\n }\n _ref = model[this.resource.toString()].has_many;\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n association_name = _ref[_i];\n pluralized_association = model.pluralize(association_name);\n association = this[pluralized_association];\n if (!association.route) {\n association.route = \"/\" + (model.pluralize(this.resource.toString())) + \"/\" + id + \"/\" + (model.pluralize(association.resource));\n for (_j = 0, _len1 = association.length; _j < _len1; _j++) {\n associated = association[_j];\n if (!associated.route && (associated.parent != null)) {\n associated.route = \"/\" + (model.pluralize(this.resource.toString())) + \"/\" + id + \"/\" + (model.pluralize(association.resource));\n }\n }\n }\n }\n return true;\n },\n autosave: function() {\n throw 'Not implemented yet';\n }\n },\n has_one: {\n nest_attributes: function() {\n var association_name, association_names, associations_attributes, _i, _len, _results;\n\n association_names = model[this.resource].has_one;\n if (association_names) {\n _results = [];\n for (_i = 0, _len = association_names.length; _i < _len; _i++) {\n association_name = association_names[_i];\n associations_attributes = this[\"\" + association_name + \"_attributes\"];\n if (associations_attributes) {\n this[association_name] = this[\"build_\" + association_name](associations_attributes);\n _results.push(delete this[\"\" + association_name + \"_attributes\"]);\n } else {\n _results.push(void 0);\n }\n }\n return _results;\n }\n }\n }\n};\n\nassociable = {\n model: {\n blender: function(definition) {\n var model;\n\n model = associable.model;\n this.create_after_hooks = model.create_after_hooks;\n this.create_before_hooks = model.create_before_hooks;\n if (this.has_many && $.type(this.has_many) !== 'array') {\n this.has_many = [this.has_many];\n }\n if (this.has_one && $.type(this.has_one) !== 'array') {\n this.has_one = [this.has_one];\n }\n if (this.belongs_to && $.type(this.belongs_to) !== 'array') {\n this.belongs_to = [this.belongs_to];\n }\n this.has_many || (this.has_many = []);\n this.has_one || (this.has_one = []);\n this.belongs_to || (this.belongs_to = []);\n return true;\n },\n create_after_hooks: function(definition) {\n var association_attributes, association_name, association_proxy, old_dirty, old_resource_id, options, resource, _i, _j, _k, _len, _len1, _len2, _name, _ref, _ref1, _ref2, _results;\n\n options = model[this.resource.name || this.resource.toString()];\n if (options.has_many) {\n _ref = options.has_many;\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n resource = _ref[_i];\n association_proxy = {\n resource: resource,\n parent_resource: this.resource,\n parent: this\n };\n association_name = model.pluralize(resource);\n association_attributes = this[association_name] || [];\n this[_name = \"\" + association_name + \"_attributes\"] || (this[_name] = []);\n if (association_attributes.length) {\n this[\"\" + association_name + \"_attributes\"] = this[\"\" + association_name + \"_attributes\"].concat(association_attributes);\n }\n this[association_name] = $.extend(association_proxy, plural);\n }\n this.after('saved', callbacks.has_many.update_association);\n callbacks.has_many.nest_attributes.call(this);\n }\n if (options.has_one) {\n _ref1 = options.has_one;\n for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {\n resource = _ref1[_j];\n association_proxy = {\n resource: resource,\n parent_resource: this.resource,\n owner: this\n };\n association_proxy[this.resource.toString()] = this;\n this[\"build_\" + resource] = $.proxy(singular.build, association_proxy);\n this[\"create_\" + resource] = $.proxy(singular.create, association_proxy);\n }\n callbacks.has_one.nest_attributes.call(this);\n }\n if (options.belongs_to) {\n _ref2 = options.belongs_to;\n _results = [];\n for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {\n resource = _ref2[_k];\n association_proxy = {\n resource: resource,\n parent_resource: this.resource,\n parent: this,\n owner: this\n };\n association_proxy[this.resource.toString()] = this;\n this[\"build_\" + resource] = $.proxy(singular.build, association_proxy);\n this[\"create_\" + resource] = $.proxy(singular.create, association_proxy);\n old_resource_id = this[\"\" + resource + \"_id\"];\n old_dirty = this.dirty;\n this[\"\" + resource + \"_id\"] = null;\n this.subscribe(\"\" + resource + \"_id\", $.proxy(subscribers.belongs_to.foreign_key, association_proxy));\n this.subscribe(resource.toString(), $.proxy(subscribers.belongs_to.associated_changed, association_proxy));\n this[\"\" + resource + \"_id\"] = old_resource_id;\n _results.push(this.dirty = old_dirty);\n }\n return _results;\n }\n },\n create_before_hooks: function(record) {\n var association_proxy, definition, resource, _i, _len, _ref, _results;\n\n definition = this;\n if (definition.belongs_to) {\n _ref = definition.belongs_to;\n _results = [];\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n resource = _ref[_i];\n association_proxy = {\n resource: resource,\n parent_resource: this.resource,\n owner: record\n };\n _results.push(modifiers.belongs_to.associated_loader.call(association_proxy));\n }\n return _results;\n }\n }\n },\n record: {\n after_initialize: function(attributes) {\n if (this.resource == null) {\n throw new Error('resource must be defined in order to associate');\n }\n return model[this.resource.name || this.resource.toString()].create_after_hooks.call(this);\n },\n before_initialize: function(creation) {\n if (!this.resource) {\n throw new Error('resource must be defined in order to associate');\n }\n return model[this.resource.name || this.resource.toString()].create_before_hooks(creation);\n }\n }\n};\n\nmodel = root.model;\n\nmodel.mix(function(modelable) {\n modelable.after_mix.push(associable.model.blender);\n modelable.record.before_initialize.push(associable.record.before_initialize);\n return modelable.record.after_initialize.push(associable.record.after_initialize);\n});\n\nmodel.associable = {\n mix: function(blender) {\n return blender(singular, plural);\n }\n};\n//@ sourceURL=indemma/lib/record/associable.js"
));
require.register("indemma/lib/record/persistable.js", Function("exports, require, module",
-"var handlers, model, persistable, record;\n\nrequire('./queryable');\n\nhandlers = {\n store_after_saved: function() {\n var storage;\n\n storage = model[this.resource.toString()].storage;\n if (this._id) {\n return storage.store(this._id, this);\n }\n }\n};\n\npersistable = {\n record: {\n after_initialize: function() {\n return this.after('saved', handlers.store_after_saved);\n }\n }\n};\n\nmodel = window.model;\n\nrecord = window.record;\n\nmodel.persistable = true;\n\nmodel.mix(function(modelable) {\n return modelable.record.after_initialize.push(persistable.record.after_initialize);\n});\n//@ sourceURL=indemma/lib/record/persistable.js"
+"var handlers, model, persistable, record;\n\nrequire('./queryable');\n\nhandlers = {\n store_after_saved: function() {\n var storage;\n\n storage = model[this.resource.toString()].storage;\n if (this._id) {\n return storage.store(this._id, this);\n }\n }\n};\n\npersistable = {\n record: {\n after_initialize: function() {\n var storage;\n\n if (this._id) {\n storage = model[this.resource.toString()].storage;\n return storage.store(this._id, this);\n } else {\n return this.after('saved', handlers.store_after_saved);\n }\n }\n }\n};\n\nmodel = window.model;\n\nrecord = window.record;\n\nmodel.persistable = true;\n\nmodel.mix(function(modelable) {\n return modelable.record.after_initialize.push(persistable.record.after_initialize);\n});\n//@ sourceURL=indemma/lib/record/persistable.js"
));
require.register("indemma/lib/record/storable.js", Function("exports, require, module",
-"var extend, merge, model, record, stampit, storable;\n\nextend = require('assimilate');\n\nmerge = extend.withStrategy('deep');\n\nstampit = require('../../vendor/stampit');\n\nstorable = stampit({\n store: function(keypath, value, options) {\n var collection, entry, key, _i, _len;\n\n collection = this.database;\n keypath = keypath.toString().split('.');\n key = keypath.pop();\n for (_i = 0, _len = keypath.length; _i < _len; _i++) {\n entry = keypath[_i];\n collection[entry] || (collection[entry] = {});\n collection = collection[entry];\n }\n if (arguments.length === 1) {\n this.reads++;\n return collection[key];\n } else {\n this.writes++;\n value.sustained = true;\n return collection[key] = value;\n }\n },\n values: function() {\n return Object.values(this.database);\n }\n}, {\n type: 'object',\n writes: 0,\n reads: 0\n}, function() {\n this.database || (this.database = {});\n return this;\n});\n\nmodel = window.model;\n\nrecord = window.record;\n\nmodel.storable = true;\n\nmodule.exports = storable;\n//@ sourceURL=indemma/lib/record/storable.js"
+"var extend, merge, model, record, stampit, storable;\n\nextend = require('assimilate');\n\nmerge = extend.withStrategy('deep');\n\nstampit = require('../../vendor/stampit');\n\nstorable = stampit({\n store: function(keypath, value, options) {\n var collection, entry, key, _i, _len;\n\n collection = this.database;\n keypath = keypath.toString().split('.');\n key = keypath.pop();\n for (_i = 0, _len = keypath.length; _i < _len; _i++) {\n entry = keypath[_i];\n collection[entry] || (collection[entry] = {});\n collection = collection[entry];\n }\n if (arguments.length === 1) {\n this.reads++;\n return collection[key];\n } else {\n this.writes++;\n value.sustained || (value.sustained = true);\n return collection[key] = value;\n }\n },\n values: function() {\n return Object.values(this.database);\n }\n}, {\n type: 'object',\n writes: 0,\n reads: 0\n}, function() {\n this.database || (this.database = {});\n return this;\n});\n\nmodel = window.model;\n\nrecord = window.record;\n\nmodel.storable = true;\n\nmodule.exports = storable;\n//@ sourceURL=indemma/lib/record/storable.js"
));
require.register("indemma/lib/record/queryable.js", Function("exports, require, module",
-"var extend, model, queryable, record, stampit, storable;\n\nextend = require('assimilate');\n\nstorable = require('./storable');\n\nstampit = require('../../vendor/stampit');\n\nqueryable = {\n storage: storable(),\n find: function(key) {\n return this.storage.store(key);\n },\n all: function() {\n return this.storage.values();\n },\n where: function() {\n throw new Error('queryable.where: Not implemented yet');\n }\n};\n\nmodel = window.model;\n\nrecord = window.record;\n\nmodel.queryable = true;\n\nmodule.exports = queryable;\n\nmodel.mix(function(modelable) {\n return extend(modelable, queryable);\n});\n//@ sourceURL=indemma/lib/record/queryable.js"
+"var extend, model, queryable, record, stampit, storable;\n\nextend = require('assimilate');\n\nstorable = require('./storable');\n\nstampit = require('../../vendor/stampit');\n\nqueryable = {\n storage: storable(),\n find: function(key) {\n if (!key) {\n throw new TypeError(\"InvalidFind: resource.find was called with a falsey value\");\n }\n return this.storage.store(key);\n },\n all: function() {\n return this.storage.values();\n },\n where: function() {\n throw new Error('queryable.where: Not implemented yet');\n }\n};\n\nmodel = window.model;\n\nrecord = window.record;\n\nmodel.queryable = true;\n\nmodule.exports = queryable;\n\nmodel.mix(function(modelable) {\n return extend(modelable, queryable);\n});\n//@ sourceURL=indemma/lib/record/queryable.js"
));
require.register("indemma/lib/record/resource.js", Function("exports, require, module",
-"var model, resource, resourceable, stampit;\n\nstampit = require('../../vendor/stampit');\n\nrequire('../../vendor/owl/pluralize');\n\nresource = stampit({\n toString: function() {\n return this.name;\n }\n}, {\n name: 'unknown',\n scope: null,\n singular: false\n}, function() {\n var _base;\n\n if (this.original_reference) {\n stampit.mixIn(this.original_reference, this);\n this.original_reference.toString = this.toString;\n (_base = this.original_reference).param_name || (_base.param_name = this.name);\n return this.original_reference;\n }\n this.param_name || (this.param_name = this.name);\n return this;\n});\n\nresourceable = {\n pluralize: function(word, count, plural) {\n if (!(word && word.length)) {\n throw new TypeError(\"Invalid string passed to pluralize '\" + word + \"'\");\n }\n if (word.indexOf('s') !== word.length - 1) {\n return owl.pluralize(word, count, plural);\n } else {\n return word;\n }\n },\n singularize: function(word) {\n if (!(word && word.length)) {\n throw new TypeError(\"Invalid string passed to singularize '\" + word + \"'\");\n }\n if (word.lastIndexOf('s') === word.length - 1) {\n return word.substring(0, word.length - 1);\n } else {\n return word;\n }\n },\n route: {\n get: function() {\n var route;\n\n if (this.initial_route != null) {\n return this.initial_route;\n }\n if (typeof this.resource === 'string') {\n this.resource = {\n name: this.resource\n };\n }\n route = '/';\n if (this.parent != null) {\n route += \"\" + this.parent.route + \"/\" + this.parent._id + \"/\";\n }\n if (this.resource.scope != null) {\n route += this.resource.scope + '/';\n }\n route += this.resource.singular ? this.resource.name : model.pluralize(this.resource.name);\n this.initial_route = route;\n return route;\n },\n set: function(value) {\n return this.initial_route = value;\n }\n },\n parent_id: {\n get: function() {\n if (this[this.parent_resource]) {\n return this[this.parent_resource]._id;\n }\n },\n set: function() {\n return console.error('Warning changing associations throught parent_id not allowed for security and style guide purposes');\n }\n },\n initialize: function() {\n var resource_definition, _ref;\n\n if (this.parent_resource) {\n Object.defineProperty(this, \"\" + this.parent_resource + \"_id\", {\n value: resourceable.parent_id,\n configurable: true,\n enumerable: true\n });\n }\n resource_definition = {};\n if (typeof this.resource === 'string') {\n resource_definition = {\n name: this.resource\n };\n }\n if (typeof this.resource === 'object') {\n this.resource.original_reference = this.resource;\n resource_definition = this.resource;\n }\n resource_definition.parent = this.parent_resource;\n this.resource = resource(resource_definition);\n return (_ref = this.route) != null ? _ref : Object.defineProperty(this, 'route', resourceable.route);\n }\n};\n\nmodel = window.model;\n\nmodel.mix(function(modelable) {\n modelable.record.after_initialize.unshift(resourceable.initialize);\n return modelable.after_mix.unshift(resourceable.initialize);\n});\n\nmodel.singularize = resourceable.singularize;\n\nmodel.pluralize = resourceable.pluralize;\n//@ sourceURL=indemma/lib/record/resource.js"
+"var descriptors, model, resource, resourceable, stampit;\n\nstampit = require('../../vendor/stampit');\n\nrequire('../../vendor/owl/pluralize');\n\nresource = stampit({\n toString: function() {\n return this.name;\n }\n}, {\n name: 'unknown',\n scope: null,\n singular: false\n}, function() {\n var _base;\n\n if (this.original_reference) {\n stampit.mixIn(this.original_reference, this);\n this.original_reference.toString = this.toString;\n (_base = this.original_reference).param_name || (_base.param_name = this.name);\n return this.original_reference;\n }\n this.param_name || (this.param_name = this.name);\n return this;\n});\n\ndescriptors = {\n route: {\n get: function() {\n var route;\n\n if (typeof this.resource === 'string') {\n this.resource = {\n name: this.resource\n };\n }\n route = '/';\n if (this.parent != null) {\n route += \"\" + this.parent.route + \"/\" + this.parent._id + \"/\";\n }\n if (this.resource.scope != null) {\n route += this.resource.scope + '/';\n }\n route += this.resource.singular ? this.resource.name : model.pluralize(this.resource.name);\n return this.route = route;\n },\n configurable: true\n }\n};\n\nresourceable = {\n pluralize: function(word, count, plural) {\n if (!(word && word.length)) {\n throw new TypeError(\"Invalid string passed to pluralize '\" + word + \"'\");\n }\n if (word.indexOf('s') !== word.length - 1) {\n return owl.pluralize(word, count, plural);\n } else {\n return word;\n }\n },\n singularize: function(word) {\n if (!(word && word.length)) {\n throw new TypeError(\"Invalid string passed to singularize '\" + word + \"'\");\n }\n if (word.lastIndexOf('s') === word.length - 1) {\n return word.substring(0, word.length - 1);\n } else {\n return word;\n }\n },\n initialize: function() {\n var resource_definition, _ref;\n\n resource_definition = {};\n if (typeof this.resource === 'string') {\n resource_definition = {\n name: this.resource\n };\n }\n if (typeof this.resource === 'object') {\n this.resource.original_reference = this.resource;\n resource_definition = this.resource;\n }\n resource_definition.parent = this.parent_resource;\n this.resource = resource(resource_definition);\n return (_ref = this.route) != null ? _ref : Object.defineProperty(this, 'route', descriptors.route);\n }\n};\n\nmodel = window.model;\n\nmodel.mix(function(modelable) {\n modelable.record.after_initialize.unshift(resourceable.initialize);\n return modelable.after_mix.unshift(resourceable.initialize);\n});\n\nmodel.singularize = resourceable.singularize;\n\nmodel.pluralize = resourceable.pluralize;\n//@ sourceURL=indemma/lib/record/resource.js"
));
require.register("indemma/lib/record/rest.js", Function("exports, require, module",
"var $, request;\n\n$ = require('jquery');\n\nmodule.exports = {\n get: function(data) {\n return request.call(this, 'get', (this._id ? \"\" + this.route + \"/\" + this._id : this.route), data);\n },\n put: function(data) {\n return request.call(this, 'put', (this._id ? \"\" + this.route + \"/\" + this._id : this.route), data);\n },\n post: function(data) {\n return request.call(this, 'post', this.route, data);\n },\n \"delete\": function(data) {\n return request.call(this, 'delete', (this._id ? \"\" + this.route + \"/\" + this._id : this.route), data);\n }\n};\n\nrequest = function(method, url, data) {\n var param_name;\n\n param_name = this.resource.param_name || this.resource.toString();\n if (!data && this.json) {\n data = {};\n data[param_name] = this.json();\n }\n if (data && data[param_name]) {\n delete data[param_name]['id'];\n delete data[param_name]['_id'];\n }\n return $.ajax({\n url: url,\n data: data,\n type: method,\n dataType: 'json',\n context: this\n });\n};\n//@ sourceURL=indemma/lib/record/rest.js"
));
require.register("indemma/lib/record/restfulable.js", Function("exports, require, module",
-"var $, merge, model, observable, record, rest, restful, type, util,\n __slice = [].slice;\n\nmerge = require('assimilate').withStrategy('deep');\n\ntype = require('type');\n\nobservable = require('observable').mixin;\n\n$ = require('jquery');\n\nrest = require('./rest.js');\n\nutil = {\n model: {\n map: function(models) {\n var model, _i, _len, _results;\n\n _results = [];\n for (_i = 0, _len = models.length; _i < _len; _i++) {\n model = models[_i];\n _results.push(this(model));\n }\n return _results;\n }\n }\n};\n\nrestful = {\n model: {\n create: function() {\n var attributes, callback, params, record, savings, _i, _j, _len;\n\n params = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), callback = arguments[_i++];\n if (!arguments.length) {\n throw new TypeError(\"No arguments provided for \" + this.resource + \".create\");\n }\n if (typeof callback !== 'function') {\n params.push(callback);\n callback = void 0;\n }\n if (!params.length) {\n params.unshift({});\n }\n savings = [];\n for (_j = 0, _len = params.length; _j < _len; _j++) {\n attributes = params[_j];\n record = this(attributes);\n record.dirty = true;\n savings.push(record.save(callback));\n }\n return $.when.apply($, savings);\n },\n all: function(conditions, callback) {\n if (conditions == null) {\n conditions = {};\n }\n if (typeof conditions === 'function') {\n callback = conditions;\n conditions = {};\n }\n return $.when(rest.get.call(this, conditions)).then(util.model.map).done(callback);\n },\n first: function(conditions, callback) {\n var namespaced;\n\n if (conditions == null) {\n conditions = {};\n }\n if (typeof conditions === 'function') {\n callback = conditions;\n conditions = {};\n }\n namespaced = conditions[this.resource] || {};\n namespaced.limit = 1;\n namespaced.order = 'desc';\n return this.all(conditions, callback);\n },\n get: function(action, data) {\n var old_route, payload, promise, resource, route;\n\n if (data == null) {\n data = {};\n }\n old_route = this.route;\n this.route = \"/\" + (model.pluralize(this.resource.name));\n if (action) {\n this.route += \"/\" + action;\n }\n resource = data.resource;\n if (data && data.json) {\n data = data.json();\n }\n if (resource != null) {\n payload = data;\n data = {};\n data[resource] = payload;\n }\n promise = rest.get.call(this, data);\n route = old_route;\n return promise;\n },\n put: rest.put,\n \"delete\": rest[\"delete\"]\n },\n record: {\n reload: function() {\n var data, param, params, promise, _i, _len;\n\n params = 1 <= arguments.length ? __slice.call(arguments, 0) : [];\n data = params.pop();\n if (type(data) !== 'object') {\n params.push(data);\n }\n promise = rest.get.call(this, data || {});\n promise.done(this.assign_attributes);\n promise.fail(this.failed);\n for (_i = 0, _len = params.length; _i < _len; _i++) {\n param = params[_i];\n promise.done(param);\n }\n return promise;\n },\n assign_attributes: function(attributes) {\n var association, association_attributes, association_name, associations_attributes, attribute, message, singular_resource, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _results;\n\n _ref = model[this.resource.toString()].has_many;\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n association_name = _ref[_i];\n associations_attributes = attributes[association_name];\n delete attributes[association_name];\n association = this[association_name];\n if (association == null) {\n message = \"Association '\" + association_name + \"' not found. \\n\";\n message += \"For record with resource \" + this.resource + \". \\n\";\n message += \"Probably defined on server side but not on client side.\\n\";\n message += \"Skipping association assignment!\";\n console.warn(message);\n continue;\n }\n if (association.length) {\n Array.prototype.splice.call(association, 0);\n }\n if (!((associations_attributes != null) && associations_attributes.length)) {\n continue;\n }\n singular_resource = model.singularize(association_name);\n for (_j = 0, _len1 = associations_attributes.length; _j < _len1; _j++) {\n association_attributes = associations_attributes[_j];\n _ref1 = model[singular_resource].has_many;\n for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {\n association_name = _ref1[_k];\n association_attributes[\"\" + association_name + \"_attributes\"] = association_attributes[association_name];\n delete association_attributes[association_name];\n }\n }\n association.add.apply(association, associations_attributes);\n }\n _ref2 = model[this.resource.toString()].has_one;\n for (_l = 0, _len3 = _ref2.length; _l < _len3; _l++) {\n association_name = _ref2[_l];\n association_attributes = attributes[association_name];\n delete attributes[association_name];\n delete attributes[association_name + \"_attributes\"];\n if (association_attributes) {\n this[association_name] = this[\"build_\" + association_name](association_attributes);\n }\n }\n _results = [];\n for (attribute in attributes) {\n if (attribute !== this[attribute]) {\n _results.push(this[attribute] = attributes[attribute]);\n }\n }\n return _results;\n },\n destroy: function(doned, failed, data) {\n var promise;\n\n if (!((this.id != null) || (this._id != null))) {\n throw new Error('Can\\'t delete record without id!');\n }\n promise = rest[\"delete\"].call(this, data);\n promise.done(this.destroyed);\n promise.fail(this.failed);\n promise.done(doned);\n promise.fail(failed);\n return promise;\n },\n saving: false,\n salvation: null,\n save: function(doned, failed, data) {\n var salvation;\n\n if (this.saving) {\n return this.salvation;\n }\n this.lock = JSON.stringify(this.json());\n if (!this.dirty) {\n salvation = $.Deferred().resolveWith(this, null);\n }\n salvation || (salvation = rest[this._id ? 'put' : 'post'].call(this, data));\n this.salvation = salvation;\n this.saving = true;\n salvation.done(this.saved);\n salvation.fail(this.failed);\n salvation.always(function() {\n return this.saving = false;\n });\n salvation.done(doned);\n salvation.fail(failed);\n return salvation;\n },\n saved: function(data) {\n var callback, _i, _len, _ref, _results;\n\n if (this.lock === JSON.stringify(this.json())) {\n this.dirty = false;\n delete this.lock;\n } else {\n return this.save();\n }\n if (data != null) {\n this.assign_attributes(data);\n }\n if (this.after_save) {\n _ref = this.after_save;\n _results = [];\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n callback = _ref[_i];\n throw \"Not supported after_save callback: \" + callback;\n }\n return _results;\n }\n },\n failed: function(xhr, error, status) {\n var attribute_name, definition, e, message, messages, payload, _i, _len, _ref;\n\n payload = xhr.responseJSON;\n try {\n payload || (payload = JSON.parse(xhr.responseText));\n } catch (_error) {\n e = _error;\n }\n payload || (payload = xhr.responseText);\n switch (xhr.status) {\n case 422:\n definition = model[this.resource];\n _ref = payload.errors;\n for (attribute_name in _ref) {\n messages = _ref[attribute_name];\n if (!definition.associations) {\n definition.associations = definition.has_one.concat(definition.has_many.concat(definition.belongs_to));\n }\n if (!(this.hasOwnProperty(attribute_name) || definition.hasOwnProperty(attribute_name) || definition.associations.indexOf(attribute_name) !== -1 || attribute_name === 'base')) {\n message = \"Server returned an validation error message for a attribute that is not defined in your model.\\n\";\n message += \"The attribute was '\" + attribute_name + \"', the model resource was '\" + this.resource + \"'.\\n\";\n message += \"The model definition keys were '\" + (JSON.stringify(Object.keys(definition))) + \"'.\\n\";\n message += \"Please remove server validation, or update your model definition.\";\n throw new TypeError(message);\n }\n for (_i = 0, _len = messages.length; _i < _len; _i++) {\n message = messages[_i];\n this.errors.add(attribute_name, 'server', {\n server_message: message\n });\n }\n }\n break;\n default:\n message = \"Fail in \" + this.resource + \".save:\\n\";\n message += \"Record: \" + this + \"\\n\";\n message += \"Status: \" + status + \" (\" + (payload.status || xhr.status) + \")\\n\";\n message += \"Error : \" + (payload.error || payload.message || payload);\n }\n return this.saving = false;\n },\n toString: function() {\n var serialized;\n\n serialized = {};\n serialized[this.resource] = this.json();\n return JSON.stringify(serialized);\n },\n json: function(methods) {\n var attribute, json, name, value, _i, _len, _ref;\n\n if (methods == null) {\n methods = {};\n }\n json = {};\n for (name in this) {\n value = this[name];\n if (!(type(value) !== 'function')) {\n continue;\n }\n if (value == null) {\n continue;\n }\n if (type(value) === 'object') {\n if (value.toJSON != null) {\n json[name] = value.toJSON(methods[name]);\n } else {\n _ref = this.nested_attributes;\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n attribute = _ref[_i];\n if (attribute === name) {\n json[\"\" + name + \"_attributes\"] = value.json(methods[name]);\n }\n }\n }\n } else {\n json[name] = value;\n }\n }\n observable.unobserve(json);\n delete json.dirty;\n delete json.resource;\n delete json.route;\n delete json.initial_route;\n delete json.after_initialize;\n delete json.before_initialize;\n delete json.parent_resource;\n delete json.nested_attributes;\n delete json.saving;\n delete json.salvation;\n delete json.sustained;\n delete json.element;\n delete json[\"default\"];\n delete json.lock;\n delete json.validated;\n delete json.validation;\n return json;\n }\n }\n};\n\nrestful.toJSON = restful.json;\n\nmodel = window.model;\n\nrecord = window.record;\n\nmodel.restfulable = true;\n\nrecord.mix(function(recordable) {\n return merge(recordable, restful.record);\n});\n\nmodel.mix(function(modelable) {\n return merge(modelable, restful.model);\n});\n\nmodel.associable && model.associable.mix(function(singular_association, plural_association) {\n plural_association.get = function() {\n if (this.parent != null) {\n this.route || (this.route = \"\" + this.parent.route + \"/\" + this.parent._id + \"/\" + (model.pluralize(this.resource.name)));\n }\n return rest.get.apply(this, arguments);\n };\n return plural_association.post = function() {\n if (this.parent != null) {\n this.route || (this.route = \"\" + this.parent.route + \"/\" + this.parent._id + \"/\" + (model.pluralize(this.resource.name)));\n }\n return rest.post.apply(this, arguments);\n };\n});\n//@ sourceURL=indemma/lib/record/restfulable.js"
+"var $, merge, model, observable, record, rest, restful, root, type, util,\n __slice = [].slice;\n\nmerge = require('assimilate').withStrategy('deep');\n\ntype = require('type');\n\nobservable = require('observable').mixin;\n\n$ = require('jquery');\n\nrest = require('./rest.js');\n\nroot = typeof exports !== \"undefined\" && exports !== null ? exports : this;\n\nutil = {\n model: {\n map: function(records) {\n var record, _i, _len, _results;\n\n _results = [];\n for (_i = 0, _len = records.length; _i < _len; _i++) {\n record = records[_i];\n _results.push(this(record));\n }\n return _results;\n }\n }\n};\n\nrestful = {\n model: {\n create: function() {\n var attributes, callback, params, record, savings, _i, _j, _len;\n\n params = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), callback = arguments[_i++];\n if (!arguments.length) {\n throw new TypeError(\"No arguments provided for \" + this.resource + \".create\");\n }\n if (typeof callback !== 'function') {\n params.push(callback);\n callback = void 0;\n }\n if (!params.length) {\n params.unshift({});\n }\n savings = [];\n for (_j = 0, _len = params.length; _j < _len; _j++) {\n attributes = params[_j];\n record = this(attributes);\n record.dirty = true;\n savings.push(record.save(callback));\n }\n return $.when.apply($, savings);\n },\n all: function(conditions, doned, failed) {\n if (conditions == null) {\n conditions = {};\n }\n if (typeof conditions === 'function') {\n doned = conditions;\n conditions = {};\n }\n return $.when(rest.get.call(this, conditions)).then(util.model.map).done(doned).fail(failed);\n },\n first: function(conditions, callback) {\n var namespaced;\n\n if (conditions == null) {\n conditions = {};\n }\n if (typeof conditions === 'function') {\n callback = conditions;\n conditions = {};\n }\n namespaced = conditions[this.resource] || {};\n namespaced.limit = 1;\n namespaced.order = 'desc';\n return this.all(conditions, callback);\n },\n get: function(action, data) {\n var default_route, old_route, payload, promise, resource;\n\n if (data == null) {\n data = {};\n }\n old_route = this.route;\n default_route = \"/\" + (model.pluralize(this.resource.name));\n if (default_route !== this.route) {\n this.route = default_route;\n }\n if (action) {\n Object.defineProperty(this, 'route', {\n value: \"\" + default_route + \"/\" + action,\n configurable: true\n });\n }\n resource = data.resource;\n if (data && data.json) {\n data = data.json();\n }\n if (resource != null) {\n payload = data;\n data = {};\n data[resource] = payload;\n }\n promise = rest.get.call(this, data);\n Object.defineProperty(this, 'route', {\n value: old_route,\n configurable: true\n });\n return promise;\n },\n put: rest.put,\n \"delete\": rest[\"delete\"]\n },\n record: {\n ready: function(callback) {\n return callback.call(this);\n },\n reload: function() {\n var data, param, params, promise, _i, _len;\n\n params = 1 <= arguments.length ? __slice.call(arguments, 0) : [];\n data = params.pop();\n if (type(data) !== 'object') {\n params.push(data);\n }\n promise = rest.get.call(this, data || {});\n promise.done(this.assign_attributes);\n promise.fail(this.failed);\n this.reloading = promise;\n this.ready = function() {\n console.warn(\"resource.ready was deprecated, please use resource.reloading.done\");\n return promise.done.apply(promise, arguments);\n };\n for (_i = 0, _len = params.length; _i < _len; _i++) {\n param = params[_i];\n promise.done(param);\n }\n return promise;\n },\n assign_attributes: function(attributes) {\n var association, association_attributes, association_name, associations_attributes, attribute, message, name, singular_resource, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _results;\n\n _ref = model[this.resource.toString()].has_many;\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n association_name = _ref[_i];\n associations_attributes = attributes[association_name];\n delete attributes[association_name];\n association = this[association_name];\n if (association == null) {\n message = \"Association '\" + association_name + \"' not found. \\n\";\n message += \"For record with resource \" + this.resource + \". \\n\";\n message += \"Probably defined on server side but not on client side.\\n\";\n message += \"Skipping association assignment!\";\n console.warn(message);\n continue;\n }\n if (association.length) {\n Array.prototype.splice.call(association, 0);\n }\n if (!((associations_attributes != null) && associations_attributes.length)) {\n continue;\n }\n singular_resource = model.singularize(association_name);\n for (_j = 0, _len1 = associations_attributes.length; _j < _len1; _j++) {\n association_attributes = associations_attributes[_j];\n _ref1 = model[singular_resource].has_many;\n for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {\n association_name = _ref1[_k];\n association_attributes[\"\" + association_name + \"_attributes\"] = association_attributes[association_name];\n delete association_attributes[association_name];\n }\n }\n association.add.apply(association, associations_attributes);\n }\n _ref2 = model[this.resource.toString()].has_one;\n for (_l = 0, _len3 = _ref2.length; _l < _len3; _l++) {\n association_name = _ref2[_l];\n association_attributes = attributes[association_name];\n delete attributes[association_name];\n delete attributes[association_name + \"_attributes\"];\n if (association_attributes) {\n this[association_name] = this[\"build_\" + association_name](association_attributes);\n }\n }\n _results = [];\n for (name in attributes) {\n attribute = attributes[name];\n if (attribute !== this[name]) {\n if (type(attribute) === 'object') {\n if (JSON.stringify(attribute) !== JSON.stringify(this[name])) {\n _results.push(this[name] = attributes[name]);\n } else {\n _results.push(void 0);\n }\n } else {\n _results.push(this[name] = attributes[name]);\n }\n }\n }\n return _results;\n },\n destroy: function(doned, failed, data) {\n var promise;\n\n if (!((this.id != null) || (this._id != null))) {\n throw new Error('Can\\'t delete record without id!');\n }\n promise = rest[\"delete\"].call(this, data);\n promise.done(this.destroyed);\n promise.fail(this.failed);\n promise.done(doned);\n promise.fail(failed);\n return promise;\n },\n saving: false,\n salvation: null,\n save: function(doned, failed, data) {\n var lock, salvation;\n\n lock = JSON.stringify(this.json());\n if (this.saving) {\n if (this.lock === lock) {\n return this.salvation;\n } else {\n this.salvation.abort();\n }\n }\n this.lock = lock;\n if (!this.dirty) {\n salvation = $.Deferred().resolveWith(this, null);\n }\n this.saving = true;\n salvation || (salvation = rest[this._id ? 'put' : 'post'].call(this, data));\n this.salvation = salvation;\n salvation.done(this.saved);\n salvation.fail(this.failed);\n salvation.always(function() {\n return this.saving = false;\n });\n salvation.done(doned);\n salvation.fail(failed);\n return salvation;\n },\n saved: function(data) {\n var callback, _i, _len, _ref, _results;\n\n if (this.lock === JSON.stringify(this.json())) {\n this.dirty = false;\n delete this.lock;\n }\n if (data != null) {\n this.assign_attributes(data);\n }\n if (this.after_save) {\n _ref = this.after_save;\n _results = [];\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n callback = _ref[_i];\n throw \"Not supported after_save callback: \" + callback;\n }\n return _results;\n }\n },\n failed: function(xhr, error, status) {\n var attribute_name, definition, e, message, messages, payload, _i, _len, _ref;\n\n payload = xhr.responseJSON;\n try {\n payload || (payload = JSON.parse(xhr.responseText));\n } catch (_error) {\n e = _error;\n }\n payload || (payload = xhr.responseText);\n switch (xhr.status) {\n case 0:\n message = status || xhr.statusText;\n switch (message) {\n case 'abort':\n console.info(\"salvation probably aborted\");\n break;\n case 'error':\n console.info(\"server probably unreachable\");\n break;\n default:\n throw new Error('Unhandled status code for xhr');\n }\n break;\n case 422:\n definition = model[this.resource.toString()];\n _ref = payload.errors;\n for (attribute_name in _ref) {\n messages = _ref[attribute_name];\n if (!definition.associations) {\n definition.associations = definition.has_one.concat(definition.has_many.concat(definition.belongs_to));\n }\n if (!(this.hasOwnProperty(attribute_name) || definition.hasOwnProperty(attribute_name) || definition.associations.indexOf(attribute_name) !== -1 || attribute_name === 'base')) {\n message = \"Server returned an validation error message for a attribute that is not defined in your model.\\n\";\n message += \"The attribute was '\" + attribute_name + \"', the model resource was '\" + this.resource + \"'.\\n\";\n message += \"The model definition keys were '\" + (JSON.stringify(Object.keys(definition))) + \"'.\\n\";\n message += \"Please remove server validation, or update your model definition.\";\n throw new TypeError(message);\n }\n for (_i = 0, _len = messages.length; _i < _len; _i++) {\n message = messages[_i];\n this.errors.add(attribute_name, 'server', {\n server_message: message\n });\n }\n }\n break;\n default:\n message = \"Fail in \" + this.resource + \".save:\\n\";\n message += \"Record: \" + this + \"\\n\";\n message += \"Status: \" + status + \" (\" + (payload || xhr).status + \")\\n\";\n message += \"Error : \" + (payload.error || payload.message || payload);\n console.log(message);\n }\n return this.saving = false;\n },\n toString: function() {\n var serialized;\n\n serialized = {};\n serialized[this.resource] = this.json();\n return JSON.stringify(serialized);\n },\n json: function(methods) {\n var attribute, definition, json, name, value, _i, _len, _ref;\n\n if (methods == null) {\n methods = {};\n }\n json = {};\n definition = model[this.resource.toString()];\n for (name in this) {\n if (!(type(value))) {\n continue;\n }\n if (definition.belongs_to.indexOf(name) !== -1 && this.nested_attributes.indexOf(name) === -1) {\n continue;\n }\n value = this[name];\n if (value == null) {\n continue;\n }\n if (type(value) === 'function') {\n continue;\n }\n if (type(value) === 'object') {\n if (value.toJSON != null) {\n json[name] = value.toJSON(methods[name]);\n } else {\n _ref = this.nested_attributes;\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n attribute = _ref[_i];\n if (attribute === name) {\n json[\"\" + name + \"_attributes\"] = value.json(methods[name]);\n }\n }\n }\n } else {\n json[name] = value;\n }\n }\n observable.unobserve(json);\n delete json.dirty;\n delete json.resource;\n delete json.route;\n delete json.initial_route;\n delete json.after_initialize;\n delete json.before_initialize;\n delete json.parent_resource;\n delete json.nested_attributes;\n delete json.reloading;\n delete json.ready;\n delete json.saving;\n delete json.salvation;\n delete json.sustained;\n delete json.element;\n delete json[\"default\"];\n delete json.lock;\n delete json.validated;\n delete json.validation;\n return json;\n }\n }\n};\n\nrestful.toJSON = restful.json;\n\nmodel = window.model;\n\nrecord = window.record;\n\nmodel.restfulable = true;\n\nrecord.mix(function(recordable) {\n return merge(recordable, restful.record);\n});\n\nmodel.mix(function(modelable) {\n return merge(modelable, restful.model);\n});\n\nmodel.associable && model.associable.mix(function(singular_association, plural_association) {\n plural_association.get = function() {\n if (this.parent != null) {\n this.route || (this.route = \"\" + this.parent.route + \"/\" + this.parent._id + \"/\" + (model.pluralize(this.resource.name)));\n }\n return rest.get.apply(this, arguments);\n };\n return plural_association.post = function() {\n if (this.parent != null) {\n this.route || (this.route = \"\" + this.parent.route + \"/\" + this.parent._id + \"/\" + (model.pluralize(this.resource.name)));\n }\n return rest.post.apply(this, arguments);\n };\n});\n//@ sourceURL=indemma/lib/record/restfulable.js"
));
require.register("indemma/lib/record/scopable.js", Function("exports, require, module",
-"var $, builders, defaults, extend, merge, model, record, rest, scopable, stampit,\n __slice = [].slice;\n\nrequire('./restfulable');\n\nrequire('./resource');\n\nstampit = require('../../vendor/stampit');\n\nextend = require('assimilate');\n\nmerge = extend.withStrategy('deep');\n\n$ = require('jquery');\n\nrest = require('./rest');\n\nscopable = {\n builder: stampit().enclose(function() {\n return stampit.mixIn(function(name, type) {\n var builder;\n\n if ($.type(type) === 'function') {\n this[\"$\" + name] = type() || new type;\n type = $.type(this[\"$\" + name]);\n } else {\n this[\"$\" + name] = defaults[type] || type;\n }\n if ($.type(type) !== 'string') {\n type = $.type(type);\n }\n builder = builders[type];\n if (builder == null) {\n throw \"Unknown scope type: '\" + type + \"', For model with resource: '\" + this.resource + \"'\";\n }\n this.scope.declared.push(name);\n return this[name] = builder({\n name: name\n });\n }, {\n data: {},\n then: [],\n fail: [],\n declared: [],\n fetch: function(data, done, fail) {\n var deferred, scope;\n\n scope = extend({}, this.scope.data);\n if (scope.noned != null) {\n deferred = $.Deferred();\n deferred.resolveWith(this, [[]]);\n } else {\n deferred = rest.get.call(this, extend(scope, data));\n }\n deferred.done(this.scope.then.concat(done)).fail([this.scope.fail, fail]);\n this.scope.clear();\n return deferred;\n },\n clear: function() {\n this.data = {};\n return this.callbacks = [];\n }\n });\n }),\n base: stampit().state({\n name: 'unamed_scope'\n }),\n record: {\n failed: function(xhr, error, status) {\n var e, message, payload;\n\n payload = xhr.responseJSON;\n try {\n payload || (payload = JSON.parse(xhr.responseText));\n } catch (_error) {\n e = _error;\n }\n payload || (payload = xhr.responseText);\n switch (xhr.status) {\n case 422:\n this.valid = false;\n return this.errors = payload.errors;\n default:\n message = \"Fail in \" + this.resource + \".save:\\n\";\n message += \"Record: \" + this + \"\\n\";\n message += \"Status: \" + status + \" (\" + (payload.status || xhr.status) + \")\\n\";\n message += \"Error : \" + (payload.error || payload.message || payload);\n }\n return console.error(message);\n }\n },\n model: {\n none: function() {\n this.scope.data.noned = true;\n return this;\n },\n fetch: function(data, done, fail) {\n return this.scope.fetch.call(this, data, done, fail);\n },\n forward_scopes_to_associations: function() {\n var associated_factory, associated_resource, association, association_name, factory, forwarder, generate_forwarder, scope, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2, _ref3, _ref4;\n\n factory = model[this.resource.name];\n _ref = factory.has_many;\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n association_name = _ref[_i];\n associated_resource = model.singularize(association_name);\n associated_factory = model[associated_resource];\n if (!model[associated_resource]) {\n console.warn(\"Associated factory not found for associated resource: \" + associated_resource);\n continue;\n }\n association = this[association_name];\n association.scope = scopable.builder(association);\n _ref1 = associated_factory.scope.declared;\n for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {\n scope = _ref1[_j];\n association.scope(scope, associated_factory[\"$\" + scope]);\n }\n }\n _ref2 = factory.has_one;\n for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {\n associated_resource = _ref2[_k];\n if (!model[associated_resource]) {\n console.warn(\"Associated factory not found for associated resource: \" + associated_resource);\n continue;\n }\n _ref3 = model[associated_resource].scope.declared;\n for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {\n scope = _ref3[_l];\n this[associated_resource][scope] = factory[scope];\n }\n }\n if (factory.belongs_to.length) {\n generate_forwarder = function(associated_resource) {\n var declared_scopes;\n\n associated_factory = model[associated_resource];\n if (!associated_factory) {\n return console.warn(\"Associated factory not found for associated resource: \" + associated_resource);\n }\n declared_scopes = associated_factory.scope.declared;\n return function() {\n var _len4, _m, _results;\n\n _results = [];\n for (_m = 0, _len4 = declared_scopes.length; _m < _len4; _m++) {\n scope = declared_scopes[_m];\n _results.push(this[associated_resource][scope] = associated_factory[scope]);\n }\n return _results;\n };\n };\n _ref4 = factory.belongs_to;\n for (_m = 0, _len4 = _ref4.length; _m < _len4; _m++) {\n associated_resource = _ref4[_m];\n forwarder = generate_forwarder(associated_resource);\n this.after(\"build_\" + associated_resource, forwarder);\n }\n }\n return true;\n }\n },\n after_mix: function() {\n var name, property, type, _results;\n\n this.scope = scopable.builder(this);\n _results = [];\n for (property in this) {\n type = this[property];\n if (property.charAt(0) === '$') {\n name = property.substring(1);\n _results.push(this.scope(name, type));\n } else {\n _results.push(void 0);\n }\n }\n return _results;\n }\n};\n\nbuilders = {\n string: stampit().enclose(function() {\n var base;\n\n base = scopable.base(this);\n return stampit.mixIn(function() {\n var callbacks, value, _base, _name;\n\n value = arguments[0], callbacks = 2 <= arguments.length ? __slice.call(arguments, 1) : [];\n callbacks.length && (this.scope.then = this.scope.then.concat(callbacks));\n (_base = this.scope.data)[_name = base.name] || (_base[_name] = value != null ? value : this[\"$\" + base.name]);\n return this;\n });\n }),\n boolean: stampit().enclose(function() {\n var base;\n\n base = scopable.base(this);\n return stampit.mixIn(function() {\n var callbacks, value, _base, _name;\n\n value = arguments[0], callbacks = 2 <= arguments.length ? __slice.call(arguments, 1) : [];\n callbacks.length && (this.scope.then = this.scope.then.concat(callbacks));\n (_base = this.scope.data)[_name = base.name] || (_base[_name] = value != null ? value : this[\"$\" + base.name]);\n return this;\n });\n }),\n array: stampit().enclose(function() {\n var base;\n\n base = scopable.base(this);\n return stampit.mixIn(function() {\n var values, _base, _name;\n\n values = 1 <= arguments.length ? __slice.call(arguments, 0) : [];\n (_base = this.scope.data)[_name = base.name] || (_base[_name] = values != null ? values : this[\"$\" + base.name]);\n return this;\n });\n })\n};\n\ndefaults = {\n boolean: true,\n array: []\n};\n\nmodel = window.model;\n\nrecord = window.record;\n\nmodel.scopable = true;\n\nmodel.mix(function(modelable) {\n merge(modelable, scopable.model);\n return modelable.after_mix.push(scopable.after_mix);\n});\n\nif (model.associable) {\n model.mix(function(modelable) {\n return modelable.record.after_initialize.push(function() {\n return scopable.model.forward_scopes_to_associations.call(this);\n });\n });\n model.associable.mix(function(singular_association, plural_association) {\n plural_association.all = plural_association.reload = function(data, done, fail) {\n var promises, reload;\n\n if (this.parent != null) {\n this.route || (this.route = \"\" + this.parent.route + \"/\" + this.parent._id + \"/\" + (model.pluralize(this.resource)));\n }\n promises = [];\n if (typeof data === 'function') {\n done = data;\n data = void 0;\n }\n promises.push(this.scope.fetch.call(this, data, null, scopable.record.failed));\n reload = $.when.apply(jQuery, promises);\n reload.done(function(records, status) {\n var association_name, singular_resource, _i, _j, _len, _len1, _ref;\n\n Array.prototype.splice.call(this, 0);\n if (!records.length) {\n return;\n }\n singular_resource = model.singularize(this.resource);\n for (_i = 0, _len = records.length; _i < _len; _i++) {\n record = records[_i];\n _ref = model[singular_resource].has_many;\n for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {\n association_name = _ref[_j];\n record[\"\" + association_name + \"_attributes\"] = record[association_name];\n delete record[association_name];\n }\n }\n this.add.apply(this, records);\n records.splice(0);\n return records.push.apply(records, this);\n });\n reload.done(done);\n reload.fail(fail);\n return reload;\n };\n return plural_association.each = function(callback) {\n var _this = this;\n\n if (this.parent != null) {\n this.route || (this.route = \"\" + this.parent.route + \"/\" + this.parent._id + \"/\" + (model.pluralize(this.resource)));\n }\n return this.get().done(function(records) {\n var _i, _len, _results;\n\n _results = [];\n for (_i = 0, _len = _this.length; _i < _len; _i++) {\n record = _this[_i];\n _results.push(callback(record));\n }\n return _results;\n });\n };\n });\n}\n//@ sourceURL=indemma/lib/record/scopable.js"
+"var $, builders, defaults, extend, merge, model, observable, record, rest, scopable, stampit, util,\n __slice = [].slice;\n\nrequire('./restfulable');\n\nrequire('./resource');\n\nstampit = require('../../vendor/stampit');\n\nextend = require('assimilate');\n\nobservable = require('observable').mixin;\n\nmerge = extend.withStrategy('deep');\n\n$ = require('jquery');\n\nrest = require('./rest');\n\nutil = {\n model: {\n map: function(records) {\n var index, record, _i, _len, _results;\n\n _results = [];\n for (index = _i = 0, _len = records.length; _i < _len; index = ++_i) {\n record = records[index];\n _results.push((this.build || this).call(this, record));\n }\n return _results;\n }\n }\n};\n\nscopable = {\n builder: stampit().enclose(function() {\n return stampit.mixIn(function(name, type) {\n var builder;\n\n if ($.type(type) === 'function') {\n this[\"$\" + name] = type() || new type;\n type = $.type(this[\"$\" + name]);\n } else {\n this[\"$\" + name] = defaults[type] || type;\n }\n if ($.type(type) !== 'string') {\n type = $.type(type);\n }\n builder = builders[type];\n if (builder == null) {\n throw \"Unknown scope type: '\" + type + \"', For model with resource: '\" + this.resource + \"'\";\n }\n this.scope.declared.push(name);\n return this[name] = builder({\n name: name\n });\n }, {\n data: {},\n then: [],\n fail: [],\n declared: [],\n fetch: function(data, done, fail) {\n var deferred, scope;\n\n if (typeof data === 'function') {\n done = data;\n data = {};\n }\n scope = extend({}, this.scope.data);\n observable.unobserve(scope);\n if (scope.noned != null) {\n deferred = $.Deferred();\n deferred.resolveWith(this, [[]]);\n } else {\n deferred = rest.get.call(this, extend(scope, data));\n }\n deferred.then(util.model.map).done(this.scope.then.concat([done])).fail(this.scope.fail.concat([fail]));\n this.scope.clear();\n return deferred;\n },\n clear: function() {\n this.data = {};\n return this.callbacks = [];\n }\n });\n }),\n base: stampit().state({\n name: 'unamed_scope'\n }),\n record: {\n failed: function(xhr, error, status) {\n var e, message, payload;\n\n payload = xhr.responseJSON;\n try {\n payload || (payload = JSON.parse(xhr.responseText));\n } catch (_error) {\n e = _error;\n }\n payload || (payload = xhr.responseText);\n switch (xhr.status) {\n case 422:\n this.valid = false;\n return this.errors = payload.errors;\n default:\n message = \"Fail in \" + this.resource + \".save:\\n\";\n message += \"Record: \" + this + \"\\n\";\n message += \"Status: \" + status + \" (\" + (payload.status || xhr.status) + \")\\n\";\n message += \"Error : \" + (payload.error || payload.message || payload);\n }\n return console.error(message);\n }\n },\n model: {\n none: function() {\n this.scope.data.noned = true;\n return this;\n },\n fetch: function(data, done, fail) {\n if (typeof data === 'function') {\n done = data;\n data = null;\n }\n return this.scope.fetch.call(this, data, done, fail);\n },\n forward_scopes_to_associations: function() {\n var associated_factory, associated_resource, association, association_name, factory, forwarder, generate_forwarder, scope, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2, _ref3, _ref4;\n\n factory = model[this.resource.name];\n _ref = factory.has_many;\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n association_name = _ref[_i];\n associated_resource = model.singularize(association_name);\n associated_factory = model[associated_resource];\n if (!model[associated_resource]) {\n console.warn(\"Associated factory not found for associated resource: \" + associated_resource);\n continue;\n }\n association = this[association_name];\n association.scope = scopable.builder(association);\n _ref1 = associated_factory.scope.declared;\n for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {\n scope = _ref1[_j];\n association.scope(scope, associated_factory[\"$\" + scope]);\n }\n }\n _ref2 = factory.has_one;\n for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {\n associated_resource = _ref2[_k];\n if (!model[associated_resource]) {\n console.warn(\"Associated factory not found for associated resource: \" + associated_resource);\n continue;\n }\n _ref3 = model[associated_resource].scope.declared;\n for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {\n scope = _ref3[_l];\n this[associated_resource][scope] = factory[scope];\n }\n }\n if (factory.belongs_to.length) {\n generate_forwarder = function(associated_resource) {\n var declared_scopes;\n\n associated_factory = model[associated_resource];\n if (!associated_factory) {\n return console.warn(\"Associated factory not found for associated resource: \" + associated_resource);\n }\n declared_scopes = associated_factory.scope.declared;\n return function() {\n var _len4, _m, _results;\n\n _results = [];\n for (_m = 0, _len4 = declared_scopes.length; _m < _len4; _m++) {\n scope = declared_scopes[_m];\n _results.push(this[associated_resource][scope] = associated_factory[scope]);\n }\n return _results;\n };\n };\n _ref4 = factory.belongs_to;\n for (_m = 0, _len4 = _ref4.length; _m < _len4; _m++) {\n associated_resource = _ref4[_m];\n forwarder = generate_forwarder(associated_resource);\n this.after(\"build_\" + associated_resource, forwarder);\n }\n }\n return true;\n }\n },\n after_mix: function() {\n var name, property, type, _results;\n\n this.scope = scopable.builder(this);\n _results = [];\n for (property in this) {\n type = this[property];\n if (property.charAt(0) === '$') {\n name = property.substring(1);\n _results.push(this.scope(name, type));\n } else {\n _results.push(void 0);\n }\n }\n return _results;\n }\n};\n\nbuilders = {\n string: stampit().enclose(function() {\n var base;\n\n base = scopable.base(this);\n return stampit.mixIn(function() {\n var callbacks, value, _base, _name;\n\n value = arguments[0], callbacks = 2 <= arguments.length ? __slice.call(arguments, 1) : [];\n callbacks.length && (this.scope.then = this.scope.then.concat(callbacks));\n (_base = this.scope.data)[_name = base.name] || (_base[_name] = value != null ? value : this[\"$\" + base.name]);\n return this;\n });\n }),\n boolean: stampit().enclose(function() {\n var base;\n\n base = scopable.base(this);\n return stampit.mixIn(function() {\n var callbacks, value, _base, _name;\n\n value = arguments[0], callbacks = 2 <= arguments.length ? __slice.call(arguments, 1) : [];\n callbacks.length && (this.scope.then = this.scope.then.concat(callbacks));\n (_base = this.scope.data)[_name = base.name] || (_base[_name] = value != null ? value : this[\"$\" + base.name]);\n return this;\n });\n }),\n array: stampit().enclose(function() {\n var base;\n\n base = scopable.base(this);\n return stampit.mixIn(function() {\n var values, _base, _name;\n\n values = 1 <= arguments.length ? __slice.call(arguments, 0) : [];\n (_base = this.scope.data)[_name = base.name] || (_base[_name] = values != null ? values : this[\"$\" + base.name]);\n return this;\n });\n })\n};\n\ndefaults = {\n boolean: true,\n array: []\n};\n\nmodel = window.model;\n\nrecord = window.record;\n\nmodel.scopable = true;\n\nmodel.mix(function(modelable) {\n merge(modelable, scopable.model);\n return modelable.after_mix.push(scopable.after_mix);\n});\n\nif (model.associable) {\n model.mix(function(modelable) {\n return modelable.record.after_initialize.push(function() {\n return scopable.model.forward_scopes_to_associations.call(this);\n });\n });\n model.associable.mix(function(singular_association, plural_association) {\n plural_association.all = plural_association.reload = function(data, done, fail) {\n var promises, reload;\n\n if (this.parent != null) {\n this.route || (this.route = \"\" + this.parent.route + \"/\" + this.parent._id + \"/\" + (model.pluralize(this.resource)));\n }\n promises = [];\n if (typeof data === 'function') {\n done = data;\n data = void 0;\n }\n promises.push(this.scope.fetch.call(this, data, null, scopable.record.failed));\n reload = $.when.apply(jQuery, promises);\n reload.done(function(records, status) {\n var association_name, singular_resource, _i, _j, _len, _len1, _ref;\n\n Array.prototype.splice.call(this, 0);\n if (!records.length) {\n return;\n }\n singular_resource = model.singularize(this.resource);\n for (_i = 0, _len = records.length; _i < _len; _i++) {\n record = records[_i];\n _ref = model[singular_resource].has_many;\n for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {\n association_name = _ref[_j];\n record[\"\" + association_name + \"_attributes\"] = record[association_name];\n delete record[association_name];\n }\n }\n this.add.apply(this, records);\n records.splice(0);\n return records.push.apply(records, this);\n });\n reload.done(done);\n reload.fail(fail);\n return reload;\n };\n return plural_association.each = function(callback) {\n var _this = this;\n\n if (this.parent != null) {\n this.route || (this.route = \"\" + this.parent.route + \"/\" + this.parent._id + \"/\" + (model.pluralize(this.resource)));\n }\n return this.get().done(function(records) {\n var _i, _len, _results;\n\n _results = [];\n for (_i = 0, _len = _this.length; _i < _len; _i++) {\n record = _this[_i];\n _results.push(callback(record));\n }\n return _results;\n });\n };\n });\n}\n//@ sourceURL=indemma/lib/record/scopable.js"
));
require.register("indemma/lib/record/maid.js", Function("exports, require, module",
"var maid, model;\n\nmaid = {\n model: function() {\n if (this.washing != null) {\n return this.record.after_initialize.push(maid.record);\n }\n },\n record: function() {\n return this.subscribe('dirty', function(dirty) {\n var _this = this;\n\n return dirty && setTimeout(function() {\n return _this.save();\n }, 500);\n });\n }\n};\n\nmodel = window.model;\n\nmodel.mix(function(modelable) {\n return modelable.after_mix.unshift(maid.model);\n});\n//@ sourceURL=indemma/lib/record/maid.js"
));
require.register("indemma/lib/record/translationable.js", Function("exports, require, module",
"var extend, extensions, root;\n\nroot = typeof exports !== \"undefined\" && exports !== null ? exports : window;\n\nextend = require('assimilate');\n\nextensions = {\n model: {\n human_attribute_name: function(attribute_name) {\n var _ref, _ref1;\n\n return ((_ref = this.translation) != null ? (_ref1 = _ref.attributes) != null ? _ref1[attribute_name] : void 0 : void 0) || attribute_name;\n }\n }\n};\n\nmodel.mix(function(modelable) {\n return extend(modelable, extensions.model);\n});\n//@ sourceURL=indemma/lib/record/translationable.js"
));
+require.register("indemma/lib/record/validations/validatorable.js", Function("exports, require, module",
+"var stampit;\n\nstampit = require('../../../vendor/stampit');\n\nmodule.exports = stampit({\n validate: function() {\n throw new Error('Composed factory must override the validate method');\n },\n validate_each: function() {\n throw new Error('Composed factory must override the validate each method');\n }\n});\n//@ sourceURL=indemma/lib/record/validations/validatorable.js"
+));
require.register("indemma/lib/record/validations/confirmation.js", Function("exports, require, module",
-"var composed, confirmationable, stampit, validations;\n\nvalidations = require('../validatable');\n\nstampit = require('../../../vendor/stampit');\n\nconfirmationable = stampit({\n validate_each: function(record, attribute, value) {\n if (record[attribute] !== record[\"\" + attribute + \"_confirmation\"]) {\n return record.errors.add(\"\" + attribute + \"_confirmation\", 'confirmation', this.options);\n }\n }\n});\n\ncomposed = stampit.compose(validations.validatable, confirmationable);\n\ncomposed.definition_key = 'validates_confirmation_of';\n\nvalidations.manager.validators.confirmation = composed;\n//@ sourceURL=indemma/lib/record/validations/confirmation.js"
+"var composed, confirmationable, stampit;\n\nstampit = require('../../../vendor/stampit');\n\nconfirmationable = stampit({\n validate_each: function(record, attribute, value) {\n if (record[attribute] !== record[\"\" + attribute + \"_confirmation\"]) {\n return record.errors.add(\"\" + attribute + \"_confirmation\", 'confirmation', this.options);\n }\n }\n});\n\ncomposed = stampit.compose(require('./validatorable'), confirmationable);\n\ncomposed.definition_key = 'validates_confirmation_of';\n\nmodule.exports = composed;\n//@ sourceURL=indemma/lib/record/validations/confirmation.js"
));
require.register("indemma/lib/record/validations/associated.js", Function("exports, require, module",
-"var associationable, composed, stampit, validations;\n\nvalidations = require('../validatable');\n\nstampit = require('../../../vendor/stampit');\n\nassociationable = stampit({\n validate_each: function(record, attribute, value) {\n var associated_validation;\n\n if (record[attribute]) {\n if (model[record.resource].has_one.indexOf(attribute) === -1) {\n throw new Error('Only has_one associations are supported to validates_associated');\n }\n associated_validation = record[attribute].validate();\n associated_validation.done(function() {\n if (record[attribute].errors.length) {\n return record.errors.add(attribute, 'associated', this.options);\n }\n });\n return associated_validation;\n }\n }\n});\n\ncomposed = stampit.compose(validations.validatable, associationable);\n\ncomposed.definition_key = 'validates_associated';\n\nvalidations.manager.validators.association = composed;\n//@ sourceURL=indemma/lib/record/validations/associated.js"
+"var associationable, composed, stampit;\n\nstampit = require('../../../vendor/stampit');\n\nassociationable = stampit({\n validate_each: function(record, attribute, value) {\n var associated_validation;\n\n if (record[attribute]) {\n if (model[record.resource].has_one.indexOf(attribute) === -1) {\n throw new Error('Only has_one associations are supported to validates_associated');\n }\n associated_validation = record[attribute].validate();\n associated_validation.done(function() {\n if (record[attribute].errors.length) {\n return record.errors.add(attribute, 'associated', this.options);\n }\n });\n return associated_validation;\n }\n }\n});\n\ncomposed = stampit.compose(require('./validatorable'), associationable);\n\ncomposed.definition_key = 'validates_associated';\n\nmodule.exports = composed;\n//@ sourceURL=indemma/lib/record/validations/associated.js"
));
require.register("indemma/lib/record/validations/presence.js", Function("exports, require, module",
-"var composed, presenceable, stampit, validations;\n\nvalidations = require('../validatable');\n\nstampit = require('../../../vendor/stampit');\n\npresenceable = stampit({\n validate_each: function(record, attribute, value) {\n if (value === null || value === '' || value === void 0) {\n return record.errors.add(attribute, 'blank', this.options);\n }\n }\n});\n\ncomposed = stampit.compose(validations.validatable, presenceable);\n\ncomposed.definition_key = 'validates_presence_of';\n\nvalidations.manager.validators.presence = composed;\n//@ sourceURL=indemma/lib/record/validations/presence.js"
+"var composed, presenceable, stampit;\n\nstampit = require('../../../vendor/stampit');\n\npresenceable = stampit({\n validate_each: function(record, attribute, value) {\n if (value === null || value === '' || value === void 0) {\n return record.errors.add(attribute, 'blank', this.options);\n }\n }\n});\n\ncomposed = stampit.compose(require('./validatorable'), presenceable);\n\ncomposed.definition_key = 'validates_presence_of';\n\nmodule.exports = composed;\n//@ sourceURL=indemma/lib/record/validations/presence.js"
));
require.register("indemma/lib/record/validations/remote.js", Function("exports, require, module",
-"var composed, remoteable, rest, root, stampit, validations;\n\nroot = typeof exports !== \"undefined\" && exports !== null ? exports : window;\n\nvalidations = require('../validatable');\n\nrest = require('../rest');\n\nstampit = require('../../../vendor/stampit');\n\nremoteable = stampit({\n validate_each: function(record, attribute, value) {\n var data,\n _this = this;\n\n data = this.json(record);\n return this.post(data).done(function(json) {\n return _this.succeeded(json, record);\n });\n },\n json: function(record) {\n var data, param, _base;\n\n param = this.resource.param_name || this.resource.toString();\n data = {};\n data[param] = record.json();\n (_base = data[param]).id || (_base.id = data[param]._id);\n delete data[param]._id;\n return data;\n },\n post: function(data) {\n return jQuery.ajax({\n url: this.route,\n data: data,\n type: 'post',\n dataType: 'json',\n context: this\n });\n },\n succeeded: function(json, record) {\n var error_message, error_messages, _i, _len, _results;\n\n error_messages = json[this.attribute_name];\n if (!error_messages) {\n return;\n }\n _results = [];\n for (_i = 0, _len = error_messages.length; _i < _len; _i++) {\n error_message = error_messages[_i];\n _results.push(record.errors.add(this.attribute_name, 'server', {\n server_message: error_message\n }));\n }\n return _results;\n }\n}, {\n message: \"Remote validation failed\",\n route: null\n}, function() {\n var pluralized_resource;\n\n pluralized_resource = model.pluralize(this.model.resource.toString());\n this.resource = this.model.resource;\n this.route || (this.route = \"/\" + pluralized_resource + \"/validate\");\n return this;\n});\n\ncomposed = stampit.compose(validations.validatable, remoteable);\n\ncomposed.definition_key = 'validates_remotely';\n\nvalidations.manager.validators.remote = composed;\n//@ sourceURL=indemma/lib/record/validations/remote.js"
+"var composed, remoteable, rest, stampit;\n\nrest = require('../rest');\n\nstampit = require('../../../vendor/stampit');\n\nremoteable = stampit({\n validate_each: function(record, attribute, value) {\n var data,\n _this = this;\n\n data = this.json(record);\n return this.post(data).done(function(json) {\n return _this.succeeded(json, record);\n });\n },\n json: function(record) {\n var data, param, _base;\n\n param = this.resource.param_name || this.resource.toString();\n data = {};\n data[param] = record.json();\n (_base = data[param]).id || (_base.id = data[param]._id);\n delete data[param]._id;\n return data;\n },\n post: function(data) {\n return jQuery.ajax({\n url: this.route,\n data: data,\n type: 'post',\n dataType: 'json',\n context: this\n });\n },\n succeeded: function(json, record) {\n var error_message, error_messages, _i, _len, _results;\n\n error_messages = json[this.attribute_name];\n if (!error_messages) {\n return;\n }\n _results = [];\n for (_i = 0, _len = error_messages.length; _i < _len; _i++) {\n error_message = error_messages[_i];\n _results.push(record.errors.add(this.attribute_name, 'server', {\n server_message: error_message\n }));\n }\n return _results;\n }\n}, {\n message: \"Remote validation failed\",\n route: null\n}, function() {\n var pluralized_resource;\n\n pluralized_resource = model.pluralize(this.model.resource.toString());\n this.resource = this.model.resource;\n this.route || (this.route = \"/\" + pluralized_resource + \"/validate\");\n return this;\n});\n\ncomposed = stampit.compose(require('./validatorable'), remoteable);\n\ncomposed.definition_key = 'validates_remotely';\n\nmodule.exports = composed;\n//@ sourceURL=indemma/lib/record/validations/remote.js"
));
require.register("indemma/lib/record/validations/type.js", Function("exports, require, module",
-"var composed, stampit, typeable, validations;\n\nvalidations = require('../validatable');\n\nstampit = require('../../../vendor/stampit');\n\ntypeable = stampit({\n validate_each: function(record, attribute, value) {\n this.type || (this.type = model[record.resource.toString()][attribute]);\n if (value) {\n if (value instanceof this.type) {\n this.type_name || (this.type_name = this.type.name);\n if (!value.valid) {\n return record.errors.add(attribute, 'type', {\n type_name: this.type_name != null\n });\n }\n } else {\n throw new Error(\"Invalid attribute value type! Found \" + (typeof value) + \" expected \" + this.type.name);\n }\n }\n }\n});\n\ncomposed = stampit.compose(validations.validatable, typeable);\n\ncomposed.definition_key = 'validates_type_of';\n\nvalidations.manager.validators.type = composed;\n//@ sourceURL=indemma/lib/record/validations/type.js"
+"var composed, stampit, typeable, validations;\n\nvalidations = require('../validatable');\n\nstampit = require('../../../vendor/stampit');\n\ntypeable = stampit({\n validate_each: function(record, attribute, value) {\n this.type || (this.type = model[record.resource.toString()][attribute]);\n if (value) {\n if (value instanceof this.type) {\n this.type_name || (this.type_name = this.type.name);\n if (!value.valid) {\n return record.errors.add(attribute, 'type', {\n type_name: this.type_name != null\n });\n }\n } else {\n throw new Error(\"Invalid attribute value type! Found \" + (typeof value) + \" expected \" + this.type.name);\n }\n }\n }\n});\n\ncomposed = stampit.compose(require('./validatorable'), typeable);\n\ncomposed.definition_key = 'validates_type_of';\n\nmodule.exports = composed;\n//@ sourceURL=indemma/lib/record/validations/type.js"
));
require.register("indemma/lib/record/validations/cpf.js", Function("exports, require, module",
-"var composed, cpfable, stampit, validations;\n\nvalidations = require('../validatable');\n\nstampit = require('../../../vendor/stampit');\n\ncpfable = stampit({\n validate_format: function(value) {\n var c, d1, dv, i, v, _i, _j;\n\n value = value.replace(/[\\.\\-]/g, \"\");\n if (value.length < 11) {\n return false;\n }\n if (value.match(/^(0+|1+|2+|3+|4+|5+|6+|7+|8+|9+)$/)) {\n return false;\n }\n c = value.substr(0, 9);\n dv = value.substr(9, 2);\n d1 = 0;\n v = false;\n i = 0;\n for (i = _i = 1; _i <= 9; i = ++_i) {\n d1 += c.charAt(i) * (10 - i);\n }\n if (d1 === 0) {\n return false;\n }\n d1 = 11 - (d1 % 11);\n if (d1 > 9) {\n d1 = 0;\n }\n if (+dv.charAt(0) !== d1) {\n return false;\n }\n d1 *= 2;\n for (i = _j = 1; _j <= 9; i = ++_j) {\n d1 += c.charAt(i) * (11 - i);\n }\n d1 = 11 - (d1 % 11);\n if (d1 > 9) {\n d1 = 0;\n }\n if (+dv.charAt(1) !== d1) {\n return false;\n }\n return true;\n },\n validate_each: function(record, attribute, value) {\n if (value && !this.validate_format(value)) {\n return record.errors.add(attribute, 'cpf', this.options);\n }\n }\n});\n\ncomposed = stampit.compose(validations.validatable, cpfable);\n\ncomposed.definition_key = 'validates_cpf_format';\n\nvalidations.manager.validators.cpf = composed;\n//@ sourceURL=indemma/lib/record/validations/cpf.js"
+"var composed, cpfable, stampit;\n\nstampit = require('../../../vendor/stampit');\n\ncpfable = stampit({\n validate_format: function(value) {\n var c, d1, dv, i, v, _i, _j;\n\n value = value.replace(/[\\.\\-]/g, \"\");\n if (value.length < 11) {\n return false;\n }\n if (value.match(/^(0+|1+|2+|3+|4+|5+|6+|7+|8+|9+)$/)) {\n return false;\n }\n c = value.substr(0, 9);\n dv = value.substr(9, 2);\n d1 = 0;\n v = false;\n i = 0;\n for (i = _i = 0; _i <= 9; i = ++_i) {\n d1 += c.charAt(i) * (10 - i);\n }\n if (d1 === 0) {\n return false;\n }\n d1 = 11 - (d1 % 11);\n if (d1 > 9) {\n d1 = 0;\n }\n if (+dv.charAt(0) !== d1) {\n return false;\n }\n d1 *= 2;\n for (i = _j = 0; _j <= 9; i = ++_j) {\n d1 += c.charAt(i) * (11 - i);\n }\n d1 = 11 - (d1 % 11);\n if (d1 > 9) {\n d1 = 0;\n }\n if (+dv.charAt(1) !== d1) {\n return false;\n }\n return true;\n },\n validate_each: function(record, attribute, value) {\n if (value && !this.validate_format(value)) {\n return record.errors.add(attribute, 'cpf', this.options);\n }\n }\n});\n\ncomposed = stampit.compose(require('./validatorable'), cpfable);\n\ncomposed.definition_key = 'validates_cpf_format';\n\nmodule.exports = composed;\n//@ sourceURL=indemma/lib/record/validations/cpf.js"
));
require.register("indemma/lib/record/validatable.js", Function("exports, require, module",
-"var errorsable, extensions, initializers, manager, messages, observable, root, stampit, type, validatable;\n\nrequire('./translationable');\n\nroot = typeof exports !== \"undefined\" && exports !== null ? exports : window;\n\nstampit = require('../../vendor/stampit');\n\nobservable = require('observable').mixin;\n\ntype = require('type');\n\nmessages = {\n blank: function(attribute_name) {\n attribute_name = this.human_attribute_name(attribute_name);\n return \"O campo \" + attribute_name + \" não pode ficar em branco.\";\n },\n cpf: function(attribute_name) {\n attribute_name = this.human_attribute_name(attribute_name);\n return \"O campo \" + attribute_name + \" não está válido.\";\n },\n confirmation: function(attribute_name) {\n var confirmation_attribute_name;\n\n confirmation_attribute_name = this.human_attribute_name(attribute_name);\n attribute_name = this.human_attribute_name(attribute_name.replace('_confirmation', ''));\n return \"O campo \" + attribute_name + \" não está de acordo com o campo \" + confirmation_attribute_name + \".\";\n },\n associated: function(attribute_name) {\n attribute_name = this.human_attribute_name(attribute_name);\n return \"O registro associado \" + attribute_name + \" não é válido.\";\n },\n server: function(attribute_name, options) {\n if (attribute_name === 'base') {\n return options.server_message;\n } else {\n attribute_name = this.human_attribute_name(attribute_name);\n return \"\" + attribute_name + \" \" + options.server_message + \".\";\n }\n },\n type: function(attribute_name, options) {\n attribute_name = this.human_attribute_name(attribute_name);\n return \"O campo \" + attribute_name + \" não está válido.\";\n }\n};\n\nerrorsable = stampit({\n add: function(attribute_name, message_key, options) {\n var translator;\n\n this.push([attribute_name, message_key, options]);\n this.messages[attribute_name] = '';\n translator = messages[message_key];\n if (translator != null) {\n return this.messages[attribute_name] += translator.call(this.model, attribute_name, options);\n } else {\n return this.messages[attribute_name] += message_key;\n }\n },\n clear: function() {\n var attribute_name, _results;\n\n if (this.length) {\n this.length = 0;\n _results = [];\n for (attribute_name in this.messages) {\n _results.push(this.messages[attribute_name] = null);\n }\n return _results;\n }\n },\n push: Array.prototype.push,\n splice: Array.prototype.splice,\n indexOf: Array.prototype.indexOf\n}, {\n model: null,\n messages: null,\n length: 0\n}, function() {\n this.messages = {};\n return this;\n});\n\ninitializers = {\n define_triggers: function() {\n this.errors = errorsable({\n model: model[this.resource]\n });\n this.before('save', function() {\n if (this.save) {\n return this.validate();\n }\n });\n this.validated = false;\n this.subscribe('dirty', function(value) {\n return this.validated = false;\n });\n return Object.defineProperty(this, 'valid', {\n get: function() {\n this.validate();\n if (this.validation.state() === 'resolved') {\n return !this.errors.length;\n } else {\n return null;\n }\n },\n set: function() {\n throw new TypeError(\"You can't set the value for the valid property.\");\n },\n enumerable: false\n });\n },\n create_validators: function(definitions) {\n var definition, name, validator, validator_options, _ref, _results;\n\n this.validators = [];\n _ref = manager.validators;\n _results = [];\n for (name in _ref) {\n validator = _ref[name];\n definition = definitions[validator.definition_key];\n if (definition) {\n if (type(definition) !== 'array') {\n definition = [definition];\n }\n _results.push((function() {\n var _i, _len, _results1;\n\n _results1 = [];\n for (_i = 0, _len = definition.length; _i < _len; _i++) {\n validator_options = definition[_i];\n if (type(validator_options) !== 'object') {\n validator_options = {\n attribute_name: validator_options\n };\n }\n validator_options.model = this;\n this.validators.push(validator(validator_options));\n _results1.push(delete definitions[validator.definition_key]);\n }\n return _results1;\n }).call(this));\n } else {\n _results.push(void 0);\n }\n }\n return _results;\n }\n};\n\nextensions = {\n model: {\n validators: null\n },\n record: {\n validate_attribute: function(attribute, doned, failed) {\n var results, validation, validator, _i, _len, _ref;\n\n this.errors.messages[attribute] = null;\n results = [this, attribute];\n _ref = model[this.resource.toString()].validators;\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n validator = _ref[_i];\n if (validator.attribute_name === attribute) {\n results.push(validator.validate_each(this, validator.attribute_name, this[validator.attribute_name]));\n }\n }\n validation = jQuery.when.apply(jQuery, results);\n validation.done(doned);\n validation.fail(failed);\n return validation;\n },\n validate: function(doned, failed) {\n var results, validator, _i, _len, _ref;\n\n if (this.validated && !this.dirty) {\n return this.validation;\n }\n this.errors.clear();\n results = [this];\n _ref = model[this.resource.toString()].validators;\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n validator = _ref[_i];\n results.push(validator.validate_each(this, validator.attribute_name, this[validator.attribute_name]));\n }\n this.validation = jQuery.when.apply(jQuery, results);\n this.validation.done(doned);\n this.validation.fail(failed);\n this.validation.then(function(record) {\n return record.validated = true;\n });\n return this.validation;\n }\n }\n};\n\nmanager = {\n validators: {}\n};\n\nvalidatable = stampit({\n validate: function() {\n throw new Error('Composed factory must override the validate method');\n },\n validate_each: function() {\n throw new Error('Composed factory must override the validate each method');\n }\n});\n\nmodel.mix(function(modelable) {\n jQuery.extend(modelable, extensions.model);\n jQuery.extend(modelable.record, extensions.record);\n modelable.after_mix.unshift(initializers.create_validators);\n modelable.record.after_initialize.push(initializers.define_triggers);\n return model.validators = manager.validators;\n});\n\nroot.validatable = validatable;\n\nroot.manager = manager;\n\nrequire('./validations/confirmation');\n\nrequire('./validations/associated');\n\nrequire('./validations/presence');\n\nrequire('./validations/remote');\n\nrequire('./validations/type');\n\nrequire('./validations/cpf');\n//@ sourceURL=indemma/lib/record/validatable.js"
+"var errorsable, extensions, initializers, manager, messages, observable, root, stampit, type;\n\nrequire('./translationable');\n\nroot = typeof exports !== \"undefined\" && exports !== null ? exports : this;\n\nstampit = require('../../vendor/stampit');\n\nobservable = require('observable').mixin;\n\ntype = require('type');\n\nmessages = {\n blank: function(attribute_name) {\n attribute_name = this.human_attribute_name(attribute_name);\n return \"O campo \" + attribute_name + \" não pode ficar em branco.\";\n },\n cpf: function(attribute_name) {\n attribute_name = this.human_attribute_name(attribute_name);\n return \"O campo \" + attribute_name + \" não está válido.\";\n },\n confirmation: function(attribute_name) {\n var confirmation_attribute_name;\n\n confirmation_attribute_name = this.human_attribute_name(attribute_name);\n attribute_name = this.human_attribute_name(attribute_name.replace('_confirmation', ''));\n return \"O campo \" + attribute_name + \" não está de acordo com o campo \" + confirmation_attribute_name + \".\";\n },\n associated: function(attribute_name) {\n attribute_name = this.human_attribute_name(attribute_name);\n return \"O registro associado \" + attribute_name + \" não é válido.\";\n },\n server: function(attribute_name, options) {\n if (attribute_name === 'base') {\n return options.server_message;\n } else {\n attribute_name = this.human_attribute_name(attribute_name);\n return \"\" + attribute_name + \" \" + options.server_message + \".\";\n }\n },\n type: function(attribute_name, options) {\n attribute_name = this.human_attribute_name(attribute_name);\n return \"O campo \" + attribute_name + \" não está válido.\";\n }\n};\n\nerrorsable = stampit({\n add: function(attribute_name, message_key, options) {\n var translator;\n\n this.push([attribute_name, message_key, options]);\n this.messages[attribute_name] = '';\n translator = messages[message_key];\n if (translator != null) {\n return this.messages[attribute_name] += translator.call(this.model, attribute_name, options);\n } else {\n return this.messages[attribute_name] += message_key;\n }\n },\n clear: function() {\n var attribute_name, _results;\n\n if (this.length) {\n this.length = 0;\n _results = [];\n for (attribute_name in this.messages) {\n _results.push(this.messages[attribute_name] = null);\n }\n return _results;\n }\n },\n push: Array.prototype.push,\n splice: Array.prototype.splice,\n indexOf: Array.prototype.indexOf\n}, {\n model: null,\n messages: null,\n length: 0\n}, function() {\n this.messages = {};\n return this;\n});\n\ninitializers = {\n define_triggers: function() {\n this.errors = errorsable({\n model: model[this.resource]\n });\n this.before('save', function() {\n if (this.save) {\n return this.validate();\n }\n });\n this.validated = false;\n this.subscribe('dirty', function(value) {\n return value && (this.validated = false);\n });\n return Object.defineProperty(this, 'valid', {\n get: function() {\n this.validate();\n if (this.validation.state() === 'resolved') {\n return !this.errors.length;\n } else {\n return null;\n }\n },\n set: function() {\n throw new TypeError(\"You can't set the value for the valid property.\");\n },\n enumerable: false\n });\n },\n create_validators: function(definitions) {\n var definition, name, validator, validator_options, _ref, _results;\n\n this.validators = [];\n _ref = manager.validators;\n _results = [];\n for (name in _ref) {\n validator = _ref[name];\n definition = definitions[validator.definition_key];\n if (definition) {\n if (type(definition) !== 'array') {\n definition = [definition];\n }\n _results.push((function() {\n var _i, _len, _results1;\n\n _results1 = [];\n for (_i = 0, _len = definition.length; _i < _len; _i++) {\n validator_options = definition[_i];\n if (type(validator_options) !== 'object') {\n validator_options = {\n attribute_name: validator_options\n };\n }\n validator_options.model = this;\n this.validators.push(validator(validator_options));\n _results1.push(delete definitions[validator.definition_key]);\n }\n return _results1;\n }).call(this));\n } else {\n _results.push(void 0);\n }\n }\n return _results;\n }\n};\n\nextensions = {\n model: {\n validators: null\n },\n record: {\n validate_attribute: function(attribute, doned, failed) {\n var results, validation, validator, _i, _len, _ref;\n\n this.errors.messages[attribute] = null;\n results = [this, attribute];\n _ref = model[this.resource.toString()].validators;\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n validator = _ref[_i];\n if (validator.attribute_name === attribute) {\n results.push(validator.validate_each(this, validator.attribute_name, this[validator.attribute_name]));\n }\n }\n validation = jQuery.when.apply(jQuery, results);\n validation.done(doned);\n validation.fail(failed);\n return validation;\n },\n validate: function(doned, failed) {\n var results, validator, _i, _len, _ref;\n\n if (this.validated && !this.dirty) {\n return this.validation;\n }\n this.errors.clear();\n results = [this];\n _ref = model[this.resource.toString()].validators;\n for (_i = 0, _len = _ref.length; _i < _len; _i++) {\n validator = _ref[_i];\n results.push(validator.validate_each(this, validator.attribute_name, this[validator.attribute_name]));\n }\n this.validation = jQuery.when.apply(jQuery, results);\n this.validation.done(doned);\n this.validation.fail(failed);\n this.validation.then(function(record) {\n var old_dirty;\n\n old_dirty = record.dirty;\n record.dirty = null;\n record.validated || (record.validated = true);\n return record.dirty = old_dirty;\n });\n return this.validation;\n }\n }\n};\n\nmanager = {\n validators: {}\n};\n\nmodel.mix(function(modelable) {\n jQuery.extend(modelable, extensions.model);\n jQuery.extend(modelable.record, extensions.record);\n modelable.after_mix.unshift(initializers.create_validators);\n modelable.record.after_initialize.push(initializers.define_triggers);\n return model.validators = manager.validators;\n});\n\nmanager.validators.confirmation = require('./validations/confirmation');\n\nmanager.validators.associated = require('./validations/associated');\n\nmanager.validators.presence = require('./validations/presence');\n\nmanager.validators.remote = require('./validations/remote');\n\nmanager.validators.type = require('./validations/type');\n\nmanager.validators.cpf = require('./validations/cpf');\n//@ sourceURL=indemma/lib/record/validatable.js"
));
require.register("indemma/lib/extensions/rivets.js", Function("exports, require, module",
"var root;\n\nroot = typeof exports !== \"undefined\" && exports !== null ? exports : this;\n\nmodel.rivets = function() {\n var model_extensions;\n\n model_extensions = {\n record: {\n tie: function(element) {\n var lasso;\n\n lasso = {};\n lasso[this.resource] = this;\n return rivets.bind(element, lasso);\n }\n },\n preloadData: true\n };\n return model.mix(function(modelable) {\n return $.extend(true, modelable, model_extensions);\n });\n};\n//@ sourceURL=indemma/lib/extensions/rivets.js"
));
require.alias("pluma-assimilate/dist/assimilate.js", "indemma/deps/assimilate/dist/assimilate.js");