vendor/components/indefinido-indemma/build/test.js in ende-0.4.10 vs vendor/components/indefinido-indemma/build/test.js in ende-0.4.11

- old
+ new

@@ -267,10 +267,10 @@ )); require.register("indemma/lib/record/resource.js", Function("exports, require, module", "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" +"var $, data_for, 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\ndata_for = function() {\n var data, 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 data;\n};\n\nrequest = function(method, url, data) {\n data = data_for.call(this, data);\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, 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 every: 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.every(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 e, name, property, serialized;\n\n serialized = {};\n serialized[this.resource] = this.json();\n try {\n return JSON.stringify(serialized);\n } catch (_error) {\n e = _error;\n console.warn(\"restfulable.toString: Failed to stringify record: \" + e.message + \". retrying...\");\n for (name in serialized) {\n property = serialized[name];\n if (typeof property === 'object') {\n delete serialized[name];\n }\n }\n return JSON.stringify(serialized);\n }\n },\n json: function(methods) {\n var definition, json, name, nature, nested, value;\n\n if (methods == null) {\n methods = {};\n }\n json = {};\n definition = model[this.resource.toString()];\n for (name in this) {\n if (observable.ignores.indexOf(name) !== -1) {\n continue;\n }\n nested = this.nested_attributes.indexOf(name) !== -1;\n if (!nested && (definition.belongs_to.indexOf(name) !== -1 || definition.has_one.indexOf(name) !== -1 || definition.has_many.indexOf(name) !== -1)) {\n continue;\n }\n value = this[name];\n if (value == null) {\n continue;\n }\n nature = type(value);\n if (nature === 'function') {\n continue;\n }\n if (nature === 'object' || nature === 'element') {\n if (nested) {\n if (!value.json) {\n console.warn(\"json: Tryied to serialize nested attribute '\" + name + \"' without serialization method!\");\n continue;\n }\n json[\"\" + name + \"_attributes\"] = value.json(methods[name]);\n } else if ((value.toJSON != null) || (value.json != null)) {\n if (value.resource) {\n continue;\n }\n if (value.json != null) {\n json[name] = value.json(methods[name]);\n } else {\n json[name] = value.toJSON(methods[name]);\n }\n } else {\n continue;\n }\n } else {\n json[name] = value;\n }\n }\n json = 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 delete json.errors;\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",