combo_box 0.0.4 → 0.0.5

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.4
1
+ 0.0.5
@@ -4,19 +4,19 @@
4
4
 
5
5
  (function ($) {
6
6
 
7
-
7
+ "use strict";
8
8
 
9
9
  $.setComboBox = function (element, selected) {
10
10
  element.prop("valueField").val(selected.id);
11
11
  element.comboBoxCache = selected.label;
12
- element.val(element.comboBoxCache);
12
+ element.val(element.comboBoxCache);
13
13
  element.attr("size", (element.comboBoxCache.length < 32 ? 32 : element.comboBoxCache.length > element.maxSize ? element.maxSize : element.comboBoxCache.length));
14
14
  element.prop("valueField").trigger("emulated:change");
15
- return true;
15
+ return true;
16
16
  };
17
17
 
18
18
  $.getComboBox = function (element) {
19
- return {id: element.prop("valueField").val(), label: element.val()};
19
+ return {id: element.prop("valueField").val(), label: element.val()};
20
20
  };
21
21
 
22
22
  // Initializes combo-box controls
@@ -31,12 +31,12 @@
31
31
  element.maxSize = parseInt(element.attr('data-max-size'), 10);
32
32
  if (isNaN(element.maxSize) || element.maxSize === 0) { element.maxSize = 64; }
33
33
  element.size = (element.comboBoxCache.length < 32 ? 32 : element.comboBoxCache.length > element.maxSize ? element.maxSize : element.comboBoxCache.length);
34
-
34
+
35
35
  element.autocomplete({
36
36
  source: element.attr('data-combo-box'),
37
37
  minLength: 1,
38
38
  select: function (event, ui) {
39
- return $.setComboBox(element, ui.item);
39
+ return $.setComboBox(element, ui.item);
40
40
  }
41
41
  });
42
42
  element.prop("alreadyBound", true);
@@ -44,28 +44,28 @@
44
44
  return true;
45
45
  };
46
46
  $.initializeComboBoxes = function () {
47
- $('input[data-combo-box]').each($.initializeComboBox);
48
- }
47
+ $('input[data-combo-box]').each($.initializeComboBox);
48
+ };
49
49
  // Bind elements with the method
50
50
  // $('input[data-combo-box]').ready($.initializeComboBoxes);
51
51
  $(document).ready($.initializeComboBoxes);
52
52
  $(document).ajaxComplete($.initializeComboBoxes);
53
53
 
54
54
  $("a[data-permute-combo-box]").live("click", function () {
55
- var elements = $($(this).attr("data-permute-combo-box"));
56
- for (var i = 0; i < elements.length; i += 1) {
57
- if ($(elements[i]).attr("data-combo-box") === undefined || $(elements[i]).attr("data-combo-box") === null) {
58
- elements[i] = $("input[data-value-container='" + $(elements[i]).attr("id") + "']");
59
- }
60
- }
61
- if (elements.length > 1) {
62
- var vt = $.getComboBox($(elements[0]));
63
- for (var i = 1; i < elements.length; i += 1) {
64
- $.setComboBox($(elements[i-1]), $.getComboBox($(elements[i])));
65
- }
66
- $.setComboBox($(elements[elements.length - 1]), vt);
67
- }
68
- return false;
55
+ var elements = $($(this).attr("data-permute-combo-box")), i;
56
+ for (i = 0; i < elements.length; i += 1) {
57
+ if ($(elements[i]).attr("data-combo-box") === undefined || $(elements[i]).attr("data-combo-box") === null) {
58
+ elements[i] = $("input[data-value-container='" + $(elements[i]).attr("id") + "']");
59
+ }
60
+ }
61
+ if (elements.length > 1) {
62
+ var vt = $.getComboBox($(elements[0]));
63
+ for (i = 1; i < elements.length; i += 1) {
64
+ $.setComboBox($(elements[i-1]), $.getComboBox($(elements[i])));
65
+ }
66
+ $.setComboBox($(elements[elements.length - 1]), vt);
67
+ }
68
+ return false;
69
69
  });
70
-
71
- })(jQuery);
70
+
71
+ })(jQuery);
@@ -26,16 +26,17 @@ module ComboBox
26
26
  choices = {:action=>action[1], :controller=>action[0]}
27
27
  end
28
28
  choices[:controller] ||= options.delete(:controller) || controller.controller_name
29
- unless ComboBox::CompiledLabels.methods.include?("item_label_for_#{choices[:action]}_in_#{choices[:controller]}".to_sym)
30
- needed_controller = "#{choices[:controller].to_s.classify.pluralize}Controller"
31
- needed_controller.constantize
32
- unless ComboBox::CompiledLabels.methods.include?("item_label_for_#{choices[:action]}_in_#{choices[:controller]}".to_sym)
33
- raise Exception.new("It seems there is no search_for declaration corresponding to #{choices[:action]} in #{needed_controller}")
34
- end
35
- end
29
+ # unless ComboBox::CompiledLabels.methods.include?("item_label_for_#{choices[:action]}_in_#{choices[:controller]}".to_sym)
30
+ # needed_controller = "#{choices[:controller].to_s.classify.pluralize}Controller"
31
+ # needed_controller.constantize
32
+ # unless ComboBox::CompiledLabels.methods.include?("item_label_for_#{choices[:action]}_in_#{choices[:controller]}".to_sym)
33
+ # raise Exception.new("It seems there is no search_for declaration corresponding to #{choices[:action]} in #{needed_controller}")
34
+ # end
35
+ # end
36
36
  html_options[:id] ||= "#{object_name}_#{method}"
37
37
  html = ""
38
- html << tag(:input, :type=>:text, "data-combo-box"=>url_for(choices.merge(:format=>:json)), "data-value-container"=>html_options[:id], :value=>ComboBox::CompiledLabels.send("item_label_for_#{choices[:action]}_in_#{choices[:controller]}", object.send(method.to_s.gsub(/_id$/,''))), :size=>html_options.delete(:size)||32)
38
+ # ComboBox::CompiledLabels.send("item_label_for_#{choices[:action]}_in_#{choices[:controller]}", object.send(method.to_s.gsub(/_id$/,'')))
39
+ html << tag(:input, :type=>:text, "data-combo-box"=>url_for(choices.merge(:format=>:json)), "data-value-container"=>html_options[:id], :value=>item_label(object.send(method.to_s.gsub(/_id$/,'')), choices[:action], choices[:controller]), :size=>html_options.delete(:size)||32)
39
40
  html << hidden_field(object_name, method, html_options)
40
41
  return html.html_safe
41
42
  end
@@ -79,14 +80,16 @@ module ComboBox
79
80
 
80
81
  def item_label(record, item_action, item_controller=nil)
81
82
  item_controller ||= controller.controller_name
82
- unless ComboBox::CompiledLabels.methods.include?("item_label_for_#{item_action}_in_#{item_controller}".to_sym)
83
+ method_name = "item_label_for_#{item_action}_in_#{item_controller}".to_sym
84
+ unless ComboBox::CompiledLabels.respond_to?(method_name)
83
85
  needed_controller = "#{item_controller.to_s.classify.pluralize}Controller"
84
86
  needed_controller.constantize
85
- unless ComboBox::CompiledLabels.methods.include?("item_label_for_#{item_action}_in_#{item_controller}".to_sym)
86
- raise Exception.new("It seems there is no search_for declaration corresponding to #{item_action} in #{needed_controller}")
87
+ # require "#{item_controller}_controller"
88
+ unless ComboBox::CompiledLabels.respond_to?(method_name)
89
+ raise Exception.new("It seems there is no 'search_for' declaration corresponding to #{item_action} in #{needed_controller} (#{ComboBox::CompiledLabels.methods.sort.to_sentence})")
87
90
  end
88
91
  end
89
- return ComboBox::CompiledLabels.send("item_label_for_#{item_action}_in_#{item_controller}", record)
92
+ return ComboBox::CompiledLabels.send(method_name, record)
90
93
  end
91
94
 
92
95
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: combo_box
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-09-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &25950140 !ruby/object:Gem::Requirement
16
+ requirement: &16367380 !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: *25950140
24
+ version_requirements: *16367380
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: jquery-rails
27
- requirement: &25949660 !ruby/object:Gem::Requirement
27
+ requirement: &16366460 !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: *25949660
35
+ version_requirements: *16366460
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: jeweler
38
- requirement: &25949180 !ruby/object:Gem::Requirement
38
+ requirement: &16365480 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.6.4
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *25949180
46
+ version_requirements: *16365480
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rcov
49
- requirement: &25948700 !ruby/object:Gem::Requirement
49
+ requirement: &16362580 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *25948700
57
+ version_requirements: *16362580
58
58
  description: Adds helpers for Rails views and controller in order to manage 'dynamic
59
59
  select'. It uses jQuery UI as support for inobtrusive use in forms. It's not the
60
60
  classic Autocompleter, its use is limited to belongs_to reflections.
@@ -93,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  segments:
95
95
  - 0
96
- hash: 3818061861584846825
96
+ hash: 2191780791033431926
97
97
  required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  none: false
99
99
  requirements:
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  requirements: []
104
104
  rubyforge_project:
105
- rubygems_version: 1.8.7
105
+ rubygems_version: 1.8.6
106
106
  signing_key:
107
107
  specification_version: 3
108
108
  summary: Adds the combo_box control in Rails 3 based on jQuery UI