joosy 1.2.0.alpha.73 → 1.2.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gruntfile.coffee +56 -18
- data/bower.json +1 -1
- data/build/joosy/form.js +1 -0
- data/build/joosy/resources.js +1 -0
- data/build/joosy.js +2 -2774
- data/package.json +5 -4
- data/source/joosy/application.coffee +9 -7
- data/source/joosy/{extensions/resources-form/form.coffee → form.coffee} +58 -51
- data/source/joosy/helpers/form.coffee +241 -0
- data/source/joosy/helpers/index.coffee +3 -0
- data/source/joosy/helpers/routes.coffee +3 -1
- data/source/joosy/helpers/view.coffee +9 -9
- data/source/joosy/joosy.coffee +3 -5
- data/source/joosy/module.coffee +9 -4
- data/source/joosy/modules/dom.coffee +33 -31
- data/source/joosy/modules/events.coffee +24 -20
- data/source/joosy/modules/filters.coffee +38 -35
- data/source/joosy/modules/page/title.coffee +3 -3
- data/source/joosy/modules/renderer.coffee +23 -18
- data/source/joosy/modules/resources/identity_map.coffee +45 -0
- data/source/joosy/modules/resources/model.coffee +146 -0
- data/source/joosy/modules/widgets_manager.coffee +8 -8
- data/source/joosy/resources/array.coffee +0 -5
- data/source/joosy/resources/hash.coffee +8 -13
- data/source/joosy/resources/index.coffee +2 -0
- data/source/joosy/{extensions/resources → resources}/rest.coffee +48 -19
- data/source/joosy/resources/scalar.coffee +8 -10
- data/source/joosy/router.coffee +13 -12
- data/source/joosy/templaters/jst.coffee +3 -2
- data/source/joosy/widget.coffee +17 -15
- data/source/joosy.coffee +2 -0
- data/source/vendor/es5-shim.js +1316 -0
- data/source/vendor/inflections.js +598 -0
- data/source/vendor/metamorph.js +457 -0
- data/spec/helpers/matchers.coffee +4 -4
- data/spec/joosy/core/application_spec.coffee +1 -1
- data/spec/joosy/core/helpers/view_spec.coffee +2 -2
- data/spec/joosy/core/joosy_spec.coffee +8 -4
- data/spec/joosy/core/modules/dom_spec.coffee +7 -7
- data/spec/joosy/core/modules/events_spec.coffee +2 -2
- data/spec/joosy/core/modules/filters_spec.coffee +7 -8
- data/spec/joosy/core/modules/module_spec.coffee +5 -5
- data/spec/joosy/core/router_spec.coffee +3 -3
- data/spec/joosy/core/widget_spec.coffee +6 -6
- data/spec/joosy/environments/amd_spec.coffee +4 -2
- data/spec/joosy/environments/global_spec.coffee +1 -1
- data/spec/joosy/{extensions/form → form}/form_spec.coffee +9 -16
- data/spec/joosy/{extensions/form → form}/helpers/forms_spec.coffee +5 -5
- data/spec/joosy/{core/resources → resources}/array_spec.coffee +2 -2
- data/spec/joosy/{core/resources → resources}/hash_spec.coffee +0 -8
- data/spec/joosy/{core/modules/resources → resources/modules}/cacher_spec.coffee +0 -0
- data/spec/joosy/resources/modules/identity_map_spec.coffee +47 -0
- data/spec/joosy/{extensions/resources/base_spec.coffee → resources/modules/model_spec.coffee} +28 -48
- data/spec/joosy/{extensions/resources → resources}/rest_spec.coffee +29 -22
- data/spec/joosy/{core/resources → resources}/scalar_spec.coffee +8 -8
- data/templates/application/application.coffee.tt +0 -2
- data/templates/environment/app/haml/index.haml +2 -2
- data/templates/environment/package.json +1 -1
- metadata +23 -19
- data/build/joosy/extensions/resources-form.js +0 -590
- data/build/joosy/extensions/resources.js +0 -561
- data/source/joosy/extensions/resources/base.coffee +0 -282
- data/source/joosy/extensions/resources/index.coffee +0 -1
- data/source/joosy/extensions/resources-form/helpers/form.coffee +0 -104
- data/source/joosy/extensions/resources-form/index.coffee +0 -1
- data/source/metamorph.coffee +0 -410
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: joosy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.0.
|
4
|
+
version: 1.2.0.beta.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boris Staal
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-09-
|
13
|
+
date: 2013-09-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sprockets
|
@@ -53,19 +53,16 @@ files:
|
|
53
53
|
- README.md
|
54
54
|
- bower.json
|
55
55
|
- build/joosy.js
|
56
|
-
- build/joosy/
|
57
|
-
- build/joosy/
|
56
|
+
- build/joosy/form.js
|
57
|
+
- build/joosy/resources.js
|
58
58
|
- joosy.gemspec
|
59
59
|
- lib/joosy.rb
|
60
60
|
- package.json
|
61
61
|
- source/joosy.coffee
|
62
62
|
- source/joosy/application.coffee
|
63
|
-
- source/joosy/
|
64
|
-
- source/joosy/
|
65
|
-
- source/joosy/
|
66
|
-
- source/joosy/extensions/resources/base.coffee
|
67
|
-
- source/joosy/extensions/resources/index.coffee
|
68
|
-
- source/joosy/extensions/resources/rest.coffee
|
63
|
+
- source/joosy/form.coffee
|
64
|
+
- source/joosy/helpers/form.coffee
|
65
|
+
- source/joosy/helpers/index.coffee
|
69
66
|
- source/joosy/helpers/routes.coffee
|
70
67
|
- source/joosy/helpers/view.coffee
|
71
68
|
- source/joosy/helpers/widgets.coffee
|
@@ -82,16 +79,22 @@ files:
|
|
82
79
|
- source/joosy/modules/renderer.coffee
|
83
80
|
- source/joosy/modules/resources.coffee
|
84
81
|
- source/joosy/modules/resources/cacher.coffee
|
82
|
+
- source/joosy/modules/resources/identity_map.coffee
|
83
|
+
- source/joosy/modules/resources/model.coffee
|
85
84
|
- source/joosy/modules/time_manager.coffee
|
86
85
|
- source/joosy/modules/widgets_manager.coffee
|
87
86
|
- source/joosy/page.coffee
|
88
87
|
- source/joosy/resources/array.coffee
|
89
88
|
- source/joosy/resources/hash.coffee
|
89
|
+
- source/joosy/resources/index.coffee
|
90
|
+
- source/joosy/resources/rest.coffee
|
90
91
|
- source/joosy/resources/scalar.coffee
|
91
92
|
- source/joosy/router.coffee
|
92
93
|
- source/joosy/templaters/jst.coffee
|
93
94
|
- source/joosy/widget.coffee
|
94
|
-
- source/
|
95
|
+
- source/vendor/es5-shim.js
|
96
|
+
- source/vendor/inflections.js
|
97
|
+
- source/vendor/metamorph.js
|
95
98
|
- spec/helpers/ground.coffee
|
96
99
|
- spec/helpers/matchers.coffee
|
97
100
|
- spec/joosy/core/application_spec.coffee
|
@@ -106,21 +109,22 @@ files:
|
|
106
109
|
- spec/joosy/core/modules/log_spec.coffee
|
107
110
|
- spec/joosy/core/modules/module_spec.coffee
|
108
111
|
- spec/joosy/core/modules/renderer_spec.coffee
|
109
|
-
- spec/joosy/core/modules/resources/cacher_spec.coffee
|
110
112
|
- spec/joosy/core/modules/time_manager_spec.coffee
|
111
113
|
- spec/joosy/core/page_spec.coffee
|
112
|
-
- spec/joosy/core/resources/array_spec.coffee
|
113
|
-
- spec/joosy/core/resources/hash_spec.coffee
|
114
|
-
- spec/joosy/core/resources/scalar_spec.coffee
|
115
114
|
- spec/joosy/core/router_spec.coffee
|
116
115
|
- spec/joosy/core/templaters/jst_spec.coffee
|
117
116
|
- spec/joosy/core/widget_spec.coffee
|
118
117
|
- spec/joosy/environments/amd_spec.coffee
|
119
118
|
- spec/joosy/environments/global_spec.coffee
|
120
|
-
- spec/joosy/
|
121
|
-
- spec/joosy/
|
122
|
-
- spec/joosy/
|
123
|
-
- spec/joosy/
|
119
|
+
- spec/joosy/form/form_spec.coffee
|
120
|
+
- spec/joosy/form/helpers/forms_spec.coffee
|
121
|
+
- spec/joosy/resources/array_spec.coffee
|
122
|
+
- spec/joosy/resources/hash_spec.coffee
|
123
|
+
- spec/joosy/resources/modules/cacher_spec.coffee
|
124
|
+
- spec/joosy/resources/modules/identity_map_spec.coffee
|
125
|
+
- spec/joosy/resources/modules/model_spec.coffee
|
126
|
+
- spec/joosy/resources/rest_spec.coffee
|
127
|
+
- spec/joosy/resources/scalar_spec.coffee
|
124
128
|
- spec/support/test.js
|
125
129
|
- tasks/joosy.coffee
|
126
130
|
- templates/application/application.coffee.tt
|
@@ -1,590 +0,0 @@
|
|
1
|
-
(function() {
|
2
|
-
var __hasProp = {}.hasOwnProperty,
|
3
|
-
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
4
|
-
|
5
|
-
Joosy.Form = (function(_super) {
|
6
|
-
__extends(Form, _super);
|
7
|
-
|
8
|
-
Form.include(Joosy.Modules.DOM);
|
9
|
-
|
10
|
-
Form.include(Joosy.Modules.Log);
|
11
|
-
|
12
|
-
Form.include(Joosy.Modules.Events);
|
13
|
-
|
14
|
-
Form.prototype.invalidationClass = 'field_with_errors';
|
15
|
-
|
16
|
-
Form.prototype.substitutions = {};
|
17
|
-
|
18
|
-
Form.mapElements({
|
19
|
-
'fields': 'input,select,textarea'
|
20
|
-
});
|
21
|
-
|
22
|
-
Form.submit = function(form, options) {
|
23
|
-
if (options == null) {
|
24
|
-
options = {};
|
25
|
-
}
|
26
|
-
form = new this(form, options);
|
27
|
-
form.$container.submit();
|
28
|
-
form.unbind();
|
29
|
-
return null;
|
30
|
-
};
|
31
|
-
|
32
|
-
Form.attach = function() {
|
33
|
-
return (function(func, args, ctor) {
|
34
|
-
ctor.prototype = func.prototype;
|
35
|
-
var child = new ctor, result = func.apply(child, args);
|
36
|
-
return Object(result) === result ? result : child;
|
37
|
-
})(Joosy.Form, arguments, function(){});
|
38
|
-
};
|
39
|
-
|
40
|
-
function Form(form, options) {
|
41
|
-
var method, _ref,
|
42
|
-
_this = this;
|
43
|
-
if (options == null) {
|
44
|
-
options = {};
|
45
|
-
}
|
46
|
-
if (Object.isFunction(options)) {
|
47
|
-
this.success = options;
|
48
|
-
} else {
|
49
|
-
Object.each(options, function(key, value) {
|
50
|
-
return _this[key] = value;
|
51
|
-
});
|
52
|
-
}
|
53
|
-
this.$container = $(form);
|
54
|
-
if (this.$container.length === 0) {
|
55
|
-
return;
|
56
|
-
}
|
57
|
-
this.__assignElements();
|
58
|
-
this.__delegateEvents();
|
59
|
-
method = (_ref = this.$container.get(0).getAttribute('method')) != null ? _ref.toLowerCase() : void 0;
|
60
|
-
if (method && !['get', 'post'].any(method)) {
|
61
|
-
this.__markMethod(method);
|
62
|
-
this.$container.attr('method', 'POST');
|
63
|
-
}
|
64
|
-
this.$container.ajaxForm({
|
65
|
-
dataType: 'json',
|
66
|
-
beforeSend: function() {
|
67
|
-
if (_this.__debounce.apply(_this, arguments)) {
|
68
|
-
return false;
|
69
|
-
}
|
70
|
-
_this.__before.apply(_this, arguments);
|
71
|
-
_this.__pending_request = true;
|
72
|
-
_this.debugAs(_this, 'beforeSend: pending_request = true');
|
73
|
-
return true;
|
74
|
-
},
|
75
|
-
success: function() {
|
76
|
-
_this.__pending_request = false;
|
77
|
-
_this.debugAs(_this, 'success: pending_request = false');
|
78
|
-
return _this.__success.apply(_this, arguments);
|
79
|
-
},
|
80
|
-
error: function() {
|
81
|
-
_this.__pending_request = false;
|
82
|
-
_this.debugAs(_this, 'error: pending_request = false');
|
83
|
-
return _this.__error.apply(_this, arguments);
|
84
|
-
},
|
85
|
-
xhr: function() {
|
86
|
-
var xhr;
|
87
|
-
xhr = $.ajaxSettings.xhr();
|
88
|
-
if ((xhr.upload != null) && _this.progress) {
|
89
|
-
xhr.upload.onprogress = function(event) {
|
90
|
-
if (event.lengthComputable) {
|
91
|
-
return _this.progress((event.position / event.total * 100).round(2));
|
92
|
-
}
|
93
|
-
};
|
94
|
-
}
|
95
|
-
return xhr;
|
96
|
-
}
|
97
|
-
});
|
98
|
-
if (this.resource != null) {
|
99
|
-
this.fill(this.resource, options);
|
100
|
-
delete this.resource;
|
101
|
-
}
|
102
|
-
if (this.action != null) {
|
103
|
-
this.$container.attr('action', this.action);
|
104
|
-
this.$container.attr('method', 'POST');
|
105
|
-
}
|
106
|
-
if (this.method != null) {
|
107
|
-
this.__markMethod(this.method);
|
108
|
-
}
|
109
|
-
}
|
110
|
-
|
111
|
-
Form.prototype.unbind = function() {
|
112
|
-
return this.$container.unbind('submit').find('input:submit,input:image,button:submit').unbind('click');
|
113
|
-
};
|
114
|
-
|
115
|
-
Form.prototype.fill = function(resource, options) {
|
116
|
-
var data, filler, url,
|
117
|
-
_this = this;
|
118
|
-
if (Object.isFunction(resource.build)) {
|
119
|
-
resource = resource.build();
|
120
|
-
}
|
121
|
-
this.__resource = resource;
|
122
|
-
if ((options != null ? options.decorator : void 0) != null) {
|
123
|
-
data = options.decorator(resource.data);
|
124
|
-
} else {
|
125
|
-
data = resource.data;
|
126
|
-
}
|
127
|
-
filler = function(data, scope) {
|
128
|
-
if (data.__joosy_form_filler_lock) {
|
129
|
-
return;
|
130
|
-
}
|
131
|
-
data.__joosy_form_filler_lock = true;
|
132
|
-
Object.each(data, function(property, val) {
|
133
|
-
var entity, i, input, key, _i, _len, _results;
|
134
|
-
key = _this.concatFieldName(scope, property);
|
135
|
-
input = _this.$fields().filter("[name='" + key + "']:not(:file),[name='" + (key.underscore()) + "']:not(:file),[name='" + (key.camelize(false)) + "']:not(:file)");
|
136
|
-
if (input.length > 0) {
|
137
|
-
if (input.is(':checkbox')) {
|
138
|
-
if (val) {
|
139
|
-
input.attr('checked', 'checked');
|
140
|
-
} else {
|
141
|
-
input.removeAttr('checked');
|
142
|
-
}
|
143
|
-
} else if (input.is(':radio')) {
|
144
|
-
input.filter("[value='" + val + "']").attr('checked', 'checked');
|
145
|
-
} else {
|
146
|
-
input.val(val);
|
147
|
-
}
|
148
|
-
}
|
149
|
-
if (val instanceof Joosy.Resources.Array) {
|
150
|
-
_results = [];
|
151
|
-
for (i = _i = 0, _len = val.length; _i < _len; i = ++_i) {
|
152
|
-
entity = val[i];
|
153
|
-
_results.push(filler(entity.data, _this.concatFieldName(scope, "[" + property + "_attributes][" + i + "]")));
|
154
|
-
}
|
155
|
-
return _results;
|
156
|
-
} else if (val instanceof Joosy.Resources.REST) {
|
157
|
-
return filler(val.data, _this.concatFieldName(scope, "[" + property + "_attributes]"));
|
158
|
-
} else if (Object.isObject(val) || Object.isArray(val)) {
|
159
|
-
return filler(val, key);
|
160
|
-
} else {
|
161
|
-
|
162
|
-
}
|
163
|
-
});
|
164
|
-
return delete data.__joosy_form_filler_lock;
|
165
|
-
};
|
166
|
-
filler(data, resource.__entityName || options.resourceName);
|
167
|
-
$('input[name=_method]', this.$container).remove();
|
168
|
-
if (resource.id()) {
|
169
|
-
this.__markMethod((options != null ? options.method : void 0) || 'PUT');
|
170
|
-
}
|
171
|
-
url = (options != null ? options.action : void 0) || (resource.id() != null ? resource.memberPath() : resource.collectionPath());
|
172
|
-
this.$container.attr('action', url);
|
173
|
-
return this.$container.attr('method', 'POST');
|
174
|
-
};
|
175
|
-
|
176
|
-
Form.prototype.submit = function() {
|
177
|
-
return this.$container.submit();
|
178
|
-
};
|
179
|
-
|
180
|
-
Form.prototype.serialize = function(skipMethod) {
|
181
|
-
var data;
|
182
|
-
if (skipMethod == null) {
|
183
|
-
skipMethod = true;
|
184
|
-
}
|
185
|
-
data = this.$container.serialize();
|
186
|
-
if (skipMethod) {
|
187
|
-
data = data.replace(/\&?\_method\=put/i, '');
|
188
|
-
}
|
189
|
-
return data;
|
190
|
-
};
|
191
|
-
|
192
|
-
Form.prototype.__success = function(response, status, xhr) {
|
193
|
-
var _ref;
|
194
|
-
if (xhr) {
|
195
|
-
return typeof this.success === "function" ? this.success(response) : void 0;
|
196
|
-
} else if ((200 <= (_ref = response.status) && _ref < 300)) {
|
197
|
-
return this.success(response.json);
|
198
|
-
} else {
|
199
|
-
return this.__error(response.json);
|
200
|
-
}
|
201
|
-
};
|
202
|
-
|
203
|
-
Form.prototype.__before = function(xhr, settings) {
|
204
|
-
if ((this.before == null) || this.before.apply(this, arguments) === true) {
|
205
|
-
return this.$fields().removeClass(this.invalidationClass);
|
206
|
-
}
|
207
|
-
};
|
208
|
-
|
209
|
-
Form.prototype.__error = function(data) {
|
210
|
-
var error, errors,
|
211
|
-
_this = this;
|
212
|
-
errors = (function() {
|
213
|
-
if (data.responseText) {
|
214
|
-
try {
|
215
|
-
return data = jQuery.parseJSON(data.responseText);
|
216
|
-
} catch (_error) {
|
217
|
-
error = _error;
|
218
|
-
return {};
|
219
|
-
}
|
220
|
-
} else {
|
221
|
-
return data;
|
222
|
-
}
|
223
|
-
})();
|
224
|
-
if ((this.error == null) || this.error(errors) === true) {
|
225
|
-
errors = this.__stringifyErrors(errors);
|
226
|
-
Object.each(errors, function(field, notifications) {
|
227
|
-
var input;
|
228
|
-
input = _this.findField(field).addClass(_this.invalidationClass);
|
229
|
-
return typeof _this.notification === "function" ? _this.notification(input, notifications) : void 0;
|
230
|
-
});
|
231
|
-
return errors;
|
232
|
-
}
|
233
|
-
return false;
|
234
|
-
};
|
235
|
-
|
236
|
-
Form.prototype.__debounce = function(xhr) {
|
237
|
-
this.debugAs(this, "debounce: pending_request == " + this.__pending_request);
|
238
|
-
if (this.__pending_request && this.debounce !== false) {
|
239
|
-
if (this.debounce || Joosy.Form.debounceForms) {
|
240
|
-
xhr.abort();
|
241
|
-
this.debugAs(this, "debounce: xhr aborted");
|
242
|
-
return true;
|
243
|
-
}
|
244
|
-
}
|
245
|
-
return false;
|
246
|
-
};
|
247
|
-
|
248
|
-
Form.prototype.findField = function(field) {
|
249
|
-
return this.$fields().filter("[name='" + field + "']");
|
250
|
-
};
|
251
|
-
|
252
|
-
Form.prototype.__markMethod = function(method) {
|
253
|
-
if (method == null) {
|
254
|
-
method = 'PUT';
|
255
|
-
}
|
256
|
-
method = $('<input/>', {
|
257
|
-
type: 'hidden',
|
258
|
-
name: '_method',
|
259
|
-
value: method
|
260
|
-
});
|
261
|
-
return this.$container.append(method);
|
262
|
-
};
|
263
|
-
|
264
|
-
Form.prototype.__stringifyErrors = function(errors) {
|
265
|
-
var result,
|
266
|
-
_this = this;
|
267
|
-
result = {};
|
268
|
-
if (Object.isObject(errors != null ? errors.errors : void 0)) {
|
269
|
-
errors = errors.errors;
|
270
|
-
}
|
271
|
-
Object.each(errors, function(field, notifications) {
|
272
|
-
var f, name, splited, _i, _len;
|
273
|
-
if (_this.substitutions[field] != null) {
|
274
|
-
field = _this.substitutions[field];
|
275
|
-
}
|
276
|
-
if (Object.isObject(notifications) || _this.isArrayOfObjects(notifications)) {
|
277
|
-
return Object.each(_this.__foldInlineEntities(notifications), function(key, value) {
|
278
|
-
return result[field + key] = value;
|
279
|
-
});
|
280
|
-
} else {
|
281
|
-
if (field.indexOf(".") !== -1) {
|
282
|
-
splited = field.split('.');
|
283
|
-
field = splited.shift();
|
284
|
-
if (_this.resourceName || _this.__resource) {
|
285
|
-
name = _this.resourceName || _this.__resource.__entityName;
|
286
|
-
field = name + ("[" + field + "]");
|
287
|
-
}
|
288
|
-
for (_i = 0, _len = splited.length; _i < _len; _i++) {
|
289
|
-
f = splited[_i];
|
290
|
-
field += "[" + f + "]";
|
291
|
-
}
|
292
|
-
} else if (_this.resourceName || _this.__resource) {
|
293
|
-
name = _this.resourceName || _this.__resource.__entityName;
|
294
|
-
field = name + ("[" + field + "]");
|
295
|
-
}
|
296
|
-
return result[field] = notifications;
|
297
|
-
}
|
298
|
-
});
|
299
|
-
return result;
|
300
|
-
};
|
301
|
-
|
302
|
-
Form.prototype.__foldInlineEntities = function(hash, scope, result) {
|
303
|
-
var _this = this;
|
304
|
-
if (scope == null) {
|
305
|
-
scope = "";
|
306
|
-
}
|
307
|
-
if (result == null) {
|
308
|
-
result = {};
|
309
|
-
}
|
310
|
-
Object.each(hash, function(key, value) {
|
311
|
-
if (Object.isObject(value) || _this.isArrayOfObjects(value)) {
|
312
|
-
return _this.__foldInlineEntities(value, "" + scope + "[" + key + "]", result);
|
313
|
-
} else {
|
314
|
-
return result["" + scope + "[" + key + "]"] = value;
|
315
|
-
}
|
316
|
-
});
|
317
|
-
return result;
|
318
|
-
};
|
319
|
-
|
320
|
-
Form.prototype.concatFieldName = function(wrapper, name) {
|
321
|
-
var items;
|
322
|
-
items = this.splitFieldName(wrapper).concat(this.splitFieldName(name));
|
323
|
-
return "" + items[0] + "[" + (items.slice(1).join('][')) + "]";
|
324
|
-
};
|
325
|
-
|
326
|
-
Form.prototype.splitFieldName = function(name) {
|
327
|
-
var first, items;
|
328
|
-
items = name.split('][');
|
329
|
-
first = items[0].split('[');
|
330
|
-
if (first.length === 2) {
|
331
|
-
if (first[0].isBlank()) {
|
332
|
-
items.splice(0, 1, first[1]);
|
333
|
-
} else {
|
334
|
-
items.splice(0, 1, first[0], first[1]);
|
335
|
-
}
|
336
|
-
items[items.length - 1] = items[items.length - 1].split(']')[0];
|
337
|
-
}
|
338
|
-
return items;
|
339
|
-
};
|
340
|
-
|
341
|
-
Form.prototype.isArrayOfObjects = function(array) {
|
342
|
-
return Object.isArray(array) && array.every(function(elem) {
|
343
|
-
return Object.isObject(elem);
|
344
|
-
});
|
345
|
-
};
|
346
|
-
|
347
|
-
return Form;
|
348
|
-
|
349
|
-
})(Joosy.Module);
|
350
|
-
|
351
|
-
}).call(this);
|
352
|
-
(function() {
|
353
|
-
Joosy.helpers('Application', function() {
|
354
|
-
var Form, description, input,
|
355
|
-
_this = this;
|
356
|
-
description = function(resource, method, extendIds, idSuffix) {
|
357
|
-
var id;
|
358
|
-
if (Joosy.Module.hasAncestor(resource.constructor, Joosy.Resources.Base)) {
|
359
|
-
id = resource.id();
|
360
|
-
resource = resource.__entityName;
|
361
|
-
}
|
362
|
-
return {
|
363
|
-
name: resource + ("" + (method.match(/^\[.*\]$/) ? method : "[" + method + "]")),
|
364
|
-
id: resource + (id && extendIds ? '_' + id : '') + ("_" + (method.parameterize().underscore())) + (idSuffix ? '_' + idSuffix : '')
|
365
|
-
};
|
366
|
-
};
|
367
|
-
input = function(type, resource, method, options) {
|
368
|
-
var d;
|
369
|
-
if (options == null) {
|
370
|
-
options = {};
|
371
|
-
}
|
372
|
-
d = description(resource, method, options.extendIds, options.idSuffix);
|
373
|
-
delete options.extendIds;
|
374
|
-
delete options.idSuffix;
|
375
|
-
return _this.tag('input', Joosy.Module.merge({
|
376
|
-
type: type,
|
377
|
-
name: d.name,
|
378
|
-
id: d.id
|
379
|
-
}, options));
|
380
|
-
};
|
381
|
-
Form = (function() {
|
382
|
-
function Form(context, resource, options) {
|
383
|
-
this.context = context;
|
384
|
-
this.resource = resource;
|
385
|
-
this.options = options;
|
386
|
-
}
|
387
|
-
|
388
|
-
Form.prototype.label = function(method, options, content) {
|
389
|
-
if (options == null) {
|
390
|
-
options = {};
|
391
|
-
}
|
392
|
-
if (content == null) {
|
393
|
-
content = '';
|
394
|
-
}
|
395
|
-
if (!Object.isObject(options)) {
|
396
|
-
content = options;
|
397
|
-
options = {};
|
398
|
-
}
|
399
|
-
return this.context.label(this.resource, method, Joosy.Module.merge({
|
400
|
-
extendIds: this.options.extendIds
|
401
|
-
}, options), content);
|
402
|
-
};
|
403
|
-
|
404
|
-
Form.prototype.radioButton = function(method, tagValue, options) {
|
405
|
-
if (options == null) {
|
406
|
-
options = {};
|
407
|
-
}
|
408
|
-
return this.context.radioButton(this.resource, method, tagValue, Joosy.Module.merge({
|
409
|
-
extendIds: this.options.extendIds
|
410
|
-
}, options));
|
411
|
-
};
|
412
|
-
|
413
|
-
Form.prototype.textArea = function(method, options) {
|
414
|
-
if (options == null) {
|
415
|
-
options = {};
|
416
|
-
}
|
417
|
-
return this.context.textArea(this.resource, method, Joosy.Module.merge({
|
418
|
-
extendIds: this.options.extendIds
|
419
|
-
}, options));
|
420
|
-
};
|
421
|
-
|
422
|
-
Form.prototype.checkBox = function(method, options, checkedValue, uncheckedValue) {
|
423
|
-
if (options == null) {
|
424
|
-
options = {};
|
425
|
-
}
|
426
|
-
if (checkedValue == null) {
|
427
|
-
checkedValue = 1;
|
428
|
-
}
|
429
|
-
if (uncheckedValue == null) {
|
430
|
-
uncheckedValue = 0;
|
431
|
-
}
|
432
|
-
return this.context.checkBox(this.resource, method, Joosy.Module.merge({
|
433
|
-
extendIds: this.options.extendIds
|
434
|
-
}, options), checkedValue, uncheckedValue);
|
435
|
-
};
|
436
|
-
|
437
|
-
Form.prototype.select = function(method, options, htmlOptions) {
|
438
|
-
if (options == null) {
|
439
|
-
options = {};
|
440
|
-
}
|
441
|
-
if (htmlOptions == null) {
|
442
|
-
htmlOptions = {};
|
443
|
-
}
|
444
|
-
return this.context.select(this.resource, method, options, Joosy.Module.merge({
|
445
|
-
extendIds: this.options.extendIds
|
446
|
-
}, htmlOptions));
|
447
|
-
};
|
448
|
-
|
449
|
-
return Form;
|
450
|
-
|
451
|
-
})();
|
452
|
-
['text', 'file', 'hidden', 'password'].each(function(type) {
|
453
|
-
return Form.prototype[type + 'Field'] = function(method, options) {
|
454
|
-
if (options == null) {
|
455
|
-
options = {};
|
456
|
-
}
|
457
|
-
return this.context[type + 'Field'](this.resource, method, Joosy.Module.merge({
|
458
|
-
extendIds: this.options.extendIds
|
459
|
-
}, options));
|
460
|
-
};
|
461
|
-
});
|
462
|
-
this.formFor = function(resource, options, block) {
|
463
|
-
var form, uuid;
|
464
|
-
if (options == null) {
|
465
|
-
options = {};
|
466
|
-
}
|
467
|
-
if (Object.isFunction(options)) {
|
468
|
-
block = options;
|
469
|
-
options = {};
|
470
|
-
}
|
471
|
-
uuid = Joosy.uuid();
|
472
|
-
form = this.tag('form', Joosy.Module.merge(options.html || {}, {
|
473
|
-
id: uuid
|
474
|
-
}), block != null ? block.call(this, new Form(this, resource, options)) : void 0);
|
475
|
-
if (typeof this.onRefresh === "function") {
|
476
|
-
this.onRefresh(function() {
|
477
|
-
return Joosy.Form.attach('#' + uuid, Joosy.Module.merge(options, {
|
478
|
-
resource: resource
|
479
|
-
}));
|
480
|
-
});
|
481
|
-
}
|
482
|
-
return form;
|
483
|
-
};
|
484
|
-
this.label = function(resource, method, options, content) {
|
485
|
-
var d;
|
486
|
-
if (options == null) {
|
487
|
-
options = {};
|
488
|
-
}
|
489
|
-
if (content == null) {
|
490
|
-
content = '';
|
491
|
-
}
|
492
|
-
if (!Object.isObject(options)) {
|
493
|
-
content = options;
|
494
|
-
options = {};
|
495
|
-
}
|
496
|
-
d = description(resource, method, options.extendIds);
|
497
|
-
delete options.extendIds;
|
498
|
-
return this.contentTag('label', content, Joosy.Module.merge(options, {
|
499
|
-
"for": d.id
|
500
|
-
}));
|
501
|
-
};
|
502
|
-
['text', 'file', 'hidden', 'password'].each(function(type) {
|
503
|
-
return _this[type + 'Field'] = function(resource, method, options) {
|
504
|
-
if (options == null) {
|
505
|
-
options = {};
|
506
|
-
}
|
507
|
-
return input(type, resource, method, options);
|
508
|
-
};
|
509
|
-
});
|
510
|
-
this.radioButton = function(resource, method, tagValue, options) {
|
511
|
-
if (options == null) {
|
512
|
-
options = {};
|
513
|
-
}
|
514
|
-
return input('radio', resource, method, Joosy.Module.merge({
|
515
|
-
value: tagValue,
|
516
|
-
idSuffix: tagValue
|
517
|
-
}, options));
|
518
|
-
};
|
519
|
-
this.checkBox = function(resource, method, options, checkedValue, uncheckedValue) {
|
520
|
-
var box, spy;
|
521
|
-
if (options == null) {
|
522
|
-
options = {};
|
523
|
-
}
|
524
|
-
if (checkedValue == null) {
|
525
|
-
checkedValue = 1;
|
526
|
-
}
|
527
|
-
if (uncheckedValue == null) {
|
528
|
-
uncheckedValue = 0;
|
529
|
-
}
|
530
|
-
spy = this.tag('input', Joosy.Module.merge({
|
531
|
-
name: description(resource, method).name,
|
532
|
-
value: uncheckedValue,
|
533
|
-
type: 'hidden'
|
534
|
-
}));
|
535
|
-
box = input('checkbox', resource, method, Joosy.Module.merge({
|
536
|
-
value: checkedValue
|
537
|
-
}, options));
|
538
|
-
return spy + box;
|
539
|
-
};
|
540
|
-
this.select = function(resource, method, options, htmlOptions) {
|
541
|
-
var extendIds, key, opts, val,
|
542
|
-
_this = this;
|
543
|
-
if (Object.isObject(options)) {
|
544
|
-
opts = [];
|
545
|
-
for (key in options) {
|
546
|
-
val = options[key];
|
547
|
-
opts.push([val, key]);
|
548
|
-
}
|
549
|
-
} else {
|
550
|
-
opts = options;
|
551
|
-
}
|
552
|
-
if (htmlOptions.includeBlank) {
|
553
|
-
delete htmlOptions.includeBlank;
|
554
|
-
opts.unshift(['', '']);
|
555
|
-
}
|
556
|
-
opts = opts.reduce(function(str, vals) {
|
557
|
-
var params;
|
558
|
-
params = Object.isArray(vals) ? [
|
559
|
-
'option', vals[0], {
|
560
|
-
value: vals[1]
|
561
|
-
}
|
562
|
-
] : ['option', vals, {}];
|
563
|
-
if (htmlOptions.value === (Object.isArray(vals) ? vals[1] : vals)) {
|
564
|
-
params[2].selected = 'selected';
|
565
|
-
}
|
566
|
-
return str += _this.contentTag.apply(_this, params);
|
567
|
-
}, '');
|
568
|
-
extendIds = htmlOptions.extendIds;
|
569
|
-
delete htmlOptions.value;
|
570
|
-
delete htmlOptions.extendIds;
|
571
|
-
return this.contentTag('select', opts, Joosy.Module.merge(description(resource, method, extendIds), htmlOptions));
|
572
|
-
};
|
573
|
-
return this.textArea = function(resource, method, options) {
|
574
|
-
var extendIds, value;
|
575
|
-
if (options == null) {
|
576
|
-
options = {};
|
577
|
-
}
|
578
|
-
value = options.value;
|
579
|
-
extendIds = options.extendIds;
|
580
|
-
delete options.value;
|
581
|
-
delete options.extendIds;
|
582
|
-
return this.contentTag('textarea', value, Joosy.Module.merge(description(resource, method, extendIds), options));
|
583
|
-
};
|
584
|
-
});
|
585
|
-
|
586
|
-
}).call(this);
|
587
|
-
(function() {
|
588
|
-
|
589
|
-
|
590
|
-
}).call(this);
|