ende 0.1.14 → 0.2.0
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 +1 -1
- data/lib/assets/javascripts/aura/extensions/devise.js.coffee +5 -2
- data/lib/assets/javascripts/aura/extensions/models.js.coffee.erb +4 -3
- data/lib/assets/javascripts/value_objects/phone.js.coffee +8 -2
- data/lib/assets/javascripts/widgets/viewer/main.js.coffee +18 -21
- data/lib/ende/version.rb +1 -1
- data/lib/ende.rb +2 -2
- data/vendor/assets/javascripts/ende/build.js +485 -4879
- data/vendor/components/component-querystring/component.json +18 -0
- data/vendor/components/component-querystring/index.js +49 -0
- data/vendor/components/component-trim/component.json +13 -0
- data/vendor/components/component-trim/index.js +17 -0
- data/vendor/components/indefinido-indemma/.gitignore +14 -0
- data/vendor/components/indefinido-indemma/.ruby-gemset +1 -0
- data/vendor/components/indefinido-indemma/.ruby-version +1 -0
- data/vendor/components/indefinido-indemma/Gemfile +13 -0
- data/vendor/components/indefinido-indemma/Guardfile +39 -0
- data/vendor/components/indefinido-indemma/History.md +0 -0
- data/vendor/components/indefinido-indemma/Readme.md +443 -0
- data/vendor/components/indefinido-indemma/build/development.js +331 -0
- data/vendor/components/indefinido-indemma/build/release.js +21693 -0
- data/vendor/components/indefinido-indemma/build/test.js +331 -0
- data/vendor/components/indefinido-indemma/component.json +8 -9
- data/vendor/components/indefinido-indemma/components/chaijs-assertion-error/component.json +18 -0
- data/vendor/components/indefinido-indemma/components/chaijs-assertion-error/index.js +110 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/component.json +47 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/index.js +1 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/assertion.js +130 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/core/assertions.js +1270 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/interface/assert.js +1080 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/interface/expect.js +12 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/interface/should.js +76 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addChainableMethod.js +94 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addMethod.js +37 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addProperty.js +40 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/eql.js +129 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/flag.js +32 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getActual.js +19 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getEnumerableProperties.js +25 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getMessage.js +49 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getName.js +20 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getPathValue.js +102 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getProperties.js +35 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/index.js +108 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/inspect.js +320 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/objDisplay.js +48 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/overwriteMethod.js +51 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/overwriteProperty.js +54 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/test.js +26 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/transferFlags.js +44 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/type.js +45 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai.js +80 -0
- data/vendor/components/indefinido-indemma/components/component-bind/component.json +14 -0
- data/vendor/components/indefinido-indemma/components/component-bind/index.js +24 -0
- data/vendor/components/indefinido-indemma/components/component-jquery/component.json +14 -0
- data/vendor/components/indefinido-indemma/components/component-jquery/index.js +9601 -0
- data/vendor/components/indefinido-indemma/components/component-type/component.json +18 -0
- data/vendor/components/indefinido-indemma/components/component-type/index.js +32 -0
- data/vendor/components/indefinido-indemma/components/indefinido-advisable/component.json +21 -0
- data/vendor/components/indefinido-indemma/components/indefinido-advisable/index.js +1 -0
- data/vendor/components/indefinido-indemma/components/indefinido-advisable/lib/advisable.js +60 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/component.json +25 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/components/cjohansen-sinon/sinon.js +4290 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/index.js +1 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/lib/adapters/rivets.js +26 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/lib/observable.js +323 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/accessors-legacy.js +92 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/accessors.js +173 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/array.indexOf.js +8 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/object.create.js +77 -0
- data/vendor/components/indefinido-indemma/components/kapit-observe-utils/component.json +13 -0
- data/vendor/components/indefinido-indemma/components/pluma-assimilate/component.json +25 -0
- data/vendor/components/indefinido-indemma/components/pluma-assimilate/dist/assimilate.js +87 -0
- data/vendor/components/indefinido-indemma/karma.conf.js +86 -0
- data/vendor/components/indefinido-indemma/lib/record/associable.js +6 -6
- data/vendor/components/indefinido-indemma/lib/record/errors.js +1 -0
- data/vendor/components/indefinido-indemma/lib/record/resource.js +14 -3
- data/vendor/components/indefinido-indemma/lib/record/rest.js +7 -4
- data/vendor/components/indefinido-indemma/lib/record/restfulable.js +45 -15
- data/vendor/components/indefinido-indemma/lib/record/scopable.js +13 -3
- data/vendor/components/indefinido-indemma/lib/record/validatable.js +20 -9
- data/vendor/components/indefinido-indemma/lib/record/validations/confirmation.js +1 -1
- data/vendor/components/indefinido-indemma/lib/record/validations/remote.js +6 -5
- data/vendor/components/indefinido-indemma/lib/record/validations/type.js +29 -0
- data/vendor/components/indefinido-indemma/lib/record.js +1 -11
- data/vendor/components/indefinido-indemma/spec/record/associable_spec.js +76 -0
- data/vendor/components/indefinido-indemma/spec/record/resource_spec.js +90 -0
- data/vendor/components/indefinido-indemma/spec/record/rest_spec.js +32 -0
- data/vendor/components/indefinido-indemma/spec/record/restfulable_spec.js +232 -0
- data/vendor/components/indefinido-indemma/spec/record/scopable_spec.js +201 -0
- data/vendor/components/indefinido-indemma/spec/record/translationable.js +28 -0
- data/vendor/components/indefinido-indemma/spec/record/validatable_spec.js +111 -0
- data/vendor/components/indefinido-indemma/spec/record/validations/associated_spec.js +43 -0
- data/vendor/components/indefinido-indemma/spec/record/validations/confirmation_spec.js +36 -0
- data/vendor/components/indefinido-indemma/spec/record/validations/cpf_spec.js +35 -0
- data/vendor/components/indefinido-indemma/spec/record/validations/presence_spec.js +28 -0
- data/vendor/components/indefinido-indemma/spec/record/validations/remote_spec.js +86 -0
- data/vendor/components/indefinido-indemma/spec/record/validations/type_spec.js +48 -0
- data/vendor/components/indefinido-indemma/spec/record_spec.js +37 -0
- data/vendor/components/indefinido-indemma/spec/spec_helper.js +11 -0
- data/vendor/components/indefinido-indemma/spec/support/value_objects/phone.js +45 -0
- data/vendor/components/indefinido-indemma/src/lib/extensions/rivets.coffee +17 -0
- data/vendor/components/indefinido-indemma/src/lib/record/associable.coffee +173 -0
- data/vendor/components/indefinido-indemma/src/lib/record/errors.coffee +20 -0
- data/vendor/components/indefinido-indemma/src/lib/record/maid.coffee +16 -0
- data/vendor/components/indefinido-indemma/src/lib/record/resource.coffee +103 -0
- data/vendor/components/indefinido-indemma/src/lib/record/rest.coffee +28 -0
- data/vendor/components/indefinido-indemma/src/lib/record/restfulable.coffee +314 -0
- data/vendor/components/indefinido-indemma/src/lib/record/scopable.coffee +266 -0
- data/vendor/components/indefinido-indemma/src/lib/record/translationable.coffee +18 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validatable.coffee +209 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validations/associated.coffee +32 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validations/confirmation.coffee +19 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validations/cpf.coffee +58 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validations/presence.coffee +19 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validations/remote.coffee +65 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee +32 -0
- data/vendor/components/indefinido-indemma/src/lib/record.coffee +123 -0
- data/vendor/components/indefinido-indemma/src/spec/record/associable_spec.coffee +63 -0
- data/vendor/components/indefinido-indemma/src/spec/record/resource_spec.coffee +64 -0
- data/vendor/components/indefinido-indemma/src/spec/record/rest_spec.coffee +22 -0
- data/vendor/components/indefinido-indemma/src/spec/record/restfulable_spec.coffee +164 -0
- data/vendor/components/indefinido-indemma/src/spec/record/scopable_spec.coffee +181 -0
- data/vendor/components/indefinido-indemma/src/spec/record/translationable.coffee +19 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validatable_spec.coffee +100 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validations/associated_spec.coffee +35 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validations/confirmation_spec.coffee +25 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validations/cpf_spec.coffee +28 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validations/presence_spec.coffee +24 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee +72 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validations/type_spec.coffee +33 -0
- data/vendor/components/indefinido-indemma/src/spec/record_spec.coffee +23 -0
- data/vendor/components/indefinido-indemma/src/spec/spec_helper.coffee +9 -0
- data/vendor/components/indefinido-indemma/src/spec/support/value_objects/phone.coffee +30 -0
- data/vendor/components/indefinido-indemma/vendor/owl/pluralize.js +190 -0
- data/vendor/components/indefinido-observable/lib/observable.js +3 -0
- metadata +119 -2
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
this.Phone = (function() {
|
|
2
|
+
function Phone(area_code, number) {
|
|
3
|
+
var _ref;
|
|
4
|
+
|
|
5
|
+
this.area_code = area_code;
|
|
6
|
+
this.number = number;
|
|
7
|
+
if (typeof this.area_code === 'object') {
|
|
8
|
+
_ref = this.area_code, this.area_code = _ref.area_code, this.number = _ref.number;
|
|
9
|
+
}
|
|
10
|
+
if (!this.number) {
|
|
11
|
+
this.number = this.area_code;
|
|
12
|
+
this.area_code = null;
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(this, 'valid', {
|
|
15
|
+
get: this.validate
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
Phone.prototype.validate = function() {
|
|
20
|
+
return (this.area_code != null) && (this.number != null);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
Phone.prototype.toString = function() {
|
|
24
|
+
var formatted_number;
|
|
25
|
+
|
|
26
|
+
if (this.number != null) {
|
|
27
|
+
formatted_number = this.number.substr(0, 4) + '-' + this.number.substr(4);
|
|
28
|
+
}
|
|
29
|
+
if (this.area_code != null) {
|
|
30
|
+
return "(" + this.area_code + ") " + formatted_number;
|
|
31
|
+
} else {
|
|
32
|
+
return formatted_number;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
Phone.prototype.toJSON = function() {
|
|
37
|
+
return {
|
|
38
|
+
area_code: this.area_code,
|
|
39
|
+
number: this.number
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return Phone;
|
|
44
|
+
|
|
45
|
+
})();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
root = exports ? this
|
|
2
|
+
|
|
3
|
+
model.rivets = ->
|
|
4
|
+
|
|
5
|
+
model_extensions =
|
|
6
|
+
record:
|
|
7
|
+
tie: (element) ->
|
|
8
|
+
lasso = {}
|
|
9
|
+
lasso[@resource] = @
|
|
10
|
+
rivets.bind element, lasso
|
|
11
|
+
|
|
12
|
+
# Always preload data into the template
|
|
13
|
+
preloadData: true
|
|
14
|
+
|
|
15
|
+
model.mix (modelable) ->
|
|
16
|
+
# TODO remove jquery dependency
|
|
17
|
+
$.extend true, modelable, model_extensions
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
|
|
2
|
+
root = window
|
|
3
|
+
$ = require 'jquery'
|
|
4
|
+
|
|
5
|
+
require './resource'
|
|
6
|
+
|
|
7
|
+
# Store association methods
|
|
8
|
+
# TODO Implement setter for route
|
|
9
|
+
plural = # has_many ## TODO embeds_many
|
|
10
|
+
add : (params...) -> @push @build attributes for attributes in params
|
|
11
|
+
create: (params...) ->
|
|
12
|
+
for attributes in params
|
|
13
|
+
record = @build attributes
|
|
14
|
+
@push record
|
|
15
|
+
record.save()
|
|
16
|
+
build: (data = {}) ->
|
|
17
|
+
data.parent_resource = @parent_resource
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# TODO Setup a before save callback to generate route when there is no id
|
|
21
|
+
data.route ||= "#{@parent.route}/#{@parent._id}/#{model.pluralize @resource.toString()}" if @parent?
|
|
22
|
+
throw "associable.has_many: cannot redefine route of association #{@parent_resource}.#{@resource} from #{@route} to #{data.route}" if @route isnt data.route and @route
|
|
23
|
+
# Adds parent record to children side of association, if not set
|
|
24
|
+
# TODO check if this reference is unmade on instance elimination
|
|
25
|
+
data[@parent_resource] ||= @parent
|
|
26
|
+
|
|
27
|
+
# TODO store a singular copy of the resource for better performace
|
|
28
|
+
model[model.singularize @resource] data
|
|
29
|
+
push : Array.prototype.push
|
|
30
|
+
|
|
31
|
+
length : 0
|
|
32
|
+
json : (methods, omissions) -> record.json(methods, omissions) for record in @
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
singular = # belongs_to, has_one ## TODO embeds_one, embedded_in
|
|
36
|
+
create: (data) -> model[@resource].create $.extend {}, @, data
|
|
37
|
+
build : (data) ->
|
|
38
|
+
# Adds child record of association to parent, and returns new
|
|
39
|
+
# record
|
|
40
|
+
@[@parent_resource][@resource] = model[@resource] $.extend {}, @, data
|
|
41
|
+
|
|
42
|
+
# TODO Better association segregation
|
|
43
|
+
associable =
|
|
44
|
+
# @ = model
|
|
45
|
+
model: (options) ->
|
|
46
|
+
console.error 'resource must be defined in order to associate' unless @resource?
|
|
47
|
+
|
|
48
|
+
callbacks =
|
|
49
|
+
# Forward association nested attributes
|
|
50
|
+
has_many:
|
|
51
|
+
nest_attributes: ->
|
|
52
|
+
# TODO only nest specified nested attributes on model definition
|
|
53
|
+
association_names = model[@resource].has_many
|
|
54
|
+
if association_names
|
|
55
|
+
for association_name in association_names
|
|
56
|
+
associations_attributes = @["#{association_name}_attributes"]
|
|
57
|
+
if associations_attributes and associations_attributes.length
|
|
58
|
+
association = @[model.pluralize association_name]
|
|
59
|
+
|
|
60
|
+
unless association
|
|
61
|
+
message = "has_many.nest_attributes: Association not found for #{association_name}. \n"
|
|
62
|
+
message += "did you set it on model declaration? \n has_many: #{association_name} "
|
|
63
|
+
throw message
|
|
64
|
+
|
|
65
|
+
# TODO store a singular copy of the resource for better performace
|
|
66
|
+
association.resource = model.singularize association.resource
|
|
67
|
+
association.add.apply association, associations_attributes
|
|
68
|
+
association.resource = model.pluralize association.resource
|
|
69
|
+
|
|
70
|
+
# TODO Update route after setting the id
|
|
71
|
+
# TODO Update route association only once for each associated record
|
|
72
|
+
update_association: (data) ->
|
|
73
|
+
id = @_id || data && (data._id || data.id)
|
|
74
|
+
|
|
75
|
+
# Keep trying until we have a id
|
|
76
|
+
return unless id
|
|
77
|
+
|
|
78
|
+
for association_name in model[@resource.toString()].has_many
|
|
79
|
+
pluralized_association = model.pluralize association_name
|
|
80
|
+
association = @[pluralized_association]
|
|
81
|
+
|
|
82
|
+
# TODO setter of association.route
|
|
83
|
+
# to automatically update associated records
|
|
84
|
+
unless association.route
|
|
85
|
+
association.route = "/#{model.pluralize @resource.toString()}/#{id}/#{model.pluralize association.resource}"
|
|
86
|
+
|
|
87
|
+
for associated in association
|
|
88
|
+
if not associated.route and associated.parent?
|
|
89
|
+
associated.route = "/#{model.pluralize @resource.toString()}/#{id}/#{model.pluralize association.resource}"
|
|
90
|
+
|
|
91
|
+
true
|
|
92
|
+
autosave: ->
|
|
93
|
+
@save()
|
|
94
|
+
|
|
95
|
+
# TODO autosave
|
|
96
|
+
# @after_save.push ->
|
|
97
|
+
# model[@resource] =
|
|
98
|
+
#
|
|
99
|
+
@has_many = [@has_many ] if @has_many and $.type(@has_many) != 'array'
|
|
100
|
+
@has_one = [@has_one ] if @has_one and $.type(@has_one) != 'array'
|
|
101
|
+
@belongs_to = [@belongs_to] if @belongs_to and $.type(@belongs_to) != 'array'
|
|
102
|
+
|
|
103
|
+
@has_many ||= []
|
|
104
|
+
@has_one ||= []
|
|
105
|
+
@belongs_to ||= []
|
|
106
|
+
|
|
107
|
+
# TODO better organisation of this code
|
|
108
|
+
# inside this function: @ = record (running on after_initialize)
|
|
109
|
+
@create_associations = ->
|
|
110
|
+
# Create association methods
|
|
111
|
+
# Setup one to many association in model
|
|
112
|
+
if options.has_many
|
|
113
|
+
|
|
114
|
+
# TODO accept more options on has_many association creation
|
|
115
|
+
for resource in options.has_many
|
|
116
|
+
# unless model[resource]
|
|
117
|
+
# throw "Model not found for association with resource '#{resource}', on association 'has_many' "
|
|
118
|
+
|
|
119
|
+
# TODO instantiate default resources in has_many association
|
|
120
|
+
# @resource = model[resource].resource
|
|
121
|
+
|
|
122
|
+
# TODO Remember to clear association proxy when object is destroyed
|
|
123
|
+
association_proxy = resource: resource, parent_resource: @resource, parent: @
|
|
124
|
+
association_name = model.pluralize resource
|
|
125
|
+
@[association_name] = $.extend association_proxy, plural
|
|
126
|
+
|
|
127
|
+
# Update association attribute
|
|
128
|
+
@after 'saved', callbacks.has_many.update_association
|
|
129
|
+
|
|
130
|
+
# Forward nested attributes
|
|
131
|
+
callbacks.has_many.nest_attributes.call @
|
|
132
|
+
|
|
133
|
+
if options.has_one
|
|
134
|
+
for resource in options.has_one
|
|
135
|
+
# unless model[resource]
|
|
136
|
+
# throw "Model not found for association with resource '#{resource}', on association 'has_one' "
|
|
137
|
+
|
|
138
|
+
association_proxy = resource: resource, parent_resource: @resource
|
|
139
|
+
association_proxy[@resource] = @
|
|
140
|
+
|
|
141
|
+
@["build_#{resource}" ] = $.proxy singular.build , association_proxy
|
|
142
|
+
@["create_#{resource}"] = $.proxy singular.create, association_proxy
|
|
143
|
+
|
|
144
|
+
if options.belongs_to
|
|
145
|
+
|
|
146
|
+
for resource in options.belongs_to
|
|
147
|
+
# unless model[resource]
|
|
148
|
+
# throw "Model not found for association with resource '#{resource}', on association 'belongs_to' "
|
|
149
|
+
|
|
150
|
+
association_proxy = resource: resource, parent_resource: @resource
|
|
151
|
+
|
|
152
|
+
# TODO override default setter to set resource_id from parent resource FTW!
|
|
153
|
+
association_proxy[@resource] = @
|
|
154
|
+
|
|
155
|
+
@["build_#{resource}" ] = $.proxy singular.build , association_proxy
|
|
156
|
+
@["create_#{resource}"] = $.proxy singular.create, association_proxy
|
|
157
|
+
|
|
158
|
+
# @ = record
|
|
159
|
+
record: (options) ->
|
|
160
|
+
console.error 'resource must be defined in order to associate' unless @resource?
|
|
161
|
+
model[@resource.name || @resource.toString()].create_associations.call @
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
# Extend indemma
|
|
165
|
+
model = root.model # TODO better way to get parent
|
|
166
|
+
model.mix (modelable) ->
|
|
167
|
+
modelable.after_mix.push associable.model
|
|
168
|
+
modelable.record.after_initialize.push associable.record
|
|
169
|
+
|
|
170
|
+
# This allows to extendind the associable mixin
|
|
171
|
+
model.associable =
|
|
172
|
+
mix : (blender) ->
|
|
173
|
+
blender singular, plural
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# TODO externalize errorsable from validatable
|
|
2
|
+
# errorsable = stampit
|
|
3
|
+
# add: (attribute, message_key, options) ->
|
|
4
|
+
#
|
|
5
|
+
# @push [attribute, message_key, options]
|
|
6
|
+
# @messages[attribute_name] messages[message_key](attribute_name)
|
|
7
|
+
#
|
|
8
|
+
# clear: ->
|
|
9
|
+
# if @length
|
|
10
|
+
# @length = 0
|
|
11
|
+
# @messages = {}
|
|
12
|
+
#
|
|
13
|
+
# push: Array.prototype.push
|
|
14
|
+
# splice: Array.prototype.splice
|
|
15
|
+
# ,
|
|
16
|
+
# messages: {}
|
|
17
|
+
# length: 0
|
|
18
|
+
# , ->
|
|
19
|
+
# @messages = []
|
|
20
|
+
# @
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
maid =
|
|
2
|
+
|
|
3
|
+
model : ->
|
|
4
|
+
@record.after_initialize.push maid.record if @washing?
|
|
5
|
+
|
|
6
|
+
record: ->
|
|
7
|
+
|
|
8
|
+
@subscribe 'dirty', (dirty) ->
|
|
9
|
+
dirty && setTimeout =>
|
|
10
|
+
@save()
|
|
11
|
+
, 500
|
|
12
|
+
|
|
13
|
+
# Extend indemma
|
|
14
|
+
model = window.model
|
|
15
|
+
model.mix (modelable) ->
|
|
16
|
+
modelable.after_mix.unshift maid.model
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
stampit = require '../../vendor/stampit'
|
|
2
|
+
require '../../vendor/owl/pluralize'
|
|
3
|
+
|
|
4
|
+
# TODO Think of a better name
|
|
5
|
+
resource = stampit
|
|
6
|
+
toString: -> @name
|
|
7
|
+
# TODO move resourceable.route() to here
|
|
8
|
+
,
|
|
9
|
+
name : 'unknown'
|
|
10
|
+
scope : null
|
|
11
|
+
singular: false
|
|
12
|
+
, ->
|
|
13
|
+
|
|
14
|
+
# TODO better integration with record.coffee, and stop storing
|
|
15
|
+
# original reference
|
|
16
|
+
if @original_reference
|
|
17
|
+
stampit.mixIn @original_reference, @
|
|
18
|
+
@original_reference.toString = @toString
|
|
19
|
+
@original_reference.param_name ||= @name
|
|
20
|
+
|
|
21
|
+
return @original_reference
|
|
22
|
+
|
|
23
|
+
@param_name ||= @name
|
|
24
|
+
|
|
25
|
+
@
|
|
26
|
+
|
|
27
|
+
resourceable =
|
|
28
|
+
pluralize: (word, count, plural) ->
|
|
29
|
+
throw new TypeError "Invalid string passed to pluralize '#{word}'" unless word and word.length
|
|
30
|
+
|
|
31
|
+
unless word.indexOf('s') == word.length - 1
|
|
32
|
+
owl.pluralize word, count, plural
|
|
33
|
+
else
|
|
34
|
+
word
|
|
35
|
+
|
|
36
|
+
singularize: (word) ->
|
|
37
|
+
throw new TypeError "Invalid string passed to singularize '#{word}'" unless word and word.length
|
|
38
|
+
|
|
39
|
+
if word.lastIndexOf('s') == word.length - 1
|
|
40
|
+
word.substring 0, word.length - 1
|
|
41
|
+
else
|
|
42
|
+
word
|
|
43
|
+
|
|
44
|
+
# TODO move to resourceable method
|
|
45
|
+
route:
|
|
46
|
+
get: ->
|
|
47
|
+
return @initial_route if @initial_route?
|
|
48
|
+
|
|
49
|
+
# TODO use resource object on associations!
|
|
50
|
+
@resource = name: @resource if typeof @resource == 'string'
|
|
51
|
+
|
|
52
|
+
route = '/'
|
|
53
|
+
route += "#{@parent.route}/#{@parent._id}/" if @parent?
|
|
54
|
+
route += @resource.scope + '/' if @resource.scope?
|
|
55
|
+
|
|
56
|
+
route += if @resource.singular then @resource.name else model.pluralize @resource.name
|
|
57
|
+
@initial_route = route
|
|
58
|
+
|
|
59
|
+
route
|
|
60
|
+
|
|
61
|
+
set: (value) -> @initial_route = value
|
|
62
|
+
|
|
63
|
+
parent_id:
|
|
64
|
+
get: -> @[@parent_resource]._id
|
|
65
|
+
set: -> console.error 'Warning changing associations throught parent_id not allowed for security and style guide purposes' # TODO
|
|
66
|
+
|
|
67
|
+
initialize: ->
|
|
68
|
+
# Set parent attribute and default nested route
|
|
69
|
+
if @parent_resource
|
|
70
|
+
Object.defineProperty @, "#{@parent_resource}_id", resourceable.parent_id
|
|
71
|
+
|
|
72
|
+
# Setup resource
|
|
73
|
+
resource_definition = {}
|
|
74
|
+
resource_definition = name: @resource if typeof @resource == 'string'
|
|
75
|
+
if typeof @resource == 'object'
|
|
76
|
+
# TODO deeper resource integration with record.coffee, and remove original reference
|
|
77
|
+
# To prevent reference lost and allow dinamic modification of resources
|
|
78
|
+
# we need to preserve the original reference
|
|
79
|
+
@resource.original_reference = @resource
|
|
80
|
+
|
|
81
|
+
resource_definition = @resource
|
|
82
|
+
|
|
83
|
+
# TODO remove mentions of @parent_resource and use only resource: {parent: ...}
|
|
84
|
+
resource_definition.parent = @parent_resource
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@resource = resource resource_definition
|
|
90
|
+
|
|
91
|
+
# TODO Support route parsing, and change route to /parents/:id/childrens
|
|
92
|
+
@route ? Object.defineProperty @, 'route', resourceable.route
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
# Extend indemma
|
|
96
|
+
model = window.model # TODO better way to get parent
|
|
97
|
+
|
|
98
|
+
model.mix (modelable) ->
|
|
99
|
+
modelable.record.after_initialize.unshift resourceable.initialize
|
|
100
|
+
modelable.after_mix.unshift resourceable.initialize
|
|
101
|
+
|
|
102
|
+
model.singularize = resourceable.singularize
|
|
103
|
+
model.pluralize = resourceable.pluralize
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
$ = require 'jquery'
|
|
2
|
+
|
|
3
|
+
module.exports =
|
|
4
|
+
# TODO render route in the object itself with getter, and normalize this methods
|
|
5
|
+
get : (data) -> request.call @, 'get' , (if @_id then "#{@route}/#{@_id}" else @route), data
|
|
6
|
+
put : (data) -> request.call @, 'put' , (if @_id then "#{@route}/#{@_id}" else @route), data # TODO change from put to patch
|
|
7
|
+
post : (data) -> request.call @, 'post' , @route, data
|
|
8
|
+
delete: (data) -> request.call @, 'delete', @route, data
|
|
9
|
+
|
|
10
|
+
request = (method, url, data) ->
|
|
11
|
+
param_name = @resource.param_name || @resource.toString()
|
|
12
|
+
|
|
13
|
+
# TODO optmize this serialization lookup
|
|
14
|
+
if not data and @json
|
|
15
|
+
data = {}
|
|
16
|
+
data[param_name] = @json()
|
|
17
|
+
|
|
18
|
+
if data and data[param_name]
|
|
19
|
+
delete data[param_name]['id']
|
|
20
|
+
delete data[param_name]['_id']
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
$.ajax
|
|
24
|
+
url : url
|
|
25
|
+
data : data
|
|
26
|
+
type : method
|
|
27
|
+
dataType: 'json'
|
|
28
|
+
context : @
|