joosy 1.2.0.alpha.41 → 1.2.0.alpha.51

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