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
data/README.rdoc
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
= inline_forms
|
2
2
|
|
3
|
-
|
3
|
+
Ever tired of setting up forms to manage your data? Inline Forms aims at quick and easy setup of models, migrations and controllers and providing a user-friendly interface.
|
4
|
+
|
5
|
+
= Usage
|
6
|
+
|
7
|
+
Look in the generator files for a hint about usage. In short:
|
8
|
+
rails g inline_forms Person first_name:string last_name:string age:dropdown_with_integers
|
9
|
+
will create a model, a migration an a controller. In the model you would only have to add
|
10
|
+
values for the dropdown, or instance 12..45.
|
11
|
+
In going to /persons you would see a nice form to add and edit persons.
|
12
|
+
|
13
|
+
It's work in progress.
|
14
|
+
|
4
15
|
|
5
16
|
== Contributing to inline_forms
|
6
17
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0
|
@@ -54,15 +54,14 @@ class InlineFormsController < ApplicationController
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
# :edit presents a form to edit one specific
|
57
|
+
# :edit presents a form to edit one specific attribute from an object
|
58
58
|
#
|
59
59
|
# GET /examples/1/edit
|
60
60
|
#
|
61
61
|
def edit
|
62
62
|
@object = @Klass.find(params[:id])
|
63
|
-
@
|
63
|
+
@attribute = params[:attribute]
|
64
64
|
@form_element = params[:form_element]
|
65
|
-
@values = params[:values]
|
66
65
|
@sub_id = params[:sub_id]
|
67
66
|
@update_span = params[:update]
|
68
67
|
respond_to do |format|
|
@@ -79,69 +78,65 @@ class InlineFormsController < ApplicationController
|
|
79
78
|
def create
|
80
79
|
object = @Klass.new
|
81
80
|
@update_span = params[:update]
|
82
|
-
attributes = object.
|
83
|
-
attributes
|
84
|
-
|
85
|
-
send("#{form_element.to_s}_update", object, attribute, values)
|
81
|
+
attributes = object.inline_forms_attribute_list
|
82
|
+
attributes.each do | name, attribute, form_element |
|
83
|
+
send("#{form_element.to_s}_update", object, attribute)
|
86
84
|
end
|
87
85
|
object.save
|
88
|
-
@objects = @Klass.
|
86
|
+
@objects = @Klass.paginate :page => params[:page], :order => 'created_at DESC'
|
89
87
|
respond_to do |format|
|
90
88
|
# found this here: http://www.ruby-forum.com/topic/211467
|
91
89
|
format.js { render(:update) {|page| page.replace_html @update_span, :partial => 'inline_forms/index'}
|
92
90
|
}
|
93
91
|
end
|
94
92
|
end
|
95
|
-
# :update updates a specific
|
93
|
+
# :update updates a specific attribute from an object.
|
96
94
|
#
|
97
95
|
# PUT /examples/1
|
98
96
|
#
|
99
97
|
def update
|
100
98
|
@object = @Klass.find(params[:id])
|
101
|
-
@
|
99
|
+
@attribute = params[:attribute]
|
102
100
|
@form_element = params[:form_element]
|
103
|
-
@values = params[:values]
|
104
101
|
@sub_id = params[:sub_id]
|
105
102
|
@update_span = params[:update]
|
106
|
-
|
107
|
-
send("#{@form_element.to_s}_update", @object, @field, @values)
|
103
|
+
send("#{@form_element.to_s}_update", @object, @attribute)
|
108
104
|
@object.save
|
109
105
|
respond_to do |format|
|
110
106
|
# found this here: http://www.ruby-forum.com/topic/211467
|
111
|
-
format.js { render(:update) {|page| page.replace_html @update_span, :inline => '<%= send("#{@form_element.to_s}_show", @object, @
|
107
|
+
format.js { render(:update) {|page| page.replace_html @update_span, :inline => '<%= send("#{@form_element.to_s}_show", @object, @attribute) %>' }
|
112
108
|
}
|
113
109
|
end
|
114
110
|
end
|
115
111
|
|
116
|
-
# :show shows one
|
112
|
+
# :show shows one attribute (attribute) from a record (object). It inludes the link to 'edit'
|
117
113
|
#
|
118
|
-
# GET /examples/1?
|
114
|
+
# GET /examples/1?attribute=name&form_element=text
|
119
115
|
#
|
120
116
|
|
121
117
|
def show
|
122
118
|
@object = @Klass.find(params[:id])
|
123
|
-
@
|
119
|
+
@attribute = params[:attribute]
|
124
120
|
@form_element = params[:form_element]
|
125
121
|
if @form_element == "associated"
|
126
122
|
@sub_id = params[:sub_id]
|
127
123
|
if @sub_id.to_i > 0
|
128
|
-
@associated_record_id = @object.send(@
|
129
|
-
@associated_record = @object.send(@
|
124
|
+
@associated_record_id = @object.send(@attribute.to_s.singularize + "_ids").index(@sub_id.to_i)
|
125
|
+
@associated_record = @object.send(@attribute)[@associated_record_id]
|
130
126
|
end
|
131
127
|
end
|
132
128
|
@update_span = params[:update]
|
133
|
-
if @
|
129
|
+
if @attribute.nil?
|
134
130
|
respond_to do |format|
|
135
|
-
@attributes = @object.
|
131
|
+
@attributes = @object.inline_forms_attribute_list
|
136
132
|
# found this here: http://www.ruby-forum.com/topic/211467
|
137
|
-
format.js { render(:update) {|page| page.replace_html @update_span, :inline => '<%= send( "inline_forms_show_record", @object
|
133
|
+
format.js { render(:update) {|page| page.replace_html @update_span, :inline => '<%= send( "inline_forms_show_record", @object) %>' }
|
138
134
|
}
|
139
135
|
end
|
140
136
|
else
|
141
|
-
@values = params[:values]
|
142
137
|
respond_to do |format|
|
143
138
|
# found this here: http://www.ruby-forum.com/topic/211467
|
144
|
-
format.js { render(:update) {|page| page.replace_html @update_span, :inline => '<%= send("#{@form_element}_show", @object, @
|
139
|
+
format.js { render(:update) {|page| page.replace_html @update_span, :inline => '<%= send("#{@form_element}_show", @object, @attribute) %>' }
|
145
140
|
}
|
146
141
|
end
|
147
142
|
end
|
@@ -1,92 +1,94 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
1
|
+
InlineForms::SPECIAL_COLUMN_TYPES[:associated]=:references
|
2
|
+
|
3
|
+
# associated
|
4
|
+
def associated_show(object, attribute)
|
5
|
+
#show a list of records
|
6
|
+
out = ""
|
7
|
+
if @sub_id && @sub_id.to_i > 0
|
8
|
+
# if it's not a new record (sub_id > 0) then just update the list-element
|
9
|
+
out << '<li>'
|
10
|
+
out << link_to( @associated_record._presentation,
|
11
|
+
send('edit_' + @Klass.to_s.underscore + '_path', object,
|
12
|
+
:attribute => attribute,
|
13
|
+
:sub_id => @sub_id,
|
14
|
+
:form_element => this_method.reverse.sub(/.*_/,'').reverse,
|
15
|
+
:values => values,
|
16
|
+
:update => "attribute_#{attribute.to_s.singularize}_#{@sub_id.to_s}" ),
|
17
|
+
:method => :get,
|
18
|
+
:remote => true )
|
19
|
+
out << '</li>'
|
20
|
+
else
|
21
|
+
# if it's a new record (sub_id == 0) then update the whole <ul> and redraw all list-elements
|
22
|
+
out << "<ul class='associated #{attribute}' id='list_#{attribute}_#{object.id.to_s}'>" if @sub_id.nil?
|
23
|
+
out << '<li class="associated_new">'
|
24
|
+
out << link_to( 'new', send('edit_' + @Klass.to_s.underscore + '_path',
|
25
|
+
object,
|
26
|
+
:attribute => attribute,
|
27
|
+
:sub_id => 0,
|
28
|
+
:form_element => this_method.sub(/_[a-z]+$/,''),
|
29
|
+
:values => values,
|
30
|
+
:update => "list_#{attribute}_#{object.id.to_s}" ),
|
31
|
+
:method => :get,
|
32
|
+
:remote => true )
|
33
|
+
out << '</li>'
|
34
|
+
if not object.send(attribute.to_s.pluralize).empty?
|
35
|
+
# if there are things to show, show them
|
36
|
+
object.send(attribute.to_s.pluralize).each do |m|
|
37
|
+
out << "<span id='attribute_#{attribute.to_s.singularize}_#{m.id.to_s}'>"
|
38
|
+
out << '<li>'
|
39
|
+
out << link_to( m._presentation, send('edit_' + @Klass.to_s.underscore + '_path',
|
40
|
+
object,
|
41
|
+
:attribute => attribute,
|
42
|
+
:sub_id => m.id,
|
43
|
+
:form_element => this_method.sub(/_[a-z]+$/,''),
|
44
|
+
:values => values,
|
45
|
+
:update => "attribute_#{attribute.to_s.singularize}_#{m.id.to_s}" ),
|
46
|
+
:method => :get,
|
47
|
+
:remote => true )
|
48
|
+
out << '</li>'
|
49
|
+
out << '</span>'
|
51
50
|
end
|
52
|
-
# add a 'new' link for creating a new record
|
53
|
-
out << '</ul>' if @sub_id.nil?
|
54
51
|
end
|
55
|
-
|
52
|
+
# add a 'new' link for creating a new record
|
53
|
+
out << '</ul>' if @sub_id.nil?
|
56
54
|
end
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
55
|
+
raw(out)
|
56
|
+
end
|
57
|
+
|
58
|
+
def associated_edit(object, attribute)
|
59
|
+
# @sub_id is the id of the associated record
|
60
|
+
if @sub_id.to_i > 0
|
61
|
+
# only if @sub_id > 0, means we have a associated record
|
62
|
+
@associated_record_id = object.send(attribute.to_s.singularize + "_ids").index(@sub_id.to_i)
|
63
|
+
@associated_record = object.send(attribute)[@associated_record_id]
|
64
|
+
@update_span = "attribute_#{attribute.to_s.singularize}_#{@sub_id.to_s}"
|
65
|
+
else
|
66
|
+
# but if @sub_id = 0, then we are dealing with a new associated record
|
67
|
+
# in that case, we .new a record, and the update_span is the whole <ul>
|
68
|
+
@associated_record = attribute.to_s.singularize.capitalize.constantize.new
|
69
|
+
@update_span = 'list_' + attribute.to_s + '_' + object.id.to_s
|
71
70
|
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
@
|
86
|
-
# have no fear
|
87
|
-
send("#{@subform_element}_update", @associated_record, @subform_field, nil)
|
88
|
-
end
|
89
|
-
@associated_record.save
|
71
|
+
render :partial => "inline_forms/subform"
|
72
|
+
end
|
73
|
+
|
74
|
+
def associated_update(object, attribute)
|
75
|
+
return if object.id.nil?
|
76
|
+
if @sub_id.to_i > 0
|
77
|
+
# get the existing associated record
|
78
|
+
@associated_record_id = object.send(attribute.to_s.singularize + "_ids").index(@sub_id.to_i)
|
79
|
+
@associated_record = object.send(attribute)[@associated_record_id]
|
80
|
+
@update_span = "attribute_" + attribute.to_s.singularize + '_' + @sub_id.to_s
|
81
|
+
else
|
82
|
+
# create a new associated record
|
83
|
+
@associated_record = object.send(attribute.to_sym).new
|
84
|
+
@update_span = 'list_' + attribute.to_s + '_' + object.id.to_s
|
90
85
|
end
|
86
|
+
# process the sub_form attributes (attributes). These are declared in the model!
|
87
|
+
@associated_record.inline_forms_attribute_list.each do | @subform_description, @subform_attribute, @subform_element |
|
88
|
+
# have no fear
|
89
|
+
send("#{@subform_element}_update", @associated_record, @subform_attribute)
|
90
|
+
end
|
91
|
+
@associated_record.save
|
91
92
|
end
|
92
93
|
|
94
|
+
|
@@ -1,16 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
1
|
+
InlineForms::SPECIAL_COLUMN_TYPES[:check_box]=:boolean
|
2
|
+
# boolean, bit unaptly named check_box
|
3
|
+
def check_box_show(object, attribute)
|
4
|
+
values ||= { 'false' => 'no', 'true' => 'yes' }
|
5
|
+
link_to_inline_edit object, attribute, values[object.send(attribute).to_s]
|
6
|
+
end
|
7
|
+
|
8
|
+
def check_box_edit(object, attribute)
|
9
|
+
check_box_tag attribute.to_s, 1, object.send(attribute)
|
10
|
+
end
|
11
|
+
|
12
|
+
def check_box_update(object, attribute)
|
13
|
+
object[attribute.to_s.to_sym] = params[attribute.to_s.to_sym].nil? ? 0 : 1
|
15
14
|
end
|
16
15
|
|
@@ -1,36 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
out << '</ul>'
|
1
|
+
InlineForms::SPECIAL_COLUMN_TYPES[:checklist]=:references
|
2
|
+
|
3
|
+
# checklist
|
4
|
+
def checklist_show(object, attribute)
|
5
|
+
out = '<ul class="checklist">'
|
6
|
+
out << link_to_inline_edit(object, attribute) if object.send(attribute).empty?
|
7
|
+
object.send(attribute).sort.each do | item |
|
8
|
+
out << '<li>'
|
9
|
+
out << link_to_inline_edit(object, attribute, item.title)
|
10
|
+
out << '</li>'
|
13
11
|
end
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
out << '</ul>'
|
12
|
+
out << '</ul>'
|
13
|
+
end
|
14
|
+
|
15
|
+
def checklist_edit(object, attribute)
|
16
|
+
object.send(attribute).build if object.send(attribute).empty?
|
17
|
+
values = object.send(attribute).first.class.name.constantize.find(:all) # TODO bring order
|
18
|
+
out = '<div class="edit_form_checklist">'
|
19
|
+
out << '<ul>'
|
20
|
+
values.each do | item |
|
21
|
+
out << '<li>'
|
22
|
+
out << check_box_tag( attribute + '[' + item.id.to_s + ']', 'yes', object.send(attribute.singularize + "_ids").include?(item.id) )
|
23
|
+
out << '<div class="edit_form_checklist_text">'
|
24
|
+
out << h(item.title)
|
29
25
|
out << '</div>'
|
26
|
+
out << '<div style="clear: both;"></div>'
|
27
|
+
out << '</li>'
|
30
28
|
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
out << '</ul>'
|
30
|
+
out << '</div>'
|
31
|
+
end
|
32
|
+
|
33
|
+
def checklist_update(object, attribute)
|
34
|
+
params[attribute] ||= {}
|
35
|
+
object.send(attribute.singularize + '_ids=', params[attribute].keys)
|
35
36
|
end
|
36
37
|
|
@@ -1,20 +1,20 @@
|
|
1
|
-
|
2
|
-
InlineForms::SPECIAL_COLUMN_TYPES[:date_select]=:date
|
1
|
+
InlineForms::SPECIAL_COLUMN_TYPES[:date_select]=:date
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
3
|
+
# date
|
4
|
+
def date_select_show(object, attribute)
|
5
|
+
link_to_inline_edit object, attribute, object.send(attribute)
|
6
|
+
end
|
7
|
+
|
8
|
+
def date_select_edit(object, attribute)
|
9
|
+
out = text_field_tag attribute, object[attribute]
|
10
|
+
out << '<SCRIPT>'.html_safe
|
11
|
+
out << "$(function() { ".html_safe
|
12
|
+
out << '$("#'.html_safe + attribute.to_s.html_safe + '").datepicker();'.html_safe
|
13
|
+
out << '});'.html_safe
|
14
|
+
out << '</SCRIPT>'.html_safe
|
15
|
+
return out
|
16
|
+
end
|
17
|
+
|
18
|
+
def date_select_update(object, attribute)
|
19
|
+
object[attribute.to_sym] = params[attribute.to_sym]
|
20
20
|
end
|