ende 0.2.10 → 0.2.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -19209,6 +19209,199 @@ if (typeof module == "object" && typeof require == "function") {
19209
19209
 
19210
19210
  return sinon;}.call(typeof window != 'undefined' && window || {}));
19211
19211
 
19212
+ });
19213
+ require.register("indefinido-indemma/vendor/owl/pluralize.js", function(exports, require, module){
19214
+ /* This file is part of OWL Pluralization.
19215
+
19216
+ OWL Pluralization is free software: you can redistribute it and/or
19217
+ modify it under the terms of the GNU Lesser General Public License
19218
+ as published by the Free Software Foundation, either version 3 of
19219
+ the License, or (at your option) any later version.
19220
+
19221
+ OWL Pluralization is distributed in the hope that it will be useful,
19222
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
19223
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19224
+ GNU Lesser General Public License for more details.
19225
+
19226
+ You should have received a copy of the GNU Lesser General Public
19227
+ License along with OWL Pluralization. If not, see
19228
+ <http://www.gnu.org/licenses/>.
19229
+ */
19230
+
19231
+ // prepare the owl namespace.
19232
+ if ( typeof owl === 'undefined' ) owl = {};
19233
+
19234
+ owl.pluralize = (function() {
19235
+ var userDefined = {};
19236
+
19237
+ function capitalizeSame(word, sampleWord) {
19238
+ if ( sampleWord.match(/^[A-Z]/) ) {
19239
+ return word.charAt(0).toUpperCase() + word.slice(1);
19240
+ } else {
19241
+ return word;
19242
+ }
19243
+ }
19244
+
19245
+ // returns a plain Object having the given keys,
19246
+ // all with value 1, which can be used for fast lookups.
19247
+ function toKeys(keys) {
19248
+ keys = keys.split(',');
19249
+ var keysLength = keys.length;
19250
+ var table = {};
19251
+ for ( var i=0; i < keysLength; i++ ) {
19252
+ table[ keys[i] ] = 1;
19253
+ }
19254
+ return table;
19255
+ }
19256
+
19257
+ // words that are always singular, always plural, or the same in both forms.
19258
+ var 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");
19259
+
19260
+ var irregular = {
19261
+ // pronouns
19262
+ I: 'we',
19263
+ you: 'you',
19264
+ he: 'they',
19265
+ it: 'they', // or them
19266
+ me: 'us',
19267
+ you: 'you',
19268
+ him: 'them',
19269
+ them: 'them',
19270
+ myself: 'ourselves',
19271
+ yourself: 'yourselves',
19272
+ himself: 'themselves',
19273
+ herself: 'themselves',
19274
+ itself: 'themselves',
19275
+ themself: 'themselves',
19276
+ oneself: 'oneselves',
19277
+
19278
+ child: 'children',
19279
+ dwarf: 'dwarfs', // dwarfs are real; dwarves are fantasy.
19280
+ mongoose: 'mongooses',
19281
+ mythos: 'mythoi',
19282
+ ox: 'oxen',
19283
+ soliloquy: 'soliloquies',
19284
+ trilby: 'trilbys',
19285
+ person: 'people',
19286
+ forum: 'forums', // fora is ok but uncommon.
19287
+
19288
+ // latin plural in popular usage.
19289
+ syllabus: 'syllabi',
19290
+ alumnus: 'alumni',
19291
+ genus: 'genera',
19292
+ viscus: 'viscera',
19293
+ stigma: 'stigmata'
19294
+ };
19295
+
19296
+ var suffixRules = [
19297
+ // common suffixes
19298
+ [ /man$/i, 'men' ],
19299
+ [ /([lm])ouse$/i, '$1ice' ],
19300
+ [ /tooth$/i, 'teeth' ],
19301
+ [ /goose$/i, 'geese' ],
19302
+ [ /foot$/i, 'feet' ],
19303
+ [ /zoon$/i, 'zoa' ],
19304
+ [ /([tcsx])is$/i, '$1es' ],
19305
+
19306
+ // fully assimilated suffixes
19307
+ [ /ix$/i, 'ices' ],
19308
+ [ /^(cod|mur|sil|vert)ex$/i, '$1ices' ],
19309
+ [ /^(agend|addend|memorand|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi)um$/i, '$1a' ],
19310
+ [ /^(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|\w+hedr)on$/i, '$1a' ],
19311
+ [ /^(alumn|alg|vertebr)a$/i, '$1ae' ],
19312
+
19313
+ // churches, classes, boxes, etc.
19314
+ [ /([cs]h|ss|x)$/i, '$1es' ],
19315
+
19316
+ // words with -ves plural form
19317
+ [ /([aeo]l|[^d]ea|ar)f$/i, '$1ves' ],
19318
+ [ /([nlw]i)fe$/i, '$1ves' ],
19319
+
19320
+ // -y
19321
+ [ /([aeiou])y$/i, '$1ys' ],
19322
+ [ /(^[A-Z][a-z]*)y$/, '$1ys' ], // case sensitive!
19323
+ [ /y$/i, 'ies' ],
19324
+
19325
+ // -o
19326
+ [ /([aeiou])o$/i, '$1os' ],
19327
+ [ /^(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' ],
19328
+ [ /o$/i, 'oes' ],
19329
+
19330
+ // words ending in s...
19331
+ [ /s$/i, 'ses' ]
19332
+ ];
19333
+
19334
+ // pluralizes the given singular noun. There are three ways to call it:
19335
+ // pluralize(noun) -> pluralNoun
19336
+ // Returns the plural of the given noun.
19337
+ // Example:
19338
+ // pluralize("person") -> "people"
19339
+ // pluralize("me") -> "us"
19340
+ //
19341
+ // pluralize(noun, count) -> plural or singular noun
19342
+ // Inflect the noun according to the count, returning the singular noun
19343
+ // if the count is 1.
19344
+ // Examples:
19345
+ // pluralize("person", 3) -> "people"
19346
+ // pluralize("person", 1) -> "person"
19347
+ // pluralize("person", 0) -> "people"
19348
+ //
19349
+ // pluralize(noun, count, plural) -> plural or singular noun
19350
+ // you can provide an irregular plural yourself as the 3rd argument.
19351
+ // Example:
19352
+ // pluralize("château", 2 "châteaux") -> "châteaux"
19353
+ function pluralize(word, count, plural) {
19354
+ // handle the empty string reasonably.
19355
+ if ( word === '' ) return '';
19356
+
19357
+ // singular case.
19358
+ if ( count === 1 ) return word;
19359
+
19360
+ // life is very easy if an explicit plural was provided.
19361
+ if ( typeof plural === 'string' ) return plural;
19362
+
19363
+ var lowerWord = word.toLowerCase();
19364
+
19365
+ // user defined rules have the highest priority.
19366
+ if ( lowerWord in userDefined ) {
19367
+ return capitalizeSame(userDefined[lowerWord], word);
19368
+ }
19369
+
19370
+ // single letters are pluralized with 's, "I got five A's on
19371
+ // my report card."
19372
+ if ( word.match(/^[A-Z]$/) ) return word + "'s";
19373
+
19374
+ // some word don't change form when plural.
19375
+ if ( word.match(/fish$|ois$|sheep$|deer$|pox$|itis$/i) ) return word;
19376
+ if ( word.match(/^[A-Z][a-z]*ese$/) ) return word; // Nationalities.
19377
+ if ( lowerWord in uninflected ) return word;
19378
+
19379
+ // there's a known set of words with irregular plural forms.
19380
+ if ( lowerWord in irregular ) {
19381
+ return capitalizeSame(irregular[lowerWord], word);
19382
+ }
19383
+
19384
+ // try to pluralize the word depending on its suffix.
19385
+ var suffixRulesLength = suffixRules.length;
19386
+ for ( var i=0; i < suffixRulesLength; i++ ) {
19387
+ var rule = suffixRules[i];
19388
+ if ( word.match(rule[0]) ) {
19389
+ return word.replace(rule[0], rule[1]);
19390
+ }
19391
+ }
19392
+
19393
+ // if all else fails, just add s.
19394
+ return word + 's';
19395
+ }
19396
+
19397
+ pluralize.define = function(word, plural) {
19398
+ userDefined[word.toLowerCase()] = plural;
19399
+ }
19400
+
19401
+ return pluralize;
19402
+
19403
+ })();
19404
+
19212
19405
  });
19213
19406
  require.register("indefinido-indemma/lib/record.js", function(exports, require, module){
19214
19407
  var $, advisable, bind, extend, merge, observable, type,
@@ -19234,7 +19427,8 @@ this.model = (function() {
19234
19427
  modelable = {
19235
19428
  after_mix: [],
19236
19429
  record: {
19237
- after_initialize: []
19430
+ after_initialize: [],
19431
+ before_initialize: []
19238
19432
  },
19239
19433
  all: function() {
19240
19434
  return this.cache;
@@ -19245,11 +19439,6 @@ this.model = (function() {
19245
19439
  params = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
19246
19440
  throw 'model.create not implemented yet, try using the restful.model.create method';
19247
19441
  },
19248
- find: function(id) {
19249
- return this.where({
19250
- id: id
19251
- }, true);
19252
- },
19253
19442
  where: function(conditions, first) {
19254
19443
  var record, results, _i, _len, _ref;
19255
19444
 
@@ -19279,7 +19468,7 @@ this.model = (function() {
19279
19468
  }
19280
19469
  };
19281
19470
  initialize_record = function(data) {
19282
- var after_initialize, callback, instance, _i, _len, _ref;
19471
+ var after_initialize, callback, creation, index, instance, _i, _j, _len, _len1, _ref, _ref1;
19283
19472
 
19284
19473
  if (data == null) {
19285
19474
  data = {
@@ -19292,12 +19481,18 @@ this.model = (function() {
19292
19481
  data.route || (data.route = this.route);
19293
19482
  data.nested_attributes = this.nested_attributes || [];
19294
19483
  after_initialize = (data.after_initialize || []).concat(this.record.after_initialize);
19295
- instance = record.call(extend(Object.create(data), this.record, {
19484
+ creation = extend(Object.create(data), this.record, creation, {
19296
19485
  after_initialize: after_initialize
19297
- }));
19298
- _ref = instance.after_initialize;
19299
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
19300
- callback = _ref[_i];
19486
+ });
19487
+ _ref = this.record.before_initialize;
19488
+ for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
19489
+ callback = _ref[index];
19490
+ callback.call(this, creation);
19491
+ }
19492
+ instance = record.call(creation);
19493
+ _ref1 = instance.after_initialize;
19494
+ for (index = _j = 0, _len1 = _ref1.length; _j < _len1; index = ++_j) {
19495
+ callback = _ref1[index];
19301
19496
  callback.call(instance, instance);
19302
19497
  }
19303
19498
  delete instance.after_initialize;
@@ -19321,6 +19516,7 @@ this.model = (function() {
19321
19516
  extend(instance, merge(this, modelable));
19322
19517
  this.record = instance.record = merge({}, instance.record, modelable.record);
19323
19518
  this.record.after_initialize = instance.record.after_initialize = instance.record.after_initialize.concat(after_initialize);
19519
+ this.record.before_initialize = instance.record.before_initialize.concat([]);
19324
19520
  _ref = modelable.after_mix;
19325
19521
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
19326
19522
  callback = _ref[_i];
@@ -19371,13 +19567,15 @@ exports.model = this.model;
19371
19567
 
19372
19568
  });
19373
19569
  require.register("indefinido-indemma/lib/record/associable.js", function(exports, require, module){
19374
- var $, associable, model, plural, root, singular,
19570
+ var $, associable, callbacks, extend, model, modifiers, plural, root, singular, subscribers,
19375
19571
  __slice = [].slice;
19376
19572
 
19377
19573
  root = window;
19378
19574
 
19379
19575
  $ = require('jquery');
19380
19576
 
19577
+ extend = require('assimilate');
19578
+
19381
19579
  require('./resource');
19382
19580
 
19383
19581
  plural = {
@@ -19421,7 +19619,10 @@ plural = {
19421
19619
  data[_name = this.parent_resource] || (data[_name] = this.parent);
19422
19620
  return model[model.singularize(this.resource)](data);
19423
19621
  },
19424
- push: Array.prototype.push,
19622
+ push: function() {
19623
+ console.warn("" + this.resource + ".push is deprecated and will be removed, please use add instead");
19624
+ return Array.prototype.push.apply(this, arguments);
19625
+ },
19425
19626
  length: 0,
19426
19627
  json: function(methods, omissions) {
19427
19628
  var record, _i, _len, _results;
@@ -19437,92 +19638,192 @@ plural = {
19437
19638
 
19438
19639
  singular = {
19439
19640
  create: function(data) {
19440
- return model[this.resource].create($.extend({}, this, data));
19641
+ return model[this.resource].create(extend({}, this, data));
19441
19642
  },
19442
19643
  build: function(data) {
19443
- return this[this.parent_resource][this.resource] = model[this.resource]($.extend({}, this, data));
19644
+ return this.owner[this.resource.toString()] = model[this.resource.toString()](extend({}, this, data));
19444
19645
  }
19445
19646
  };
19446
19647
 
19447
- associable = {
19448
- model: function(options) {
19449
- var callbacks;
19648
+ subscribers = {
19649
+ belongs_to: {
19650
+ foreign_key: function(resource_id) {
19651
+ var associated, association_name, current_resource_id, resource, _ref;
19450
19652
 
19451
- if (this.resource == null) {
19452
- console.error('resource must be defined in order to associate');
19653
+ association_name = this.resource.toString();
19654
+ if (resource_id === null || resource_id === void 0) {
19655
+ this.dirty = true;
19656
+ this.owner[association_name] = resource_id;
19657
+ return resource_id;
19658
+ }
19659
+ current_resource_id = (_ref = this.owner[association_name]) != null ? _ref._id : void 0;
19660
+ if (resource_id !== current_resource_id) {
19661
+ resource = model[association_name];
19662
+ if (!resource) {
19663
+ console.warn("subscribers.belongs_to.foreign_key: associated factory not found for model: " + association_name);
19664
+ return resource_id;
19665
+ }
19666
+ associated = resource.find(resource_id);
19667
+ associated || (associated = resource({
19668
+ _id: resource_id
19669
+ }));
19670
+ this.owner.observed[association_name] = associated;
19671
+ }
19672
+ return resource_id;
19673
+ },
19674
+ associated_changed: function(associated) {
19675
+ return this.owner.observed["" + (this.resource.toString()) + "_id"] = associated ? associated._id : null;
19453
19676
  }
19454
- callbacks = {
19455
- has_many: {
19456
- nest_attributes: function() {
19457
- var association, association_name, association_names, associations_attributes, message, _i, _len, _results;
19677
+ }
19678
+ };
19458
19679
 
19459
- association_names = model[this.resource].has_many;
19460
- if (association_names) {
19461
- _results = [];
19462
- for (_i = 0, _len = association_names.length; _i < _len; _i++) {
19463
- association_name = association_names[_i];
19464
- associations_attributes = this["" + association_name + "_attributes"];
19465
- if (associations_attributes && associations_attributes.length) {
19466
- association = this[model.pluralize(association_name)];
19467
- if (!association) {
19468
- message = "has_many.nest_attributes: Association not found for " + association_name + ". \n";
19469
- message += "did you set it on model declaration? \n has_many: " + association_name + " ";
19470
- throw message;
19471
- }
19472
- association.resource = model.singularize(association.resource);
19473
- association.add.apply(association, associations_attributes);
19474
- _results.push(association.resource = model.pluralize(association.resource));
19475
- } else {
19476
- _results.push(void 0);
19477
- }
19478
- }
19479
- return _results;
19680
+ modifiers = {
19681
+ belongs_to: {
19682
+ associated_loader: function() {
19683
+ var association_name,
19684
+ _this = this;
19685
+
19686
+ association_name = this.resource.toString();
19687
+ return Object.defineProperty(this.owner, association_name, {
19688
+ set: function(associated) {
19689
+ return this.observed[association_name] = associated;
19690
+ },
19691
+ get: function() {
19692
+ var associated, associated_id, resource;
19693
+
19694
+ associated = _this.owner.observed[association_name];
19695
+ associated_id = _this.owner.observed[association_name + '_id'];
19696
+ if (!(((associated != null ? associated._id : void 0) != null) || associated_id)) {
19697
+ return associated;
19698
+ }
19699
+ if (associated != null ? associated.sustained : void 0) {
19700
+ return associated;
19480
19701
  }
19702
+ resource = model[association_name];
19703
+ if (!resource) {
19704
+ console.warn("subscribers.belongs_to.foreign_key: associated factory not found for model: " + association_name);
19705
+ return associated;
19706
+ }
19707
+ associated = resource.find(associated_id || associated._id);
19708
+ associated || (associated = resource({
19709
+ _id: associated_id
19710
+ }));
19711
+ resource.storage.store(associated._id, associated);
19712
+ associated.reload();
19713
+ return _this.owner.observed[association_name] = associated;
19481
19714
  },
19482
- update_association: function(data) {
19483
- var associated, association, association_name, id, pluralized_association, _i, _j, _len, _len1, _ref;
19715
+ configurable: true,
19716
+ enumerable: true
19717
+ });
19718
+ }
19719
+ }
19720
+ };
19484
19721
 
19485
- id = this._id || data && (data._id || data.id);
19486
- if (!id) {
19487
- return;
19722
+ callbacks = {
19723
+ has_many: {
19724
+ nest_attributes: function() {
19725
+ var association, association_name, association_names, associations_attributes, message, _i, _len, _results;
19726
+
19727
+ association_names = model[this.resource].has_many;
19728
+ if (association_names) {
19729
+ _results = [];
19730
+ for (_i = 0, _len = association_names.length; _i < _len; _i++) {
19731
+ association_name = association_names[_i];
19732
+ associations_attributes = this["" + association_name + "_attributes"];
19733
+ if (associations_attributes && associations_attributes.length) {
19734
+ association = this[model.pluralize(association_name)];
19735
+ if (!association) {
19736
+ message = "has_many.nest_attributes: Association not found for " + association_name + ". \n";
19737
+ message += "did you set it on model declaration? \n has_many: " + association_name + " ";
19738
+ throw message;
19739
+ }
19740
+ association.resource = model.singularize(association.resource);
19741
+ association.add.apply(association, associations_attributes);
19742
+ _results.push(association.resource = model.pluralize(association.resource));
19743
+ } else {
19744
+ _results.push(void 0);
19488
19745
  }
19489
- _ref = model[this.resource.toString()].has_many;
19490
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
19491
- association_name = _ref[_i];
19492
- pluralized_association = model.pluralize(association_name);
19493
- association = this[pluralized_association];
19494
- if (!association.route) {
19495
- association.route = "/" + (model.pluralize(this.resource.toString())) + "/" + id + "/" + (model.pluralize(association.resource));
19496
- for (_j = 0, _len1 = association.length; _j < _len1; _j++) {
19497
- associated = association[_j];
19498
- if (!associated.route && (associated.parent != null)) {
19499
- associated.route = "/" + (model.pluralize(this.resource.toString())) + "/" + id + "/" + (model.pluralize(association.resource));
19500
- }
19501
- }
19746
+ }
19747
+ return _results;
19748
+ }
19749
+ },
19750
+ update_association: function(data) {
19751
+ var associated, association, association_name, id, pluralized_association, _i, _j, _len, _len1, _ref;
19752
+
19753
+ id = this._id || data && (data._id || data.id);
19754
+ if (!id) {
19755
+ return;
19756
+ }
19757
+ _ref = model[this.resource.toString()].has_many;
19758
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
19759
+ association_name = _ref[_i];
19760
+ pluralized_association = model.pluralize(association_name);
19761
+ association = this[pluralized_association];
19762
+ if (!association.route) {
19763
+ association.route = "/" + (model.pluralize(this.resource.toString())) + "/" + id + "/" + (model.pluralize(association.resource));
19764
+ for (_j = 0, _len1 = association.length; _j < _len1; _j++) {
19765
+ associated = association[_j];
19766
+ if (!associated.route && (associated.parent != null)) {
19767
+ associated.route = "/" + (model.pluralize(this.resource.toString())) + "/" + id + "/" + (model.pluralize(association.resource));
19502
19768
  }
19503
19769
  }
19504
- return true;
19505
- },
19506
- autosave: function() {
19507
- return this.save();
19508
19770
  }
19509
19771
  }
19510
- };
19511
- if (this.has_many && $.type(this.has_many) !== 'array') {
19512
- this.has_many = [this.has_many];
19513
- }
19514
- if (this.has_one && $.type(this.has_one) !== 'array') {
19515
- this.has_one = [this.has_one];
19772
+ return true;
19773
+ },
19774
+ autosave: function() {
19775
+ throw 'Not implemented yet';
19516
19776
  }
19517
- if (this.belongs_to && $.type(this.belongs_to) !== 'array') {
19518
- this.belongs_to = [this.belongs_to];
19777
+ },
19778
+ has_one: {
19779
+ nest_attributes: function() {
19780
+ var association_name, association_names, associations_attributes, _i, _len, _results;
19781
+
19782
+ association_names = model[this.resource].has_one;
19783
+ if (association_names) {
19784
+ _results = [];
19785
+ for (_i = 0, _len = association_names.length; _i < _len; _i++) {
19786
+ association_name = association_names[_i];
19787
+ associations_attributes = this["" + association_name + "_attributes"];
19788
+ if (associations_attributes) {
19789
+ this[association_name] = this["build_" + association_name](associations_attributes);
19790
+ _results.push(delete this["" + association_name + "_attributes"]);
19791
+ } else {
19792
+ _results.push(void 0);
19793
+ }
19794
+ }
19795
+ return _results;
19796
+ }
19519
19797
  }
19520
- this.has_many || (this.has_many = []);
19521
- this.has_one || (this.has_one = []);
19522
- this.belongs_to || (this.belongs_to = []);
19523
- return this.create_associations = function() {
19524
- var association_name, association_proxy, resource, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _results;
19798
+ }
19799
+ };
19800
+
19801
+ associable = {
19802
+ model: {
19803
+ blender: function(definition) {
19804
+ var model;
19805
+
19806
+ model = associable.model;
19807
+ this.create_after_hooks = model.create_after_hooks;
19808
+ this.create_before_hooks = model.create_before_hooks;
19809
+ if (this.has_many && $.type(this.has_many) !== 'array') {
19810
+ this.has_many = [this.has_many];
19811
+ }
19812
+ if (this.has_one && $.type(this.has_one) !== 'array') {
19813
+ this.has_one = [this.has_one];
19814
+ }
19815
+ if (this.belongs_to && $.type(this.belongs_to) !== 'array') {
19816
+ this.belongs_to = [this.belongs_to];
19817
+ }
19818
+ this.has_many || (this.has_many = []);
19819
+ this.has_one || (this.has_one = []);
19820
+ this.belongs_to || (this.belongs_to = []);
19821
+ return true;
19822
+ },
19823
+ create_after_hooks: function(definition) {
19824
+ var association_name, association_proxy, old_resource_id, options, resource, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _results;
19525
19825
 
19826
+ options = model[this.resource.name || this.resource.toString()];
19526
19827
  if (options.has_many) {
19527
19828
  _ref = options.has_many;
19528
19829
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@@ -19544,12 +19845,14 @@ associable = {
19544
19845
  resource = _ref1[_j];
19545
19846
  association_proxy = {
19546
19847
  resource: resource,
19547
- parent_resource: this.resource
19848
+ parent_resource: this.resource,
19849
+ owner: this
19548
19850
  };
19549
- association_proxy[this.resource] = this;
19851
+ association_proxy[this.resource.toString()] = this;
19550
19852
  this["build_" + resource] = $.proxy(singular.build, association_proxy);
19551
19853
  this["create_" + resource] = $.proxy(singular.create, association_proxy);
19552
19854
  }
19855
+ callbacks.has_one.nest_attributes.call(this);
19553
19856
  }
19554
19857
  if (options.belongs_to) {
19555
19858
  _ref2 = options.belongs_to;
@@ -19558,29 +19861,69 @@ associable = {
19558
19861
  resource = _ref2[_k];
19559
19862
  association_proxy = {
19560
19863
  resource: resource,
19561
- parent_resource: this.resource
19864
+ parent_resource: this.resource,
19865
+ parent: this,
19866
+ owner: this
19562
19867
  };
19563
- association_proxy[this.resource] = this;
19868
+ association_proxy[this.resource.toString()] = this;
19564
19869
  this["build_" + resource] = $.proxy(singular.build, association_proxy);
19565
- _results.push(this["create_" + resource] = $.proxy(singular.create, association_proxy));
19870
+ this["create_" + resource] = $.proxy(singular.create, association_proxy);
19871
+ old_resource_id = this["" + resource + "_id"];
19872
+ this["" + resource + "_id"] = null;
19873
+ this.subscribe("" + resource + "_id", $.proxy(subscribers.belongs_to.foreign_key, association_proxy));
19874
+ this.subscribe(resource.toString(), $.proxy(subscribers.belongs_to.associated_changed, association_proxy));
19875
+ this.resource_id = old_resource_id;
19876
+ if (this["" + resource + "_id"] && !this[resource]) {
19877
+ _results.push(this.publish("" + resource + "_id", this["" + resource + "_id"]));
19878
+ } else {
19879
+ _results.push(void 0);
19880
+ }
19566
19881
  }
19567
19882
  return _results;
19568
19883
  }
19569
- };
19884
+ },
19885
+ create_before_hooks: function(record) {
19886
+ var association_proxy, definition, resource, _i, _len, _ref, _results;
19887
+
19888
+ definition = this;
19889
+ if (definition.belongs_to) {
19890
+ _ref = definition.belongs_to;
19891
+ _results = [];
19892
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
19893
+ resource = _ref[_i];
19894
+ association_proxy = {
19895
+ resource: resource,
19896
+ parent_resource: this.resource,
19897
+ owner: record
19898
+ };
19899
+ _results.push(modifiers.belongs_to.associated_loader.call(association_proxy));
19900
+ }
19901
+ return _results;
19902
+ }
19903
+ }
19570
19904
  },
19571
- record: function(options) {
19572
- if (this.resource == null) {
19573
- console.error('resource must be defined in order to associate');
19905
+ record: {
19906
+ after_initialize: function(attributes) {
19907
+ if (this.resource == null) {
19908
+ throw new Error('resource must be defined in order to associate');
19909
+ }
19910
+ return model[this.resource.name || this.resource.toString()].create_after_hooks.call(this);
19911
+ },
19912
+ before_initialize: function(creation) {
19913
+ if (!this.resource) {
19914
+ throw new Error('resource must be defined in order to associate');
19915
+ }
19916
+ return model[this.resource.name || this.resource.toString()].create_before_hooks(creation);
19574
19917
  }
19575
- return model[this.resource.name || this.resource.toString()].create_associations.call(this);
19576
19918
  }
19577
19919
  };
19578
19920
 
19579
19921
  model = root.model;
19580
19922
 
19581
19923
  model.mix(function(modelable) {
19582
- modelable.after_mix.push(associable.model);
19583
- return modelable.record.after_initialize.push(associable.record);
19924
+ modelable.after_mix.push(associable.model.blender);
19925
+ modelable.record.before_initialize.push(associable.record.before_initialize);
19926
+ return modelable.record.after_initialize.push(associable.record.after_initialize);
19584
19927
  });
19585
19928
 
19586
19929
  model.associable = {
@@ -19589,12 +19932,135 @@ model.associable = {
19589
19932
  }
19590
19933
  };
19591
19934
 
19935
+ });
19936
+ require.register("indefinido-indemma/lib/record/persistable.js", function(exports, require, module){
19937
+ var handlers, model, persistable, record;
19938
+
19939
+ require('./queryable');
19940
+
19941
+ handlers = {
19942
+ store_after_saved: function() {
19943
+ var storage;
19944
+
19945
+ storage = model[this.resource.toString()].storage;
19946
+ if (this._id) {
19947
+ return storage.store(this._id, this);
19948
+ }
19949
+ }
19950
+ };
19951
+
19952
+ persistable = {
19953
+ record: {
19954
+ after_initialize: function() {
19955
+ return this.after('saved', handlers.store_after_saved);
19956
+ }
19957
+ }
19958
+ };
19959
+
19960
+ model = window.model;
19961
+
19962
+ record = window.record;
19963
+
19964
+ model.persistable = true;
19965
+
19966
+ model.mix(function(modelable) {
19967
+ return modelable.record.after_initialize.push(persistable.record.after_initialize);
19968
+ });
19969
+
19970
+ });
19971
+ require.register("indefinido-indemma/lib/record/storable.js", function(exports, require, module){
19972
+ var extend, merge, model, record, stampit, storable;
19973
+
19974
+ extend = require('assimilate');
19975
+
19976
+ merge = extend.withStrategy('deep');
19977
+
19978
+ stampit = require('../../vendor/stampit');
19979
+
19980
+ storable = stampit({
19981
+ store: function(keypath, value, options) {
19982
+ var collection, entry, key, _i, _len;
19983
+
19984
+ collection = this.database;
19985
+ keypath = keypath.toString().split('.');
19986
+ key = keypath.pop();
19987
+ for (_i = 0, _len = keypath.length; _i < _len; _i++) {
19988
+ entry = keypath[_i];
19989
+ collection[entry] || (collection[entry] = {});
19990
+ collection = collection[entry];
19991
+ }
19992
+ if (arguments.length === 1) {
19993
+ this.reads++;
19994
+ return collection[key];
19995
+ } else {
19996
+ this.writes++;
19997
+ value.sustained = true;
19998
+ return collection[key] = value;
19999
+ }
20000
+ },
20001
+ values: function() {
20002
+ return Object.values(this.database);
20003
+ }
20004
+ }, {
20005
+ type: 'object',
20006
+ writes: 0,
20007
+ reads: 0
20008
+ }, function() {
20009
+ this.database || (this.database = {});
20010
+ return this;
20011
+ });
20012
+
20013
+ model = window.model;
20014
+
20015
+ record = window.record;
20016
+
20017
+ model.storable = true;
20018
+
20019
+ module.exports = storable;
20020
+
20021
+ });
20022
+ require.register("indefinido-indemma/lib/record/queryable.js", function(exports, require, module){
20023
+ var extend, model, queryable, record, stampit, storable;
20024
+
20025
+ extend = require('assimilate');
20026
+
20027
+ storable = require('./storable');
20028
+
20029
+ stampit = require('../../vendor/stampit');
20030
+
20031
+ queryable = {
20032
+ storage: storable(),
20033
+ find: function(key) {
20034
+ return this.storage.store(key);
20035
+ },
20036
+ all: function() {
20037
+ return this.storage.values();
20038
+ },
20039
+ where: function() {
20040
+ throw new Error('queryable.where: Not implemented yet');
20041
+ }
20042
+ };
20043
+
20044
+ model = window.model;
20045
+
20046
+ record = window.record;
20047
+
20048
+ model.queryable = true;
20049
+
20050
+ module.exports = queryable;
20051
+
20052
+ model.mix(function(modelable) {
20053
+ return extend(modelable, queryable);
20054
+ });
20055
+
19592
20056
  });
19593
20057
  require.register("indefinido-indemma/lib/record/resource.js", function(exports, require, module){
19594
20058
  var model, resource, resourceable, stampit;
19595
20059
 
19596
20060
  stampit = require('../../vendor/stampit');
19597
20061
 
20062
+ require('../../vendor/owl/pluralize');
20063
+
19598
20064
  resource = stampit({
19599
20065
  toString: function() {
19600
20066
  return this.name;
@@ -19617,12 +20083,12 @@ resource = stampit({
19617
20083
  });
19618
20084
 
19619
20085
  resourceable = {
19620
- pluralize: function(word) {
20086
+ pluralize: function(word, count, plural) {
19621
20087
  if (!(word && word.length)) {
19622
20088
  throw new TypeError("Invalid string passed to pluralize '" + word + "'");
19623
20089
  }
19624
20090
  if (word.indexOf('s') !== word.length - 1) {
19625
- return word + 's';
20091
+ return owl.pluralize(word, count, plural);
19626
20092
  } else {
19627
20093
  return word;
19628
20094
  }
@@ -19666,7 +20132,9 @@ resourceable = {
19666
20132
  },
19667
20133
  parent_id: {
19668
20134
  get: function() {
19669
- return this[this.parent_resource]._id;
20135
+ if (this[this.parent_resource]) {
20136
+ return this[this.parent_resource]._id;
20137
+ }
19670
20138
  },
19671
20139
  set: function() {
19672
20140
  return console.error('Warning changing associations throught parent_id not allowed for security and style guide purposes');
@@ -19676,7 +20144,11 @@ resourceable = {
19676
20144
  var resource_definition, _ref;
19677
20145
 
19678
20146
  if (this.parent_resource) {
19679
- Object.defineProperty(this, "" + this.parent_resource + "_id", resourceable.parent_id);
20147
+ Object.defineProperty(this, "" + this.parent_resource + "_id", {
20148
+ value: resourceable.parent_id,
20149
+ configurable: true,
20150
+ enumerable: true
20151
+ });
19680
20152
  }
19681
20153
  resource_definition = {};
19682
20154
  if (typeof this.resource === 'string') {
@@ -19722,7 +20194,7 @@ module.exports = {
19722
20194
  return request.call(this, 'post', this.route, data);
19723
20195
  },
19724
20196
  "delete": function(data) {
19725
- return request.call(this, 'delete', this.route, data);
20197
+ return request.call(this, 'delete', (this._id ? "" + this.route + "/" + this._id : this.route), data);
19726
20198
  }
19727
20199
  };
19728
20200
 
@@ -19830,8 +20302,14 @@ restful = {
19830
20302
  get: function(action, data) {
19831
20303
  var old_route, payload, promise, resource, route;
19832
20304
 
20305
+ if (data == null) {
20306
+ data = {};
20307
+ }
19833
20308
  old_route = this.route;
19834
- this.route = "/" + (model.pluralize(this.resource.name)) + "/" + action;
20309
+ this.route = "/" + (model.pluralize(this.resource.name));
20310
+ if (action) {
20311
+ this.route += "/" + action;
20312
+ }
19835
20313
  resource = data.resource;
19836
20314
  if (data && data.json) {
19837
20315
  data = data.json();
@@ -19845,20 +20323,24 @@ restful = {
19845
20323
  route = old_route;
19846
20324
  return promise;
19847
20325
  },
19848
- put: rest.put
20326
+ put: rest.put,
20327
+ "delete": rest["delete"]
19849
20328
  },
19850
20329
  record: {
19851
20330
  reload: function() {
19852
- var argument, promise, _i, _len;
20331
+ var data, param, params, promise, _i, _len;
19853
20332
 
19854
- promise = rest.get.call(this);
20333
+ params = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
20334
+ data = params.pop();
20335
+ if (type(data) !== 'object') {
20336
+ params.push(data);
20337
+ }
20338
+ promise = rest.get.call(this, data || {});
19855
20339
  promise.done(this.assign_attributes);
19856
20340
  promise.fail(this.failed);
19857
- for (_i = 0, _len = arguments.length; _i < _len; _i++) {
19858
- argument = arguments[_i];
19859
- if (type(argument) === 'function') {
19860
- promise.done(argument);
19861
- }
20341
+ for (_i = 0, _len = params.length; _i < _len; _i++) {
20342
+ param = params[_i];
20343
+ promise.done(param);
19862
20344
  }
19863
20345
  return promise;
19864
20346
  },
@@ -19902,13 +20384,16 @@ restful = {
19902
20384
  association_name = _ref2[_l];
19903
20385
  association_attributes = attributes[association_name];
19904
20386
  delete attributes[association_name];
20387
+ delete attributes[association_name + "_attributes"];
19905
20388
  if (association_attributes) {
19906
20389
  this[association_name] = this["build_" + association_name](association_attributes);
19907
20390
  }
19908
20391
  }
19909
20392
  _results = [];
19910
20393
  for (attribute in attributes) {
19911
- _results.push(this[attribute] = attributes[attribute]);
20394
+ if (attribute !== this[attribute]) {
20395
+ _results.push(this[attribute] = attributes[attribute]);
20396
+ }
19912
20397
  }
19913
20398
  return _results;
19914
20399
  },
@@ -19972,7 +20457,7 @@ restful = {
19972
20457
  }
19973
20458
  },
19974
20459
  failed: function(xhr, error, status) {
19975
- var attribute_name, definition, e, message, messages, payload, _ref, _results;
20460
+ var attribute_name, definition, e, message, messages, payload, _i, _len, _ref;
19976
20461
 
19977
20462
  payload = xhr.responseJSON;
19978
20463
  try {
@@ -19985,37 +20470,33 @@ restful = {
19985
20470
  case 422:
19986
20471
  definition = model[this.resource];
19987
20472
  _ref = payload.errors;
19988
- _results = [];
19989
20473
  for (attribute_name in _ref) {
19990
20474
  messages = _ref[attribute_name];
19991
- if (!(this.hasOwnProperty(attribute_name) || definition.hasOwnProperty(attribute_name))) {
20475
+ if (!definition.associations) {
20476
+ definition.associations = definition.has_one.concat(definition.has_many.concat(definition.belongs_to));
20477
+ }
20478
+ if (!(this.hasOwnProperty(attribute_name) || definition.hasOwnProperty(attribute_name) || definition.associations.indexOf(attribute_name) !== -1 || attribute_name === 'base')) {
19992
20479
  message = "Server returned an validation error message for a attribute that is not defined in your model.\n";
19993
20480
  message += "The attribute was '" + attribute_name + "', the model resource was '" + this.resource + "'.\n";
19994
20481
  message += "The model definition keys were '" + (JSON.stringify(Object.keys(definition))) + "'.\n";
19995
20482
  message += "Please remove server validation, or update your model definition.";
19996
20483
  throw new TypeError(message);
19997
20484
  }
19998
- _results.push((function() {
19999
- var _i, _len, _results1;
20000
-
20001
- _results1 = [];
20002
- for (_i = 0, _len = messages.length; _i < _len; _i++) {
20003
- message = messages[_i];
20004
- _results1.push(this.errors.add(attribute_name, 'server', {
20005
- server_message: message
20006
- }));
20007
- }
20008
- return _results1;
20009
- }).call(this));
20485
+ for (_i = 0, _len = messages.length; _i < _len; _i++) {
20486
+ message = messages[_i];
20487
+ this.errors.add(attribute_name, 'server', {
20488
+ server_message: message
20489
+ });
20490
+ }
20010
20491
  }
20011
- return _results;
20012
20492
  break;
20013
20493
  default:
20014
20494
  message = "Fail in " + this.resource + ".save:\n";
20015
20495
  message += "Record: " + this + "\n";
20016
20496
  message += "Status: " + status + " (" + (payload.status || xhr.status) + ")\n";
20017
- return message += "Error : " + (payload.error || payload.message || payload);
20497
+ message += "Error : " + (payload.error || payload.message || payload);
20018
20498
  }
20499
+ return this.saving = false;
20019
20500
  },
20020
20501
  toString: function() {
20021
20502
  var serialized;
@@ -20061,10 +20542,12 @@ restful = {
20061
20542
  delete json.route;
20062
20543
  delete json.initial_route;
20063
20544
  delete json.after_initialize;
20545
+ delete json.before_initialize;
20064
20546
  delete json.parent_resource;
20065
20547
  delete json.nested_attributes;
20066
20548
  delete json.saving;
20067
20549
  delete json.salvation;
20550
+ delete json.sustained;
20068
20551
  delete json.element;
20069
20552
  delete json["default"];
20070
20553
  delete json.lock;
@@ -20141,7 +20624,7 @@ scopable = {
20141
20624
  }
20142
20625
  builder = builders[type];
20143
20626
  if (builder == null) {
20144
- throw "Unknown scope type " + type + " for model with resource " + model.resource;
20627
+ throw "Unknown scope type: '" + type + "', For model with resource: '" + this.resource + "'";
20145
20628
  }
20146
20629
  this.scope.declared.push(name);
20147
20630
  return this[name] = builder({
@@ -20210,7 +20693,7 @@ scopable = {
20210
20693
  forward_scopes_to_associations: function() {
20211
20694
  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;
20212
20695
 
20213
- factory = model[this.resource];
20696
+ factory = model[this.resource.name];
20214
20697
  _ref = factory.has_many;
20215
20698
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
20216
20699
  association_name = _ref[_i];
@@ -20290,6 +20773,19 @@ scopable = {
20290
20773
  };
20291
20774
 
20292
20775
  builders = {
20776
+ string: stampit().enclose(function() {
20777
+ var base;
20778
+
20779
+ base = scopable.base(this);
20780
+ return stampit.mixIn(function() {
20781
+ var callbacks, value, _base, _name;
20782
+
20783
+ value = arguments[0], callbacks = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
20784
+ callbacks.length && (this.scope.then = this.scope.then.concat(callbacks));
20785
+ (_base = this.scope.data)[_name = base.name] || (_base[_name] = value != null ? value : this["$" + base.name]);
20786
+ return this;
20787
+ });
20788
+ }),
20293
20789
  boolean: stampit().enclose(function() {
20294
20790
  var base;
20295
20791
 
@@ -20665,7 +21161,7 @@ cpfable = stampit({
20665
21161
  if (d1 > 9) {
20666
21162
  d1 = 0;
20667
21163
  }
20668
- if (+dv.charAt(0 !== d1)) {
21164
+ if (+dv.charAt(0) !== d1) {
20669
21165
  return false;
20670
21166
  }
20671
21167
  d1 *= 2;
@@ -20729,8 +21225,12 @@ messages = {
20729
21225
  return "O registro associado " + attribute_name + " não é válido.";
20730
21226
  },
20731
21227
  server: function(attribute_name, options) {
20732
- attribute_name = this.human_attribute_name(attribute_name);
20733
- return "" + attribute_name + " " + options.server_message + ".";
21228
+ if (attribute_name === 'base') {
21229
+ return options.server_message;
21230
+ } else {
21231
+ attribute_name = this.human_attribute_name(attribute_name);
21232
+ return "" + attribute_name + " " + options.server_message + ".";
21233
+ }
20734
21234
  },
20735
21235
  type: function(attribute_name, options) {
20736
21236
  attribute_name = this.human_attribute_name(attribute_name);
@@ -20764,7 +21264,8 @@ errorsable = stampit({
20764
21264
  }
20765
21265
  },
20766
21266
  push: Array.prototype.push,
20767
- splice: Array.prototype.splice
21267
+ splice: Array.prototype.splice,
21268
+ indexOf: Array.prototype.indexOf
20768
21269
  }, {
20769
21270
  model: null,
20770
21271
  messages: null,
@@ -20785,7 +21286,7 @@ initializers = {
20785
21286
  }
20786
21287
  });
20787
21288
  this.validated = false;
20788
- this.subscribe('dirty', function() {
21289
+ this.subscribe('dirty', function(value) {
20789
21290
  return this.validated = false;
20790
21291
  });
20791
21292
  return Object.defineProperty(this, 'valid', {
@@ -20866,7 +21367,7 @@ extensions = {
20866
21367
  validate: function(doned, failed) {
20867
21368
  var results, validator, _i, _len, _ref;
20868
21369
 
20869
- if (this.validated) {
21370
+ if (this.validated && !this.dirty) {
20870
21371
  return this.validation;
20871
21372
  }
20872
21373
  this.errors.clear();
@@ -28764,7 +29265,7 @@ require.register("ened/vendor/assets/javascripts/lennon/lennon.js", function(exp
28764
29265
  //-- Hashify internal links if history is not available
28765
29266
  } else {
28766
29267
  if ( !$this.data('lennonized') ) {
28767
- $this.attr('href', '/#' + href).data('lennonized', true);
29268
+ $this.attr('href', '/#!' + href).data('lennonized', true);
28768
29269
  }
28769
29270
  }
28770
29271
  });
@@ -28825,15 +29326,15 @@ require.register("ened/vendor/assets/javascripts/lennon/lennon.js", function(exp
28825
29326
  i, j,
28826
29327
  paramKeys,
28827
29328
  params,
28828
- path = options.historyEnabled? window.location.pathname : window.location.hash.replace('#', '') || '/';
29329
+ path = options.historyEnabled? window.location.pathname : window.location.hash.replace('#!', '') || '/';
28829
29330
 
28830
29331
  //-- If we land on the page with a hash value and history is enabled, redirect to the non-hash page
28831
- if ( window.location.hash && options.historyEnabled ) {
28832
- window.location.href = window.location.hash.replace('#', '');
29332
+ if ( window.location.hash.indexOf('#!') != -1 && options.historyEnabled ) {
29333
+ window.location.href = window.location.hash.replace('#!', '');
28833
29334
 
28834
29335
  //-- If we land on the page with a path and history is disabled, redirect to the hash page
28835
29336
  } else if ( '/' !== window.location.pathname && !options.historyEnabled ) {
28836
- window.location.href = '/#' + window.location.pathname;
29337
+ window.location.href = '/#!' + window.location.pathname;
28837
29338
  }
28838
29339
 
28839
29340
  //-- Process the route
@@ -29463,8 +29964,12 @@ require.alias("components-modernizr/modernizr.js", "components-modernizr/index.j
29463
29964
  require.alias("indefinido-indemma/index.js", "ened/deps/indemma/index.js");
29464
29965
  require.alias("indefinido-indemma/vendor/stampit.js", "ened/deps/indemma/vendor/stampit.js");
29465
29966
  require.alias("indefinido-indemma/vendor/sinon.js", "ened/deps/indemma/vendor/sinon.js");
29967
+ require.alias("indefinido-indemma/vendor/owl/pluralize.js", "ened/deps/indemma/vendor/owl/pluralize.js");
29466
29968
  require.alias("indefinido-indemma/lib/record.js", "ened/deps/indemma/lib/record.js");
29467
29969
  require.alias("indefinido-indemma/lib/record/associable.js", "ened/deps/indemma/lib/record/associable.js");
29970
+ require.alias("indefinido-indemma/lib/record/persistable.js", "ened/deps/indemma/lib/record/persistable.js");
29971
+ require.alias("indefinido-indemma/lib/record/storable.js", "ened/deps/indemma/lib/record/storable.js");
29972
+ require.alias("indefinido-indemma/lib/record/queryable.js", "ened/deps/indemma/lib/record/queryable.js");
29468
29973
  require.alias("indefinido-indemma/lib/record/resource.js", "ened/deps/indemma/lib/record/resource.js");
29469
29974
  require.alias("indefinido-indemma/lib/record/rest.js", "ened/deps/indemma/lib/record/rest.js");
29470
29975
  require.alias("indefinido-indemma/lib/record/restfulable.js", "ened/deps/indemma/lib/record/restfulable.js");