inline_forms 0.7.4 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +12 -1
- data/VERSION +1 -1
- data/app/controllers/inline_forms_controller.rb +19 -24
- data/app/helpers/form_elements/associated.rb +87 -85
- data/app/helpers/form_elements/check_box.rb +13 -14
- data/app/helpers/form_elements/checklist.rb +32 -31
- data/app/helpers/form_elements/date.rb +18 -18
- data/app/helpers/form_elements/dropdown.rb +17 -16
- data/app/helpers/form_elements/dropdown_with_integers.rb +18 -24
- data/app/helpers/form_elements/dropdown_with_values.rb +14 -21
- data/app/helpers/form_elements/geo_code_curacao.rb +14 -15
- data/app/helpers/form_elements/image.rb +13 -12
- data/app/helpers/form_elements/scale_with_integers.rb +20 -24
- data/app/helpers/form_elements/scale_with_values.rb +21 -0
- data/app/helpers/form_elements/text_area.rb +12 -12
- data/app/helpers/form_elements/text_field.rb +12 -12
- data/app/helpers/inline_forms_helper.rb +80 -44
- data/app/views/inline_forms/_edit.html.erb +5 -8
- data/app/views/inline_forms/_index.html.erb +5 -4
- data/app/views/inline_forms/_new.html.erb +3 -3
- data/app/views/inline_forms/_subform.html.erb +1 -1
- data/app/views/inline_forms/index.html.erb +4 -3
- data/app/views/layouts/inline_forms.rhtml +1 -1
- data/inline_forms.gemspec +3 -3
- data/lib/generators/inline_forms/inline_forms_generator.rb +16 -16
- data/lib/generators/inline_forms/templates/model.erb +5 -1
- data/lib/inline_forms.rb +43 -38
- metadata +6 -6
- data/app/helpers/form_elements/range.rb +0 -15
@@ -1,18 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
1
|
+
InlineForms::SPECIAL_COLUMN_TYPES[:dropdown]=:belongs_to
|
2
|
+
|
3
|
+
# dropdown
|
4
|
+
def dropdown_show(object, attribute)
|
5
|
+
attribute_value = object.send(attribute)._presentation rescue nil
|
6
|
+
link_to_inline_edit object, attribute, attribute_value
|
7
|
+
end
|
8
|
+
|
9
|
+
def dropdown_edit(object, attribute)
|
10
|
+
object.send('build_' + attribute.to_s) unless object.send(attribute)
|
11
|
+
values = object.send(attribute).class.name.constantize.find(:all) # TODO bring order!
|
12
|
+
# 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!
|
13
|
+
collection_select( ('_' + object.class.to_s.downcase).to_sym, attribute.to_s.foreign_key.to_sym, values, 'id', '_presentation', :selected => object.send(attribute).id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def dropdown_update(object, attribute)
|
17
|
+
object[attribute.to_s.foreign_key.to_sym] = params[('_' + object.class.to_s.downcase).to_sym][attribute.to_s.foreign_key.to_sym]
|
17
18
|
end
|
18
19
|
|
@@ -1,26 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
def dropdown_with_integers_edit(object, attribute, values)
|
18
|
-
# 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!
|
19
|
-
values = values.sort {|a,b| a[1].to_i<=>b[1].to_i}
|
20
|
-
collection_select( ('_' + object.class.to_s.downcase).to_sym, attribute.to_sym, values, 'first', 'last', :selected => object.send(attribute))
|
21
|
-
end
|
22
|
-
def dropdown_with_integers_update(object, attribute, values)
|
23
|
-
object[attribute.to_sym] = params[('_' + object.class.to_s.downcase).to_sym][attribute.to_sym]
|
24
|
-
end
|
1
|
+
InlineForms::SPECIAL_COLUMN_TYPES[:dropdown_with_integers]=:integer
|
2
|
+
|
3
|
+
# dropdown_with_integers generates a dropdown menu
|
4
|
+
# with the given list of integers as options
|
5
|
+
#
|
6
|
+
# values must be a Range or a one-dimensional array of Integers
|
7
|
+
def dropdown_with_integers_show(object, attribute)
|
8
|
+
values = attribute_values(object, attribute)
|
9
|
+
link_to_inline_edit object, attribute, values[object.send(attribute)][1]
|
10
|
+
end
|
11
|
+
|
12
|
+
def dropdown_with_integers_edit(object, attribute)
|
13
|
+
# 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!
|
14
|
+
values = attribute_values(object, attribute)
|
15
|
+
collection_select( ('_' + object.class.to_s.downcase).to_sym, attribute.to_sym, values, 'first', 'last', :selected => object.send(attribute))
|
25
16
|
end
|
26
17
|
|
18
|
+
def dropdown_with_integers_update(object, attribute)
|
19
|
+
object[attribute.to_sym] = params[('_' + object.class.to_s.downcase).to_sym][attribute.to_sym]
|
20
|
+
end
|
@@ -1,23 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
# 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!
|
16
|
-
values = values.sort {|a,b| a[1]<=>b[1]}
|
17
|
-
collection_select( ('_' + object.class.to_s.downcase).to_sym, attribute.to_sym, values, 'first', 'last', :selected => object.send(attribute))
|
18
|
-
end
|
19
|
-
def dropdown_with_values_update(object, attribute, values)
|
20
|
-
object[attribute.to_sym] = params[('_' + object.class.to_s.downcase).to_sym][attribute.to_sym]
|
21
|
-
end
|
1
|
+
InlineForms::SPECIAL_COLUMN_TYPES[:dropdown_with_values]=:integer
|
2
|
+
|
3
|
+
# dropdown_with_values
|
4
|
+
def dropdown_with_values_show(object, attribute)
|
5
|
+
values = attribute_values(object, attribute)
|
6
|
+
link_to_inline_edit object, attribute, values[object.send(attribute).to_s]
|
7
|
+
end
|
8
|
+
def dropdown_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
|
+
collection_select( ('_' + object.class.to_s.downcase).to_sym, attribute.to_sym, values, 'first', 'last', :selected => object.send(attribute))
|
12
|
+
end
|
13
|
+
def dropdown_with_values_update(object, attribute)
|
14
|
+
object[attribute.to_sym] = params[('_' + object.class.to_s.downcase).to_sym][attribute.to_sym]
|
22
15
|
end
|
23
16
|
|
@@ -1,17 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
1
|
+
InlineForms::SPECIAL_COLUMN_TYPES[:geo_code_curacao]=:string
|
2
|
+
|
3
|
+
# geo_code_curacao
|
4
|
+
def geo_code_curacao_show(object, attribute)
|
5
|
+
attribute_value = object.send(attribute)._presentation rescue nil
|
6
|
+
link_to_inline_edit object, attribute, attribute_value
|
7
|
+
end
|
8
|
+
def geo_code_curacao_edit(object, attribute)
|
9
|
+
text_field_with_auto_complete :geo_code_curacao, :street, :skip_style => true
|
10
|
+
end
|
11
|
+
def geo_code_curacao_update(object, attribute)
|
12
|
+
# extract the geocode
|
13
|
+
geo_code = params[attribute.to_sym][:street].scan(/\d\d\d\d\d\d/).to_s || nil
|
14
|
+
object[attribute.to_sym] = GeoCodeCuracao.new(geo_code).valid? ? geo_code : nil
|
16
15
|
end
|
17
16
|
|
@@ -1,13 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
InlineForms::SPECIAL_COLUMN_TYPES[:image]=:image
|
2
|
+
|
3
|
+
# image via paperclip
|
4
|
+
def image_show(object, attribute)
|
5
|
+
link_to_inline_image_edit object, attribute
|
6
|
+
end
|
7
|
+
|
8
|
+
def image_edit(object, attribute)
|
9
|
+
file_attribute object.class.to_s.downcase, attribute
|
10
|
+
end
|
11
|
+
|
12
|
+
def image_update(object, attribute)
|
13
|
+
object.send(attribute+'=',values)
|
13
14
|
end
|
@@ -1,26 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
def scale_with_integers_update(object, attribute, values)
|
23
|
-
object[attribute.to_sym] = params[('_' + object.class.to_s.downcase).to_sym][attribute.to_sym]
|
24
|
-
end
|
1
|
+
InlineForms::SPECIAL_COLUMN_TYPES[:scale_with_integers]=:integer
|
2
|
+
|
3
|
+
# scale_with_integers generates a scale
|
4
|
+
# with the given list of integers as options
|
5
|
+
#
|
6
|
+
# values must be a Range or a one-dimensional array of Integers
|
7
|
+
#
|
8
|
+
def scale_with_integers_show(object, attribute)
|
9
|
+
values = attribute_values(object, attribute)
|
10
|
+
link_to_inline_edit object, attribute, values[object.send(attribute).to_s]
|
11
|
+
end
|
12
|
+
|
13
|
+
def scale_with_integers_edit(object, attribute)
|
14
|
+
# 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!
|
15
|
+
values = attribute_values(object, attribute)
|
16
|
+
collection_select( ('_' + object.class.to_s.downcase).to_sym, attribute.to_sym, values, 'first', 'last', :selected => object.send(attribute))
|
17
|
+
end
|
18
|
+
|
19
|
+
def scale_with_integers_update(object, attribute)
|
20
|
+
object[attribute.to_sym] = params[('_' + object.class.to_s.downcase).to_sym][attribute.to_sym]
|
25
21
|
end
|
26
22
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
InlineForms::SPECIAL_COLUMN_TYPES[:scale_with_values]=:integer
|
2
|
+
|
3
|
+
# scale_with_values generates a scale
|
4
|
+
# with the given list of values as options
|
5
|
+
#
|
6
|
+
# values must be a hash { integer => string, ... } or an one-dimensional array of strings
|
7
|
+
def scale_with_values_show(object, attribute)
|
8
|
+
values = attribute_values(object, attribute)
|
9
|
+
link_to_inline_edit object, attribute, values[object.send(attribute)]
|
10
|
+
end
|
11
|
+
|
12
|
+
def scale_with_values_edit(object, attribute)
|
13
|
+
# 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!
|
14
|
+
values = attribute_values(object, attribute)
|
15
|
+
collection_select( ('_' + object.class.to_s.downcase).to_sym, attribute.to_sym, values, 'first', 'last', :selected => object.send(attribute))
|
16
|
+
end
|
17
|
+
|
18
|
+
def scale_with_values_update(object, attribute)
|
19
|
+
object[attribute.to_sym] = params[('_' + object.class.to_s.downcase).to_sym][attribute.to_sym]
|
20
|
+
end
|
21
|
+
|
@@ -1,13 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
InlineForms::SPECIAL_COLUMN_TYPES[:text_area]=:text
|
2
|
+
|
3
|
+
def text_area_show(object, attribute)
|
4
|
+
link_to_inline_edit object, attribute, object.send(attribute)
|
5
|
+
end
|
6
|
+
|
7
|
+
def text_area_edit(object, attribute)
|
8
|
+
text_area_tag attribute, object[attribute], :class => 'attribute_text_area'
|
9
|
+
end
|
10
|
+
|
11
|
+
def text_area_update(object, attribute)
|
12
|
+
object[attribute.to_sym] = params[attribute.to_sym]
|
13
13
|
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
InlineForms::SPECIAL_COLUMN_TYPES[:text_field]=:string
|
2
|
+
|
3
|
+
def text_field_show(object, attribute)
|
4
|
+
link_to_inline_edit object, attribute, object.send(attribute)
|
5
|
+
end
|
6
|
+
|
7
|
+
def text_field_edit(object, attribute)
|
8
|
+
text_field_tag attribute, object[attribute], :class => 'input_text_field'
|
9
|
+
end
|
10
|
+
|
11
|
+
def text_field_update(object, attribute)
|
12
|
+
object[attribute.to_sym] = params[attribute.to_sym]
|
13
13
|
end
|
14
14
|
|
@@ -1,24 +1,31 @@
|
|
1
|
-
|
1
|
+
module InlineFormsHelper
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
# load form elements. Each element goes into a separate file
|
4
|
+
# and defines a _show, _edit and _update method.
|
5
|
+
#
|
6
|
+
INLINE_FORMS_PATH = File.dirname(__FILE__) + "/form_elements/"
|
7
|
+
Dir[INLINE_FORMS_PATH + "*.rb"].each do |form_element|
|
8
|
+
require form_element
|
9
|
+
end
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
|
11
|
+
# default inline forms attribute list, for models that don't have an inline_attribute_attribute_list defined.
|
12
|
+
INLINE_FORMS_DEFAULT_ATTRIBUTE_LIST = { :name => [ 'name', :text ] }
|
13
|
+
|
14
|
+
# show a record by iterating through its attribute list
|
15
|
+
def inline_forms_show_record(object, attributes=nil)
|
16
|
+
attributes ||= object.inline_forms_attribute_list
|
10
17
|
out = String.new
|
11
|
-
attributes.each do | attribute, name, form_element
|
12
|
-
css_class_id = "
|
18
|
+
attributes.each do | attribute, name, form_element |
|
19
|
+
css_class_id = "attribute_#{attribute}_#{object.id}"
|
13
20
|
name_cell = content_tag :td, :valign=>'top' do
|
14
|
-
content_tag :div, :class=> "
|
21
|
+
content_tag :div, :class=> "attribute_name attribute_#{attribute} form_element_#{form_element}" do
|
15
22
|
h(name)
|
16
23
|
end
|
17
24
|
end
|
18
25
|
value_cell = content_tag :td, :valign=>'top' do
|
19
|
-
content_tag :div, :class=> "
|
26
|
+
content_tag :div, :class=> "attribute_value attribute_#{attribute} form_element_#{form_element}" do
|
20
27
|
content_tag :span, :id => css_class_id do
|
21
|
-
send("#{form_element
|
28
|
+
send("#{form_element}_show", object, attribute)
|
22
29
|
end
|
23
30
|
end
|
24
31
|
end
|
@@ -29,22 +36,25 @@ module InlineFormsHelper
|
|
29
36
|
return content_tag :table, raw(out), :cellspacing => 0, :cellpadding => 0
|
30
37
|
end
|
31
38
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
39
|
+
# show the form for a new record
|
40
|
+
#
|
41
|
+
# associated records are NOT shown!
|
42
|
+
#
|
43
|
+
def inline_forms_new_record(object, attributes=nil)
|
44
|
+
attributes ||= object.inline_forms_attribute_list
|
45
|
+
out = String.new
|
46
|
+
attributes.each do | attribute, name, form_element |
|
37
47
|
if not form_element.to_sym == :associated
|
38
|
-
css_class_id = "
|
48
|
+
css_class_id = "attribute_#{attribute}_#{object.id}"
|
39
49
|
name_cell = content_tag :td, :valign=>'top' do
|
40
|
-
content_tag :div, :class=> "
|
50
|
+
content_tag :div, :class=> "attribute_name attribute_#{attribute} form_element_#{form_element}" do
|
41
51
|
h(name)
|
42
52
|
end
|
43
53
|
end
|
44
54
|
value_cell = content_tag :td, :valign=>'top' do
|
45
|
-
content_tag :div, :class=> "
|
55
|
+
content_tag :div, :class=> "attribute_value attribute_#{attribute} form_element_#{form_element}" do
|
46
56
|
content_tag :span, :id => css_class_id do
|
47
|
-
send("#{form_element
|
57
|
+
send("#{form_element}_edit", object, attribute)
|
48
58
|
end
|
49
59
|
end
|
50
60
|
end
|
@@ -53,50 +63,76 @@ module InlineFormsHelper
|
|
53
63
|
end
|
54
64
|
return content_tag :table, raw(out), :cellspacing => 0, :cellpadding => 0
|
55
65
|
end
|
66
|
+
|
56
67
|
# display a list of objects
|
57
|
-
def
|
58
|
-
t =
|
68
|
+
def inline_forms_list(objects, tag=:li)
|
69
|
+
t = String.new
|
59
70
|
objects.each do |object|
|
60
71
|
css_class_id = @Klass.to_s.underscore + '_' + object.id.to_s
|
61
72
|
t += content_tag tag, :id => css_class_id do
|
62
|
-
|
63
|
-
|
73
|
+
link_to h(object._presentation),
|
74
|
+
send( @Klass.to_s.underscore + '_path', object, :update => css_class_id),
|
75
|
+
:remote => true
|
64
76
|
end
|
65
77
|
end
|
66
78
|
return raw(t)
|
67
79
|
end
|
80
|
+
|
68
81
|
# link for new item
|
69
|
-
def
|
70
|
-
link_to text,
|
82
|
+
def inline_forms_new_record_link(text='new', update_span='inline_forms_list')
|
83
|
+
link_to text,
|
84
|
+
send('new_' + @Klass.to_s.underscore + '_path', :update => update_span),
|
85
|
+
:remote => true
|
71
86
|
end
|
72
|
-
|
73
|
-
|
74
87
|
|
75
88
|
private
|
76
89
|
|
77
90
|
# link_to_inline_edit
|
78
|
-
def link_to_inline_edit(object, attribute, attribute_value
|
91
|
+
def link_to_inline_edit(object, attribute, attribute_value)
|
79
92
|
attribute_value = h(attribute_value)
|
80
93
|
spaces = attribute_value.length > 40 ? 0 : 40 - attribute_value.length
|
81
94
|
attribute_value << " ".html_safe * spaces
|
82
|
-
link_to raw(attribute_value),
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
95
|
+
link_to raw(attribute_value),
|
96
|
+
send( 'edit_' + @Klass.to_s.underscore + '_path',
|
97
|
+
object,
|
98
|
+
:attribute => attribute.to_s,
|
99
|
+
:form_element => calling_method.sub(/_[a-z]+$/,''),
|
100
|
+
:update => "attribute_#{attribute}_#{object.id}" ),
|
101
|
+
:remote => true
|
89
102
|
end
|
90
103
|
|
104
|
+
# link to inline image edit
|
91
105
|
def link_to_inline_image_edit(object, attribute)
|
92
|
-
text= image_tag object.send(attribute
|
106
|
+
text= image_tag object.send(attribute).send('url', :thumb)
|
107
|
+
link_to text,
|
108
|
+
send('edit_' + @Klass.to_s.underscore + '_path',
|
109
|
+
object,
|
110
|
+
:attribute => attribute.to_s,
|
111
|
+
:form_element => calling_method.sub(/_[a-z]+$/,''),
|
112
|
+
:update => "attribute_#{attribute}_#{object.id}" ),
|
113
|
+
:remote => true
|
114
|
+
end
|
93
115
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
116
|
+
# get the values for an attribute
|
117
|
+
#
|
118
|
+
# values should be a Hash { integer => string, ... }
|
119
|
+
#
|
120
|
+
# or a one-dimensional array of strings
|
121
|
+
#
|
122
|
+
# or a Range
|
123
|
+
#
|
124
|
+
def attribute_values(object, attribute)
|
125
|
+
values = object.inline_forms_attribute_list.assoc(attribute.to_sym)[3]
|
126
|
+
raise "No Values defined in #{@Klass}, #{attribute}" if values.nil?
|
127
|
+
unless values.is_a?(Hash)
|
128
|
+
temp = Array.new
|
129
|
+
values.to_a.each_index do |i|
|
130
|
+
temp << [ i, values.to_a[i] ]
|
131
|
+
end
|
132
|
+
values = temp.sort {|a,b| a[1]<=>b[1]}
|
133
|
+
end
|
134
|
+
logger.info values.inspect
|
135
|
+
values
|
100
136
|
end
|
101
137
|
|
102
138
|
end
|