inline_forms 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -357,4 +357,5 @@ ul.checklist li {
357
357
  float: left;
358
358
  min-width: 60px;
359
359
  text-align: right;
360
+ font-family: monospace;
360
361
  }
@@ -3,11 +3,11 @@ InlineForms::SPECIAL_COLUMN_TYPES[:slider_with_values]=:integer
3
3
  # slider_with_values
4
4
  def slider_with_values_show(object, attribute)
5
5
  values = attribute_values(object, attribute)
6
- value = object.send(attribute)
7
- display_value = values[value][1]
6
+ value = object.send(attribute).to_i # should be an int
7
+ display_value = values.assoc(value)[1] # values should be [ [ 0, value ], [ 3, value2 ] .... ] and we lookup the key, not the place in the array!
8
8
  css_id = "#{object.class.to_s.underscore}_#{object.id}_#{attribute}"
9
9
  if value == 0
10
- out = "?"
10
+ out = "?" # we use this as the 'unknown' value. So in the data, 0 should always be the unknown value. This gives problems with sliders where the real value is 0.
11
11
  else
12
12
  out = "".html_safe
13
13
  out << "<div class='slider slider_#{attribute.to_s}' id='slider_#{css_id}'></div>".html_safe
@@ -19,7 +19,7 @@ def slider_with_values_show(object, attribute)
19
19
  var displayvalues = ' + values.collect {|x| x[1]}.inspect + ';
20
20
  $( "#slider_' + css_id + '" ).slider(
21
21
  {
22
- value:' + object.send(attribute).to_s + ',
22
+ value:' + value.to_s + ',
23
23
  range: "min",
24
24
  disabled: true,
25
25
  min: 0,
@@ -36,10 +36,12 @@ end
36
36
  def slider_with_values_edit(object, attribute)
37
37
  # the leading underscore is to avoid name conflicts, like 'email' and 'email_type' will result in 'email' and 'email[email_type_id]' in the form!
38
38
  values = attribute_values(object, attribute)
39
+ value = object.send(attribute).to_i # should be an int, will be 0 if nil
39
40
  css_id = "#{object.class.to_s.underscore}_#{object.id}_#{attribute}"
41
+ display_value = values.assoc(value)[1] # values should be [ [ 0, value ], [ 3, value2 ] .... ] and we lookup the key, not the place in the array!
40
42
  out = "".html_safe
41
43
  out << "<div class='slider slider_#{attribute.to_s}' id='slider_#{css_id}'></div>".html_safe
42
- out << "<div class='slider_value' id='value_#{css_id}'>#{values[object.send(attribute)][1]}</div>".html_safe
44
+ out << "<div class='slider_value' id='value_#{css_id}'>#{display_value}</div>".html_safe
43
45
  out << "<div style='clear: both' />".html_safe
44
46
  out << "<input type='hidden' name='_#{object.class.to_s.underscore}[#{attribute}]' value='0' id='input_#{css_id}' />".html_safe
45
47
  out << ('<script>
@@ -47,7 +49,7 @@ def slider_with_values_edit(object, attribute)
47
49
  var displayvalues = ' + values.collect {|x| x[1]}.inspect + ';
48
50
  $( "#slider_' + css_id + '" ).slider(
49
51
  {
50
- value:' + object.send(attribute).to_s + ',
52
+ value:' + value.to_s + ',
51
53
  range: "min",
52
54
  min: 0,
53
55
  max: 5,
@@ -57,13 +59,14 @@ def slider_with_values_edit(object, attribute)
57
59
  $( "#value_' + css_id + '" ).html( displayvalues[ui.value] );
58
60
  }
59
61
  }
60
- );
61
- $( "#value_' + css_id + '" ).html(displayvalues[' + object.send(attribute).to_s + ']);
62
- $( "#input_' + css_id + '" ).val(' + object.send(attribute).to_s + ');
63
- });
62
+ );').html_safe
63
+ out << ('$( "#value_' + css_id + '" ).html(displayvalues[' + value.to_s + ']);').html_safe
64
+ out << ('$( "#input_' + css_id + '" ).val(' + value.to_s + ');').html_safe
65
+ out << ('});
64
66
  </script>').html_safe
65
67
  out
66
68
  end
69
+
67
70
  def slider_with_values_update(object, attribute)
68
71
  object[attribute.to_sym] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_sym]
69
72
  end
@@ -1,3 +1,3 @@
1
1
  module InlineForms
2
- VERSION = "1.3.2"
2
+ VERSION = "1.3.3"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inline_forms
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
- - 2
10
- version: 1.3.2
9
+ - 3
10
+ version: 1.3.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ace Suares
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-15 00:00:00 Z
18
+ date: 2012-02-27 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec-rails
@@ -259,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
259
259
  requirements: []
260
260
 
261
261
  rubyforge_project: inline_forms
262
- rubygems_version: 1.8.15
262
+ rubygems_version: 1.8.11
263
263
  signing_key:
264
264
  specification_version: 3
265
265
  summary: Inline editing of forms.