inline_forms 1.2.5 → 1.2.7
Sign up to get free protection for your applications and to get access to all the features.
@@ -5,14 +5,15 @@ InlineForms::SPECIAL_COLUMN_TYPES[:radio_button]=:integer
|
|
5
5
|
|
6
6
|
def radio_button_show(object, attribute)
|
7
7
|
values = attribute_values(object, attribute)
|
8
|
-
link_to_inline_edit object, attribute, object.send(attribute)
|
8
|
+
link_to_inline_edit object, attribute, values.assoc(object.send(attribute))[1] #TODO code for values.assoc(object.send(attribute)) = nil
|
9
9
|
end
|
10
10
|
|
11
11
|
def radio_button_edit(object, attribute)
|
12
12
|
out ='<ul class="radio_list">'
|
13
|
-
attribute_values(object, attribute)
|
13
|
+
values = attribute_values(object, attribute)
|
14
|
+
values.each do |key,value|
|
14
15
|
out << '<li>'
|
15
|
-
out << radio_button_tag(attribute.to_s,
|
16
|
+
out << radio_button_tag(attribute.to_s, key, key == object.send(attribute))
|
16
17
|
out << value
|
17
18
|
out << '</li>'
|
18
19
|
end
|
@@ -21,6 +22,6 @@ def radio_button_edit(object, attribute)
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def radio_button_update(object, attribute)
|
24
|
-
object[attribute.to_s.to_sym] = params[attribute.to_s.to_sym]
|
25
|
+
object[attribute.to_s.to_sym] = params[attribute.to_s.to_sym]
|
25
26
|
end
|
26
27
|
|
@@ -122,6 +122,19 @@ module InlineFormsHelper
|
|
122
122
|
# if we have an array ['a','d','b'] will result in [[0,'a'],[2,'b'],[1,'d']] (sorted on value)
|
123
123
|
# 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)
|
124
124
|
# TODO work this out better!
|
125
|
+
# 2012-01-23 Use Cases
|
126
|
+
# [ :sex , "sex", :radio_button, { 1 => 'f', 2 => 'm' } ],
|
127
|
+
# in this case we want the attribute in the database to be 1 or 2. From that attribute, we need to find the value.
|
128
|
+
# using an array, won't work, since [ 'v', 'm' ][1] would be 'm' in stead of 'v'
|
129
|
+
# so values should be a hash. BUT since we don't have sorted hashes (ruby 1,.8.7), the order of the values in the edit screen will be random.
|
130
|
+
# so we DO need an array, and look up by index.
|
131
|
+
# [[1,'v'],[2,'m]] and then use #assoc:
|
132
|
+
# assoc(obj) → new_ary or nil
|
133
|
+
# Searches through an array whose elements are also arrays comparing obj with the first element of each contained array using obj.==.
|
134
|
+
# Returns the first contained array that matches (that is, the first associated array), or nil if no match is found. See also Array#rassoc.
|
135
|
+
# like value=values.assoc(attribute_from_database)[1] (the [1] is needed since the result of #assoc = [1,'v'] and we need the 'v')
|
136
|
+
# I feel it's ugly but it works.
|
137
|
+
|
125
138
|
attributes = @inline_forms_attribute_list || object.inline_forms_attribute_list # if we do this as a form_element, @inline.. is nil!!!
|
126
139
|
values = attributes.assoc(attribute.to_sym)[3]
|
127
140
|
raise "No Values defined in #{@Klass}, #{attribute}" if values.nil?
|
@@ -140,7 +153,6 @@ module InlineFormsHelper
|
|
140
153
|
end
|
141
154
|
values
|
142
155
|
end
|
143
|
-
|
144
156
|
end
|
145
157
|
|
146
158
|
module Kernel
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# == usage:
|
2
|
+
# in your model, add:
|
3
|
+
# validates :sex, :must_be_a_value => true;
|
4
|
+
#
|
5
|
+
# this checks against the objects attribute_values
|
6
|
+
class MustBeAValueValidator < ActiveModel::EachValidator
|
7
|
+
|
8
|
+
def error_message
|
9
|
+
"is geen geldige keuze."
|
10
|
+
end
|
11
|
+
|
12
|
+
def help_message
|
13
|
+
"U dient een keuze te maken."
|
14
|
+
end
|
15
|
+
|
16
|
+
def validate_each(record, attribute, value)
|
17
|
+
values = attribute_values(record, attribute)
|
18
|
+
if values.assoc(value).nil?
|
19
|
+
record.errors[attribute] << (options[:message] || error_message )
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
def attribute_values(object, attribute)
|
25
|
+
# if we have a range 1..6 will result in [[0,1],[1,2],[2,3],...,[5,6]]
|
26
|
+
# or range -3..3 will result in [[0,-3],[1,-2],[2,-1],...,[6,3]]
|
27
|
+
# if we have an array ['a','d','b'] will result in [[0,'a'],[2,'b'],[1,'d']] (sorted on value)
|
28
|
+
# 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)
|
29
|
+
# TODO work this out better!
|
30
|
+
# 2012-01-23 Use Cases
|
31
|
+
# [ :sex , "sex", :radio_button, { 1 => 'f', 2 => 'm' } ],
|
32
|
+
# in this case we want the attribute in the database to be 1 or 2. From that attribute, we need to find the value.
|
33
|
+
# using an array, won't work, since [ 'v', 'm' ][1] would be 'm' in stead of 'v'
|
34
|
+
# so values should be a hash. BUT since we don't have sorted hashes (ruby 1,.8.7), the order of the values in the edit screen will be random.
|
35
|
+
# so we DO need an array, and look up by index.
|
36
|
+
# [[1,'v'],[2,'m]] and then use #assoc:
|
37
|
+
# assoc(obj) → new_ary or nil
|
38
|
+
# Searches through an array whose elements are also arrays comparing obj with the first element of each contained array using obj.==.
|
39
|
+
# Returns the first contained array that matches (that is, the first associated array), or nil if no match is found. See also Array#rassoc.
|
40
|
+
# like value=values.assoc(attribute_from_database)[1] (the [1] is needed since the result of #assoc = [1,'v'] and we need the 'v')
|
41
|
+
# I feel it's ugly but it works.
|
42
|
+
|
43
|
+
attributes = @inline_forms_attribute_list || object.inline_forms_attribute_list # if we do this as a form_element, @inline.. is nil!!!
|
44
|
+
values = attributes.assoc(attribute.to_sym)[3]
|
45
|
+
raise "No Values defined in #{@Klass}, #{attribute}" if values.nil?
|
46
|
+
if values.is_a?(Hash)
|
47
|
+
temp = Array.new
|
48
|
+
values.to_a.each do |k,v|
|
49
|
+
temp << [ k, v ]
|
50
|
+
end
|
51
|
+
values = temp.sort {|a,b| a[0]<=>b[0]}
|
52
|
+
else
|
53
|
+
temp = Array.new
|
54
|
+
values.to_a.each_index do |i|
|
55
|
+
temp << [ i, values.to_a[i] ]
|
56
|
+
end
|
57
|
+
values = temp.sort {|a,b| a[1]<=>b[1]}
|
58
|
+
end
|
59
|
+
values
|
60
|
+
end
|
61
|
+
end
|
data/lib/inline_forms.rb
CHANGED
data/lib/inline_forms/version.rb
CHANGED
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: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 7
|
10
|
+
version: 1.2.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ace Suares
|
@@ -167,6 +167,7 @@ files:
|
|
167
167
|
- lib/app/validators/is_a_curacao_id_number_validator.rb
|
168
168
|
- lib/app/validators/is_curacao_phone_validator.rb
|
169
169
|
- lib/app/validators/is_email_address_validator.rb
|
170
|
+
- lib/app/validators/must_be_a_value_validator.rb
|
170
171
|
- lib/app/validators/must_be_present_validator.rb
|
171
172
|
- lib/app/validators/must_be_unique_validator.rb
|
172
173
|
- lib/app/views/devise/confirmations/new.html.erb
|
@@ -241,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
241
242
|
requirements: []
|
242
243
|
|
243
244
|
rubyforge_project: inline_forms
|
244
|
-
rubygems_version: 1.8.
|
245
|
+
rubygems_version: 1.8.11
|
245
246
|
signing_key:
|
246
247
|
specification_version: 3
|
247
248
|
summary: Inline editing of forms.
|