formize 0.0.19 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.19
1
+ 0.0.20
@@ -60,16 +60,20 @@ $.datepicker.regional['zh-TW'] = { closeText: '關閉', prevText: '<上月'
60
60
  // Replaces `$(selector).live("ready", handler)` which don't work
61
61
  // It rebinds automatically after each ajax request all not-binded.
62
62
  $.behaviours = [];
63
- $.behave = function (selector, eventType, handler) {
64
- if (eventType == "load") {
65
- $(document).ready(function(event) {
66
- $(selector).each(handler);
67
- $(selector).prop('alreadyBound', true);
68
- });
69
- $.behaviours.push({selector: selector, handler: handler});
70
- } else {
71
- $(selector).live(eventType, handler);
72
- }
63
+ $.behave = function (selector, events, handler) {
64
+ events = events.split(/\s+/ig);
65
+ for (var i = 0; i < events.length; i += 1) {
66
+ event = events[i];
67
+ if (event === "load") {
68
+ $(document).ready(function(event) {
69
+ $(selector).each(handler);
70
+ $(selector).prop('alreadyBound', true);
71
+ });
72
+ $.behaviours.push({selector: selector, handler: handler});
73
+ } else {
74
+ $(selector).live(event, handler);
75
+ }
76
+ }
73
77
  }
74
78
  // Rebinds unbound elements on each ajax request.
75
79
  $(document).ajaxComplete(function () {
@@ -108,7 +112,7 @@ $.datepicker.regional['zh-TW'] = { closeText: '關閉', prevText: '&#x3c;上月'
108
112
  modal: true,
109
113
  width: 'auto',
110
114
  // height: 'auto',
111
- height: $(document).height()*0.8
115
+ height: $(window).height()*0.8
112
116
  });
113
117
  $.ajaxDialogInitialize(frame);
114
118
  frame.dialog("open");
@@ -138,6 +142,7 @@ $.datepicker.regional['zh-TW'] = { closeText: '關閉', prevText: '&#x3c;上月'
138
142
  $("#" + frame_id + " form").each(function (index, form) {
139
143
  $(form).attr('data-dialog', frame_id);
140
144
  });
145
+
141
146
  };
142
147
 
143
148
  $.submitAjaxForm = function () {
@@ -186,6 +191,7 @@ $.datepicker.regional['zh-TW'] = { closeText: '關閉', prevText: '&#x3c;上月'
186
191
  // Submits dialog forms
187
192
  $.behave(".ajax-dialog form[data-dialog]", "submit", $.submitAjaxForm);
188
193
 
194
+
189
195
  })(jQuery);
190
196
 
191
197
  var Formize = {};
@@ -207,6 +213,12 @@ Formize.refreshDependents = function (event) {
207
213
  success: function(data, textStatus, response) {
208
214
  if (mode == 'update') {
209
215
  $(item).html(response.responseText);
216
+ } else if (mode == 'update-value') {
217
+ if (element.data("attribute")) {
218
+ $(item).val($.parseJSON(data)[element.data("attribute")]);
219
+ } else {
220
+ $(item).val(response.responseText);
221
+ }
210
222
  } else {
211
223
  $(item).replaceWith(response.responseText);
212
224
  }
@@ -222,22 +234,20 @@ Formize.refreshDependents = function (event) {
222
234
  return false;
223
235
  }
224
236
 
225
- Formize.Toggles = {
226
-
227
- ifChecked: function () {
228
- var check_box = $(this);
229
- if (check_box.prop("checked")) {
230
- $(check_box.attr('data-show')).slideDown();
231
- $(check_box.attr('data-hide')).slideUp();
232
- } else {
233
- $(check_box.attr('data-show')).slideUp();
234
- $(check_box.attr('data-hide')).slideDown();
235
- }
237
+ Formize.toggleCheckboxes = function () {
238
+ var checkable = $(this);
239
+ if (checkable.prop("checked")) {
240
+ $(checkable.attr('data-show')).slideDown();
241
+ $(checkable.attr('data-hide')).slideUp();
242
+ } else {
243
+ $(checkable.attr('data-show')).slideUp();
244
+ $(checkable.attr('data-hide')).slideDown();
236
245
  }
246
+ };
237
247
 
238
- }
239
-
240
-
248
+ Formize.toggleRadios = function () {
249
+ $("input[type='radio'][data-show], input[type='radio'][data-hide]").each(Formize.toggleCheckboxes);
250
+ };
241
251
 
242
252
  // Initializes unroll inputs
243
253
  $.behave('input[data-unroll]', 'load', function() {
@@ -271,12 +281,12 @@ $.behave('input[data-unroll]', 'load', function() {
271
281
  // Initializes date fields
272
282
  $.behave('input[data-datepicker]', "load", function() {
273
283
  var element = $(this);
274
- var locale = element.attr("data-locale");
284
+ var locale = element.data("locale");
275
285
  var options = $.datepicker.regional[locale];
276
- if (element.attr("data-date-format") !== null) {
277
- options['dateFormat'] = element.attr("data-date-format");
286
+ if (element.data("date-format") !== null) {
287
+ options['dateFormat'] = element.data("date-format");
278
288
  }
279
- options['altField'] = '#'+element.attr("data-datepicker");
289
+ options['altField'] = '#'+element.data("datepicker");
280
290
  options['altFormat'] = 'yy-mm-dd';
281
291
  options['defaultDate'] = element.val();
282
292
  element.datepicker(options);
@@ -287,15 +297,15 @@ $.behave('input[data-datepicker]', "load", function() {
287
297
  // Can't work properly with actual datetimepicker
288
298
  // $.behave('input[data-datetimepicker]', "load", function() {
289
299
  // var element = $(this);
290
- // var locale = element.attr("data-locale");
300
+ // var locale = element.data("locale");
291
301
  // var options = $.datepicker.regional[locale];
292
- // if (element.attr("data-date-format") !== null) {
293
- // options['dateFormat'] = element.attr("data-date-format");
302
+ // if (element.data("date-format") !== null) {
303
+ // options['dateFormat'] = element.data("date-format");
294
304
  // }
295
- // if (element.attr("data-time-format") !== null) {
296
- // options['timeFormat'] = element.attr("data-time-format");
305
+ // if (element.data("time-format") !== null) {
306
+ // options['timeFormat'] = element.data("time-format");
297
307
  // }
298
- // options['altField'] = '#'+element.attr("data-datetimepicker");
308
+ // options['altField'] = '#'+element.data("datetimepicker");
299
309
  // options['altFormat'] = 'yy-mm-dd';
300
310
  // options['altFieldTimeOnly'] = false;
301
311
  // options['showSecond'] = true;
@@ -306,6 +316,7 @@ $.behave('input[data-datepicker]', "load", function() {
306
316
 
307
317
  // Initializes resizable text areas
308
318
  // Minimal size is defined on default size of the area
319
+ /*
309
320
  $.behave('textarea[data-resizable]', "load", function() {
310
321
  var element = $(this);
311
322
  element.resizable({
@@ -316,7 +327,7 @@ $.behave('textarea[data-resizable]', "load", function() {
316
327
  stop: function (event, ui) { $(this).css("padding-bottom", "0px"); }
317
328
  });
318
329
  });
319
-
330
+ */
320
331
  // Opens a dialog for a resource creation
321
332
  $.behave("a[data-add-item]", "click", function() {
322
333
  var element = $(this);
@@ -348,8 +359,8 @@ $.behave("a[data-add-item]", "click", function() {
348
359
  $.behave("input[data-autocomplete]", "load", function () {
349
360
  var element = $(this);
350
361
  element.autocomplete({
351
- source: element.attr("data-autocomplete"),
352
- minLength: parseInt(element.attr("data-min-length") || 1)
362
+ source: element.data("autocomplete"),
363
+ minLength: parseInt(element.data("min-length") || 1)
353
364
  });
354
365
  });
355
366
 
@@ -360,6 +371,12 @@ $.behave("*[data-dependents]", "emulated:change", Formize.refreshDependents);
360
371
  $.behave("select[data-dependents]", "keypress", Formize.refreshDependents);
361
372
 
362
373
  // Hide/show blocks depending on check boxes
363
- $.behave("input[data-show], input[data-hide]", "load", Formize.Toggles.ifChecked);
364
- $.behave("input[data-show], input[data-hide]", "change", Formize.Toggles.ifChecked);
374
+ $.behave("input[type='checkbox'][data-show], input[type='checkbox'][data-hide]", "load", Formize.toggleCheckboxes);
375
+ $.behave("input[type='checkbox'][data-show], input[type='checkbox'][data-hide]", "change", Formize.toggleCheckboxes)
376
+ $.behave("input[type='radio'][data-show], input[type='radio'][data-hide]", "load", Formize.toggleCheckboxes);
377
+ $.behave("input[type='radio'][data-show], input[type='radio'][data-hide]", "change", Formize.toggleRadios)
378
+ // $.behave("input[data-show], input[data-hide]", "load", Formize.Toggles.ifChecked);
379
+ // $.behave("input[data-show], input[data-hide]", "change", Formize.Toggles.ifChecked);
380
+ //$.behave("input[type='checkbox'], input[type='radio']", "load", Formize.toggleCheckables);
381
+ //$.behave("input[type='checkbox'], input[type='radio']", "change", Formize.toggleCheckables);
365
382
 
@@ -4,16 +4,20 @@
4
4
  // Replaces `$(selector).live("ready", handler)` which don't work
5
5
  // It rebinds automatically after each ajax request all not-binded.
6
6
  $.behaviours = [];
7
- $.behave = function (selector, eventType, handler) {
8
- if (eventType == "load") {
9
- $(document).ready(function(event) {
10
- $(selector).each(handler);
11
- $(selector).prop('alreadyBound', true);
12
- });
13
- $.behaviours.push({selector: selector, handler: handler});
14
- } else {
15
- $(selector).live(eventType, handler);
16
- }
7
+ $.behave = function (selector, events, handler) {
8
+ events = events.split(/\s+/ig);
9
+ for (var i = 0; i < events.length; i += 1) {
10
+ event = events[i];
11
+ if (event === "load") {
12
+ $(document).ready(function(event) {
13
+ $(selector).each(handler);
14
+ $(selector).prop('alreadyBound', true);
15
+ });
16
+ $.behaviours.push({selector: selector, handler: handler});
17
+ } else {
18
+ $(selector).live(event, handler);
19
+ }
20
+ }
17
21
  }
18
22
  // Rebinds unbound elements on each ajax request.
19
23
  $(document).ajaxComplete(function () {
@@ -52,7 +56,7 @@
52
56
  modal: true,
53
57
  width: 'auto',
54
58
  // height: 'auto',
55
- height: $(document).height()*0.8
59
+ height: $(window).height()*0.8
56
60
  });
57
61
  $.ajaxDialogInitialize(frame);
58
62
  frame.dialog("open");
@@ -82,6 +86,7 @@
82
86
  $("#" + frame_id + " form").each(function (index, form) {
83
87
  $(form).attr('data-dialog', frame_id);
84
88
  });
89
+
85
90
  };
86
91
 
87
92
  $.submitAjaxForm = function () {
@@ -130,6 +135,7 @@
130
135
  // Submits dialog forms
131
136
  $.behave(".ajax-dialog form[data-dialog]", "submit", $.submitAjaxForm);
132
137
 
138
+
133
139
  })(jQuery);
134
140
 
135
141
  var Formize = {};
@@ -151,6 +157,12 @@ Formize.refreshDependents = function (event) {
151
157
  success: function(data, textStatus, response) {
152
158
  if (mode == 'update') {
153
159
  $(item).html(response.responseText);
160
+ } else if (mode == 'update-value') {
161
+ if (element.data("attribute")) {
162
+ $(item).val($.parseJSON(data)[element.data("attribute")]);
163
+ } else {
164
+ $(item).val(response.responseText);
165
+ }
154
166
  } else {
155
167
  $(item).replaceWith(response.responseText);
156
168
  }
@@ -166,22 +178,20 @@ Formize.refreshDependents = function (event) {
166
178
  return false;
167
179
  }
168
180
 
169
- Formize.Toggles = {
170
-
171
- ifChecked: function () {
172
- var check_box = $(this);
173
- if (check_box.prop("checked")) {
174
- $(check_box.attr('data-show')).slideDown();
175
- $(check_box.attr('data-hide')).slideUp();
176
- } else {
177
- $(check_box.attr('data-show')).slideUp();
178
- $(check_box.attr('data-hide')).slideDown();
179
- }
181
+ Formize.toggleCheckboxes = function () {
182
+ var checkable = $(this);
183
+ if (checkable.prop("checked")) {
184
+ $(checkable.attr('data-show')).slideDown();
185
+ $(checkable.attr('data-hide')).slideUp();
186
+ } else {
187
+ $(checkable.attr('data-show')).slideUp();
188
+ $(checkable.attr('data-hide')).slideDown();
180
189
  }
190
+ };
181
191
 
182
- }
183
-
184
-
192
+ Formize.toggleRadios = function () {
193
+ $("input[type='radio'][data-show], input[type='radio'][data-hide]").each(Formize.toggleCheckboxes);
194
+ };
185
195
 
186
196
  // Initializes unroll inputs
187
197
  $.behave('input[data-unroll]', 'load', function() {
@@ -215,12 +225,12 @@ $.behave('input[data-unroll]', 'load', function() {
215
225
  // Initializes date fields
216
226
  $.behave('input[data-datepicker]', "load", function() {
217
227
  var element = $(this);
218
- var locale = element.attr("data-locale");
228
+ var locale = element.data("locale");
219
229
  var options = $.datepicker.regional[locale];
220
- if (element.attr("data-date-format") !== null) {
221
- options['dateFormat'] = element.attr("data-date-format");
230
+ if (element.data("date-format") !== null) {
231
+ options['dateFormat'] = element.data("date-format");
222
232
  }
223
- options['altField'] = '#'+element.attr("data-datepicker");
233
+ options['altField'] = '#'+element.data("datepicker");
224
234
  options['altFormat'] = 'yy-mm-dd';
225
235
  options['defaultDate'] = element.val();
226
236
  element.datepicker(options);
@@ -231,15 +241,15 @@ $.behave('input[data-datepicker]', "load", function() {
231
241
  // Can't work properly with actual datetimepicker
232
242
  // $.behave('input[data-datetimepicker]', "load", function() {
233
243
  // var element = $(this);
234
- // var locale = element.attr("data-locale");
244
+ // var locale = element.data("locale");
235
245
  // var options = $.datepicker.regional[locale];
236
- // if (element.attr("data-date-format") !== null) {
237
- // options['dateFormat'] = element.attr("data-date-format");
246
+ // if (element.data("date-format") !== null) {
247
+ // options['dateFormat'] = element.data("date-format");
238
248
  // }
239
- // if (element.attr("data-time-format") !== null) {
240
- // options['timeFormat'] = element.attr("data-time-format");
249
+ // if (element.data("time-format") !== null) {
250
+ // options['timeFormat'] = element.data("time-format");
241
251
  // }
242
- // options['altField'] = '#'+element.attr("data-datetimepicker");
252
+ // options['altField'] = '#'+element.data("datetimepicker");
243
253
  // options['altFormat'] = 'yy-mm-dd';
244
254
  // options['altFieldTimeOnly'] = false;
245
255
  // options['showSecond'] = true;
@@ -250,6 +260,7 @@ $.behave('input[data-datepicker]', "load", function() {
250
260
 
251
261
  // Initializes resizable text areas
252
262
  // Minimal size is defined on default size of the area
263
+ /*
253
264
  $.behave('textarea[data-resizable]', "load", function() {
254
265
  var element = $(this);
255
266
  element.resizable({
@@ -260,7 +271,7 @@ $.behave('textarea[data-resizable]', "load", function() {
260
271
  stop: function (event, ui) { $(this).css("padding-bottom", "0px"); }
261
272
  });
262
273
  });
263
-
274
+ */
264
275
  // Opens a dialog for a resource creation
265
276
  $.behave("a[data-add-item]", "click", function() {
266
277
  var element = $(this);
@@ -292,8 +303,8 @@ $.behave("a[data-add-item]", "click", function() {
292
303
  $.behave("input[data-autocomplete]", "load", function () {
293
304
  var element = $(this);
294
305
  element.autocomplete({
295
- source: element.attr("data-autocomplete"),
296
- minLength: parseInt(element.attr("data-min-length") || 1)
306
+ source: element.data("autocomplete"),
307
+ minLength: parseInt(element.data("min-length") || 1)
297
308
  });
298
309
  });
299
310
 
@@ -304,5 +315,11 @@ $.behave("*[data-dependents]", "emulated:change", Formize.refreshDependents);
304
315
  $.behave("select[data-dependents]", "keypress", Formize.refreshDependents);
305
316
 
306
317
  // Hide/show blocks depending on check boxes
307
- $.behave("input[data-show], input[data-hide]", "load", Formize.Toggles.ifChecked);
308
- $.behave("input[data-show], input[data-hide]", "change", Formize.Toggles.ifChecked);
318
+ $.behave("input[type='checkbox'][data-show], input[type='checkbox'][data-hide]", "load", Formize.toggleCheckboxes);
319
+ $.behave("input[type='checkbox'][data-show], input[type='checkbox'][data-hide]", "change", Formize.toggleCheckboxes)
320
+ $.behave("input[type='radio'][data-show], input[type='radio'][data-hide]", "load", Formize.toggleCheckboxes);
321
+ $.behave("input[type='radio'][data-show], input[type='radio'][data-hide]", "change", Formize.toggleRadios)
322
+ // $.behave("input[data-show], input[data-hide]", "load", Formize.Toggles.ifChecked);
323
+ // $.behave("input[data-show], input[data-hide]", "change", Formize.Toggles.ifChecked);
324
+ //$.behave("input[type='checkbox'], input[type='radio']", "load", Formize.toggleCheckables);
325
+ //$.behave("input[type='checkbox'], input[type='radio']", "change", Formize.toggleCheckables);
@@ -12,7 +12,7 @@ module Formize
12
12
  format = I18n.translate('date.formats.'+format.to_s)
13
13
  Formize::DATE_FORMAT_TOKENS.each{|js, rb| format.gsub!(rb, js)}
14
14
  html = ""
15
- html << hidden_field_tag(name, value.to_s(:db))
15
+ html << hidden_field_tag(name, (value.is_a?(Date) ? value.to_s(:db) : value.to_s))
16
16
  html << tag(:input, :type=>:text, "data-datepicker"=>name, "data-date-format"=>format, :value=>localized_value, "data-locale"=>::I18n.locale, :size=>options.delete(:size)||10)
17
17
  return html.html_safe
18
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.0.20
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-19 00:00:00.000000000Z
12
+ date: 2011-09-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &12364680 !ruby/object:Gem::Requirement
16
+ requirement: &15013920 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *12364680
24
+ version_requirements: *15013920
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: jquery-rails
27
- requirement: &12362020 !ruby/object:Gem::Requirement
27
+ requirement: &15001720 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *12362020
35
+ version_requirements: *15001720
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: fastercsv
38
- requirement: &12359700 !ruby/object:Gem::Requirement
38
+ requirement: &14997320 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *12359700
46
+ version_requirements: *14997320
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &12086380 !ruby/object:Gem::Requirement
49
+ requirement: &14986600 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *12086380
57
+ version_requirements: *14986600
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &12083820 !ruby/object:Gem::Requirement
60
+ requirement: &14984080 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *12083820
68
+ version_requirements: *14984080
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rdoc
71
- requirement: &12060320 !ruby/object:Gem::Requirement
71
+ requirement: &14982280 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: 2.4.2
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *12060320
79
+ version_requirements: *14982280
80
80
  description: Like simple_form or formtastic, it aims to handle easily forms but taking
81
81
  in account AJAX and HTML5 on depending fields mainly.
82
82
  email: brice.texier@ekylibre.org
@@ -209,7 +209,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
209
209
  version: '0'
210
210
  segments:
211
211
  - 0
212
- hash: 1687169217529318085
212
+ hash: 1168190452550627795
213
213
  required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  none: false
215
215
  requirements: