inline_forms 0.8.5 → 0.8.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/controllers/inline_forms_controller.rb +8 -2
- data/app/helpers/form_elements/associated.rb +88 -85
- data/app/helpers/form_elements/question_list.rb +43 -0
- data/app/helpers/inline_forms_helper.rb +28 -8
- data/app/views/inline_forms/_edit.html.erb +3 -3
- data/app/views/inline_forms/_subform.html.erb +5 -1
- data/inline_forms.gemspec +2 -1
- data/lib/generators/inline_forms/inline_forms_generator.rb +1 -2
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.6
|
@@ -100,8 +100,10 @@ class InlineFormsController < ApplicationController
|
|
100
100
|
@form_element = params[:form_element]
|
101
101
|
@sub_id = params[:sub_id]
|
102
102
|
@update_span = params[:update]
|
103
|
+
logger.info @form_element.to_s
|
103
104
|
send("#{@form_element.to_s}_update", @object, @attribute)
|
104
105
|
@object.save
|
106
|
+
logger.info "after"
|
105
107
|
respond_to do |format|
|
106
108
|
# found this here: http://www.ruby-forum.com/topic/211467
|
107
109
|
format.js { render(:update) {|page| page.replace_html @update_span, :inline => '<%= send("#{@form_element.to_s}_show", @object, @attribute) %>' }
|
@@ -118,6 +120,7 @@ class InlineFormsController < ApplicationController
|
|
118
120
|
@object = @Klass.find(params[:id])
|
119
121
|
@attribute = params[:attribute]
|
120
122
|
@form_element = params[:form_element]
|
123
|
+
close = params[:close] || false
|
121
124
|
if @form_element == "associated"
|
122
125
|
@sub_id = params[:sub_id]
|
123
126
|
if @sub_id.to_i > 0
|
@@ -130,8 +133,11 @@ class InlineFormsController < ApplicationController
|
|
130
133
|
respond_to do |format|
|
131
134
|
@attributes = @object.inline_forms_attribute_list
|
132
135
|
# found this here: http://www.ruby-forum.com/topic/211467
|
133
|
-
|
134
|
-
|
136
|
+
if close
|
137
|
+
format.js { render(:update) {|page| page.replace_html @update_span, :inline => '<%= link_to h(@object._presentation), send(@object.class.to_s.underscore + "_path", @object, :update => @update_span), :remote => true %>' } }
|
138
|
+
else
|
139
|
+
format.js { render(:update) {|page| page.replace_html @update_span, :inline => '<%= send( "inline_forms_show_record", @object) %>' } }
|
140
|
+
end
|
135
141
|
end
|
136
142
|
else
|
137
143
|
respond_to do |format|
|
@@ -3,89 +3,92 @@ InlineForms::SPECIAL_COLUMN_TYPES[:associated]=:no_migration
|
|
3
3
|
# associated
|
4
4
|
def associated_show(object, attribute)
|
5
5
|
#show a list of records
|
6
|
-
|
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
|
-
:update => "attribute_#{attribute.to_s.singularize}_#{@sub_id.to_s}" ),
|
16
|
-
:method => :get,
|
17
|
-
:remote => true )
|
18
|
-
out << '</li>'
|
19
|
-
else
|
20
|
-
# if it's a new record (sub_id == 0) then update the whole <ul> and redraw all list-elements
|
21
|
-
out << "<ul class='associated #{attribute}' id='list_#{attribute}_#{object.id.to_s}'>" if @sub_id.nil?
|
22
|
-
out << '<li class="associated_new">'
|
23
|
-
out << link_to( 'new', send('edit_' + @Klass.to_s.underscore + '_path',
|
24
|
-
object,
|
25
|
-
:attribute => attribute,
|
26
|
-
:sub_id => 0,
|
27
|
-
:form_element => this_method.sub(/_[a-z]+$/,''),
|
28
|
-
:update => "list_#{attribute}_#{object.id.to_s}" ),
|
29
|
-
:method => :get,
|
30
|
-
:remote => true )
|
31
|
-
out << '</li>'
|
32
|
-
if not object.send(attribute.to_s.pluralize).empty?
|
33
|
-
# if there are things to show, show them
|
34
|
-
object.send(attribute.to_s.pluralize).each do |m|
|
35
|
-
out << "<span id='attribute_#{attribute.to_s.singularize}_#{m.id.to_s}'>"
|
36
|
-
out << '<li>'
|
37
|
-
out << link_to( m._presentation, send('edit_' + @Klass.to_s.underscore + '_path',
|
38
|
-
object,
|
39
|
-
:attribute => attribute,
|
40
|
-
:sub_id => m.id,
|
41
|
-
:form_element => this_method.sub(/_[a-z]+$/,''),
|
42
|
-
:update => "attribute_#{attribute.to_s.singularize}_#{m.id.to_s}" ),
|
43
|
-
:method => :get,
|
44
|
-
:remote => true )
|
45
|
-
out << '</li>'
|
46
|
-
out << '</span>'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
# add a 'new' link for creating a new record
|
50
|
-
out << '</ul>' if @sub_id.nil?
|
51
|
-
end
|
52
|
-
raw(out)
|
6
|
+
inline_forms_list(object.send(attribute.to_s.pluralize))
|
53
7
|
end
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
8
|
+
#
|
9
|
+
# out = String.new
|
10
|
+
# if @sub_id && @sub_id.to_i > 0
|
11
|
+
# # if it's not a new record (sub_id > 0) then just update the list-element
|
12
|
+
# out << '<li>'
|
13
|
+
# out << link_to( @associated_record._presentation,
|
14
|
+
# send('edit_' + @Klass.to_s.underscore + '_path', object,
|
15
|
+
# :attribute => attribute,
|
16
|
+
# :sub_id => @sub_id,
|
17
|
+
# :form_element => this_method.reverse.sub(/.*_/,'').reverse,
|
18
|
+
# :update => "attribute_#{attribute.to_s.singularize}_#{@sub_id.to_s}" ),
|
19
|
+
# :method => :get,
|
20
|
+
# :remote => true )
|
21
|
+
# out << '</li>'
|
22
|
+
# else
|
23
|
+
# # if it's a new record (sub_id == 0) then update the whole <ul> and redraw all list-elements
|
24
|
+
# out << "<ul class='associated #{attribute}' id='list_#{attribute}_#{object.id.to_s}'>" if @sub_id.nil?
|
25
|
+
# out << '<li class="associated_new">'
|
26
|
+
# out << link_to( 'new', send('edit_' + @Klass.to_s.underscore + '_path',
|
27
|
+
# object,
|
28
|
+
# :attribute => attribute,
|
29
|
+
# :sub_id => 0,
|
30
|
+
# :form_element => this_method.sub(/_[a-z]+$/,''),
|
31
|
+
# :update => "list_#{attribute}_#{object.id.to_s}" ),
|
32
|
+
# :method => :get,
|
33
|
+
# :remote => true )
|
34
|
+
# out << '</li>'
|
35
|
+
# if not object.send(attribute.to_s.pluralize).empty?
|
36
|
+
# # if there are things to show, show them
|
37
|
+
# object.send(attribute.to_s.pluralize).each do |m|
|
38
|
+
# out << "<span id='attribute_#{attribute.to_s.singularize}_#{m.id.to_s}'>"
|
39
|
+
# out << '<li>'
|
40
|
+
# out << link_to( m._presentation, send('edit_' + @Klass.to_s.underscore + '_path',
|
41
|
+
# object,
|
42
|
+
# :attribute => attribute,
|
43
|
+
# :sub_id => m.id,
|
44
|
+
# :form_element => this_method.sub(/_[a-z]+$/,''),
|
45
|
+
# :update => "attribute_#{attribute.to_s.singularize}_#{m.id.to_s}" ),
|
46
|
+
# :method => :get,
|
47
|
+
# :remote => true )
|
48
|
+
# out << '</li>'
|
49
|
+
# out << '</span>'
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
# # add a 'new' link for creating a new record
|
53
|
+
# out << '</ul>' if @sub_id.nil?
|
54
|
+
# end
|
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
|
70
|
+
# end
|
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
|
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) unless @subform_element == :associated
|
90
|
+
# end
|
91
|
+
# @associated_record.save
|
92
|
+
#end
|
93
|
+
#
|
94
|
+
#
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#InlineForms::SPECIAL_COLUMN_TYPES[:question_list]=:no_migration
|
2
|
+
|
3
|
+
# checklist
|
4
|
+
def question_list_show(object, attribute)
|
5
|
+
out = '<ul class="question_list">'
|
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._presentation )
|
10
|
+
out << '</li>'
|
11
|
+
end
|
12
|
+
out << '</ul>'
|
13
|
+
out.html_safe
|
14
|
+
end
|
15
|
+
|
16
|
+
def question_list_edit(object, attribute)
|
17
|
+
object.send(attribute).build if object.send(attribute).empty?
|
18
|
+
values = object.send(attribute).first.class.name.constantize.find(:all) # TODO bring order
|
19
|
+
out = '<div class="edit_form_checklist">'
|
20
|
+
out << '<ul>'
|
21
|
+
Question.all.each do | question |
|
22
|
+
out << '<li>'
|
23
|
+
out << h(question._presentation)
|
24
|
+
unless question.subquestions.empty?
|
25
|
+
out << '<ul>'
|
26
|
+
question.subquestions.each do | subquestion |
|
27
|
+
out << '<li>'
|
28
|
+
out << h(subquestion._presentation)
|
29
|
+
out << '</li>'
|
30
|
+
end
|
31
|
+
out << '</ul>'
|
32
|
+
end
|
33
|
+
out << '</li>'
|
34
|
+
end
|
35
|
+
out << '</ul>'
|
36
|
+
out << '</div>'
|
37
|
+
out.html_safe
|
38
|
+
end
|
39
|
+
|
40
|
+
def question_list_update(object, attribute)
|
41
|
+
params[attribute] ||= {}
|
42
|
+
object.send(attribute.singularize + '_ids=', params[attribute].keys)
|
43
|
+
end
|
@@ -15,8 +15,13 @@ module InlineFormsHelper
|
|
15
15
|
def inline_forms_show_record(object, attributes=nil)
|
16
16
|
attributes ||= object.inline_forms_attribute_list
|
17
17
|
out = String.new
|
18
|
+
css_class_id = object.class.to_s.underscore + '_' + object.id.to_s
|
19
|
+
close_link = link_to h(object._presentation + " - CLOSE "),
|
20
|
+
send( object.class.to_s.underscore + '_path', object, :update => css_class_id, :close => true ),
|
21
|
+
:remote => true
|
22
|
+
out << close_link
|
18
23
|
attributes.each do | attribute, name, form_element |
|
19
|
-
css_class_id = "
|
24
|
+
css_class_id = "#{object.class.to_s.underscore}_#{object.id}_#{attribute}"
|
20
25
|
name_cell = content_tag :td, :valign=>'top' do
|
21
26
|
content_tag :div, :class=> "attribute_name attribute_#{attribute} form_element_#{form_element}" do
|
22
27
|
h(name)
|
@@ -44,7 +49,7 @@ module InlineFormsHelper
|
|
44
49
|
attributes ||= object.inline_forms_attribute_list
|
45
50
|
out = String.new
|
46
51
|
attributes.each do | attribute, name, form_element |
|
47
|
-
unless form_element.to_sym == :associated
|
52
|
+
unless form_element.to_sym == :associated
|
48
53
|
css_class_id = "attribute_#{attribute}_#{object.id}"
|
49
54
|
name_cell = content_tag :td, :valign=>'top' do
|
50
55
|
content_tag :div, :class=> "attribute_name attribute_#{attribute} form_element_#{form_element}" do
|
@@ -64,14 +69,28 @@ module InlineFormsHelper
|
|
64
69
|
return content_tag :table, raw(out), :cellspacing => 0, :cellpadding => 0
|
65
70
|
end
|
66
71
|
|
67
|
-
# display a list of objects
|
72
|
+
# # display a list of objects
|
73
|
+
# def inline_forms_list(objects, tag=:li)
|
74
|
+
# t = String.new
|
75
|
+
# objects.each do |object|
|
76
|
+
# css_class_id = @Klass.to_s.underscore + '_' + object.id.to_s
|
77
|
+
# t += content_tag tag, :id => css_class_id do
|
78
|
+
# link_to h(object._presentation),
|
79
|
+
# send( @Klass.to_s.underscore + '_path', object, :update => css_class_id),
|
80
|
+
# :remote => true
|
81
|
+
# end
|
82
|
+
# end
|
83
|
+
# return raw(t)
|
84
|
+
# end
|
85
|
+
|
86
|
+
# display a list of objects without links
|
68
87
|
def inline_forms_list(objects, tag=:li)
|
69
88
|
t = String.new
|
70
89
|
objects.each do |object|
|
71
|
-
css_class_id =
|
90
|
+
css_class_id = object.class.to_s.underscore + '_' + object.id.to_s
|
72
91
|
t += content_tag tag, :id => css_class_id do
|
73
|
-
link_to h(object._presentation),
|
74
|
-
send(
|
92
|
+
link_to h(object._presentation),
|
93
|
+
send( object.class.to_s.underscore + '_path', object, :update => css_class_id),
|
75
94
|
:remote => true
|
76
95
|
end
|
77
96
|
end
|
@@ -92,12 +111,13 @@ module InlineFormsHelper
|
|
92
111
|
attribute_value = h(attribute_value)
|
93
112
|
spaces = attribute_value.length > 40 ? 0 : 40 - attribute_value.length
|
94
113
|
attribute_value << " ".html_safe * spaces
|
114
|
+
css_class_id = "#{object.class.to_s.underscore}_#{object.id}_#{attribute}"
|
95
115
|
link_to attribute_value,
|
96
|
-
send( 'edit_' +
|
116
|
+
send( 'edit_' + object.class.to_s.underscore + '_path',
|
97
117
|
object,
|
98
118
|
:attribute => attribute.to_s,
|
99
119
|
:form_element => calling_method.sub(/_[a-z]+$/,''),
|
100
|
-
:update =>
|
120
|
+
:update => css_class_id ),
|
101
121
|
:remote => true
|
102
122
|
end
|
103
123
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<% form_tag send(@
|
1
|
+
<% form_tag send(@object.class.to_s.underscore + '_path', :update => @update_span ,
|
2
2
|
:attribute => @attribute,
|
3
3
|
:form_element => @form_element,
|
4
4
|
:sub_id => @sub_id ),
|
@@ -7,9 +7,9 @@
|
|
7
7
|
:class => "edit_form",
|
8
8
|
:remote => true do -%>
|
9
9
|
<div class="edit_form_field">
|
10
|
-
<%= send("#{@form_element
|
10
|
+
<%= send("#{@form_element}_edit", @object, @attribute) %>
|
11
11
|
</div>
|
12
|
-
<%= link_to( send( @
|
12
|
+
<%= link_to( send( @object.class.to_s.underscore + '_path', :update => @update_span || "field_#{@attribute}_#{@object.id.to_s}",
|
13
13
|
:attribute => @attribute,
|
14
14
|
:form_element => @form_element,
|
15
15
|
:sub_id => @sub_id ),
|
@@ -8,7 +8,11 @@
|
|
8
8
|
</td>
|
9
9
|
<td valign="top">
|
10
10
|
<div class="subform_field-value">
|
11
|
-
|
11
|
+
<% if @subform_element == :associated -%>
|
12
|
+
<%= inline_forms_list @associated_record.send(@subform_field) %>
|
13
|
+
<% else %>
|
14
|
+
<%= send("#{@subform_element}_edit", @associated_record, @subform_field.to_s) %>
|
15
|
+
<% end %>
|
12
16
|
</div>
|
13
17
|
</td>
|
14
18
|
</tr>
|
data/inline_forms.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{inline_forms}
|
8
|
-
s.version = "0.8.
|
8
|
+
s.version = "0.8.6"
|
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"]
|
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
|
|
34
34
|
"app/helpers/form_elements/dropdown_with_values.rb",
|
35
35
|
"app/helpers/form_elements/geo_code_curacao.rb",
|
36
36
|
"app/helpers/form_elements/image.rb",
|
37
|
+
"app/helpers/form_elements/question_list.rb",
|
37
38
|
"app/helpers/form_elements/scale_with_integers.rb",
|
38
39
|
"app/helpers/form_elements/scale_with_values.rb",
|
39
40
|
"app/helpers/form_elements/text_area.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: 51
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
9
|
+
- 6
|
10
|
+
version: 0.8.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ace Suares
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- app/helpers/form_elements/dropdown_with_values.rb
|
106
106
|
- app/helpers/form_elements/geo_code_curacao.rb
|
107
107
|
- app/helpers/form_elements/image.rb
|
108
|
+
- app/helpers/form_elements/question_list.rb
|
108
109
|
- app/helpers/form_elements/scale_with_integers.rb
|
109
110
|
- app/helpers/form_elements/scale_with_values.rb
|
110
111
|
- app/helpers/form_elements/text_area.rb
|