inline_forms 0.9.1 → 0.9.2
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 +2 -2
- data/app/helpers/inline_forms_helper.rb +25 -12
- data/app/views/inline_forms/_header.html.erb +1 -1
- data/app/views/inline_forms/_index.html.erb +2 -6
- data/app/views/inline_forms/index.html.erb +2 -5
- data/inline_forms.gemspec +1 -3
- data/lib/inline_forms.rb +3 -2
- metadata +3 -5
- data/app/helpers/form_elements/associated.rb +0 -94
- data/app/views/inline_forms/_subform.html.erb +0 -20
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.2
|
@@ -83,9 +83,9 @@ class InlineFormsController < ApplicationController
|
|
83
83
|
send("#{form_element.to_s}_update", object, attribute) unless form_element == :associated
|
84
84
|
end
|
85
85
|
if object.save
|
86
|
-
flash[:success] = "Successfully created
|
86
|
+
flash[:success] = "Successfully created #{object.class.to_s.downcase}."
|
87
87
|
else
|
88
|
-
flash[:error] = "
|
88
|
+
flash[:error] = "Failed to create #{object.class.to_s.downcase}."
|
89
89
|
end
|
90
90
|
@objects = @Klass.paginate :page => params[:page], :order => 'created_at DESC'
|
91
91
|
respond_to do |format|
|
@@ -37,7 +37,11 @@ module InlineFormsHelper
|
|
37
37
|
value_cell = content_tag :td, :valign=>'top' do
|
38
38
|
content_tag :div, :class=> "attribute_value attribute_#{attribute} form_element_#{form_element}" do
|
39
39
|
content_tag :span, :id => css_class_id do
|
40
|
-
|
40
|
+
if form_element == :associated
|
41
|
+
inline_forms_list(object.send(attribute.to_s.pluralize), attribute )
|
42
|
+
else
|
43
|
+
send("#{form_element}_show", object, attribute)
|
44
|
+
end
|
41
45
|
end
|
42
46
|
end
|
43
47
|
end
|
@@ -53,8 +57,16 @@ module InlineFormsHelper
|
|
53
57
|
# associated records are NOT shown!
|
54
58
|
#
|
55
59
|
def inline_forms_new_record(object, attributes=nil)
|
56
|
-
attributes ||= object.inline_forms_attribute_list
|
57
60
|
out = String.new
|
61
|
+
out += content_tag :tr do
|
62
|
+
content_tag :th, :colspan => 2, :valign=>'top' do
|
63
|
+
content_tag :div, :class=> "object_presentation" do
|
64
|
+
"New #{object.class.to_s}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
out << "\n"
|
69
|
+
attributes ||= object.inline_forms_attribute_list
|
58
70
|
attributes.each do | attribute, name, form_element |
|
59
71
|
unless form_element.to_sym == :associated
|
60
72
|
css_class_id = "attribute_#{attribute}_#{object.id}"
|
@@ -77,29 +89,30 @@ module InlineFormsHelper
|
|
77
89
|
end
|
78
90
|
|
79
91
|
# display a list of objects
|
80
|
-
def inline_forms_list(objects,
|
92
|
+
def inline_forms_list(objects, attribute )
|
81
93
|
t = String.new
|
94
|
+
# link to new
|
95
|
+
update_span = attribute.to_s.underscore + '_list'
|
96
|
+
t += content_tag :li, :class => "new_record_link_li" do
|
97
|
+
link_to "New",
|
98
|
+
send('new_' + attribute.to_s.singularize.underscore + '_path', :update => update_span),
|
99
|
+
:remote => true
|
100
|
+
end
|
101
|
+
# list of objects
|
82
102
|
objects.each do |object|
|
83
103
|
css_class_id = object.class.to_s.underscore + '_' + object.id.to_s
|
84
|
-
t += content_tag
|
104
|
+
t += content_tag :li, :id => css_class_id, :class => cycle("odd", "even") do
|
85
105
|
link_to h(object._presentation),
|
86
106
|
send( object.class.to_s.underscore + '_path', object, :update => css_class_id),
|
87
107
|
:remote => true
|
88
108
|
end
|
89
109
|
end
|
90
|
-
t = content_tag :ul, :class => "inline_forms_list" do
|
110
|
+
t = content_tag :ul, :id => update_span, :class => "inline_forms_list" do
|
91
111
|
t.html_safe
|
92
112
|
end
|
93
113
|
return t
|
94
114
|
end
|
95
115
|
|
96
|
-
# link for new item
|
97
|
-
def inline_forms_new_record_link(text='new', update_span='inline_forms_list')
|
98
|
-
link_to text,
|
99
|
-
send('new_' + @Klass.to_s.underscore + '_path', :update => update_span),
|
100
|
-
:remote => true
|
101
|
-
end
|
102
|
-
|
103
116
|
private
|
104
117
|
|
105
118
|
# close icon
|
@@ -1 +1 @@
|
|
1
|
-
<div id="Header">
|
1
|
+
<div id="Header">Inline Forms</div>
|
@@ -1,10 +1,6 @@
|
|
1
1
|
<% flash.each do |key, value| %>
|
2
|
-
<div class="flash <%= key %>"><%= value %></div>
|
2
|
+
<div id="flash" class="flash <%= key %>"><%= value %></div>
|
3
3
|
<% end %>
|
4
|
-
|
5
|
-
<li class="inline_forms_new_record">
|
6
|
-
<%= inline_forms_new_record_link %>
|
7
|
-
</li>
|
8
|
-
<%= inline_forms_list(@objects) %>
|
4
|
+
<%= inline_forms_list(@objects, @Klass.to_s.pluralize) %>
|
9
5
|
<%= will_paginate @objects %>
|
10
6
|
<div id="paginate_info"><%= page_entries_info @objects %></div>
|
@@ -1,10 +1,7 @@
|
|
1
1
|
<% flash.each do |key, value| %>
|
2
|
-
<div class="flash <%= key %>"><%= value %></div>
|
2
|
+
<div id="flash" class="flash <%= key %>"><%= value %></div>
|
3
3
|
<% end %>
|
4
4
|
|
5
|
-
|
6
|
-
<%= inline_forms_new_record_link %>
|
7
|
-
</li>
|
8
|
-
<%= inline_forms_list(@objects) %>
|
5
|
+
<%= inline_forms_list(@objects, @Klass.to_s.pluralize) %>
|
9
6
|
<%= will_paginate @objects %>
|
10
7
|
<div id="paginate_info"><%= page_entries_info @objects %></div>
|
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.9.
|
8
|
+
s.version = "0.9.2"
|
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"]
|
@@ -25,7 +25,6 @@ Gem::Specification.new do |s|
|
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
27
|
"app/controllers/inline_forms_controller.rb",
|
28
|
-
"app/helpers/form_elements/associated.rb",
|
29
28
|
"app/helpers/form_elements/check_box.rb",
|
30
29
|
"app/helpers/form_elements/check_list.rb",
|
31
30
|
"app/helpers/form_elements/date.rb",
|
@@ -45,7 +44,6 @@ Gem::Specification.new do |s|
|
|
45
44
|
"app/views/inline_forms/_header.html.erb",
|
46
45
|
"app/views/inline_forms/_index.html.erb",
|
47
46
|
"app/views/inline_forms/_new.html.erb",
|
48
|
-
"app/views/inline_forms/_subform.html.erb",
|
49
47
|
"app/views/inline_forms/index.html.erb",
|
50
48
|
"app/views/layouts/inline_forms.rhtml",
|
51
49
|
"inline_forms.gemspec",
|
data/lib/inline_forms.rb
CHANGED
@@ -86,8 +86,9 @@ module InlineForms
|
|
86
86
|
# :country => [ "country", :dropdown ],
|
87
87
|
# to the inline_forms_attribute_list in the model.
|
88
88
|
#
|
89
|
-
SPECIAL_COLUMN_TYPES = {
|
90
|
-
|
89
|
+
SPECIAL_COLUMN_TYPES = {
|
90
|
+
:associated => :no_migration
|
91
|
+
}
|
91
92
|
# When a column has the type of :references or :belongs_to, then
|
92
93
|
# there will be a line in the migration reflecting that, but not in the model.
|
93
94
|
# == Why?
|
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: 63
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 2
|
10
|
+
version: 0.9.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ace Suares
|
@@ -96,7 +96,6 @@ files:
|
|
96
96
|
- Rakefile
|
97
97
|
- VERSION
|
98
98
|
- app/controllers/inline_forms_controller.rb
|
99
|
-
- app/helpers/form_elements/associated.rb
|
100
99
|
- app/helpers/form_elements/check_box.rb
|
101
100
|
- app/helpers/form_elements/check_list.rb
|
102
101
|
- app/helpers/form_elements/date.rb
|
@@ -116,7 +115,6 @@ files:
|
|
116
115
|
- app/views/inline_forms/_header.html.erb
|
117
116
|
- app/views/inline_forms/_index.html.erb
|
118
117
|
- app/views/inline_forms/_new.html.erb
|
119
|
-
- app/views/inline_forms/_subform.html.erb
|
120
118
|
- app/views/inline_forms/index.html.erb
|
121
119
|
- app/views/layouts/inline_forms.rhtml
|
122
120
|
- inline_forms.gemspec
|
@@ -1,94 +0,0 @@
|
|
1
|
-
InlineForms::SPECIAL_COLUMN_TYPES[:associated]=:no_migration
|
2
|
-
|
3
|
-
# associated
|
4
|
-
def associated_show(object, attribute)
|
5
|
-
#show a list of records
|
6
|
-
inline_forms_list(object.send(attribute.to_s.pluralize))
|
7
|
-
end
|
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
|
-
#
|
@@ -1,20 +0,0 @@
|
|
1
|
-
<table cellpadding="0" cellspacing="0" class="subform">
|
2
|
-
<% @associated_record.inline_forms_attribute_list.each do | @subform_field, @subform_description, @subform_element | %>
|
3
|
-
<tr>
|
4
|
-
<td valign="top">
|
5
|
-
<div class="subform_field-name">
|
6
|
-
<%= h(@subform_description) %>
|
7
|
-
</div>
|
8
|
-
</td>
|
9
|
-
<td valign="top">
|
10
|
-
<div class="subform_field-value">
|
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 %>
|
16
|
-
</div>
|
17
|
-
</td>
|
18
|
-
</tr>
|
19
|
-
<% end %>
|
20
|
-
</table>
|