ende 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/component.json +4 -2
  3. data/ende.gemspec +1 -0
  4. data/lib/assets/javascripts/aura/extensions/devise.js.coffee +94 -15
  5. data/lib/assets/javascripts/aura/extensions/routes.js.coffee +21 -0
  6. data/lib/assets/javascripts/aura/extensions/states.js.coffee +3 -1
  7. data/lib/assets/javascripts/aura/extensions/widget/eventable.js.coffee +19 -21
  8. data/lib/assets/javascripts/aura/extensions/widget/lifecycleable.js.coffee +17 -1
  9. data/lib/assets/javascripts/config/initializers/jquery.js.coffee +4 -3
  10. data/lib/assets/javascripts/config/initializers/load_components.js.coffee +19 -0
  11. data/lib/assets/javascripts/ende.js.coffee +3 -1
  12. data/lib/assets/javascripts/widgets/authenticator/main.js.coffee +3 -3
  13. data/lib/assets/javascripts/widgets/viewer/main.js.coffee +189 -120
  14. data/lib/ende/users_controller_extensions.rb +14 -0
  15. data/lib/ende/version.rb +1 -1
  16. data/lib/ende.rb +5 -0
  17. data/vendor/assets/components/KapIT-observe-utils/component.json +16 -0
  18. data/vendor/assets/components/KapIT-observe-utils/lib/observe-utils.js +780 -0
  19. data/vendor/assets/components/chaijs-assertion-error/component.json +18 -0
  20. data/vendor/assets/components/chaijs-assertion-error/index.js +110 -0
  21. data/vendor/assets/components/chaijs-chai/component.json +47 -0
  22. data/vendor/assets/components/chaijs-chai/index.js +1 -0
  23. data/vendor/assets/components/chaijs-chai/lib/chai/assertion.js +130 -0
  24. data/vendor/assets/components/chaijs-chai/lib/chai/core/assertions.js +1270 -0
  25. data/vendor/assets/components/chaijs-chai/lib/chai/interface/assert.js +1080 -0
  26. data/vendor/assets/components/chaijs-chai/lib/chai/interface/expect.js +12 -0
  27. data/vendor/assets/components/chaijs-chai/lib/chai/interface/should.js +76 -0
  28. data/vendor/assets/components/chaijs-chai/lib/chai/utils/addChainableMethod.js +94 -0
  29. data/vendor/assets/components/chaijs-chai/lib/chai/utils/addMethod.js +37 -0
  30. data/vendor/assets/components/chaijs-chai/lib/chai/utils/addProperty.js +40 -0
  31. data/vendor/assets/components/chaijs-chai/lib/chai/utils/flag.js +32 -0
  32. data/vendor/assets/components/chaijs-chai/lib/chai/utils/getActual.js +19 -0
  33. data/vendor/assets/components/chaijs-chai/lib/chai/utils/getEnumerableProperties.js +25 -0
  34. data/vendor/assets/components/chaijs-chai/lib/chai/utils/getMessage.js +49 -0
  35. data/vendor/assets/components/chaijs-chai/lib/chai/utils/getName.js +20 -0
  36. data/vendor/assets/components/chaijs-chai/lib/chai/utils/getPathValue.js +102 -0
  37. data/vendor/assets/components/chaijs-chai/lib/chai/utils/getProperties.js +35 -0
  38. data/vendor/assets/components/chaijs-chai/lib/chai/utils/index.js +108 -0
  39. data/vendor/assets/components/chaijs-chai/lib/chai/utils/inspect.js +320 -0
  40. data/vendor/assets/components/chaijs-chai/lib/chai/utils/objDisplay.js +48 -0
  41. data/vendor/assets/components/chaijs-chai/lib/chai/utils/overwriteMethod.js +51 -0
  42. data/vendor/assets/components/chaijs-chai/lib/chai/utils/overwriteProperty.js +54 -0
  43. data/vendor/assets/components/chaijs-chai/lib/chai/utils/test.js +26 -0
  44. data/vendor/assets/components/chaijs-chai/lib/chai/utils/transferFlags.js +44 -0
  45. data/vendor/assets/components/chaijs-chai/lib/chai/utils/type.js +45 -0
  46. data/vendor/assets/components/chaijs-chai/lib/chai.js +80 -0
  47. data/vendor/assets/components/chaijs-deep-eql/component.json +18 -0
  48. data/vendor/assets/components/chaijs-deep-eql/lib/eql.js +257 -0
  49. data/vendor/assets/components/chaijs-type-detect/component.json +16 -0
  50. data/vendor/assets/components/chaijs-type-detect/lib/type.js +142 -0
  51. data/vendor/assets/components/component-bind/component.json +14 -0
  52. data/vendor/assets/components/component-bind/index.js +24 -0
  53. data/vendor/assets/components/component-delegate/component.json +19 -0
  54. data/vendor/assets/components/component-delegate/index.js +42 -0
  55. data/vendor/assets/components/component-event/component.json +13 -0
  56. data/vendor/assets/components/component-event/index.js +40 -0
  57. data/vendor/assets/components/component-jquery/component.json +14 -0
  58. data/vendor/assets/components/component-jquery/index.js +9601 -0
  59. data/vendor/assets/components/component-link-delegate/component.json +23 -0
  60. data/vendor/assets/components/component-link-delegate/index.js +60 -0
  61. data/vendor/assets/components/component-matches-selector/component.json +20 -0
  62. data/vendor/assets/components/component-matches-selector/index.js +45 -0
  63. data/vendor/assets/components/component-query/component.json +21 -0
  64. data/vendor/assets/components/component-query/index.js +21 -0
  65. data/vendor/assets/components/component-type/component.json +18 -0
  66. data/vendor/assets/components/component-type/index.js +32 -0
  67. data/vendor/assets/components/component-url/component.json +17 -0
  68. data/vendor/assets/components/component-url/index.js +63 -0
  69. data/vendor/assets/components/discore-closest/component.json +14 -0
  70. data/vendor/assets/components/discore-closest/index.js +18 -0
  71. data/vendor/assets/components/indefinido-advisable/component.json +21 -0
  72. data/vendor/assets/components/indefinido-advisable/index.js +1 -0
  73. data/vendor/assets/components/indefinido-advisable/lib/advisable.js +60 -0
  74. data/vendor/assets/components/indefinido-indemma/component.json +40 -0
  75. data/vendor/assets/components/indefinido-indemma/index.js +1 -0
  76. data/vendor/assets/components/indefinido-indemma/lib/extensions/rivets.js +23 -0
  77. data/vendor/assets/components/indefinido-indemma/lib/record/associable.js +217 -0
  78. data/vendor/assets/components/indefinido-indemma/lib/record/maid.js +24 -0
  79. data/vendor/assets/components/indefinido-indemma/lib/record/resource.js +104 -0
  80. data/vendor/assets/components/indefinido-indemma/lib/record/rest.js +36 -0
  81. data/vendor/assets/components/indefinido-indemma/lib/record/restfulable.js +326 -0
  82. data/vendor/assets/components/indefinido-indemma/lib/record/scopable.js +279 -0
  83. data/vendor/assets/components/indefinido-indemma/lib/record/translationable.js +19 -0
  84. data/vendor/assets/components/indefinido-indemma/lib/record/validatable.js +216 -0
  85. data/vendor/assets/components/indefinido-indemma/lib/record/validations/associated.js +30 -0
  86. data/vendor/assets/components/indefinido-indemma/lib/record/validations/confirmation.js +19 -0
  87. data/vendor/assets/components/indefinido-indemma/lib/record/validations/cpf.js +60 -0
  88. data/vendor/assets/components/indefinido-indemma/lib/record/validations/presence.js +19 -0
  89. data/vendor/assets/components/indefinido-indemma/lib/record/validations/remote.js +71 -0
  90. data/vendor/assets/components/indefinido-indemma/lib/record.js +167 -0
  91. data/vendor/assets/components/indefinido-indemma/vendor/sinon.js +4290 -0
  92. data/vendor/assets/components/indefinido-indemma/vendor/stampit.js +392 -0
  93. data/vendor/assets/components/indefinido-observable/component.json +25 -0
  94. data/vendor/assets/components/indefinido-observable/components/cjohansen-sinon/sinon.js +4290 -0
  95. data/vendor/assets/components/indefinido-observable/index.js +1 -0
  96. data/vendor/assets/components/indefinido-observable/lib/adapters/rivets.js +26 -0
  97. data/vendor/assets/components/indefinido-observable/lib/observable.js +320 -0
  98. data/vendor/assets/components/indefinido-observable/vendor/shims/accessors-legacy.js +92 -0
  99. data/vendor/assets/components/indefinido-observable/vendor/shims/accessors.js +173 -0
  100. data/vendor/assets/components/indefinido-observable/vendor/shims/array.indexOf.js +8 -0
  101. data/vendor/assets/components/indefinido-observable/vendor/shims/object.create.js +77 -0
  102. data/vendor/assets/components/mikeric-rivets/component.json +15 -0
  103. data/vendor/assets/components/mikeric-rivets/dist/rivets.js +1020 -0
  104. data/vendor/assets/components/paulmillr-es6-shim/component.json +17 -0
  105. data/vendor/assets/components/paulmillr-es6-shim/es6-shim.js +985 -0
  106. data/vendor/assets/components/pluma-assimilate/component.json +25 -0
  107. data/vendor/assets/components/pluma-assimilate/dist/assimilate.js +87 -0
  108. data/vendor/assets/components/segmentio-extend/component.json +13 -0
  109. data/vendor/assets/components/segmentio-extend/index.js +15 -0
  110. data/vendor/assets/javascripts/ende/build.js +30346 -0
  111. data/vendor/assets/javascripts/jquery/inview.js +125 -0
  112. data/vendor/assets/javascripts/lennon/lennon.js +184 -0
  113. metadata +114 -3
  114. data/lib/tasks/sprite.thor +0 -62
@@ -0,0 +1,279 @@
1
+ var $, builders, defaults, extend, merge, model, record, rest, scopable, stampit,
2
+ __slice = [].slice;
3
+
4
+ require('./restfulable');
5
+
6
+ require('./resource');
7
+
8
+ stampit = require('../../vendor/stampit');
9
+
10
+ extend = require('assimilate');
11
+
12
+ merge = extend.withStrategy('deep');
13
+
14
+ $ = require('jquery');
15
+
16
+ rest = require('./rest');
17
+
18
+ scopable = {
19
+ builder: stampit().enclose(function() {
20
+ return stampit.mixIn(function(name, type) {
21
+ var builder;
22
+
23
+ if ($.type(type) === 'function') {
24
+ this["$" + name] = type() || new type;
25
+ type = $.type(this["$" + name]);
26
+ } else {
27
+ this["$" + name] = defaults[type] || type;
28
+ }
29
+ if ($.type(type) !== 'string') {
30
+ type = $.type(type);
31
+ }
32
+ builder = builders[type];
33
+ if (builder == null) {
34
+ throw "Unknown scope type " + type + " for model with resource " + model.resource;
35
+ }
36
+ this.scope.declared.push(name);
37
+ return this[name] = builder({
38
+ name: name
39
+ });
40
+ }, {
41
+ data: {},
42
+ then: [],
43
+ fail: [],
44
+ declared: [],
45
+ fetch: function(data, done, fail) {
46
+ var promise, scope;
47
+
48
+ scope = extend({}, this.scope.data);
49
+ promise = rest.get.call(this, extend(scope, data)).done(this.scope.then.concat(done)).fail([this.scope.fail, fail]);
50
+ this.scope.clear();
51
+ return promise;
52
+ },
53
+ clear: function() {
54
+ this.data = {};
55
+ return this.callbacks = [];
56
+ }
57
+ });
58
+ }),
59
+ base: stampit().state({
60
+ name: 'unamed_scope'
61
+ }),
62
+ record: {
63
+ failed: function(xhr, error, status) {
64
+ var e, message, payload;
65
+
66
+ payload = xhr.responseJSON;
67
+ try {
68
+ payload || (payload = JSON.parse(xhr.responseText));
69
+ } catch (_error) {
70
+ e = _error;
71
+ }
72
+ payload || (payload = xhr.responseText);
73
+ switch (xhr.status) {
74
+ case 422:
75
+ this.valid = false;
76
+ return this.errors = payload.errors;
77
+ default:
78
+ message = "Fail in " + this.resource + ".save:\n";
79
+ message += "Record: " + this + "\n";
80
+ message += "Status: " + status + " (" + (payload.status || xhr.status) + ")\n";
81
+ message += "Error : " + (payload.error || payload.message || payload);
82
+ }
83
+ return console.error(message);
84
+ }
85
+ },
86
+ model: {
87
+ fetch: function(data, done, fail) {
88
+ return this.scope.fetch.call(this, data, done, fail);
89
+ },
90
+ forward_scopes_to_associations: function() {
91
+ 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;
92
+
93
+ factory = model[this.resource];
94
+ _ref = factory.has_many;
95
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
96
+ association_name = _ref[_i];
97
+ associated_resource = model.singularize(association_name);
98
+ associated_factory = model[associated_resource];
99
+ if (!model[associated_resource]) {
100
+ console.warn("Associated factory not found for associated resource: " + associated_resource);
101
+ continue;
102
+ }
103
+ association = this[association_name];
104
+ association.scope = scopable.builder(association);
105
+ _ref1 = associated_factory.scope.declared;
106
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
107
+ scope = _ref1[_j];
108
+ association.scope(scope, associated_factory["$" + scope]);
109
+ }
110
+ }
111
+ _ref2 = factory.has_one;
112
+ for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
113
+ associated_resource = _ref2[_k];
114
+ if (!model[associated_resource]) {
115
+ console.warn("Associated factory not found for associated resource: " + associated_resource);
116
+ continue;
117
+ }
118
+ _ref3 = model[associated_resource].scope.declared;
119
+ for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
120
+ scope = _ref3[_l];
121
+ this[associated_resource][scope] = factory[scope];
122
+ }
123
+ }
124
+ if (factory.belongs_to.length) {
125
+ generate_forwarder = function(associated_resource) {
126
+ var declared_scopes;
127
+
128
+ associated_factory = model[associated_resource];
129
+ if (!associated_factory) {
130
+ return console.warn("Associated factory not found for associated resource: " + associated_resource);
131
+ }
132
+ declared_scopes = associated_factory.scope.declared;
133
+ return function() {
134
+ var _len4, _m, _results;
135
+
136
+ _results = [];
137
+ for (_m = 0, _len4 = declared_scopes.length; _m < _len4; _m++) {
138
+ scope = declared_scopes[_m];
139
+ _results.push(this[associated_resource][scope] = associated_factory[scope]);
140
+ }
141
+ return _results;
142
+ };
143
+ };
144
+ _ref4 = factory.belongs_to;
145
+ for (_m = 0, _len4 = _ref4.length; _m < _len4; _m++) {
146
+ associated_resource = _ref4[_m];
147
+ forwarder = generate_forwarder(associated_resource);
148
+ this.after("build_" + associated_resource, forwarder);
149
+ }
150
+ }
151
+ return true;
152
+ }
153
+ },
154
+ after_mix: function() {
155
+ var name, property, type, _results;
156
+
157
+ this.scope = scopable.builder(this);
158
+ _results = [];
159
+ for (property in this) {
160
+ type = this[property];
161
+ if (property.charAt(0) === '$') {
162
+ name = property.substring(1);
163
+ _results.push(this.scope(name, type));
164
+ } else {
165
+ _results.push(void 0);
166
+ }
167
+ }
168
+ return _results;
169
+ }
170
+ };
171
+
172
+ builders = {
173
+ boolean: stampit().enclose(function() {
174
+ var base;
175
+
176
+ base = scopable.base(this);
177
+ return stampit.mixIn(function() {
178
+ var callbacks, value, _base, _name;
179
+
180
+ value = arguments[0], callbacks = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
181
+ callbacks.length && (this.scope.then = this.scope.then.concat(callbacks));
182
+ (_base = this.scope.data)[_name = base.name] || (_base[_name] = value != null ? value : this["$" + base.name]);
183
+ return this;
184
+ });
185
+ }),
186
+ array: stampit().enclose(function() {
187
+ var base;
188
+
189
+ base = scopable.base(this);
190
+ return stampit.mixIn(function() {
191
+ var values, _base, _name;
192
+
193
+ values = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
194
+ (_base = this.scope.data)[_name = base.name] || (_base[_name] = values != null ? values : this["$" + base.name]);
195
+ return this;
196
+ });
197
+ })
198
+ };
199
+
200
+ defaults = {
201
+ boolean: true,
202
+ array: []
203
+ };
204
+
205
+ model = window.model;
206
+
207
+ record = window.record;
208
+
209
+ model.scopable = true;
210
+
211
+ model.mix(function(modelable) {
212
+ merge(modelable, scopable.model);
213
+ return modelable.after_mix.push(scopable.after_mix);
214
+ });
215
+
216
+ if (model.associable) {
217
+ model.mix(function(modelable) {
218
+ return modelable.record.after_initialize.push(function() {
219
+ return scopable.model.forward_scopes_to_associations.call(this);
220
+ });
221
+ });
222
+ model.associable.mix(function(singular_association, plural_association) {
223
+ plural_association.all = plural_association.reload = function(data, done, fail) {
224
+ var promises, reload;
225
+
226
+ if (this.parent != null) {
227
+ this.route || (this.route = "" + this.parent.route + "/" + this.parent._id + "/" + (model.pluralize(this.resource)));
228
+ }
229
+ promises = [];
230
+ if (typeof data === 'function') {
231
+ done = data;
232
+ data = void 0;
233
+ }
234
+ promises.push(this.scope.fetch.call(this, data, null, scopable.record.failed));
235
+ reload = $.when.apply(jQuery, promises);
236
+ reload.done(function(records, status) {
237
+ var association_name, singular_resource, _i, _j, _len, _len1, _ref;
238
+
239
+ Array.prototype.splice.call(this, 0);
240
+ if (!records.length) {
241
+ return;
242
+ }
243
+ singular_resource = model.singularize(this.resource);
244
+ for (_i = 0, _len = records.length; _i < _len; _i++) {
245
+ record = records[_i];
246
+ _ref = model[singular_resource].has_many;
247
+ for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
248
+ association_name = _ref[_j];
249
+ record["" + association_name + "_attributes"] = record[association_name];
250
+ delete record[association_name];
251
+ }
252
+ }
253
+ this.add.apply(this, records);
254
+ records.splice(0);
255
+ return records.push.apply(records, this);
256
+ });
257
+ reload.done(done);
258
+ reload.fail(fail);
259
+ return reload;
260
+ };
261
+ return plural_association.each = function(callback) {
262
+ var _this = this;
263
+
264
+ if (this.parent != null) {
265
+ this.route || (this.route = "" + this.parent.route + "/" + this.parent._id + "/" + (model.pluralize(this.resource)));
266
+ }
267
+ return this.get().done(function(records) {
268
+ var _i, _len, _results;
269
+
270
+ _results = [];
271
+ for (_i = 0, _len = _this.length; _i < _len; _i++) {
272
+ record = _this[_i];
273
+ _results.push(callback(record));
274
+ }
275
+ return _results;
276
+ });
277
+ };
278
+ });
279
+ }
@@ -0,0 +1,19 @@
1
+ var extend, extensions, root;
2
+
3
+ root = typeof exports !== "undefined" && exports !== null ? exports : window;
4
+
5
+ extend = require('assimilate');
6
+
7
+ extensions = {
8
+ model: {
9
+ human_attribute_name: function(attribute_name) {
10
+ var _ref, _ref1;
11
+
12
+ return ((_ref = this.translation) != null ? (_ref1 = _ref.attributes) != null ? _ref1[attribute_name] : void 0 : void 0) || attribute_name;
13
+ }
14
+ }
15
+ };
16
+
17
+ model.mix(function(modelable) {
18
+ return extend(modelable, extensions.model);
19
+ });
@@ -0,0 +1,216 @@
1
+ var errorsable, extensions, initializers, manager, messages, observable, root, stampit, type, validatable;
2
+
3
+ require('./translationable');
4
+
5
+ root = typeof exports !== "undefined" && exports !== null ? exports : window;
6
+
7
+ stampit = require('../../vendor/stampit');
8
+
9
+ observable = require('observable').mixin;
10
+
11
+ type = require('type');
12
+
13
+ messages = {
14
+ blank: function(attribute_name) {
15
+ attribute_name = this.human_attribute_name(attribute_name);
16
+ return "O campo " + attribute_name + " não pode ficar em branco.";
17
+ },
18
+ cpf: function(attribute_name) {
19
+ attribute_name = this.human_attribute_name(attribute_name);
20
+ return "O campo " + attribute_name + " não está válido.";
21
+ },
22
+ confirmation: function(attribute_name) {
23
+ var confirmation_attribute_name;
24
+
25
+ confirmation_attribute_name = this.human_attribute_name("" + attribute_name + "_confirmation");
26
+ attribute_name = this.human_attribute_name(attribute_name);
27
+ return "O campo " + attribute_name + " não está diacordo com a confirmação " + confirmation_attribute_name + ".";
28
+ },
29
+ associated: function(attribute_name) {
30
+ attribute_name = this.human_attribute_name(attribute_name);
31
+ return "O registro associado " + attribute_name + " não é válido";
32
+ },
33
+ server: function(attribute_name, options) {
34
+ return "" + (this.human_attribute_name(attribute_name)) + " " + options.server_message + " ";
35
+ }
36
+ };
37
+
38
+ errorsable = stampit({
39
+ add: function(attribute_name, message_key, options) {
40
+ var translator;
41
+
42
+ this.push([attribute_name, message_key, options]);
43
+ this.messages[attribute_name] = '';
44
+ translator = messages[message_key];
45
+ if (translator != null) {
46
+ return this.messages[attribute_name] += translator.call(this.model, attribute_name, options);
47
+ } else {
48
+ return this.messages[attribute_name] += message_key;
49
+ }
50
+ },
51
+ clear: function() {
52
+ var attribute_name, _results;
53
+
54
+ if (this.length) {
55
+ this.length = 0;
56
+ _results = [];
57
+ for (attribute_name in this.messages) {
58
+ _results.push(this.messages[attribute_name] = null);
59
+ }
60
+ return _results;
61
+ }
62
+ },
63
+ push: Array.prototype.push,
64
+ splice: Array.prototype.splice
65
+ }, {
66
+ model: null,
67
+ messages: {},
68
+ length: 0
69
+ });
70
+
71
+ initializers = {
72
+ define_triggers: function() {
73
+ this.errors = errorsable({
74
+ model: model[this.resource]
75
+ });
76
+ this.before('save', function() {
77
+ if (this.save) {
78
+ return this.validate();
79
+ }
80
+ });
81
+ this.validated = false;
82
+ this.subscribe('dirty', function() {
83
+ return this.validated = false;
84
+ });
85
+ return Object.defineProperty(this, 'valid', {
86
+ get: function() {
87
+ this.validate();
88
+ if (this.validation.state() === 'resolved') {
89
+ return !this.errors.length;
90
+ } else {
91
+ return null;
92
+ }
93
+ },
94
+ set: function() {
95
+ throw new TypeError("You can't set the value for the valid property.");
96
+ },
97
+ enumerable: false
98
+ });
99
+ },
100
+ create_validators: function(definitions) {
101
+ var definition, name, validator, validator_options, _ref, _results;
102
+
103
+ _ref = manager.validators;
104
+ _results = [];
105
+ for (name in _ref) {
106
+ validator = _ref[name];
107
+ definition = definitions[validator.definition_key];
108
+ if (definition) {
109
+ if (type(definition) !== 'array') {
110
+ definition = [definition];
111
+ }
112
+ _results.push((function() {
113
+ var _i, _len, _results1;
114
+
115
+ _results1 = [];
116
+ for (_i = 0, _len = definition.length; _i < _len; _i++) {
117
+ validator_options = definition[_i];
118
+ if (type(validator_options) !== 'object') {
119
+ validator_options = {
120
+ attribute_name: validator_options
121
+ };
122
+ }
123
+ validator_options.model = this;
124
+ this.validators.push(validator(validator_options));
125
+ _results1.push(delete definitions[validator.definition_key]);
126
+ }
127
+ return _results1;
128
+ }).call(this));
129
+ } else {
130
+ _results.push(void 0);
131
+ }
132
+ }
133
+ return _results;
134
+ }
135
+ };
136
+
137
+ extensions = {
138
+ model: {
139
+ validators: []
140
+ },
141
+ record: {
142
+ validate_attribute: function(attribute, doned, failed) {
143
+ var results, validation, validator, _i, _len, _ref;
144
+
145
+ this.errors.messages[attribute] = null;
146
+ results = [this, attribute];
147
+ _ref = model[this.resource].validators;
148
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
149
+ validator = _ref[_i];
150
+ if (validator.attribute_name === attribute) {
151
+ results.push(validator.validate_each(this, validator.attribute_name, this[validator.attribute_name]));
152
+ }
153
+ }
154
+ validation = jQuery.when.apply(jQuery, results);
155
+ validation.done(doned);
156
+ validation.fail(failed);
157
+ return validation;
158
+ },
159
+ validate: function(doned, failed) {
160
+ var results, validator, _i, _len, _ref;
161
+
162
+ if (this.validated) {
163
+ return this.validation;
164
+ }
165
+ this.errors.clear();
166
+ results = [this];
167
+ _ref = model[this.resource].validators;
168
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
169
+ validator = _ref[_i];
170
+ results.push(validator.validate_each(this, validator.attribute_name, this[validator.attribute_name]));
171
+ }
172
+ this.validation = jQuery.when.apply(jQuery, results);
173
+ this.validation.done(doned);
174
+ this.validation.fail(failed);
175
+ this.validation.then(function(record) {
176
+ return record.validated = true;
177
+ });
178
+ return this.validation;
179
+ }
180
+ }
181
+ };
182
+
183
+ manager = {
184
+ validators: {}
185
+ };
186
+
187
+ validatable = stampit({
188
+ validate: function() {
189
+ throw new Error('Composed factory must override the validate method');
190
+ },
191
+ validate_each: function() {
192
+ throw new Error('Composed factory must override the validate each method');
193
+ }
194
+ });
195
+
196
+ model.mix(function(modelable) {
197
+ jQuery.extend(modelable, extensions.model);
198
+ jQuery.extend(modelable.record, extensions.record);
199
+ modelable.after_mix.unshift(initializers.create_validators);
200
+ modelable.record.after_initialize.push(initializers.define_triggers);
201
+ return model.validators = manager.validators;
202
+ });
203
+
204
+ root.validatable = validatable;
205
+
206
+ root.manager = manager;
207
+
208
+ require('./validations/confirmation');
209
+
210
+ require('./validations/associated');
211
+
212
+ require('./validations/presence');
213
+
214
+ require('./validations/remote');
215
+
216
+ require('./validations/cpf');
@@ -0,0 +1,30 @@
1
+ var associationable, composed, stampit, validations;
2
+
3
+ validations = require('../validatable');
4
+
5
+ stampit = require('../../../vendor/stampit');
6
+
7
+ associationable = stampit({
8
+ validate_each: function(record, attribute, value) {
9
+ var associated_validation;
10
+
11
+ if (record[attribute]) {
12
+ if (model[record.resource].has_one.indexOf(attribute) === -1) {
13
+ throw new Error('Only has_one associations are supported to validates_associated');
14
+ }
15
+ associated_validation = record[attribute].validate();
16
+ associated_validation.done(function() {
17
+ if (record[attribute].errors.length) {
18
+ return record.errors.add(attribute, 'associated', this.options);
19
+ }
20
+ });
21
+ return associated_validation;
22
+ }
23
+ }
24
+ });
25
+
26
+ composed = stampit.compose(validations.validatable, associationable);
27
+
28
+ composed.definition_key = 'validates_associated';
29
+
30
+ validations.manager.validators.association = composed;
@@ -0,0 +1,19 @@
1
+ var composed, confirmationable, stampit, validations;
2
+
3
+ validations = require('../validatable');
4
+
5
+ stampit = require('../../../vendor/stampit');
6
+
7
+ confirmationable = stampit({
8
+ validate_each: function(record, attribute, value) {
9
+ if (record[attribute] !== record["" + attribute + "_confirmation"]) {
10
+ return record.errors.add(attribute, 'confirmation', this.options);
11
+ }
12
+ }
13
+ });
14
+
15
+ composed = stampit.compose(validations.validatable, confirmationable);
16
+
17
+ composed.definition_key = 'validates_confirmation_of';
18
+
19
+ validations.manager.validators.confirmation = composed;
@@ -0,0 +1,60 @@
1
+ var composed, cpfable, stampit, validations;
2
+
3
+ validations = require('../validatable');
4
+
5
+ stampit = require('../../../vendor/stampit');
6
+
7
+ cpfable = stampit({
8
+ validate_format: function(value) {
9
+ var c, d1, dv, i, v, _i, _j;
10
+
11
+ value = value.replace(/[\.\-]/g, "");
12
+ if (value.length < 11) {
13
+ return false;
14
+ }
15
+ if (value.match(/^(0+|1+|2+|3+|4+|5+|6+|7+|8+|9+)$/)) {
16
+ return false;
17
+ }
18
+ c = value.substr(0, 9);
19
+ dv = value.substr(9, 2);
20
+ d1 = 0;
21
+ v = false;
22
+ i = 0;
23
+ for (i = _i = 1; _i <= 9; i = ++_i) {
24
+ d1 += c.charAt(i) * (10 - i);
25
+ }
26
+ if (d1 === 0) {
27
+ return false;
28
+ }
29
+ d1 = 11 - (d1 % 11);
30
+ if (d1 > 9) {
31
+ d1 = 0;
32
+ }
33
+ if (+dv.charAt(0 !== d1)) {
34
+ return false;
35
+ }
36
+ d1 *= 2;
37
+ for (i = _j = 1; _j <= 9; i = ++_j) {
38
+ d1 += c.charAt(i) * (11 - i);
39
+ }
40
+ d1 = 11 - (d1 % 11);
41
+ if (d1 > 9) {
42
+ d1 = 0;
43
+ }
44
+ if (+dv.charAt(1) !== d1) {
45
+ return false;
46
+ }
47
+ return true;
48
+ },
49
+ validate_each: function(record, attribute, value) {
50
+ if (value && !this.validate_format(value)) {
51
+ return record.errors.add(attribute, 'cpf', this.options);
52
+ }
53
+ }
54
+ });
55
+
56
+ composed = stampit.compose(validations.validatable, cpfable);
57
+
58
+ composed.definition_key = 'validates_cpf_format';
59
+
60
+ validations.manager.validators.cpf = composed;
@@ -0,0 +1,19 @@
1
+ var composed, presenceable, stampit, validations;
2
+
3
+ validations = require('../validatable');
4
+
5
+ stampit = require('../../../vendor/stampit');
6
+
7
+ presenceable = stampit({
8
+ validate_each: function(record, attribute, value) {
9
+ if (value === null || value === '' || value === void 0) {
10
+ return record.errors.add(attribute, 'blank', this.options);
11
+ }
12
+ }
13
+ });
14
+
15
+ composed = stampit.compose(validations.validatable, presenceable);
16
+
17
+ composed.definition_key = 'validates_presence_of';
18
+
19
+ validations.manager.validators.presence = composed;