formize 0.0.9 → 0.0.10

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.
Files changed (84) hide show
  1. data/.travis.yml +1 -1
  2. data/Gemfile +3 -1
  3. data/README.rdoc +7 -0
  4. data/VERSION +1 -1
  5. data/ci/Gemfile.rails-3.0.x +2 -0
  6. data/ci/{Gemfile.rails-2.3.x → Gemfile.rails-3.1.x} +3 -1
  7. data/formize.gemspec +82 -6
  8. data/lib/assets/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  9. data/lib/assets/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  10. data/lib/assets/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  11. data/lib/assets/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  12. data/lib/assets/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  13. data/lib/assets/images/ui-bg_glass_75_ffffff_1x400.png +0 -0
  14. data/lib/assets/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  15. data/lib/assets/images/ui-bg_inset-soft_95_fef1ec_1x100.png +0 -0
  16. data/lib/assets/images/ui-icons_222222_256x240.png +0 -0
  17. data/lib/assets/images/ui-icons_2e83ff_256x240.png +0 -0
  18. data/lib/assets/images/ui-icons_454545_256x240.png +0 -0
  19. data/lib/assets/images/ui-icons_888888_256x240.png +0 -0
  20. data/lib/assets/images/ui-icons_cd0a0a_256x240.png +0 -0
  21. data/lib/assets/javascripts/formize.js +238 -340
  22. data/lib/assets/javascripts/jquery.ui.formize.js +231 -0
  23. data/lib/assets/javascripts/locales/jquery.ui.datepicker-af.js +23 -0
  24. data/lib/assets/javascripts/locales/jquery.ui.datepicker-ar.js +24 -0
  25. data/lib/assets/javascripts/locales/jquery.ui.datepicker-az.js +23 -0
  26. data/lib/assets/javascripts/locales/jquery.ui.datepicker-bg.js +24 -0
  27. data/lib/assets/javascripts/locales/jquery.ui.datepicker-bs.js +23 -0
  28. data/lib/assets/javascripts/locales/jquery.ui.datepicker-ca.js +23 -0
  29. data/lib/assets/javascripts/locales/jquery.ui.datepicker-cs.js +23 -0
  30. data/lib/assets/javascripts/locales/jquery.ui.datepicker-da.js +23 -0
  31. data/lib/assets/javascripts/locales/jquery.ui.datepicker-de-CH.js +23 -0
  32. data/lib/assets/javascripts/locales/jquery.ui.datepicker-de.js +23 -0
  33. data/lib/assets/javascripts/locales/jquery.ui.datepicker-el.js +23 -0
  34. data/lib/assets/javascripts/locales/jquery.ui.datepicker-en-GB.js +23 -0
  35. data/lib/assets/javascripts/locales/jquery.ui.datepicker-eo.js +23 -0
  36. data/lib/assets/javascripts/locales/jquery.ui.datepicker-es.js +23 -0
  37. data/lib/assets/javascripts/locales/jquery.ui.datepicker-et.js +23 -0
  38. data/lib/assets/javascripts/locales/jquery.ui.datepicker-eu.js +23 -0
  39. data/lib/assets/javascripts/locales/jquery.ui.datepicker-fa.js +23 -0
  40. data/lib/assets/javascripts/locales/jquery.ui.datepicker-fi.js +23 -0
  41. data/lib/assets/javascripts/locales/jquery.ui.datepicker-fo.js +23 -0
  42. data/lib/assets/javascripts/locales/jquery.ui.datepicker-fr-CH.js +23 -0
  43. data/lib/assets/javascripts/locales/jquery.ui.datepicker-fr.js +23 -0
  44. data/lib/assets/javascripts/locales/jquery.ui.datepicker-he.js +23 -0
  45. data/lib/assets/javascripts/locales/jquery.ui.datepicker-hr.js +23 -0
  46. data/lib/assets/javascripts/locales/jquery.ui.datepicker-hu.js +23 -0
  47. data/lib/assets/javascripts/locales/jquery.ui.datepicker-hy.js +23 -0
  48. data/lib/assets/javascripts/locales/jquery.ui.datepicker-id.js +23 -0
  49. data/lib/assets/javascripts/locales/jquery.ui.datepicker-is.js +23 -0
  50. data/lib/assets/javascripts/locales/jquery.ui.datepicker-it.js +23 -0
  51. data/lib/assets/javascripts/locales/jquery.ui.datepicker-ja.js +23 -0
  52. data/lib/assets/javascripts/locales/jquery.ui.datepicker-ko.js +23 -0
  53. data/lib/assets/javascripts/locales/jquery.ui.datepicker-lt.js +23 -0
  54. data/lib/assets/javascripts/locales/jquery.ui.datepicker-lv.js +23 -0
  55. data/lib/assets/javascripts/locales/jquery.ui.datepicker-ms.js +23 -0
  56. data/lib/assets/javascripts/locales/jquery.ui.datepicker-nl-BE.js +23 -0
  57. data/lib/assets/javascripts/locales/jquery.ui.datepicker-nl.js +23 -0
  58. data/lib/assets/javascripts/locales/jquery.ui.datepicker-no.js +23 -0
  59. data/lib/assets/javascripts/locales/jquery.ui.datepicker-pl.js +23 -0
  60. data/lib/assets/javascripts/locales/jquery.ui.datepicker-pt-BR.js +23 -0
  61. data/lib/assets/javascripts/locales/jquery.ui.datepicker-ro.js +26 -0
  62. data/lib/assets/javascripts/locales/jquery.ui.datepicker-ru.js +23 -0
  63. data/lib/assets/javascripts/locales/jquery.ui.datepicker-sk.js +23 -0
  64. data/lib/assets/javascripts/locales/jquery.ui.datepicker-sl.js +24 -0
  65. data/lib/assets/javascripts/locales/jquery.ui.datepicker-sq.js +23 -0
  66. data/lib/assets/javascripts/locales/jquery.ui.datepicker-sr-SR.js +23 -0
  67. data/lib/assets/javascripts/locales/jquery.ui.datepicker-sr.js +23 -0
  68. data/lib/assets/javascripts/locales/jquery.ui.datepicker-sv.js +23 -0
  69. data/lib/assets/javascripts/locales/jquery.ui.datepicker-ta.js +23 -0
  70. data/lib/assets/javascripts/locales/jquery.ui.datepicker-th.js +23 -0
  71. data/lib/assets/javascripts/locales/jquery.ui.datepicker-tr.js +23 -0
  72. data/lib/assets/javascripts/locales/jquery.ui.datepicker-uk.js +23 -0
  73. data/lib/assets/javascripts/locales/jquery.ui.datepicker-vi.js +23 -0
  74. data/lib/assets/javascripts/locales/jquery.ui.datepicker-zh-CN.js +23 -0
  75. data/lib/assets/javascripts/locales/jquery.ui.datepicker-zh-HK.js +23 -0
  76. data/lib/assets/javascripts/locales/jquery.ui.datepicker-zh-TW.js +23 -0
  77. data/lib/assets/stylesheets/formize.css +20 -0
  78. data/lib/assets/stylesheets/jquery-ui.css +568 -0
  79. data/lib/formize/action_pack.rb +5 -5
  80. data/lib/formize/definition/field.rb +1 -1
  81. data/lib/formize/form_helper.rb +91 -3
  82. data/lib/formize/generator.rb +83 -109
  83. data/lib/generators/formize/install/install_generator.rb +25 -1
  84. metadata +103 -11
@@ -1,399 +1,297 @@
1
- /*jslint devel: true, browser: true, sloppy: true, vars: true, white: true, maxerr: 50, indent: 4 */
1
+ /*jslint devel: true, browser: true, sloppy: true, vars: true, white: true, maxerr: 50, indent: 2 */
2
2
 
3
- var Formize = {};
3
+ var Formize = {
4
+ uniqueID: function() {
5
+ var uid = 'u'+((new Date()).getTime() + "" + Math.floor(Math.random() * 1000000)).substr(0, 18);
6
+ return uid;
7
+ }
8
+ };
4
9
 
5
10
  Formize.Overlay = {
6
11
 
7
- count : 0,
8
-
9
- add : function (body) {
10
- body = body || document.body || document.getElementsByTagName("BODY")[0];
11
- var dims = document.viewport.getDimensions();
12
- var height = dims.height, width = dims.width, overlay = $('overlay');
13
- if (overlay === null) {
14
- overlay = new Element('div', {id: 'overlay', style: 'position:fixed; top:0; left 0; width:'+width+'px; height: '+height+'px; opacity: 0.5'});
15
- body.appendChild(overlay);
16
- }
12
+ count: 0,
13
+
14
+ add: function (body) {
15
+ var overlay = $('#overlay')[0];
16
+ if (overlay === null || overlay === undefined) {
17
+ overlay = $(document.createElement('div'));
18
+ overlay.attr({id: 'overlay', style: 'position:fixed; top:0; left: 0; display: none'});
19
+ $('body').append(overlay);
20
+ this.resize();
21
+ overlay.fadeIn('fast');
22
+ }
17
23
  this.count += 1;
18
- overlay.setStyle({'z-index': this.z_index()});
24
+ overlay.css('z-index', this.zIndex());
19
25
  return overlay;
20
26
  },
27
+
28
+ resize: function () {
29
+ var height = $(document).height(), width = $(document).width();
30
+ var overlay = $('#overlay');
31
+ overlay.css({width: width+'px', height: height+'px'});
32
+ },
21
33
 
22
34
  remove: function() {
23
35
  this.count -= 1;
24
- var overlay = $('overlay');
25
- if (overlay !== null) {
36
+ var overlay = $('#overlay');
37
+ if (overlay !== null) {
26
38
  if (this.count <= 0) {
27
- overlay.remove();
28
- } else {
29
- overlay.setStyle({'z-index': this.z_index()});
30
- }
39
+ overlay.fadeOut(400, function() { $(this).remove(); });
40
+ } else {
41
+ overlay.css('z-index', this.zIndex());
42
+ }
31
43
  }
32
44
  return this.count;
33
45
  },
34
46
 
35
47
  // Computes a big z-index with interval in order to intercalate dialogs
36
- z_index: function() {
37
- return (10*this.count + 10000);
48
+ zIndex: function() {
49
+ return (10*this.count + 10000);
38
50
  }
39
51
  };
40
52
 
41
53
 
54
+
42
55
  Formize.Dialog = {
43
56
 
44
- /* Opens a div like a virtual popup*/
57
+ // Opens a div like a virtual popup
45
58
  open: function (url, updated, ratio) {
46
- var body = document.body || document.getElementsByTagName("BODY")[0];
47
- var dims = document.viewport.getDimensions();
48
- var height = dims.height;
49
- var width = dims.width;
59
+ var height = $(document).height(), width = $(document).width();
50
60
  var dialog_id = 'dialog'+Formize.Overlay.count;
51
61
  if (isNaN(ratio)) { ratio = 0.6; }
52
-
62
+
53
63
  Formize.Overlay.add();
54
-
55
- return new Ajax.Request(url, {
56
- method: 'get',
57
- parameters: {dialog: dialog_id},
58
- evalScripts: true,
59
- onSuccess: function(response) {
60
- var dialog = new Element('div', {id: dialog_id, 'data-ratio': ratio, 'data-dialog-update': updated, flex: '1', 'class': 'dialog', style: 'z-index:'+(Formize.Overlay.z_index()+1)+'; position:fixed; opacity: 1'});
61
- body.appendChild(dialog);
62
- dialog.update(response.responseText);
63
- var w = ratio*width;
64
- var h = ratio*height;
65
- if (ratio <= 0) {
66
- var dialogDims = dialog.getDimensions();
67
- w = dialogDims.width;
68
- h = dialogDims.height;
69
- }
70
- dialog.setStyle('left:'+((width-w)/2)+'px; top:'+((height-h)/2)+'px; width:'+w+'px; height: '+h+'px');
71
- return dialog.resize(w, h);
64
+
65
+ $.ajax(url, {
66
+ data: {dialog: dialog_id},
67
+ success: function(data, textStatus, jqXHR) {
68
+ var dialog = $(document.createElement('div'));
69
+ dialog.attr({id: dialog_id, 'data-ratio': ratio, 'data-dialog-update': updated, flex: '1', 'class': 'dialog', style: 'z-index:'+(Formize.Overlay.zIndex()+1)+'; position:fixed; display: none;'});
70
+ $('body').append(dialog);
71
+ dialog.html(data);
72
+ Formize.Dialog.resize(dialog);
73
+ dialog.fadeIn(400, function() {
74
+ $(document).trigger("dom:update", dialog.attr('id'));
75
+ });
72
76
  },
73
- onFailure: function(response) {
74
- alert("FAILURE (Error "+response.status+"): "+response.reponseText);
77
+ error: function(jqXHR, textStatus, errorThrown) {
78
+ alert("FAILURE (Error "+textStatus+"): "+errorThrown);
75
79
  Formize.Overlay.remove();
76
80
  }
77
81
  });
78
82
  },
79
83
 
80
- /* Close a virtual popup */
81
- close: function (dialog) {
82
- dialog = $(dialog);
83
- dialog.remove();
84
- Formize.Overlay.remove();
85
- return true;
86
- }
87
-
88
-
89
- };
90
-
91
-
92
- Formize.Partials = {
93
-
94
- refresh: function (event, element) {
95
- var dependents = element.readAttribute('data-dependents').split(',');
96
- var params = new Hash();
97
- if (element.value !== null && element.value !== undefined) {
98
- params.set(element.id, element.value);
99
- dependents.each(function(item_id) {
100
- // Replaces element
101
- var item = $(item_id);
102
- if (item) {
103
- var url = item.readAttribute('data-refresh');
104
- if (url !== null) {
105
- new Ajax.Request(url, {
106
- method: 'get',
107
- asynchronous:true,
108
- evalScripts:true,
109
- parameters: params,
110
- onSuccess: function(response) {
111
- item.replace(response.responseText);
112
- $(item_id).fire("dom:loaded");
113
- },
114
- onFailure: function(response) {
115
- alert("ERROR FAILURE\n"+response.status+" "+response.statusText);
116
- }
117
- });
118
- }
119
- }
120
- });
121
- return true;
84
+ resize: function (dialog) {
85
+ var width = $(window).width(), height = $(window).height();
86
+ var ratio = parseFloat(dialog.attr('data-ratio'));
87
+ var w = dialog.width();
88
+ var h = dialog.height();
89
+ if (ratio > 0) {
90
+ w = ratio*width;
91
+ h = ratio*height;
122
92
  }
93
+ dialog.animate({left: ((width-w)/2)+'px', top: ((height-h)/2)+'px', width: w+'px', height: h+'px'});
94
+ return true;
123
95
  },
124
96
 
125
- submitDialogForm: function(event, form) {
126
- var dialog_id = form.readAttribute('data-dialog');
127
- var dialog = $(dialog_id);
128
-
129
- var field = new Element('input', { type: 'hidden', name: 'dialog', value: dialog_id });
130
- form.insert(field);
97
+ // Close a virtual popup
98
+ close: function(dialog) {
99
+ dialog = $('#'+dialog);
100
+ dialog.fadeOut(400, function() { $(this).remove(); });
101
+ Formize.Overlay.remove();
102
+ return true;
103
+ },
131
104
 
132
- new Ajax.Request(form.readAttribute('action'), {
133
- method: form.readAttribute('method') || 'post',
134
- parameters: Form.serialize(form),
135
- asynchronous: true,
136
- evalScripts: true,
137
- onLoaded: function(request){ form.fire("layout:change"); },
138
- onSuccess: function(request){
139
- if (request.responseJSON === null) {
105
+ submitForm: function(form) {
106
+ var dialog_id = form.attr('data-dialog');
107
+ var dialog = $('#'+dialog_id);
108
+
109
+ var field = $(document.createElement('input'));
110
+ field.attr({ type: 'hidden', name: 'dialog', value: dialog_id });
111
+ form.append(field);
112
+
113
+ $.ajax(form.attr('action'), {
114
+ type: form.attr('method') || 'POST',
115
+ data: form.serialize(),
116
+ success: function(data, textStatus, request) {
117
+ var record_id = request.getResponseHeader("X-Saved-Record-Id");
118
+ if (record_id === null) {
140
119
  // No return => validation error
141
- dialog.update(request.responseText);
142
- dialog.fire("layout:change");
120
+ dialog.html(request.responseText);
121
+ $(document).trigger("dom:update", dialog.attr('id'));
143
122
  } else {
144
123
  // Refresh element with its refresh URL
145
- var updated =$(dialog.readAttribute('data-dialog-update'));
146
- if (updated !== null) {
147
- var url = updated.readAttribute('data-refresh');
148
- new Ajax.Request(url, {
149
- method: 'GET',
150
- asynchronous:true,
151
- evalScripts:true,
152
- parameters: {selected: request.responseJSON.id},
153
- onSuccess: function(request) {
154
- updated.replace(request.responseText);
155
- updated.fire("layout:change");
124
+ var updated = $('#'+dialog.attr('data-dialog-update'));
125
+ if (updated[0] !== undefined) {
126
+ var url = updated.attr('data-refresh');
127
+ $.ajax(url, {
128
+ data: {selected: record_id},
129
+ success: function(data2, textStatus2, request2) {
130
+ updated.replaceWith(request2.responseText);
131
+ $(document).trigger("dom:update");
156
132
  }
157
133
  });
158
134
  }
159
135
  // Close dialog
160
- Formize.Dialog.close(dialog);
136
+ Formize.Dialog.close(dialog_id);
161
137
  }
162
- }
163
- });
164
- event.stop();
138
+ }
139
+ });
165
140
  return false;
166
- },
141
+ }
167
142
 
168
- uniqueID: function() {
169
- var uid = 'u'+((new Date()).getTime() + "" + Math.floor(Math.random() * 1000000)).substr(0, 18);
170
- return uid;
171
- },
143
+ };
172
144
 
173
- initializeUnroll: function(element) {
174
- var choices, paramName;
175
- if (element.valueField !== null && element.valueField !== undefined) {
176
- return false;
177
- }
178
145
 
179
- choices = element.readAttribute('data-choices-container');
180
- if (choices === null) {
181
- choices = new Element('div', {
182
- 'id': this.uniqueID(),
183
- 'class': "unroll-choices",
184
- 'style': "display: none"
185
- });
186
- element.insert({after: choices});
187
- element.writeAttribute('data-choices-container', choices.id);
188
- }
189
-
190
- element.unrollCache = element.value;
191
- element.valueField = $(element.readAttribute('data-value-container'));
192
- if (element.valueField === null) {
193
- alert('An input '+element.id+' with a "data-unroll" attribute must contain a "data-value-container" attribute');
194
- }
195
- element.maxResize = parseInt(element.readAttribute('data-max-resize'));
196
- if (isNaN(element.maxResize) || element.maxResize === 0) { element.maxResize = 64; }
197
- element.size = (element.unrollCache.length > element.maxResize ? element.maxResize : element.unrollCache.length);
198
-
199
- new Ajax.Autocompleter(element, choices, element.readAttribute('data-unroll'), {
200
- method: 'GET',
201
- paramName: 'search',
202
- afterUpdateElement: function(element, selected) {
203
- var model_id = /(\d+)$/.exec(selected.id)[1];
204
- element.valueField.value = model_id;
205
- element.valueField.fire("emulated:change");
206
- element.unrollCache = element.value;
207
- element.size = (element.unrollCache.length > element.maxResize ? element.maxResize : element.unrollCache.length);
146
+ Formize.refreshDependents = function (event) {
147
+ var element = $(this);
148
+ var dependents = element.attr('data-dependents');
149
+ var params = {};
150
+ if (element.val() !== null && element.val() !== undefined) {
151
+ params[element.attr('id')] = element.val();
152
+ $(dependents).each(function(index, item) {
153
+ // Replaces element
154
+ var url = $(item).attr('data-refresh');
155
+ if (url !== null) {
156
+ $.ajax(url, {
157
+ data: params,
158
+ success: function(data, textStatus, response) {
159
+ // alert("Success: "+response.responseText);
160
+ $(item).replaceWith(response.responseText);
161
+ $(document).trigger("dom:update");
162
+ },
163
+ error: function(jqXHR, textStatus, errorThrown) {
164
+ alert("FAILURE (Error "+textStatus+"): "+errorThrown);
165
+ }
166
+ });
208
167
  }
168
+ });
169
+ return true;
170
+ }
171
+ return false;
172
+ }
173
+
174
+
175
+ /**
176
+ * Special method which is a sharthand to bind every element
177
+ * concerned by the selector now and in the future. It correspond
178
+ * to a lack of functionnality of jQuery on 'load' events.
179
+ */
180
+ $.rebindeds = [];
181
+ function behave(selector, eventType, handler) {
182
+ if (eventType == "load") {
183
+ $(document).ready(function(event) {
184
+ $(selector).each(handler);
185
+ $(selector).attr('data-already-bound', 'true');
209
186
  });
187
+ $.rebindeds.push({selector: selector, handler:handler});
188
+ } else {
189
+ $(selector).live(eventType, handler);
210
190
  }
211
-
212
- };
213
-
214
-
215
- (function() {
216
- "use strict";
217
-
218
- // Refreshes dependent elements
219
- document.on("change", "*[data-dependents]", Formize.Partials.refresh);
220
- document.on("emulated:change", "*[data-dependents]", Formize.Partials.refresh);
221
-
222
- // Opens a dialog for a ressource creation
223
- document.on("click", "a[data-add-item]", function(event, element) {
224
- var list_id = element.readAttribute('data-add-item');
225
- var url = element.readAttribute('href');
226
- Formize.Dialog.open(url, list_id);
227
- event.stop();
228
- });
229
-
230
- // Closes a dialog
231
- document.on("click", "a[data-close-dialog]", function(event, element) {
232
- var dialog_id = element.readAttribute('data-close-dialog');
233
- Formize.Dialog.close(dialog_id);
234
- event.stop();
235
- });
236
-
237
- // Submits dialog forms
238
- document.on("submit", "form[data-dialog]", Formize.Partials.submitDialogForm);
239
-
240
- // Manage unroll
241
- // this is the only found way to work with dom:loaded
242
-
243
- Event.observe(window, "dom:loaded", function(event) {
244
- $$('input[data-unroll]').each(function(element) {
245
- Formize.Partials.initializeUnroll(element);
191
+ }
192
+
193
+ // Rebinds unbound elements on DOM updates.
194
+ $(document).bind('dom:update', function(event, element_id) {
195
+ var rebinded;
196
+ for (var i=0; i<$.rebindeds.length; i++) {
197
+ rebinded = $.rebindeds[i];
198
+ $(rebinded.selector).each(function(x, element){
199
+ if ($(element).attr('data-already-bound') !== 'true') {
200
+ rebinded.handler.call($(element));
201
+ $(element).attr('data-already-bound', 'true');
202
+ }
246
203
  });
247
- });
204
+ }
205
+ });
248
206
 
249
- document.on("focusin", "input[data-unroll]", function(event, element) {
250
- if (element.unrollCache === undefined) {
251
- element.unrollCache = element.value;
207
+
208
+ // Initializes unroll inputs
209
+ behave('input[data-unroll]', 'load', function() {
210
+ var element = $(this), choices, paramName;
211
+
212
+ element.unrollCache = element.val();
213
+ element.autocompleteType = "text";
214
+ element.valueField = $('#'+element.attr('data-value-container'))[0];
215
+ if ($.isEmptyObject(element.valueField)) {
216
+ alert('An input '+element.id+' with a "data-unroll" attribute must contain a "data-value-container" attribute');
217
+ element.autocompleteType = "id";
218
+ }
219
+ element.maxResize = parseInt(element.attr('data-max-resize'));
220
+ if (isNaN(element.maxResize) || element.maxResize === 0) { element.maxResize = 64; }
221
+ element.size = (element.unrollCache.length < 32 ? 32 : element.unrollCache.length > element.maxResize ? element.maxResize : element.unrollCache.length);
222
+
223
+ element.autocomplete({
224
+ source: element.attr('data-unroll'),
225
+ minLength: 1,
226
+ select: function(event, ui) {
227
+ var selected = ui.item;
228
+ element.valueField.value = selected.id;
229
+ element.unrollCache = selected.label;
230
+ element.attr("size", (element.unrollCache.length < 32 ? 32 : element.unrollCache.length > element.maxResize ? element.maxResize : element.unrollCache.length));
231
+ $(element.valueField).trigger("emulated:change");
232
+ return true;
252
233
  }
253
234
  });
235
+ });
254
236
 
255
237
 
256
- // if (1) {
257
- // if (this.value != this.unrollCache) {
258
- // this.valueField.value = '';
259
- // }
260
- // } else {
261
- // this.value = this.unrollCache;
262
- // }
263
- document.on("change", "input[data-unroll]", function(event, element) {
264
- window.setTimeout(function () {
265
- if (this.value != this.unrollCache) {
266
- this.valueField.value = '';
267
- this.valueField.fire("emulated:change");
268
- }
269
- }.bind(element), 200);
238
+ // Initializes date fields
239
+ behave('input[data-datepicker]', "load", function() {
240
+ var element = $(this);
241
+ var locale = element.attr("data-locale");
242
+ var options = $.datepicker.regional[locale];
243
+ if (element.attr("data-date-format") !== null) {
244
+ options['dateFormat'] = element.attr("data-date-format");
245
+ }
246
+ options['altField'] = '#'+element.attr("data-datepicker");
247
+ options['altFormat'] = 'yy-mm-dd';
248
+ options['defaultDate'] = element.val();
249
+ element.datepicker(options);
250
+ });
251
+
252
+ // Initializes resizable text areas
253
+ // Minimal size is defined on default size of the area
254
+ behave('textarea[data-resizable]', "load", function() {
255
+ var element = $(this);
256
+ element.resizable({
257
+ handles: "se",
258
+ minHeight: element.height(),
259
+ minWidth: element.width(),
260
+ create: function (event, ui) { $(this).css("padding-bottom", "0px"); },
261
+ stop: function (event, ui) { $(this).css("padding-bottom", "0px"); }
270
262
  });
271
-
272
- document.on("keypress", "input[data-unroll]", function(event, element) {
273
- if (event.keyCode === Event.KEY_RETURN) {
274
- event.stop();
275
- return false;
276
- } else { return true; }
263
+ });
264
+
265
+ // Opens a dialog for a ressource creation
266
+ behave("a[data-add-item]", "click", function() {
267
+ var element = $(this);
268
+ var list_id = element.attr('data-add-item');
269
+ var url = element.attr('href');
270
+ Formize.Dialog.open(url, list_id);
271
+ return false;
272
+ });
273
+
274
+ // Closes a dialog
275
+ behave("a[data-close-dialog]", "click", function() {
276
+ var dialog_id = element.attr('data-close-dialog');
277
+ Formize.Dialog.close(dialog_id);
278
+ return false;
279
+ });
280
+
281
+ // Submits dialog forms
282
+ behave("form[data-dialog]", "submit", function() {
283
+ return Formize.Dialog.submitForm($(this));
284
+ });
285
+
286
+ behave("*[data-dependents]", "change", Formize.refreshDependents);
287
+ // Compensate for changes made with keyboard
288
+ behave("select[data-dependents]", "keypress", Formize.refreshDependents);
289
+ behave("*[data-dependents]", "emulated:change", Formize.refreshDependents);
290
+
291
+ // Resizes the overlay automatically
292
+ $(window).resize(function() {
293
+ Formize.Overlay.resize();
294
+ $('.dialog').each(function(i, dialog) {
295
+ Formize.Dialog.resize($(dialog));
277
296
  });
278
-
279
- })();
280
-
281
-
282
-
283
-
284
-
285
- // function dyliChange(dyli, id) {
286
- // var dyli_hf =$(dyli);
287
- // var dyli_tf =$(dyli+'_tf');
288
-
289
- // return new Ajax.Request(dyli_hf.getAttribute('href'), {
290
- // method: 'get',
291
- // parameters: {id: id},
292
- // onSuccess: function(response) {
293
- // var obj = response.responseJSON;
294
- // if (obj!== null) {
295
- // dyli_hf.value = obj.hf_value;
296
- // dyli_tf.value = obj.tf_value;
297
- // dyli_tf.size = (dyli_tf.value.length > 64 ? 64 : dyli_tf.value.length);
298
- // }
299
- // }
300
- // });
301
- // }
302
-
303
-
304
- // function refreshList(select, request, source_url) {
305
- // return new Ajax.Request(source_url, {
306
- // method: 'get',
307
- // parameters: {selected: request.responseJSON.id},
308
- // onSuccess: function(response) {
309
- // var list = $(select);
310
- // list.update(response.responseText);
311
- // }
312
- // });
313
- // }
314
-
315
- // function refreshAutoList(dyli, request) {
316
- // return dyliChange(dyli, request.responseJSON.id);
317
- // }
318
-
319
-
320
- // (function() {
321
-
322
- // document.on("click", "a[data-new-item]", function(event, element) {
323
- // var list_id = element.readAttribute('data-new-item');
324
- // var url = element.readAttribute('href');
325
- // openDialog(url, list_id);
326
- // event.stop();
327
- // });
328
-
329
-
330
- // document.on("click", "a[data-dialog-open]", function(event, element) {
331
- // var url = element.readAttribute('data-dialog-open');
332
- // if (url === 'true') {
333
- // url = element.readAttribute('href');
334
- // }
335
- // openDialog(url, element.readAttribute('data-dialog-update'));
336
- // event.stop();
337
- // });
338
-
339
- // document.on("click", "a[data-dialog-close]", function(event, element) {
340
- // var dialog_id = element.readAttribute('data-dialog-close');
341
- // closeDialog(dialog_id);
342
- // event.stop();
343
- // });
344
-
345
- // document.on("submit", "form[data-dialog]", function(event, form) {
346
- // var dialog_id = form.readAttribute('data-dialog');
347
- // var dialog = $(dialog_id);
348
-
349
- // var field = new Element('input', { type: 'hidden', name: 'dialog', value: dialog_id });
350
- // form.insert(field);
351
-
352
- // new Ajax.Request(form.readAttribute('action'), {
353
- // method: form.readAttribute('method') || 'post',
354
- // parameters: Form.serialize(form),
355
- // asynchronous: true,
356
- // evalScripts: true,
357
- // onLoaded: function(request){ resizeDialog(dialog_id); },
358
- // onSuccess: function(request){
359
- // if (request.responseJSON === null) {
360
- // // No return => validation error
361
- // dialog.update(request.responseText).resize();
362
- // } else {
363
- // // Refresh list or execute call
364
- // var updated_id = dialog.readAttribute('data-dialog-update');
365
- // var updated = $(updated_id);
366
- // if (updated !== null) {
367
- // if (updated.readAttribute('text_field_id') === null) {
368
- // var url = updated.readAttribute('data-refresh');
369
- // var parameter = updated.readAttribute('data-id-parameter-name');
370
- // if (parameter === null) {
371
- // parameter = 'selected';
372
- // }
373
- // var parameters = $H();
374
- // parameters.set(parameter, request.responseJSON.id);
375
- // if (url !== null) {
376
- // new Ajax.Updater(updated_id, url, {
377
- // method: 'GET',
378
- // asynchronous:true,
379
- // evalScripts:true,
380
- // parameters: parameters,
381
- // onSuccess: function(request) { form.fire("layout:resize", request); }
382
- // });
383
- // }
384
- // } else {
385
- // dyliChange(updated_id, request.responseJSON.id);
386
- // }
387
- // }
388
- // // Close dialog
389
- // closeDialog(dialog_id);
390
- // }
391
- // }
392
- // });
393
- // event.stop();
394
- // return false;
395
- // });
396
-
397
-
398
-
399
- // })();
297
+ });