inline_forms 0.3.0 → 0.3.1
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/VERSION +1 -1
- data/app/controllers/inline_forms_controller.rb +24 -18
- data/app/helpers/inline_forms_helper.rb +30 -35
- data/app/views/inline_forms/_edit.html.erb +11 -8
- data/app/views/inline_forms/_new.html.erb +4 -2
- data/app/views/inline_forms/_subform.html.erb +1 -1
- data/inline_forms.gemspec +1 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
@@ -31,23 +31,7 @@ class InlineFormsController < ApplicationController
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
#
|
36
|
-
# GET /examples/1?field=name&form_element=text
|
37
|
-
#
|
38
|
-
# def show
|
39
|
-
# @object = @Klass.constantize.find(params[:id])
|
40
|
-
# @field = params[:field]
|
41
|
-
# @form_element = params[:form_element]
|
42
|
-
# if @form_element == "associated"
|
43
|
-
# @sub_id = params[:sub_id]
|
44
|
-
# if @sub_id.to_i > 0
|
45
|
-
# @associated_record_id = @object.send(@field.singularize + "_ids").index(@sub_id.to_i)
|
46
|
-
# @associated_record = @object.send(@field)[@associated_record_id]
|
47
|
-
# end
|
48
|
-
# end
|
49
|
-
# render :inline => '<%= send("#{@form_element}_show", @object, @field, @values) %>'
|
50
|
-
# end
|
34
|
+
|
51
35
|
|
52
36
|
# :new prepares a new object, updates the entire list of objects and replaces it with a new
|
53
37
|
# empty form. After pressing OK or Cancel, the list of objects is retrieved in the same way as :index
|
@@ -119,7 +103,29 @@ class InlineFormsController < ApplicationController
|
|
119
103
|
format.js { render(:update) {|page| page.replace_html @update_span, :inline => '<%= send("#{@form_element.to_s}_show", @object, @field, @values) %>' }
|
120
104
|
}
|
121
105
|
end
|
122
|
-
|
106
|
+
end
|
107
|
+
|
108
|
+
# :show shows one field (attribute) from a record (object). It inludes the link to 'edit'
|
109
|
+
#
|
110
|
+
# GET /examples/1?field=name&form_element=text
|
111
|
+
#
|
112
|
+
def show
|
113
|
+
@object = @Klass.find(params[:id])
|
114
|
+
@field = params[:field]
|
115
|
+
@form_element = params[:form_element]
|
116
|
+
if @form_element == "associated"
|
117
|
+
@sub_id = params[:sub_id]
|
118
|
+
if @sub_id.to_i > 0
|
119
|
+
@associated_record_id = @object.send(@field.singularize + "_ids").index(@sub_id.to_i)
|
120
|
+
@associated_record = @object.send(@field)[@associated_record_id]
|
121
|
+
end
|
122
|
+
end
|
123
|
+
@update_span = params[:update]
|
124
|
+
respond_to do |format|
|
125
|
+
# found this here: http://www.ruby-forum.com/topic/211467
|
126
|
+
format.js { render(:update) {|page| page.replace_html @update_span, :inline => '<%= send("#{@form_element}_show", @object, @field, @values) %>' }
|
127
|
+
}
|
128
|
+
end
|
123
129
|
end
|
124
130
|
|
125
131
|
# :destroy is not implemented
|
@@ -27,27 +27,25 @@ module InlineFormsHelper
|
|
27
27
|
when :new
|
28
28
|
attributes.each do | name, attribute, form_element, values |
|
29
29
|
#css_class_id = form_element == :associated ? "subform_#{attribute.to_s}_#{object.id}" : "field_#{attribute.to_s}_#{object.id}"
|
30
|
-
|
31
|
-
|
32
|
-
content_tag :
|
33
|
-
|
30
|
+
if not form_element.to_sym == :associated
|
31
|
+
css_class_id = "field_#{attribute.to_s}_#{object.id}"
|
32
|
+
name_cell = content_tag :td, :valign=>'top' do
|
33
|
+
content_tag :div, :class=> "field_name field_#{attribute.to_s} form_element_#{form_element.to_s}" do
|
34
|
+
h(name)
|
35
|
+
end
|
34
36
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
content_tag :span, :id => css_class_id do
|
39
|
-
if not form_element == :associated
|
37
|
+
value_cell = content_tag :td, :valign=>'top' do
|
38
|
+
content_tag :div, :class=> "field_value field_#{attribute.to_s} form_element_#{form_element.to_s}" do
|
39
|
+
content_tag :span, :id => css_class_id do
|
40
40
|
send("#{form_element.to_s}_edit", object, attribute, values)
|
41
|
-
else
|
42
|
-
#send("#{form_element.to_s}_show", object, attribute, values)
|
43
41
|
end
|
44
42
|
end
|
45
43
|
end
|
44
|
+
out += content_tag :tr, name_cell + value_cell
|
46
45
|
end
|
47
|
-
out += content_tag :tr, name_cell + value_cell
|
48
46
|
end
|
49
|
-
return content_tag :table, raw(out), :cellspacing => 0, :cellpadding => 0
|
50
47
|
end
|
48
|
+
return content_tag :table, raw(out), :cellspacing => 0, :cellpadding => 0
|
51
49
|
end
|
52
50
|
# display a list of objects
|
53
51
|
def inline_form_display_list(objects, tag=:li)
|
@@ -71,7 +69,7 @@ module InlineFormsHelper
|
|
71
69
|
end
|
72
70
|
def dropdown_edit(object, attribute, values)
|
73
71
|
object.send('build_' + attribute.to_s) unless object.send(attribute)
|
74
|
-
values = object.send(attribute).class.name.constantize.find(:all
|
72
|
+
values = object.send(attribute).class.name.constantize.find(:all) # TODO bring order!
|
75
73
|
# 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!
|
76
74
|
collection_select( ('_' + object.class.to_s.downcase).to_sym, attribute.to_s.foreign_key.to_sym, values, 'id', 'presentation', :selected => object.send(attribute).id)
|
77
75
|
end
|
@@ -160,7 +158,7 @@ module InlineFormsHelper
|
|
160
158
|
end
|
161
159
|
def checklist_edit(object, attribute, values)
|
162
160
|
object.send(attribute).build if object.send(attribute).empty?
|
163
|
-
values = object.send(attribute).first.class.name.constantize.find(:all
|
161
|
+
values = object.send(attribute).first.class.name.constantize.find(:all) # TODO bring order
|
164
162
|
out = '<div class="edit_form_checklist">'
|
165
163
|
out << '<ul>'
|
166
164
|
values.each do | item |
|
@@ -188,14 +186,13 @@ module InlineFormsHelper
|
|
188
186
|
# if it's not a new record (sub_id > 0) then just update the list-element
|
189
187
|
out << '<li>'
|
190
188
|
out << link_to( @associated_record.title,
|
191
|
-
|
192
|
-
:id => object.id,
|
189
|
+
send('edit_' + @Klass.to_s.underscore + '_path', object,
|
193
190
|
:field => attribute,
|
194
191
|
:sub_id => @sub_id,
|
195
192
|
:form_element => this_method.reverse.sub(/.*_/,'').reverse,
|
196
|
-
:values => values
|
193
|
+
:values => values,
|
194
|
+
:update => "field_#{attribute.singularize}_#{@sub_id.to_s}" ),
|
197
195
|
:method => :get,
|
198
|
-
:update => "field_#{attribute.singularize}_#{@sub_id.to_s}",
|
199
196
|
:remote => true )
|
200
197
|
out << '</li>'
|
201
198
|
else
|
@@ -206,15 +203,14 @@ module InlineFormsHelper
|
|
206
203
|
object.send(attribute.pluralize).each do |m|
|
207
204
|
out << "<span id='field_#{attribute.singularize}_#{m.id.to_s}'>"
|
208
205
|
out << '<li>'
|
209
|
-
out << link_to( m.title,
|
210
|
-
|
211
|
-
:id => object.id,
|
206
|
+
out << link_to( m.title, send('edit_' + @Klass.to_s.underscore + '_path',
|
207
|
+
object,
|
212
208
|
:field => attribute,
|
213
209
|
:sub_id => m.id,
|
214
210
|
:form_element => this_method.sub(/_[a-z]+$/,''),
|
215
|
-
:values => values
|
211
|
+
:values => values,
|
212
|
+
:update => "field_#{attribute.singularize}_#{m.id.to_s}" ),
|
216
213
|
:method => :get,
|
217
|
-
:update => "field_#{attribute.singularize}_#{m.id.to_s}",
|
218
214
|
:remote => true )
|
219
215
|
out << '</li>'
|
220
216
|
out << '</span>'
|
@@ -222,23 +218,22 @@ module InlineFormsHelper
|
|
222
218
|
end
|
223
219
|
# add a 'new' link for creating a new record
|
224
220
|
out << '<li>'
|
225
|
-
out << link_to( 'new',
|
226
|
-
|
227
|
-
:id => object.id,
|
221
|
+
out << link_to( 'new', send('edit_' + @Klass.to_s.underscore + '_path',
|
222
|
+
object,
|
228
223
|
:field => attribute,
|
229
224
|
:sub_id => 0,
|
230
225
|
:form_element => this_method.sub(/_[a-z]+$/,''),
|
231
|
-
:values => values
|
226
|
+
:values => values,
|
227
|
+
:update => "list_#{attribute}_#{object.id.to_s}" ),
|
232
228
|
:method => :get,
|
233
|
-
:update => "list_#{attribute}_#{object.id.to_s}",
|
234
229
|
:remote => true )
|
235
230
|
out << '</li>'
|
236
231
|
out << '</ul>' if @sub_id.nil?
|
237
232
|
end
|
238
|
-
out
|
233
|
+
raw(out)
|
239
234
|
end
|
240
235
|
def associated_edit(object, attribute, values)
|
241
|
-
# @sub_id is the id of the
|
236
|
+
# @sub_id is the id of the associated record
|
242
237
|
if @sub_id.to_i > 0
|
243
238
|
# only if @sub_id > 0, means we have a associated record
|
244
239
|
@associated_record_id = object.send(attribute.singularize + "_ids").index(@sub_id.to_i)
|
@@ -248,9 +243,9 @@ module InlineFormsHelper
|
|
248
243
|
# but if @sub_id = 0, then we are dealing with a new associated record
|
249
244
|
# in that case, we .new a record, and the update_span is the whole <ul>
|
250
245
|
@associated_record = attribute.singularize.capitalize.constantize.new
|
251
|
-
@update_span =
|
246
|
+
@update_span = 'list_' + attribute.to_s + '_' + object.id.to_s
|
252
247
|
end
|
253
|
-
render :partial => "subform"
|
248
|
+
render :partial => "inline_forms/subform"
|
254
249
|
end
|
255
250
|
def associated_update(object, attribute, values)
|
256
251
|
return if object.id.nil?
|
@@ -262,10 +257,10 @@ module InlineFormsHelper
|
|
262
257
|
else
|
263
258
|
# create a new associated record
|
264
259
|
@associated_record = object.send(attribute.to_sym).new
|
265
|
-
@update_span = 'list_
|
260
|
+
@update_span = 'list_' + attribute.to_s + '_' + object.id.to_s
|
266
261
|
end
|
267
262
|
# process the sub_form fields (attributes). These are declared in the model!
|
268
|
-
@associated_record.
|
263
|
+
@associated_record.inline_forms_field_list.each do | @subform_description, @subform_field, @subform_element |
|
269
264
|
# have no fear
|
270
265
|
send("#{@subform_element}_update", @associated_record, @subform_field, nil)
|
271
266
|
end
|
@@ -4,20 +4,23 @@
|
|
4
4
|
:form_element => @form_element,
|
5
5
|
:values => @values,
|
6
6
|
:sub_id => @sub_id ),
|
7
|
-
:method => :put,
|
7
|
+
:method => :put, # this is going to the update method!
|
8
8
|
:multipart => true,
|
9
9
|
:class => "edit_form",
|
10
10
|
:remote => true do -%>
|
11
11
|
<div class="edit_form_field">
|
12
12
|
<%= send("#{@form_element.to_s}_edit", @object, @field, @values) %>
|
13
13
|
</div>
|
14
|
-
<%= link_to
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
:method => :get,
|
20
|
-
:class => "edit_form_cancel"
|
14
|
+
<%= link_to( send( @Klass.to_s.underscore + '_path', :update => @update_span || "field_#{@field}_#{@object.id.to_s}",
|
15
|
+
:field => @field,
|
16
|
+
:form_element => @form_element,
|
17
|
+
:values => @values,
|
18
|
+
:sub_id => @sub_id ),
|
19
|
+
:method => :get, # this is going to the show method!
|
20
|
+
:class => "edit_form_cancel",
|
21
|
+
:remote => true ) do %>
|
22
|
+
<input type="button" name="cancel" value="cancel" />
|
23
|
+
<% end %>
|
21
24
|
<%= submit_tag "ok", :class => "edit_form_submit"-%>
|
22
25
|
<div style="clear: both;"></div>
|
23
26
|
<% end -%>
|
@@ -3,8 +3,10 @@
|
|
3
3
|
<div class="edit_form_field">
|
4
4
|
<%= inline_form_display(@object, @object.respond_to?(:inline_forms_field_list) ? @object.inline_forms_field_list : [ '', :name, :text ], :new) %>
|
5
5
|
</div>
|
6
|
-
<%= link_to
|
7
|
-
:class => "edit_form_cancel" %>
|
6
|
+
<%= link_to( send(@Klass.to_s.underscore.pluralize + '_path',:update => @update_span || 'inline_form_list'), :remote => true,
|
7
|
+
:class => "edit_form_cancel" ) do %>
|
8
|
+
<input type="button" name="cancel" value="cancel" />
|
9
|
+
<% end %>
|
8
10
|
<%= submit_tag "ok", :class => "edit_form_submit"-%>
|
9
11
|
<div style="clear: both;"></div>
|
10
12
|
<% end -%>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<table cellpadding="0" cellspacing="0" class="subform">
|
2
|
-
<% @associated_record.
|
2
|
+
<% @associated_record.inline_forms_field_list.each do | @subform_description, @subform_field, @subform_element, @values | %>
|
3
3
|
<tr>
|
4
4
|
<td valign="top">
|
5
5
|
<div class="subform_field-name">
|
data/inline_forms.gemspec
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: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ace Suares
|