ende 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/component.json +2 -2
- data/components/indefinido/indemma/master/component.json +27 -17
- data/components/indefinido/indemma/master/lib/record/associable.js +74 -75
- data/components/indefinido/indemma/master/lib/record/dirtyable.js +40 -0
- data/components/indefinido/indemma/master/lib/record/queryable.js +2 -2
- data/components/indefinido/indemma/master/lib/record/resource.js +1 -1
- data/components/indefinido/indemma/master/lib/record/rest.js +7 -2
- data/components/indefinido/indemma/master/lib/record/restfulable.js +37 -10
- data/components/indefinido/indemma/master/lib/record/scopable.js +20 -47
- data/components/indefinido/indemma/master/lib/record/storable.js +11 -0
- data/components/indefinido/indemma/master/lib/record/validatable.js +195 -1068
- data/components/indefinido/indemma/master/lib/record.js +1 -1
- data/components/indefinido/indemma/master/vendor/stampit.js +568 -242
- data/components/indefinido/observable/es6-modules/component.json +39 -0
- data/components/indefinido/{indemma/master/components/indefinido-observable → observable/es6-modules}/lib/adapters/rivets.js +3 -1
- data/components/indefinido/observable/es6-modules/lib/legacy/notifierable.js +145 -0
- data/components/indefinido/observable/es6-modules/lib/legacy/schedulerable.js +114 -0
- data/components/indefinido/observable/es6-modules/lib/lookup.js +38 -0
- data/components/indefinido/observable/es6-modules/lib/observable/keypath_observer.js +38 -0
- data/components/indefinido/observable/es6-modules/lib/observable/observation.js +45 -0
- data/components/indefinido/observable/es6-modules/lib/observable/selection.js +57 -0
- data/components/indefinido/observable/es6-modules/lib/observable/self_observer.js +38 -0
- data/components/indefinido/observable/es6-modules/lib/observable.js +90 -0
- data/components/indefinido/observable/es6-modules/lib/platform.js +12 -0
- data/components/indefinido/observable/es6-modules/vendor/observe-js/observe.js +1631 -0
- data/components/indefinido/{indemma/master/components/indefinido-observable → observable/es6-modules}/vendor/shims/accessors.js +85 -10
- data/lib/assets/javascripts/aura/extensions/rivets.js.coffee +1 -1
- data/lib/ende/version.rb +1 -1
- data/vendor/assets/components/ende_build.js +18379 -26828
- metadata +20 -128
- data/components/indefinido/indemma/master/.gitignore +0 -17
- data/components/indefinido/indemma/master/.ruby-gemset +0 -1
- data/components/indefinido/indemma/master/.ruby-version +0 -1
- data/components/indefinido/indemma/master/Gemfile +0 -13
- data/components/indefinido/indemma/master/Guardfile +0 -39
- data/components/indefinido/indemma/master/History.md +0 -0
- data/components/indefinido/indemma/master/Readme.md +0 -447
- data/components/indefinido/indemma/master/build/build.js +0 -26288
- data/components/indefinido/indemma/master/build/development.js +0 -22200
- data/components/indefinido/indemma/master/build/release.js +0 -22139
- data/components/indefinido/indemma/master/build/test.js +0 -22200
- data/components/indefinido/indemma/master/components/chaijs-assertion-error/component.json +0 -18
- data/components/indefinido/indemma/master/components/chaijs-assertion-error/index.js +0 -110
- data/components/indefinido/indemma/master/components/chaijs-chai/component.json +0 -47
- data/components/indefinido/indemma/master/components/chaijs-chai/index.js +0 -1
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/assertion.js +0 -130
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/core/assertions.js +0 -1270
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/interface/assert.js +0 -1080
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/interface/expect.js +0 -12
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/interface/should.js +0 -76
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/addChainableMethod.js +0 -94
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/addMethod.js +0 -37
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/addProperty.js +0 -40
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/eql.js +0 -129
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/flag.js +0 -32
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/getActual.js +0 -19
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/getEnumerableProperties.js +0 -25
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/getMessage.js +0 -49
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/getName.js +0 -20
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/getPathValue.js +0 -102
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/getProperties.js +0 -35
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/index.js +0 -108
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/inspect.js +0 -320
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/objDisplay.js +0 -48
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/overwriteMethod.js +0 -51
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/overwriteProperty.js +0 -54
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/test.js +0 -26
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/transferFlags.js +0 -44
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/type.js +0 -45
- data/components/indefinido/indemma/master/components/chaijs-chai/lib/chai.js +0 -80
- data/components/indefinido/indemma/master/components/component-bind/component.json +0 -14
- data/components/indefinido/indemma/master/components/component-bind/index.js +0 -24
- data/components/indefinido/indemma/master/components/component-jquery/component.json +0 -14
- data/components/indefinido/indemma/master/components/component-jquery/index.js +0 -9601
- data/components/indefinido/indemma/master/components/component-type/component.json +0 -18
- data/components/indefinido/indemma/master/components/component-type/index.js +0 -32
- data/components/indefinido/indemma/master/components/indefinido-advisable/component.json +0 -21
- data/components/indefinido/indemma/master/components/indefinido-advisable/index.js +0 -1
- data/components/indefinido/indemma/master/components/indefinido-advisable/lib/advisable.js +0 -60
- data/components/indefinido/indemma/master/components/indefinido-observable/component.json +0 -25
- data/components/indefinido/indemma/master/components/indefinido-observable/components/cjohansen-sinon/sinon.js +0 -4290
- data/components/indefinido/indemma/master/components/indefinido-observable/lib/observable.js +0 -323
- data/components/indefinido/indemma/master/components/kapit-observe-utils/component.json +0 -13
- data/components/indefinido/indemma/master/components/paulmillr-es6-shim/component.json +0 -17
- data/components/indefinido/indemma/master/components/paulmillr-es6-shim/es6-shim.js +0 -996
- data/components/indefinido/indemma/master/components/pluma-assimilate/component.json +0 -25
- data/components/indefinido/indemma/master/components/pluma-assimilate/dist/assimilate.js +0 -127
- data/components/indefinido/indemma/master/karma.conf.js +0 -76
- data/components/indefinido/indemma/master/package.json +0 -9
- data/components/indefinido/indemma/master/spec/record/associable_spec.js +0 -137
- data/components/indefinido/indemma/master/spec/record/persistable_spec.js +0 -36
- data/components/indefinido/indemma/master/spec/record/queryable_spec.js +0 -33
- data/components/indefinido/indemma/master/spec/record/resource_spec.js +0 -93
- data/components/indefinido/indemma/master/spec/record/rest_spec.js +0 -32
- data/components/indefinido/indemma/master/spec/record/restfulable_spec.js +0 -300
- data/components/indefinido/indemma/master/spec/record/scopable_spec.js +0 -212
- data/components/indefinido/indemma/master/spec/record/storable_spec.js +0 -53
- data/components/indefinido/indemma/master/spec/record/translationable.js +0 -28
- data/components/indefinido/indemma/master/spec/record/validatable_spec.js +0 -111
- data/components/indefinido/indemma/master/spec/record/validations/associated_spec.js +0 -43
- data/components/indefinido/indemma/master/spec/record/validations/confirmation_spec.js +0 -36
- data/components/indefinido/indemma/master/spec/record/validations/cpf_spec.js +0 -35
- data/components/indefinido/indemma/master/spec/record/validations/presence_spec.js +0 -28
- data/components/indefinido/indemma/master/spec/record/validations/remote_spec.js +0 -87
- data/components/indefinido/indemma/master/spec/record/validations/type_spec.js +0 -48
- data/components/indefinido/indemma/master/spec/record_spec.js +0 -37
- data/components/indefinido/indemma/master/spec/spec_helper.js +0 -11
- data/components/indefinido/indemma/master/spec/support/value_objects/phone.js +0 -45
- data/components/indefinido/indemma/master/src/lib/extensions/rivets.coffee +0 -17
- data/components/indefinido/indemma/master/src/lib/record/associable.coffee +0 -380
- data/components/indefinido/indemma/master/src/lib/record/errors.coffee +0 -20
- data/components/indefinido/indemma/master/src/lib/record/maid.coffee +0 -16
- data/components/indefinido/indemma/master/src/lib/record/persistable.coffee +0 -32
- data/components/indefinido/indemma/master/src/lib/record/queryable.coffee +0 -30
- data/components/indefinido/indemma/master/src/lib/record/resource.coffee +0 -106
- data/components/indefinido/indemma/master/src/lib/record/rest.coffee +0 -28
- data/components/indefinido/indemma/master/src/lib/record/restfulable.coffee +0 -447
- data/components/indefinido/indemma/master/src/lib/record/scopable.coffee +0 -294
- data/components/indefinido/indemma/master/src/lib/record/storable.coffee +0 -46
- data/components/indefinido/indemma/master/src/lib/record/translationable.coffee +0 -18
- data/components/indefinido/indemma/master/src/lib/record/validatable.coffee +0 -207
- data/components/indefinido/indemma/master/src/lib/record/validations/associated.coffee +0 -30
- data/components/indefinido/indemma/master/src/lib/record/validations/confirmation.coffee +0 -17
- data/components/indefinido/indemma/master/src/lib/record/validations/cpf.coffee +0 -57
- data/components/indefinido/indemma/master/src/lib/record/validations/presence.coffee +0 -16
- data/components/indefinido/indemma/master/src/lib/record/validations/remote.coffee +0 -61
- data/components/indefinido/indemma/master/src/lib/record/validations/type.coffee +0 -31
- data/components/indefinido/indemma/master/src/lib/record/validations/validatorable.coffee +0 -5
- data/components/indefinido/indemma/master/src/lib/record.coffee +0 -138
- data/components/indefinido/indemma/master/src/spec/record/associable_spec.coffee +0 -130
- data/components/indefinido/indemma/master/src/spec/record/persistable_spec.coffee +0 -30
- data/components/indefinido/indemma/master/src/spec/record/queryable_spec.coffee +0 -27
- data/components/indefinido/indemma/master/src/spec/record/resource_spec.coffee +0 -69
- data/components/indefinido/indemma/master/src/spec/record/rest_spec.coffee +0 -22
- data/components/indefinido/indemma/master/src/spec/record/restfulable_spec.coffee +0 -215
- data/components/indefinido/indemma/master/src/spec/record/scopable_spec.coffee +0 -191
- data/components/indefinido/indemma/master/src/spec/record/storable_spec.coffee +0 -40
- data/components/indefinido/indemma/master/src/spec/record/translationable.coffee +0 -19
- data/components/indefinido/indemma/master/src/spec/record/validatable_spec.coffee +0 -100
- data/components/indefinido/indemma/master/src/spec/record/validations/associated_spec.coffee +0 -35
- data/components/indefinido/indemma/master/src/spec/record/validations/confirmation_spec.coffee +0 -25
- data/components/indefinido/indemma/master/src/spec/record/validations/cpf_spec.coffee +0 -28
- data/components/indefinido/indemma/master/src/spec/record/validations/presence_spec.coffee +0 -24
- data/components/indefinido/indemma/master/src/spec/record/validations/remote_spec.coffee +0 -74
- data/components/indefinido/indemma/master/src/spec/record/validations/type_spec.coffee +0 -33
- data/components/indefinido/indemma/master/src/spec/record_spec.coffee +0 -23
- data/components/indefinido/indemma/master/src/spec/spec_helper.coffee +0 -9
- data/components/indefinido/indemma/master/src/spec/support/value_objects/phone.coffee +0 -30
- data/components/indefinido/indemma/master/vendor/object/mixin.js +0 -196
- data/components/indefinido/indemma/master/vendor/sinon.js +0 -4290
- /data/components/indefinido/{indemma/master/components/indefinido-observable → observable/es6-modules}/index.js +0 -0
- /data/components/indefinido/{indemma/master/components/indefinido-observable → observable/es6-modules}/vendor/shims/accessors-legacy.js +0 -0
- /data/components/indefinido/{indemma/master/components/indefinido-observable → observable/es6-modules}/vendor/shims/array.indexOf.js +0 -0
- /data/components/indefinido/{indemma/master/components/indefinido-observable → observable/es6-modules}/vendor/shims/object.create.js +0 -0
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
require './restfulable'
|
|
2
|
-
require './resource'
|
|
3
|
-
|
|
4
|
-
stampit = require '../../vendor/stampit'
|
|
5
|
-
extend = require 'assimilate'
|
|
6
|
-
observable = require('observable').mixin
|
|
7
|
-
merge = extend.withStrategy 'deep'
|
|
8
|
-
$ = require 'jquery'
|
|
9
|
-
rest = require './rest'
|
|
10
|
-
|
|
11
|
-
# TODO merge all with fetch and remove this util object
|
|
12
|
-
util =
|
|
13
|
-
model:
|
|
14
|
-
map: (records) ->
|
|
15
|
-
(@build or @).call @, record for record, index in records
|
|
16
|
-
|
|
17
|
-
# TODO better responsibilty division for this code
|
|
18
|
-
scopable =
|
|
19
|
-
builder: stampit().enclose ->
|
|
20
|
-
|
|
21
|
-
# Builds a given scope
|
|
22
|
-
# {param} name Scope name also, the name of method used to invoke it
|
|
23
|
-
# {param} type Default value for scope, or base class to derive default for default type
|
|
24
|
-
|
|
25
|
-
stampit.mixIn (name, type) ->
|
|
26
|
-
if $.type(type) == 'function'
|
|
27
|
-
@["$#{name}"] = type() || new type
|
|
28
|
-
type = $.type @["$#{name}"]
|
|
29
|
-
else
|
|
30
|
-
@["$#{name}"] = defaults[type] || type
|
|
31
|
-
|
|
32
|
-
type = $.type type unless $.type(type) == 'string'
|
|
33
|
-
builder = builders[type]
|
|
34
|
-
|
|
35
|
-
throw "Unknown scope type: '#{type}', For model with resource: '#{@resource}'" unless builder?
|
|
36
|
-
|
|
37
|
-
@scope.declared.push name
|
|
38
|
-
@[name] = builder name: name
|
|
39
|
-
,
|
|
40
|
-
data: {}
|
|
41
|
-
then: []
|
|
42
|
-
fail: []
|
|
43
|
-
declared: []
|
|
44
|
-
fetch: (data, done, fail) ->
|
|
45
|
-
|
|
46
|
-
if typeof data == 'function'
|
|
47
|
-
done = data
|
|
48
|
-
data = {}
|
|
49
|
-
|
|
50
|
-
scope = extend {}, @scope.data
|
|
51
|
-
observable.unobserve scope
|
|
52
|
-
|
|
53
|
-
if scope.noned?
|
|
54
|
-
deferred = $.Deferred()
|
|
55
|
-
deferred.resolveWith @, [[]]
|
|
56
|
-
else
|
|
57
|
-
deferred = rest.get.call(@, extend scope, data)
|
|
58
|
-
|
|
59
|
-
deferred
|
|
60
|
-
.then(util.model.map)
|
|
61
|
-
.done(@scope.then.concat [done])
|
|
62
|
-
.fail(@scope.fail.concat [fail])
|
|
63
|
-
|
|
64
|
-
@scope.clear()
|
|
65
|
-
|
|
66
|
-
deferred
|
|
67
|
-
|
|
68
|
-
clear: ->
|
|
69
|
-
@data = {}
|
|
70
|
-
@callbacks = []
|
|
71
|
-
|
|
72
|
-
# Shared scope stuff
|
|
73
|
-
base: stampit().state
|
|
74
|
-
name: 'unamed_scope'
|
|
75
|
-
|
|
76
|
-
record:
|
|
77
|
-
# Parse error json if any
|
|
78
|
-
failed: (xhr, error, status) ->
|
|
79
|
-
payload = xhr.responseJSON
|
|
80
|
-
try payload ||= JSON.parse(xhr.responseText) catch e
|
|
81
|
-
payload ||= xhr.responseText
|
|
82
|
-
|
|
83
|
-
# When client fail
|
|
84
|
-
switch xhr.status
|
|
85
|
-
when 422
|
|
86
|
-
@valid = false
|
|
87
|
-
return @errors = payload.errors
|
|
88
|
-
# Unknown fail
|
|
89
|
-
else
|
|
90
|
-
message = "Fail in #{@resource}.save:\n"
|
|
91
|
-
message += "Record: #{@}\n"
|
|
92
|
-
message += "Status: #{status} (#{payload.status || xhr.status})\n"
|
|
93
|
-
message += "Error : #{payload.error || payload.message || payload}"
|
|
94
|
-
|
|
95
|
-
console.error message
|
|
96
|
-
model:
|
|
97
|
-
# TODO implement getter for none property!
|
|
98
|
-
none: ->
|
|
99
|
-
@scope.data.noned = true
|
|
100
|
-
@
|
|
101
|
-
|
|
102
|
-
# TODO merge with all object
|
|
103
|
-
fetch: (data, done, fail) ->
|
|
104
|
-
if typeof data == 'function'
|
|
105
|
-
done = data
|
|
106
|
-
data = null
|
|
107
|
-
|
|
108
|
-
@scope.fetch.call @, data, done, fail
|
|
109
|
-
|
|
110
|
-
# TODO optmize this iterations or add support for stampit on associable and merge factories
|
|
111
|
-
# @ = record instance
|
|
112
|
-
forward_scopes_to_associations: ->
|
|
113
|
-
factory = model[@resource.name]
|
|
114
|
-
|
|
115
|
-
for association_name in factory.has_many
|
|
116
|
-
associated_resource = model.singularize association_name
|
|
117
|
-
associated_factory = model[associated_resource]
|
|
118
|
-
|
|
119
|
-
# TODO change this warn message into a exception when
|
|
120
|
-
# associations are renamable
|
|
121
|
-
unless model[associated_resource]
|
|
122
|
-
console.warn("Associated factory not found for associated resource: #{associated_resource}")
|
|
123
|
-
continue
|
|
124
|
-
|
|
125
|
-
association = @[association_name]
|
|
126
|
-
association.scope = scopable.builder association
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
for scope in associated_factory.scope.declared
|
|
130
|
-
association.scope scope, associated_factory["$#{scope}"]
|
|
131
|
-
|
|
132
|
-
for associated_resource in factory.has_one
|
|
133
|
-
# TODO change this warn message into a exception when
|
|
134
|
-
# associations are renamable
|
|
135
|
-
unless model[associated_resource]
|
|
136
|
-
console.warn("Associated factory not found for associated resource: #{associated_resource}")
|
|
137
|
-
continue
|
|
138
|
-
|
|
139
|
-
for scope in model[associated_resource].scope.declared
|
|
140
|
-
@[associated_resource][scope] = factory[scope]
|
|
141
|
-
|
|
142
|
-
# TODO improve associable inner workings to stampit objects
|
|
143
|
-
if factory.belongs_to.length
|
|
144
|
-
generate_forwarder = (associated_resource) ->
|
|
145
|
-
associated_factory = model[associated_resource]
|
|
146
|
-
|
|
147
|
-
# TODO change this warn message into a exception when
|
|
148
|
-
# associations are renamable
|
|
149
|
-
return console.warn("Associated factory not found for associated resource: #{associated_resource}") unless associated_factory
|
|
150
|
-
|
|
151
|
-
declared_scopes = associated_factory.scope.declared
|
|
152
|
-
|
|
153
|
-
->
|
|
154
|
-
for scope in declared_scopes
|
|
155
|
-
@[associated_resource][scope] = associated_factory[scope]
|
|
156
|
-
|
|
157
|
-
for associated_resource in factory.belongs_to
|
|
158
|
-
forwarder = generate_forwarder associated_resource
|
|
159
|
-
@after "build_#{associated_resource}", forwarder
|
|
160
|
-
|
|
161
|
-
true
|
|
162
|
-
# @ = model instance
|
|
163
|
-
after_mix: ->
|
|
164
|
-
@scope = scopable.builder @
|
|
165
|
-
|
|
166
|
-
for property, type of @
|
|
167
|
-
if property.charAt(0) == '$'
|
|
168
|
-
name = property.substring 1
|
|
169
|
-
@scope name, type
|
|
170
|
-
|
|
171
|
-
builders =
|
|
172
|
-
# Builds a string scope builder
|
|
173
|
-
string: stampit().enclose ->
|
|
174
|
-
base = scopable.base @
|
|
175
|
-
|
|
176
|
-
stampit.mixIn (value, callbacks...) ->
|
|
177
|
-
callbacks.length and @scope.then = @scope.then.concat callbacks
|
|
178
|
-
@scope.data[base.name] ||= value ? @["$#{base.name}"]
|
|
179
|
-
@
|
|
180
|
-
|
|
181
|
-
# Builds a boolean scope builder
|
|
182
|
-
boolean: stampit().enclose ->
|
|
183
|
-
base = scopable.base @
|
|
184
|
-
|
|
185
|
-
stampit.mixIn (value, callbacks...) ->
|
|
186
|
-
callbacks.length and @scope.then = @scope.then.concat callbacks
|
|
187
|
-
@scope.data[base.name] ||= value ? @["$#{base.name}"]
|
|
188
|
-
@
|
|
189
|
-
|
|
190
|
-
# Builds a array scope builder
|
|
191
|
-
array: stampit().enclose ->
|
|
192
|
-
base = scopable.base @
|
|
193
|
-
|
|
194
|
-
stampit.mixIn (values...) ->
|
|
195
|
-
@scope.data[base.name] ||= values ? @["$#{base.name}"]
|
|
196
|
-
@
|
|
197
|
-
|
|
198
|
-
defaults =
|
|
199
|
-
boolean: true
|
|
200
|
-
array: []
|
|
201
|
-
|
|
202
|
-
# Extend indemma
|
|
203
|
-
model = window.model # TODO better way to get parent
|
|
204
|
-
record = window.record # TODO better way to get parent
|
|
205
|
-
|
|
206
|
-
model.scopable = true
|
|
207
|
-
|
|
208
|
-
# TODO use stampit to extend record and model
|
|
209
|
-
#record.mix (recordable) ->
|
|
210
|
-
# merge recordable, scopable.record
|
|
211
|
-
|
|
212
|
-
model.mix (modelable) ->
|
|
213
|
-
merge modelable, scopable.model
|
|
214
|
-
|
|
215
|
-
modelable.after_mix.push scopable.after_mix
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
# TODO create a deferred to better mix models
|
|
219
|
-
if model.associable
|
|
220
|
-
model.mix (modelable) ->
|
|
221
|
-
modelable.record.after_initialize.push ->
|
|
222
|
-
scopable.model.forward_scopes_to_associations.call @
|
|
223
|
-
|
|
224
|
-
model.associable.mix (singular_association, plural_association) ->
|
|
225
|
-
|
|
226
|
-
# reload (done callbacks...)
|
|
227
|
-
plural_association.every = plural_association.reload = (data, done, fail) ->
|
|
228
|
-
# TODO move route discovery to plural_association.after_mix
|
|
229
|
-
@route ||= "#{@parent.route}/#{@parent._id}/#{model.pluralize @resource}" if @parent?
|
|
230
|
-
promises = []
|
|
231
|
-
|
|
232
|
-
# TODO better calculate fetch settings
|
|
233
|
-
# dirty = 0
|
|
234
|
-
# if more than 5 records are dirty, we reftech all
|
|
235
|
-
# if dirty < 5
|
|
236
|
-
# for record in @
|
|
237
|
-
# promises.push record.reload()
|
|
238
|
-
# else we reload everthing!
|
|
239
|
-
# else
|
|
240
|
-
#
|
|
241
|
-
# for record in @
|
|
242
|
-
# dirty++ if record.dirty
|
|
243
|
-
|
|
244
|
-
if typeof data == 'function'
|
|
245
|
-
done = data
|
|
246
|
-
data = undefined
|
|
247
|
-
|
|
248
|
-
promises.push @scope.fetch.call @, data, null, scopable.record.failed
|
|
249
|
-
|
|
250
|
-
reload = $.when.apply jQuery, promises
|
|
251
|
-
|
|
252
|
-
# Update association with data sent from the server
|
|
253
|
-
# TODO implement setter on this association and let user to set
|
|
254
|
-
reload.done (records, status) ->
|
|
255
|
-
|
|
256
|
-
# Clear current stored cache on this association
|
|
257
|
-
# it to an empty array
|
|
258
|
-
Array.prototype.splice.call @, 0
|
|
259
|
-
|
|
260
|
-
# return if no records were found by the server
|
|
261
|
-
return unless records.length
|
|
262
|
-
|
|
263
|
-
singular_resource = model.singularize @resource
|
|
264
|
-
|
|
265
|
-
# Normalize json data for building on association
|
|
266
|
-
for record in records
|
|
267
|
-
|
|
268
|
-
# TODO only nest specified nested attributes on model definition
|
|
269
|
-
# TODO create special deserialization method no plural association
|
|
270
|
-
# TODO check if we need to nest attributes in other association tipes
|
|
271
|
-
for association_name in model[singular_resource].has_many
|
|
272
|
-
record["#{association_name}_attributes"] = record[association_name]
|
|
273
|
-
delete record[association_name]
|
|
274
|
-
|
|
275
|
-
# Load new records on this association
|
|
276
|
-
@add.apply @, records
|
|
277
|
-
|
|
278
|
-
# Override the response records object with added to association records
|
|
279
|
-
records.splice 0
|
|
280
|
-
records.push.apply records, @
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
reload.done done
|
|
284
|
-
reload.fail fail
|
|
285
|
-
|
|
286
|
-
reload
|
|
287
|
-
|
|
288
|
-
plural_association.each = (callback) ->
|
|
289
|
-
@route ||= "#{@parent.route}/#{@parent._id}/#{model.pluralize @resource}" if @parent?
|
|
290
|
-
|
|
291
|
-
# TODO cache models
|
|
292
|
-
@get().done (records) =>
|
|
293
|
-
for record in @
|
|
294
|
-
callback record
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
extend = require 'assimilate'
|
|
2
|
-
merge = extend.withStrategy 'deep'
|
|
3
|
-
stampit = require '../../vendor/stampit'
|
|
4
|
-
|
|
5
|
-
storable = stampit
|
|
6
|
-
store: (keypath, value, options) ->
|
|
7
|
-
collection = @database
|
|
8
|
-
keypath = keypath.toString().split '.'
|
|
9
|
-
key = keypath.pop()
|
|
10
|
-
|
|
11
|
-
for entry in keypath
|
|
12
|
-
collection[entry] ||= {}
|
|
13
|
-
collection = collection[entry]
|
|
14
|
-
|
|
15
|
-
if arguments.length == 1
|
|
16
|
-
@reads++
|
|
17
|
-
collection[key]
|
|
18
|
-
else
|
|
19
|
-
@writes++
|
|
20
|
-
|
|
21
|
-
# TODO use object.defineProperty
|
|
22
|
-
value.sustained ||= true
|
|
23
|
-
collection[key] = value
|
|
24
|
-
|
|
25
|
-
values: ->
|
|
26
|
-
Object.values @database
|
|
27
|
-
,
|
|
28
|
-
type: 'object'
|
|
29
|
-
writes: 0
|
|
30
|
-
reads: 0
|
|
31
|
-
, ->
|
|
32
|
-
@database ||= {}
|
|
33
|
-
@
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
# Extend indemma
|
|
37
|
-
# TODO use stampit to extend record and model
|
|
38
|
-
model = window.model # TODO better way to get parent
|
|
39
|
-
record = window.record # TODO better way to get parent
|
|
40
|
-
|
|
41
|
-
model.storable = true
|
|
42
|
-
module.exports = storable
|
|
43
|
-
#model.mix (modelable) ->
|
|
44
|
-
# merge modelable, storable.model
|
|
45
|
-
|
|
46
|
-
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
root = exports ? window
|
|
2
|
-
|
|
3
|
-
# TODO better way to get core model definition
|
|
4
|
-
# model = require ...
|
|
5
|
-
|
|
6
|
-
# TODO implement method
|
|
7
|
-
# model[resource].validators_on 'field' # Get all validators related to this field
|
|
8
|
-
|
|
9
|
-
extend = require('assimilate')
|
|
10
|
-
|
|
11
|
-
extensions =
|
|
12
|
-
model:
|
|
13
|
-
human_attribute_name: (attribute_name) ->
|
|
14
|
-
@translation?.attributes?[attribute_name] or attribute_name
|
|
15
|
-
|
|
16
|
-
model.mix (modelable) ->
|
|
17
|
-
extend modelable, extensions.model
|
|
18
|
-
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
require './translationable'
|
|
2
|
-
|
|
3
|
-
root = exports ? @
|
|
4
|
-
stampit = require '../../vendor/stampit'
|
|
5
|
-
observable = require('observable').mixin
|
|
6
|
-
type = require 'type'
|
|
7
|
-
|
|
8
|
-
# TODO better model require
|
|
9
|
-
# model = require ...
|
|
10
|
-
|
|
11
|
-
# TODO Add base settings to validation
|
|
12
|
-
# TODO implement method
|
|
13
|
-
# model[resource].validators_on 'field' # Get all validators related to this field
|
|
14
|
-
|
|
15
|
-
# TODO use http://validatejs.org for internal handling
|
|
16
|
-
|
|
17
|
-
messages =
|
|
18
|
-
blank: (attribute_name) ->
|
|
19
|
-
attribute_name = @human_attribute_name attribute_name
|
|
20
|
-
"O campo #{attribute_name} não pode ficar em branco."
|
|
21
|
-
|
|
22
|
-
cpf: (attribute_name) ->
|
|
23
|
-
attribute_name = @human_attribute_name attribute_name
|
|
24
|
-
"O campo #{attribute_name} não está válido."
|
|
25
|
-
|
|
26
|
-
confirmation: (attribute_name) ->
|
|
27
|
-
confirmation_attribute_name = @human_attribute_name attribute_name
|
|
28
|
-
attribute_name = @human_attribute_name attribute_name.replace '_confirmation', ''
|
|
29
|
-
"O campo #{attribute_name} não está de acordo com o campo #{confirmation_attribute_name}."
|
|
30
|
-
|
|
31
|
-
associated: (attribute_name) ->
|
|
32
|
-
attribute_name = @human_attribute_name attribute_name
|
|
33
|
-
"O registro associado #{attribute_name} não é válido."
|
|
34
|
-
|
|
35
|
-
server: (attribute_name, options) ->
|
|
36
|
-
# TODO Better checking of base attribute case, better yet remove
|
|
37
|
-
# checking from here, just like active record
|
|
38
|
-
if attribute_name == 'base'
|
|
39
|
-
options.server_message
|
|
40
|
-
else
|
|
41
|
-
attribute_name = @human_attribute_name attribute_name
|
|
42
|
-
"#{attribute_name} #{options.server_message}."
|
|
43
|
-
|
|
44
|
-
type: (attribute_name, options) ->
|
|
45
|
-
attribute_name = @human_attribute_name attribute_name
|
|
46
|
-
"O campo #{attribute_name} não está válido."
|
|
47
|
-
|
|
48
|
-
# TODO move to errorsable.coffee
|
|
49
|
-
errorsable = stampit
|
|
50
|
-
add: (attribute_name, message_key, options) ->
|
|
51
|
-
|
|
52
|
-
@push [attribute_name, message_key, options]
|
|
53
|
-
# TODO Also push to attribute named
|
|
54
|
-
# @[attribute_name].push message_key, message, options
|
|
55
|
-
|
|
56
|
-
@messages[attribute_name] = ''
|
|
57
|
-
|
|
58
|
-
translator = messages[message_key]
|
|
59
|
-
|
|
60
|
-
if translator?
|
|
61
|
-
@messages[attribute_name] += translator.call @model, attribute_name, options
|
|
62
|
-
else
|
|
63
|
-
@messages[attribute_name] += message_key
|
|
64
|
-
|
|
65
|
-
clear: ->
|
|
66
|
-
if @length
|
|
67
|
-
@length = 0
|
|
68
|
-
@messages[attribute_name] = null for attribute_name of @messages
|
|
69
|
-
|
|
70
|
-
push: Array.prototype.push
|
|
71
|
-
splice: Array.prototype.splice
|
|
72
|
-
indexOf: Array.prototype.indexOf
|
|
73
|
-
,
|
|
74
|
-
model: null
|
|
75
|
-
messages: null
|
|
76
|
-
length: 0
|
|
77
|
-
, ->
|
|
78
|
-
@messages = {}
|
|
79
|
-
@
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
initializers =
|
|
83
|
-
define_triggers: ->
|
|
84
|
-
|
|
85
|
-
# TODO remove the extra inheritance level of model[@resource]
|
|
86
|
-
@errors = errorsable model: model[@resource]
|
|
87
|
-
|
|
88
|
-
# TODO only add after save when resourceable is included
|
|
89
|
-
# TODO @after_initialize validate_field_types
|
|
90
|
-
# TODO only execute save operation if record is valid
|
|
91
|
-
@before 'save', -> @validate() if @save
|
|
92
|
-
|
|
93
|
-
# TODO move this functionality control to validatable
|
|
94
|
-
@validated = false
|
|
95
|
-
@subscribe 'dirty', (value) -> value and @validated = false
|
|
96
|
-
|
|
97
|
-
Object.defineProperty @, 'valid',
|
|
98
|
-
get: ->
|
|
99
|
-
|
|
100
|
-
@validate()
|
|
101
|
-
|
|
102
|
-
if @validation.state() == 'resolved'
|
|
103
|
-
!@errors.length
|
|
104
|
-
else
|
|
105
|
-
null
|
|
106
|
-
|
|
107
|
-
set: -> throw new TypeError "You can't set the value for the valid property."
|
|
108
|
-
enumerable: false
|
|
109
|
-
|
|
110
|
-
create_validators: (definitions) ->
|
|
111
|
-
|
|
112
|
-
@validators = []
|
|
113
|
-
|
|
114
|
-
for name, validator of manager.validators
|
|
115
|
-
definition = definitions[validator.definition_key]
|
|
116
|
-
|
|
117
|
-
if definition
|
|
118
|
-
definition = [definition] unless type(definition) == 'array'
|
|
119
|
-
|
|
120
|
-
for validator_options in definition
|
|
121
|
-
|
|
122
|
-
# Parse validation definition
|
|
123
|
-
validator_options = attribute_name: validator_options unless type(validator_options) == 'object'
|
|
124
|
-
validator_options.model = @
|
|
125
|
-
|
|
126
|
-
# Instantiate validator
|
|
127
|
-
@validators.push validator validator_options
|
|
128
|
-
|
|
129
|
-
# Clear out definition to prevent validators from becoming
|
|
130
|
-
# attributes
|
|
131
|
-
delete definitions[validator.definition_key]
|
|
132
|
-
|
|
133
|
-
# Model and Record extensions
|
|
134
|
-
# TODO Use stampit!
|
|
135
|
-
extensions =
|
|
136
|
-
model:
|
|
137
|
-
validators: null
|
|
138
|
-
|
|
139
|
-
record:
|
|
140
|
-
|
|
141
|
-
validate_attribute: (attribute, doned, failed) ->
|
|
142
|
-
# TODO better clearing of single attribute error message
|
|
143
|
-
@errors.messages[attribute] = null
|
|
144
|
-
|
|
145
|
-
results = [@, attribute]
|
|
146
|
-
|
|
147
|
-
# TODO copy validators reference from model object to record object
|
|
148
|
-
# TODO update json serializer
|
|
149
|
-
# TODO filter validators for attribute
|
|
150
|
-
for validator in model[@resource.toString()].validators
|
|
151
|
-
if validator.attribute_name is attribute
|
|
152
|
-
results.push validator.validate_each @, validator.attribute_name, @[validator.attribute_name]
|
|
153
|
-
|
|
154
|
-
validation = jQuery.when.apply jQuery, results
|
|
155
|
-
validation.done doned
|
|
156
|
-
validation.fail failed
|
|
157
|
-
|
|
158
|
-
validation
|
|
159
|
-
|
|
160
|
-
validate: (doned, failed) ->
|
|
161
|
-
return @validation if @validated and not @dirty
|
|
162
|
-
|
|
163
|
-
@errors.clear()
|
|
164
|
-
results = [@]
|
|
165
|
-
|
|
166
|
-
# TODO copy validators reference from model object to record object
|
|
167
|
-
# TODO update json serializer
|
|
168
|
-
for validator in model[@resource.toString()].validators
|
|
169
|
-
results.push validator.validate_each @, validator.attribute_name, @[validator.attribute_name]
|
|
170
|
-
|
|
171
|
-
@validation = jQuery.when results...
|
|
172
|
-
@validation.done doned
|
|
173
|
-
@validation.fail failed
|
|
174
|
-
|
|
175
|
-
# TODO store this callback
|
|
176
|
-
@validation.done (record) -> record.validated ||= true
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
# Validators management
|
|
180
|
-
manager =
|
|
181
|
-
|
|
182
|
-
validators: {}
|
|
183
|
-
|
|
184
|
-
# TODO async validator loading
|
|
185
|
-
# for: (name) ->
|
|
186
|
-
# builder = @validators[name] ||= require "validations/#{name}"
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
# TODO better stampit integration
|
|
190
|
-
model.mix (modelable) ->
|
|
191
|
-
jQuery.extend modelable, extensions.model
|
|
192
|
-
|
|
193
|
-
jQuery.extend modelable.record, extensions.record
|
|
194
|
-
|
|
195
|
-
modelable.after_mix.unshift initializers.create_validators
|
|
196
|
-
modelable.record.after_initialize.push initializers.define_triggers
|
|
197
|
-
|
|
198
|
-
model.validators = manager.validators
|
|
199
|
-
|
|
200
|
-
# TODO async validator loading
|
|
201
|
-
manager.validators.confirmation = require './validations/confirmation'
|
|
202
|
-
manager.validators.associated = require './validations/associated'
|
|
203
|
-
manager.validators.presence = require './validations/presence'
|
|
204
|
-
manager.validators.remote = require './validations/remote'
|
|
205
|
-
manager.validators.type = require './validations/type'
|
|
206
|
-
manager.validators.cpf = require './validations/cpf'
|
|
207
|
-
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# TODO Add base settings to validation
|
|
2
|
-
# model = window.model
|
|
3
|
-
# TODO implement method
|
|
4
|
-
|
|
5
|
-
# model[resource].validators_on 'field' # Get all validators related to this field
|
|
6
|
-
|
|
7
|
-
stampit = require '../../../vendor/stampit'
|
|
8
|
-
|
|
9
|
-
associationable = stampit
|
|
10
|
-
validate_each: (record, attribute, value) ->
|
|
11
|
-
# TODO figure out why this method is being called twice
|
|
12
|
-
if record[attribute]
|
|
13
|
-
|
|
14
|
-
# TODO detect association type, and then validate
|
|
15
|
-
# current we only support has_one associations
|
|
16
|
-
unless model[record.resource].has_one.indexOf(attribute) != -1
|
|
17
|
-
throw new Error 'Only has_one associations are supported to validates_associated'
|
|
18
|
-
|
|
19
|
-
associated_validation = record[attribute].validate()
|
|
20
|
-
|
|
21
|
-
associated_validation.done ->
|
|
22
|
-
if record[attribute].errors.length
|
|
23
|
-
record.errors.add attribute, 'associated', @options
|
|
24
|
-
|
|
25
|
-
associated_validation
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
composed = stampit.compose(require('./validatorable'), associationable)
|
|
29
|
-
composed.definition_key = 'validates_associated'
|
|
30
|
-
module.exports = composed
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# TODO Add base settings to validation
|
|
2
|
-
# model = window.model
|
|
3
|
-
|
|
4
|
-
# TODO implement method
|
|
5
|
-
# model[resource].validators_on 'field' # Get all validators related to this field
|
|
6
|
-
|
|
7
|
-
stampit = require '../../../vendor/stampit'
|
|
8
|
-
|
|
9
|
-
confirmationable = stampit
|
|
10
|
-
validate_each: (record, attribute, value) ->
|
|
11
|
-
if record[attribute] != record["#{attribute}_confirmation"]
|
|
12
|
-
record.errors.add "#{attribute}_confirmation", 'confirmation', @options
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
composed = stampit.compose require('./validatorable'), confirmationable
|
|
16
|
-
composed.definition_key = 'validates_confirmation_of'
|
|
17
|
-
module.exports = composed
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
# TODO Add base settings to validation
|
|
2
|
-
# model = window.model
|
|
3
|
-
|
|
4
|
-
# TODO implement method
|
|
5
|
-
# model[resource].validators_on 'field' # Get all validators related to this field
|
|
6
|
-
|
|
7
|
-
stampit = require '../../../vendor/stampit'
|
|
8
|
-
|
|
9
|
-
cpfable = stampit
|
|
10
|
-
validate_format: (value) ->
|
|
11
|
-
value = value.replace /[\.\-]/g, ""
|
|
12
|
-
|
|
13
|
-
# Wrong cpf size
|
|
14
|
-
return false if value.length < 11
|
|
15
|
-
|
|
16
|
-
# Dummy but valid values (000.000.000-00, 111.111.111-11, ...)
|
|
17
|
-
return false if value.match /^(0+|1+|2+|3+|4+|5+|6+|7+|8+|9+)$/
|
|
18
|
-
|
|
19
|
-
# Mod 11 validation
|
|
20
|
-
c = value.substr 0, 9
|
|
21
|
-
dv = value.substr 9, 2
|
|
22
|
-
d1 = 0
|
|
23
|
-
v = false
|
|
24
|
-
i = 0
|
|
25
|
-
|
|
26
|
-
for i in [0..9]
|
|
27
|
-
d1 += c.charAt(i) * (10 - i)
|
|
28
|
-
|
|
29
|
-
return false if d1 == 0
|
|
30
|
-
|
|
31
|
-
d1 = 11 - (d1 % 11)
|
|
32
|
-
d1 = 0 if (d1 > 9 )
|
|
33
|
-
|
|
34
|
-
return false if +dv.charAt(0) != d1
|
|
35
|
-
|
|
36
|
-
d1 *= 2
|
|
37
|
-
for i in [0..9]
|
|
38
|
-
d1 += c.charAt(i) * (11 - i)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
d1 = 11 - (d1 % 11)
|
|
42
|
-
d1 = 0 if (d1 > 9 )
|
|
43
|
-
|
|
44
|
-
return false if +dv.charAt(1) != d1
|
|
45
|
-
|
|
46
|
-
true
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
validate_each: (record, attribute, value) ->
|
|
50
|
-
record.errors.add attribute, 'cpf', @options if value and not @validate_format value
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
composed = stampit.compose require('./validatorable'), cpfable
|
|
56
|
-
composed.definition_key = 'validates_cpf_format'
|
|
57
|
-
module.exports = composed
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# TODO Add base settings to validation
|
|
2
|
-
# model = window.model
|
|
3
|
-
|
|
4
|
-
# TODO implement method
|
|
5
|
-
# model[resource].validators_on 'field' # Get all validators related to this field
|
|
6
|
-
|
|
7
|
-
stampit = require '../../../vendor/stampit'
|
|
8
|
-
|
|
9
|
-
presenceable = stampit
|
|
10
|
-
validate_each: (record, attribute, value) ->
|
|
11
|
-
if value == null or value == '' or value == undefined
|
|
12
|
-
record.errors.add attribute, 'blank', @options
|
|
13
|
-
|
|
14
|
-
composed = stampit.compose require('./validatorable'), presenceable
|
|
15
|
-
composed.definition_key = 'validates_presence_of'
|
|
16
|
-
module.exports = composed
|