inline_forms 0.9.11 → 0.9.12
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/helpers/form_elements/check_box.rb +1 -1
- data/app/helpers/form_elements/scale_with_values.rb +1 -1
- data/app/helpers/form_elements/slider_with_values.rb +54 -0
- data/app/helpers/inline_forms_helper.rb +12 -1
- data/app/views/layouts/inline_forms.rhtml +1 -1
- data/inline_forms.gemspec +3 -2
- metadata +5 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.12
|
@@ -2,7 +2,7 @@ InlineForms::SPECIAL_COLUMN_TYPES[:check_box]=:boolean
|
|
2
2
|
# boolean, bit unaptly named check_box
|
3
3
|
def check_box_show(object, attribute)
|
4
4
|
values = attribute_values(object, attribute)
|
5
|
-
link_to_inline_edit object, attribute, values[object.send(attribute)
|
5
|
+
link_to_inline_edit object, attribute, values[object.send(attribute) ? 1 : 0 ][1]
|
6
6
|
end
|
7
7
|
|
8
8
|
def check_box_edit(object, attribute)
|
@@ -6,7 +6,7 @@ InlineForms::SPECIAL_COLUMN_TYPES[:scale_with_values]=:integer
|
|
6
6
|
# values must be a hash { integer => string, ... } or an one-dimensional array of strings
|
7
7
|
def scale_with_values_show(object, attribute)
|
8
8
|
values = attribute_values(object, attribute)
|
9
|
-
link_to_inline_edit object, attribute, values[object.send(attribute)]
|
9
|
+
link_to_inline_edit object, attribute, values[object.send(attribute)][1]
|
10
10
|
end
|
11
11
|
|
12
12
|
def scale_with_values_edit(object, attribute)
|
@@ -0,0 +1,54 @@
|
|
1
|
+
InlineForms::SPECIAL_COLUMN_TYPES[:slider_with_values]=:integer
|
2
|
+
|
3
|
+
# slider_with_values
|
4
|
+
def slider_with_values_show(object, attribute)
|
5
|
+
values = attribute_values(object, attribute)
|
6
|
+
link_to_inline_edit object, attribute, values[object.send(attribute)][1]
|
7
|
+
end
|
8
|
+
def slider_with_values_edit(object, attribute)
|
9
|
+
# 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!
|
10
|
+
values = attribute_values(object, attribute)
|
11
|
+
css_id = "#{object.class.to_s.underscore}_#{object.id}_#{attribute}"
|
12
|
+
out = "<div id='value_#{css_id}'>#{values[object.send(attribute)][1]}</div>".html_safe
|
13
|
+
out << "<div id='slider_#{css_id}'></div>".html_safe
|
14
|
+
out << "<input type='hidden' name='_#{object.class.to_s.underscore}[#{attribute}]' value='0' id='input_#{css_id}' />".html_safe
|
15
|
+
out << ('<script>
|
16
|
+
$(function() {
|
17
|
+
var displayvalues = ' + values.collect {|x| x[1]}.inspect + ';
|
18
|
+
$( "#slider_' + css_id + '" ).slider({
|
19
|
+
value:' + object.send(attribute).to_s + ',
|
20
|
+
min: 0,
|
21
|
+
max: 5,
|
22
|
+
step: 1,
|
23
|
+
slide: function( event, ui ) {
|
24
|
+
$( "#value_' + css_id + '" ).html( displayvalues[ui.value] );
|
25
|
+
$( "#input_' + css_id + '" ).val( ui.value );
|
26
|
+
}
|
27
|
+
});
|
28
|
+
$( "#value_' + css_id + '" ).html(displayvalues[' + object.send(attribute).to_s + ']);
|
29
|
+
$( "#input_' + css_id + '" ).val(' + object.send(attribute).to_s + ');
|
30
|
+
});
|
31
|
+
</script>').html_safe
|
32
|
+
out
|
33
|
+
end
|
34
|
+
def slider_with_values_update(object, attribute)
|
35
|
+
object[attribute.to_sym] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_sym]
|
36
|
+
end
|
37
|
+
|
38
|
+
#<style>
|
39
|
+
# #demo-frame > div.demo { padding: 10px !important; };
|
40
|
+
# </style>
|
41
|
+
#
|
42
|
+
#
|
43
|
+
#
|
44
|
+
#<div class="demo">
|
45
|
+
#
|
46
|
+
#<p>
|
47
|
+
# <label for="amount">Donation amount ($50 increments):</label>
|
48
|
+
# <input type="text" id="amount" style="border:0; color:#f6931f; font-weight:bold;" />
|
49
|
+
#</p>
|
50
|
+
#
|
51
|
+
#<div id="slider"></div>
|
52
|
+
#
|
53
|
+
#</div><!-- End demo -->
|
54
|
+
#
|
@@ -70,9 +70,20 @@ module InlineFormsHelper
|
|
70
70
|
# or a Range
|
71
71
|
#
|
72
72
|
def attribute_values(object, attribute)
|
73
|
+
# if we have a range 1..6 will result in [[0,1],[1,2],[2,3],...,[5,6]]
|
74
|
+
# or range -3..3 will result in [[0,-3],[1,-2],[2,-1],...,[6,3]]
|
75
|
+
# if we have an array ['a','d','b'] will result in [[0,'a'],[2,'b'],[1,'d']] (sorted on value)
|
76
|
+
# if we have a hash { 0=>'a', 2=>'b', 3=>'d' } will result in [[0,'a'],[2,'b'],[3,'d']] (it will keep the index and sort on the index)
|
77
|
+
# TODO work this out better!
|
73
78
|
values = object.inline_forms_attribute_list.assoc(attribute.to_sym)[3]
|
74
79
|
raise "No Values defined in #{@Klass}, #{attribute}" if values.nil?
|
75
|
-
|
80
|
+
if values.is_a?(Hash)
|
81
|
+
temp = Array.new
|
82
|
+
values.to_a.each do |k,v|
|
83
|
+
temp << [ k, v ]
|
84
|
+
end
|
85
|
+
values = temp.sort {|a,b| a[0]<=>b[0]}
|
86
|
+
else
|
76
87
|
temp = Array.new
|
77
88
|
values.to_a.each_index do |i|
|
78
89
|
temp << [ i, values.to_a[i] ]
|
@@ -4,7 +4,7 @@
|
|
4
4
|
<head>
|
5
5
|
<title><%= h(yield(:title) || "xyxyxyx") %></title>
|
6
6
|
<%= csrf_meta_tag %>
|
7
|
-
<%= stylesheet_link_tag 'inline_forms', 'jquery-ui-
|
7
|
+
<%= stylesheet_link_tag 'inline_forms', 'jquery-ui-sunny' %>
|
8
8
|
<%= javascript_include_tag :defaults, 'jquery.form', 'jquery.remotipart', :ckeditor %>
|
9
9
|
<%= yield(:head) %>
|
10
10
|
<script>
|
data/inline_forms.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{inline_forms}
|
8
|
-
s.version = "0.9.
|
8
|
+
s.version = "0.9.12"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ace Suares"]
|
12
|
-
s.date = %q{2011-06-
|
12
|
+
s.date = %q{2011-06-04}
|
13
13
|
s.description = %q{Inline Forms aims to ease the setup of forms that provide inline editing. The field list can be specified in the model.}
|
14
14
|
s.email = %q{ace@suares.an}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -36,6 +36,7 @@ Gem::Specification.new do |s|
|
|
36
36
|
"app/helpers/form_elements/question_list.rb",
|
37
37
|
"app/helpers/form_elements/scale_with_integers.rb",
|
38
38
|
"app/helpers/form_elements/scale_with_values.rb",
|
39
|
+
"app/helpers/form_elements/slider_with_values.rb",
|
39
40
|
"app/helpers/form_elements/text_area.rb",
|
40
41
|
"app/helpers/form_elements/text_field.rb",
|
41
42
|
"app/helpers/inline_forms_helper.rb",
|
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:
|
4
|
+
hash: 35
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 12
|
10
|
+
version: 0.9.12
|
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: 2011-06-
|
18
|
+
date: 2011-06-04 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- app/helpers/form_elements/question_list.rb
|
108
108
|
- app/helpers/form_elements/scale_with_integers.rb
|
109
109
|
- app/helpers/form_elements/scale_with_values.rb
|
110
|
+
- app/helpers/form_elements/slider_with_values.rb
|
110
111
|
- app/helpers/form_elements/text_area.rb
|
111
112
|
- app/helpers/form_elements/text_field.rb
|
112
113
|
- app/helpers/inline_forms_helper.rb
|