ende 0.4.7 → 0.4.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/lib/assets/javascripts/aura/extensions/states.js.coffee +19 -10
  3. data/lib/assets/javascripts/config/load_components.js.coffee +12 -6
  4. data/lib/assets/javascripts/widgets/content/main.js.coffee +2 -0
  5. data/lib/assets/javascripts/widgets/list/main.js.coffee +1 -1
  6. data/lib/assets/javascripts/widgets/viewer/main.js.coffee +1 -1
  7. data/lib/ende/version.rb +1 -1
  8. data/vendor/assets/components/build.js +32401 -0
  9. data/vendor/assets/components/ende_build.js +33 -13
  10. data/vendor/components/indefinido-indemma/Readme.md +2 -2
  11. data/vendor/components/indefinido-indemma/build/development.js +4 -4
  12. data/vendor/components/indefinido-indemma/build/release.js +15 -8
  13. data/vendor/components/indefinido-indemma/build/test.js +4 -4
  14. data/vendor/components/indefinido-indemma/lib/record/queryable.js +1 -1
  15. data/vendor/components/indefinido-indemma/lib/record/restfulable.js +12 -5
  16. data/vendor/components/indefinido-indemma/lib/record/scopable.js +1 -1
  17. data/vendor/components/indefinido-indemma/lib/record.js +1 -1
  18. data/vendor/components/indefinido-indemma/spec/record/scopable_spec.js +1 -1
  19. data/vendor/components/indefinido-indemma/src/lib/record/queryable.coffee +1 -1
  20. data/vendor/components/indefinido-indemma/src/lib/record/restfulable.coffee +16 -4
  21. data/vendor/components/indefinido-indemma/src/lib/record/scopable.coffee +1 -1
  22. data/vendor/components/indefinido-indemma/src/lib/record.coffee +1 -1
  23. data/vendor/components/indefinido-indemma/src/spec/record/scopable_spec.coffee +1 -1
  24. data/vendor/components/indefinido-observable/lib/observable.js +1 -1
  25. data/vendor/components/indefinido-observable/vendor/shims/accessors.js +17 -4
  26. metadata +3 -2
@@ -18407,7 +18407,7 @@ this.model = (function() {
18407
18407
  after_initialize: [],
18408
18408
  before_initialize: []
18409
18409
  },
18410
- all: function() {
18410
+ every: function() {
18411
18411
  return this.cache;
18412
18412
  },
18413
18413
  create: function() {
@@ -19030,7 +19030,7 @@ queryable = {
19030
19030
  }
19031
19031
  return this.storage.store(key);
19032
19032
  },
19033
- all: function() {
19033
+ every: function() {
19034
19034
  return this.storage.values();
19035
19035
  },
19036
19036
  where: function() {
@@ -19253,7 +19253,7 @@ restful = {
19253
19253
  }
19254
19254
  return $.when.apply($, savings);
19255
19255
  },
19256
- all: function(conditions, doned, failed) {
19256
+ every: function(conditions, doned, failed) {
19257
19257
  if (conditions == null) {
19258
19258
  conditions = {};
19259
19259
  }
@@ -19276,7 +19276,7 @@ restful = {
19276
19276
  namespaced = conditions[this.resource] || {};
19277
19277
  namespaced.limit = 1;
19278
19278
  namespaced.order = 'desc';
19279
- return this.all(conditions, callback);
19279
+ return this.every(conditions, callback);
19280
19280
  },
19281
19281
  get: function(action, data) {
19282
19282
  var default_route, old_route, payload, promise, resource;
@@ -19540,7 +19540,7 @@ restful = {
19540
19540
  }
19541
19541
  },
19542
19542
  json: function(methods) {
19543
- var definition, json, name, nested, value;
19543
+ var definition, json, name, nature, nested, value;
19544
19544
 
19545
19545
  if (methods == null) {
19546
19546
  methods = {};
@@ -19559,11 +19559,16 @@ restful = {
19559
19559
  if (value == null) {
19560
19560
  continue;
19561
19561
  }
19562
- if (type(value) === 'function') {
19562
+ nature = type(value);
19563
+ if (nature === 'function') {
19563
19564
  continue;
19564
19565
  }
19565
- if (type(value) === 'object') {
19566
+ if (nature === 'object' || nature === 'element') {
19566
19567
  if (nested) {
19568
+ if (!value.json) {
19569
+ console.warn("json: Tryied to serialize nested attribute '" + name + "' without serialization method!");
19570
+ continue;
19571
+ }
19567
19572
  json["" + name + "_attributes"] = value.json(methods[name]);
19568
19573
  } else if ((value.toJSON != null) || (value.json != null)) {
19569
19574
  if (value.resource) {
@@ -19574,6 +19579,8 @@ restful = {
19574
19579
  } else {
19575
19580
  json[name] = value.toJSON(methods[name]);
19576
19581
  }
19582
+ } else {
19583
+ continue;
19577
19584
  }
19578
19585
  } else {
19579
19586
  json[name] = value;
@@ -19908,7 +19915,7 @@ if (model.associable) {
19908
19915
  });
19909
19916
  });
19910
19917
  model.associable.mix(function(singular_association, plural_association) {
19911
- plural_association.all = plural_association.reload = function(data, done, fail) {
19918
+ plural_association.every = plural_association.reload = function(data, done, fail) {
19912
19919
  var promises, reload;
19913
19920
 
19914
19921
  if (this.parent != null) {
@@ -24937,7 +24944,7 @@ if (requiresDomElement) {
24937
24944
  else document.body.appendChild(fix);
24938
24945
 
24939
24946
  // Replace object with dom node
24940
- object = fix;
24947
+ object = $.extend(fix, object);
24941
24948
  }
24942
24949
 
24943
24950
  // Observe element if it is not observed
@@ -25240,10 +25247,12 @@ require.register("indefinido-observable/vendor/shims/accessors.js", function(exp
25240
25247
  hasOwnProp = ObjectProto.hasOwnProperty,
25241
25248
  getProp = Object.getOwnPropertyDescriptor,
25242
25249
  defineProp = Object.defineProperty,
25250
+ objectCreate = Object.create,
25243
25251
  toStrings = [],
25244
25252
  features = null,
25245
25253
  stack = [], detach,
25246
- prototypeBase = [Object, String, Array, Function, Boolean, Number, RegExp, Date, Error];
25254
+ fixedOwnProperty,
25255
+ prototypeBase = [Object, String, Array, Function, Boolean, Number, RegExp, Date, Error];
25247
25256
 
25248
25257
  // IE7 Does not have Element and Window defined, so only add them if
25249
25258
  // they exists check here
@@ -25397,8 +25406,12 @@ require.register("indefinido-observable/vendor/shims/accessors.js", function(exp
25397
25406
  }
25398
25407
  };
25399
25408
 
25400
- ObjectCreate = Object.create;
25401
- baseElement = document.createElement('fix');
25409
+ baseElement = document.createElement('fix');
25410
+ fixedOwnProperty = function (name) {
25411
+ if (name in baseElement) return false;
25412
+ return hasOwnProp.call(this, name);
25413
+ };
25414
+
25402
25415
 
25403
25416
  Object.create = function (prototype, properties) {
25404
25417
  var complexDescriptor, fix, descriptor, name;
@@ -25431,13 +25444,20 @@ require.register("indefinido-observable/vendor/shims/accessors.js", function(exp
25431
25444
  }
25432
25445
  }
25433
25446
 
25447
+ // Ensure most normalized for loops to work property, by
25448
+ // skiping the dom element properties on own property
25449
+ // checking.
25450
+ //
25451
+ // TODO ensure other own property methods checking
25452
+ fix.hasOwnProperty = fixedOwnProperty
25453
+
25434
25454
  Object.defineProperties(fix, properties);
25435
25455
  } else {
25436
25456
  throw new TypeError('Functions with complex descriptors not implemented yet');
25437
25457
  }
25438
25458
  return fix;
25439
25459
  } else {
25440
- return ObjectCreate(prototype, properties)
25460
+ return objectCreate(prototype, properties)
25441
25461
  }
25442
25462
  }
25443
25463
  };
@@ -4,7 +4,7 @@ indemma
4
4
 
5
5
  Indemma (mind picture → memory), client side, ES5 observable and REST, extensible modular data model.
6
6
 
7
- Current version 0.1.0
7
+ Current version 0.1.9
8
8
 
9
9
  Summary
10
10
  -------
@@ -52,7 +52,7 @@ Basic functionality: Just a copy of [ActiveRecord Interface](https://github.com/
52
52
 
53
53
  person.find(1) // {name: "Arthur Philip Dent", subscribe: ..., before: ..., after: ..., ... }
54
54
 
55
- person.all() // [{name: "Arthur Philip Dent", subscribe: ..., ... }, {name: "Ford Perfect", subscribe: ..., ... }]
55
+ person.every() // [{name: "Arthur Philip Dent", subscribe: ..., ... }, {name: "Ford Perfect", subscribe: ..., ... }]
56
56
 
57
57
  // TODO active record interface like: person.where(attribute: value)
58
58
  ```
@@ -251,7 +251,7 @@ require.register("indemma/vendor/owl/pluralize.js", Function("exports, require,
251
251
  "/* This file is part of OWL Pluralization.\r\n\r\nOWL Pluralization is free software: you can redistribute it and/or \r\nmodify it under the terms of the GNU Lesser General Public License\r\nas published by the Free Software Foundation, either version 3 of\r\nthe License, or (at your option) any later version.\r\n\r\nOWL Pluralization is distributed in the hope that it will be useful,\r\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\r\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r\nGNU Lesser General Public License for more details.\r\n\r\nYou should have received a copy of the GNU Lesser General Public \r\nLicense along with OWL Pluralization. If not, see \r\n<http://www.gnu.org/licenses/>.\r\n*/\r\n\r\n// prepare the owl namespace.\r\nif ( typeof owl === 'undefined' ) owl = {};\r\n\r\nowl.pluralize = (function() {\r\n\tvar userDefined = {};\r\n\r\n\tfunction capitalizeSame(word, sampleWord) {\r\n\t\tif ( sampleWord.match(/^[A-Z]/) ) {\r\n\t\t\treturn word.charAt(0).toUpperCase() + word.slice(1);\r\n\t\t} else {\r\n\t\t\treturn word;\r\n\t\t}\r\n\t}\r\n\r\n\t// returns a plain Object having the given keys,\r\n\t// all with value 1, which can be used for fast lookups.\r\n\tfunction toKeys(keys) {\r\n\t\tkeys = keys.split(',');\r\n\t\tvar keysLength = keys.length;\r\n\t\tvar table = {};\r\n\t\tfor ( var i=0; i < keysLength; i++ ) {\r\n\t\t\ttable[ keys[i] ] = 1;\r\n\t\t}\r\n\t\treturn table;\r\n\t}\r\n\r\n\t// words that are always singular, always plural, or the same in both forms.\r\n\tvar uninflected = toKeys(\"aircraft,advice,blues,corn,molasses,equipment,gold,information,cotton,jewelry,kin,legislation,luck,luggage,moose,music,offspring,rice,silver,trousers,wheat,bison,bream,breeches,britches,carp,chassis,clippers,cod,contretemps,corps,debris,diabetes,djinn,eland,elk,flounder,gallows,graffiti,headquarters,herpes,high,homework,innings,jackanapes,mackerel,measles,mews,mumps,news,pincers,pliers,proceedings,rabies,salmon,scissors,sea,series,shears,species,swine,trout,tuna,whiting,wildebeest,pike,oats,tongs,dregs,snuffers,victuals,tweezers,vespers,pinchers,bellows,cattle\");\r\n\r\n\tvar irregular = {\r\n\t\t// pronouns\r\n\t\tI: 'we',\r\n\t\tyou: 'you',\r\n\t\the: 'they',\r\n\t\tit: 'they', // or them\r\n\t\tme: 'us',\r\n\t\tyou: 'you',\r\n\t\thim: 'them',\r\n\t\tthem: 'them',\r\n\t\tmyself: 'ourselves',\r\n\t\tyourself: 'yourselves',\r\n\t\thimself: 'themselves',\r\n\t\therself: 'themselves',\r\n\t\titself: 'themselves',\r\n\t\tthemself: 'themselves',\r\n\t\toneself: 'oneselves',\r\n\r\n\t\tchild: 'children',\r\n\t\tdwarf: 'dwarfs', // dwarfs are real; dwarves are fantasy.\r\n\t\tmongoose: 'mongooses',\r\n\t\tmythos: 'mythoi',\r\n\t\tox: 'oxen',\r\n\t\tsoliloquy: 'soliloquies',\r\n\t\ttrilby: 'trilbys',\r\n\t\tperson: 'people',\r\n\t\tforum: 'forums', // fora is ok but uncommon.\r\n\r\n\t\t// latin plural in popular usage.\r\n\t\tsyllabus: 'syllabi',\r\n\t\talumnus: 'alumni', \r\n\t\tgenus: 'genera',\r\n\t\tviscus: 'viscera',\r\n\t\tstigma: 'stigmata'\r\n\t};\r\n\r\n\tvar suffixRules = [\r\n\t\t// common suffixes\r\n\t\t[ /man$/i, 'men' ],\r\n\t\t[ /([lm])ouse$/i, '$1ice' ],\r\n\t\t[ /tooth$/i, 'teeth' ],\r\n\t\t[ /goose$/i, 'geese' ],\r\n\t\t[ /foot$/i, 'feet' ],\r\n\t\t[ /zoon$/i, 'zoa' ],\r\n\t\t[ /([tcsx])is$/i, '$1es' ],\r\n\r\n\t\t// fully assimilated suffixes\r\n\t\t[ /ix$/i, 'ices' ],\r\n\t\t[ /^(cod|mur|sil|vert)ex$/i, '$1ices' ],\r\n\t\t[ /^(agend|addend|memorand|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi)um$/i, '$1a' ],\r\n\t\t[ /^(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|\\w+hedr)on$/i, '$1a' ],\r\n\t\t[ /^(alumn|alg|vertebr)a$/i, '$1ae' ],\r\n\t\t\r\n\t\t// churches, classes, boxes, etc.\r\n\t\t[ /([cs]h|ss|x)$/i, '$1es' ],\r\n\r\n\t\t// words with -ves plural form\r\n\t\t[ /([aeo]l|[^d]ea|ar)f$/i, '$1ves' ],\r\n\t\t[ /([nlw]i)fe$/i, '$1ves' ],\r\n\r\n\t\t// -y\r\n\t\t[ /([aeiou])y$/i, '$1ys' ],\r\n\t\t[ /(^[A-Z][a-z]*)y$/, '$1ys' ], // case sensitive!\r\n\t\t[ /y$/i, 'ies' ],\r\n\r\n\t\t// -o\r\n\t\t[ /([aeiou])o$/i, '$1os' ],\r\n\t\t[ /^(pian|portic|albin|generalissim|manifest|archipelag|ghett|medic|armadill|guan|octav|command|infern|phot|ditt|jumb|pr|dynam|ling|quart|embry|lumbag|rhin|fiasc|magnet|styl|alt|contralt|sopran|bass|crescend|temp|cant|sol|kimon)o$/i, '$1os' ],\r\n\t\t[ /o$/i, 'oes' ],\r\n\r\n\t\t// words ending in s...\r\n\t\t[ /s$/i, 'ses' ]\r\n\t];\r\n\r\n\t// pluralizes the given singular noun. There are three ways to call it:\r\n\t// pluralize(noun) -> pluralNoun\r\n\t// Returns the plural of the given noun.\r\n\t// Example: \r\n\t// pluralize(\"person\") -> \"people\"\r\n\t// pluralize(\"me\") -> \"us\"\r\n\t//\r\n\t// pluralize(noun, count) -> plural or singular noun\r\n\t// Inflect the noun according to the count, returning the singular noun\r\n\t// if the count is 1.\r\n\t// Examples:\r\n\t// pluralize(\"person\", 3) -> \"people\"\r\n\t// pluralize(\"person\", 1) -> \"person\"\r\n\t// pluralize(\"person\", 0) -> \"people\"\r\n\t//\r\n\t// pluralize(noun, count, plural) -> plural or singular noun\r\n\t// you can provide an irregular plural yourself as the 3rd argument.\r\n\t// Example:\r\n\t// pluralize(\"château\", 2 \"châteaux\") -> \"châteaux\"\r\n\tfunction pluralize(word, count, plural) {\r\n\t\t// handle the empty string reasonably.\r\n\t\tif ( word === '' ) return '';\r\n\r\n\t\t// singular case.\r\n\t\tif ( count === 1 ) return word;\r\n\r\n\t\t// life is very easy if an explicit plural was provided.\r\n\t\tif ( typeof plural === 'string' ) return plural;\r\n\r\n\t\tvar lowerWord = word.toLowerCase();\r\n\r\n\t\t// user defined rules have the highest priority.\r\n\t\tif ( lowerWord in userDefined ) {\r\n\t\t\treturn capitalizeSame(userDefined[lowerWord], word);\r\n\t\t}\r\n\r\n\t\t// single letters are pluralized with 's, \"I got five A's on\r\n\t\t// my report card.\"\r\n\t\tif ( word.match(/^[A-Z]$/) ) return word + \"'s\";\r\n\r\n\t\t// some word don't change form when plural.\r\n\t\tif ( word.match(/fish$|ois$|sheep$|deer$|pox$|itis$/i) ) return word;\r\n\t\tif ( word.match(/^[A-Z][a-z]*ese$/) ) return word; // Nationalities.\r\n\t\tif ( lowerWord in uninflected ) return word;\r\n\r\n\t\t// there's a known set of words with irregular plural forms.\r\n\t\tif ( lowerWord in irregular ) {\r\n\t\t\treturn capitalizeSame(irregular[lowerWord], word);\r\n\t\t}\r\n\t\t\r\n\t\t// try to pluralize the word depending on its suffix.\r\n\t\tvar suffixRulesLength = suffixRules.length;\r\n\t\tfor ( var i=0; i < suffixRulesLength; i++ ) {\r\n\t\t\tvar rule = suffixRules[i];\r\n\t\t\tif ( word.match(rule[0]) ) {\r\n\t\t\t\treturn word.replace(rule[0], rule[1]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// if all else fails, just add s.\r\n\t\treturn word + 's';\r\n\t}\r\n\r\n\tpluralize.define = function(word, plural) {\r\n\t\tuserDefined[word.toLowerCase()] = plural;\r\n\t}\r\n\r\n\treturn pluralize;\r\n\r\n})();\r\n//@ sourceURL=indemma/vendor/owl/pluralize.js"
252
252
  ));
253
253
  require.register("indemma/lib/record.js", Function("exports, require, module",
254
- "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, {\n _shim: {}\n }), 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"
254
+ "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 every: 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, {\n _shim: {}\n }), 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"
255
255
  ));
256
256
  require.register("indemma/lib/record/associable.js", Function("exports, require, module",
257
257
  "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, definition, temporary_observed,\n _this = this;\n\n association_name = this.resource.toString();\n if (this.owner.observed == null) {\n this.owner.observed = {};\n temporary_observed = true;\n }\n definition = 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 if (temporary_observed) {\n delete this.owner.observed;\n }\n return definition;\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"
@@ -263,7 +263,7 @@ require.register("indemma/lib/record/storable.js", Function("exports, require, m
263
263
  "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"
264
264
  ));
265
265
  require.register("indemma/lib/record/queryable.js", Function("exports, require, module",
266
- "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"
266
+ "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 every: 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"
267
267
  ));
268
268
  require.register("indemma/lib/record/resource.js", Function("exports, require, module",
269
269
  "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"
@@ -272,10 +272,10 @@ require.register("indemma/lib/record/rest.js", Function("exports, require, modul
272
272
  "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"
273
273
  ));
274
274
  require.register("indemma/lib/record/restfulable.js", Function("exports, require, module",
275
- "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 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, 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 if (type(value) === 'function') {\n continue;\n }\n if (type(value) === 'object') {\n if (nested) {\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 }\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"
275
+ "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"
276
276
  ));
277
277
  require.register("indemma/lib/record/scopable.js", Function("exports, require, module",
278
- "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"
278
+ "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.every = 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"
279
279
  ));
280
280
  require.register("indemma/lib/record/maid.js", Function("exports, require, module",
281
281
  "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"
@@ -19984,7 +19984,7 @@ this.model = (function() {
19984
19984
  after_initialize: [],
19985
19985
  before_initialize: []
19986
19986
  },
19987
- all: function() {
19987
+ every: function() {
19988
19988
  return this.cache;
19989
19989
  },
19990
19990
  create: function() {
@@ -20607,7 +20607,7 @@ queryable = {
20607
20607
  }
20608
20608
  return this.storage.store(key);
20609
20609
  },
20610
- all: function() {
20610
+ every: function() {
20611
20611
  return this.storage.values();
20612
20612
  },
20613
20613
  where: function() {
@@ -20830,7 +20830,7 @@ restful = {
20830
20830
  }
20831
20831
  return $.when.apply($, savings);
20832
20832
  },
20833
- all: function(conditions, doned, failed) {
20833
+ every: function(conditions, doned, failed) {
20834
20834
  if (conditions == null) {
20835
20835
  conditions = {};
20836
20836
  }
@@ -20853,7 +20853,7 @@ restful = {
20853
20853
  namespaced = conditions[this.resource] || {};
20854
20854
  namespaced.limit = 1;
20855
20855
  namespaced.order = 'desc';
20856
- return this.all(conditions, callback);
20856
+ return this.every(conditions, callback);
20857
20857
  },
20858
20858
  get: function(action, data) {
20859
20859
  var default_route, old_route, payload, promise, resource;
@@ -21117,7 +21117,7 @@ restful = {
21117
21117
  }
21118
21118
  },
21119
21119
  json: function(methods) {
21120
- var definition, json, name, nested, value;
21120
+ var definition, json, name, nature, nested, value;
21121
21121
 
21122
21122
  if (methods == null) {
21123
21123
  methods = {};
@@ -21136,11 +21136,16 @@ restful = {
21136
21136
  if (value == null) {
21137
21137
  continue;
21138
21138
  }
21139
- if (type(value) === 'function') {
21139
+ nature = type(value);
21140
+ if (nature === 'function') {
21140
21141
  continue;
21141
21142
  }
21142
- if (type(value) === 'object') {
21143
+ if (nature === 'object' || nature === 'element') {
21143
21144
  if (nested) {
21145
+ if (!value.json) {
21146
+ console.warn("json: Tryied to serialize nested attribute '" + name + "' without serialization method!");
21147
+ continue;
21148
+ }
21144
21149
  json["" + name + "_attributes"] = value.json(methods[name]);
21145
21150
  } else if ((value.toJSON != null) || (value.json != null)) {
21146
21151
  if (value.resource) {
@@ -21151,6 +21156,8 @@ restful = {
21151
21156
  } else {
21152
21157
  json[name] = value.toJSON(methods[name]);
21153
21158
  }
21159
+ } else {
21160
+ continue;
21154
21161
  }
21155
21162
  } else {
21156
21163
  json[name] = value;
@@ -21485,7 +21492,7 @@ if (model.associable) {
21485
21492
  });
21486
21493
  });
21487
21494
  model.associable.mix(function(singular_association, plural_association) {
21488
- plural_association.all = plural_association.reload = function(data, done, fail) {
21495
+ plural_association.every = plural_association.reload = function(data, done, fail) {
21489
21496
  var promises, reload;
21490
21497
 
21491
21498
  if (this.parent != null) {