inline_forms 0.7.4 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,20 +1,17 @@
|
|
1
1
|
<% form_tag send(@Klass.to_s.underscore + '_path', :update => @update_span ,
|
2
|
-
|
3
|
-
:field => @field,
|
2
|
+
:attribute => @attribute,
|
4
3
|
:form_element => @form_element,
|
5
|
-
:values => @values,
|
6
4
|
:sub_id => @sub_id ),
|
7
5
|
:method => :put, # this is going to the update method!
|
8
|
-
:multipart => true,
|
6
|
+
:multipart => true,
|
9
7
|
:class => "edit_form",
|
10
8
|
:remote => true do -%>
|
11
9
|
<div class="edit_form_field">
|
12
|
-
<%= send("#{@form_element.to_s}_edit", @object, @
|
10
|
+
<%= send("#{@form_element.to_s}_edit", @object, @attribute) %>
|
13
11
|
</div>
|
14
|
-
<%= link_to( send( @Klass.to_s.underscore + '_path', :update => @update_span || "field_#{@
|
15
|
-
:
|
12
|
+
<%= link_to( send( @Klass.to_s.underscore + '_path', :update => @update_span || "field_#{@attribute}_#{@object.id.to_s}",
|
13
|
+
:attribute => @attribute,
|
16
14
|
:form_element => @form_element,
|
17
|
-
:values => @values,
|
18
15
|
:sub_id => @sub_id ),
|
19
16
|
:method => :get, # this is going to the show method!
|
20
17
|
:class => "edit_form_cancel",
|
@@ -1,5 +1,6 @@
|
|
1
|
-
<li class="
|
2
|
-
<%=
|
1
|
+
<li class="inline_forms_new_record">
|
2
|
+
<%= inline_forms_new_record_link %>
|
3
3
|
</li>
|
4
|
-
<%=
|
5
|
-
|
4
|
+
<%= inline_forms_list(@objects) %>
|
5
|
+
<%= will_paginate @objects %>
|
6
|
+
<%= page_entries_info @objects %>
|
@@ -1,9 +1,9 @@
|
|
1
|
-
<% form_tag send(@Klass.to_s.underscore.pluralize + '_path', :update => @update_span || '
|
1
|
+
<% form_tag send(@Klass.to_s.underscore.pluralize + '_path', :update => @update_span || 'inline_forms_list' ),
|
2
2
|
:multipart => true, :remote => true, :class => "edit_form" do -%>
|
3
3
|
<div class="edit_form_field">
|
4
|
-
<%=
|
4
|
+
<%= inline_forms_new_record @object %>
|
5
5
|
</div>
|
6
|
-
<%= link_to( send(@Klass.to_s.underscore.pluralize + '_path',:update => @update_span || '
|
6
|
+
<%= link_to( send(@Klass.to_s.underscore.pluralize + '_path',:update => @update_span || 'inline_forms_list'), :remote => true,
|
7
7
|
:class => "edit_form_cancel" ) do %>
|
8
8
|
<input type="button" name="cancel" value="cancel" />
|
9
9
|
<% end %>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<table cellpadding="0" cellspacing="0" class="subform">
|
2
|
-
<% @associated_record.inline_forms_field_list.each do | @subform_field, @subform_description, @subform_element, @values
|
2
|
+
<% @associated_record.inline_forms_field_list.each do | @subform_field, (@subform_description, @subform_element, @values) | %>
|
3
3
|
<tr>
|
4
4
|
<td valign="top">
|
5
5
|
<div class="subform_field-name">
|
@@ -1,5 +1,6 @@
|
|
1
|
-
<li class="
|
2
|
-
<%=
|
1
|
+
<li class="inline_forms_new_record_link">
|
2
|
+
<%= inline_forms_new_record_link %>
|
3
3
|
</li>
|
4
|
-
<%=
|
4
|
+
<%= inline_forms_list(@objects) %>
|
5
5
|
<%= will_paginate @objects %>
|
6
|
+
<%= page_entries_info @objects %>
|
data/inline_forms.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{inline_forms}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.8.0"
|
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"]
|
12
|
-
s.date = %q{2011-03-
|
12
|
+
s.date = %q{2011-03-13}
|
13
13
|
s.description = %q{Inline Forms aims to ease the setup of forms that provide inline editing. The field list can be specified in the model.}
|
14
14
|
s.email = %q{ace@suares.an}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -34,8 +34,8 @@ 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/range.rb",
|
38
37
|
"app/helpers/form_elements/scale_with_integers.rb",
|
38
|
+
"app/helpers/form_elements/scale_with_values.rb",
|
39
39
|
"app/helpers/form_elements/text_area.rb",
|
40
40
|
"app/helpers/form_elements/text_field.rb",
|
41
41
|
"app/helpers/inline_forms_helper.rb",
|
@@ -11,8 +11,8 @@ module InlineForms
|
|
11
11
|
# rails g example_generator Modelname attribute:type attribute:type ...
|
12
12
|
# an array with attributes and types is created for use in the generator.
|
13
13
|
#
|
14
|
-
# Rails::Generators::GeneratedAttribute creates, among others, a
|
15
|
-
# This
|
14
|
+
# Rails::Generators::GeneratedAttribute creates, among others, a attribute_type.
|
15
|
+
# This attribute_type maps column types to form attribute helpers like text_field.
|
16
16
|
# We override it here to make our own.
|
17
17
|
#
|
18
18
|
class InlineFormsGenerator < Rails::Generators::NamedBase
|
@@ -32,13 +32,13 @@ module InlineForms
|
|
32
32
|
SPECIAL_COLUMN_TYPES.merge(DEFAULT_COLUMN_TYPES).merge(RELATIONS).merge(SPECIAL_RELATIONS)[type] || :unknown
|
33
33
|
end
|
34
34
|
|
35
|
-
# Override the
|
35
|
+
# Override the attribute_type to include our special column types.
|
36
36
|
#
|
37
37
|
# If a type is not in the Special Column Type hash, then the default
|
38
|
-
# column type hash is used, and if that fails, the
|
38
|
+
# column type hash is used, and if that fails, the attribute_type
|
39
39
|
# will be :unknown. Make sure to check your models for the :unknown.
|
40
40
|
#
|
41
|
-
def
|
41
|
+
def attribute_type
|
42
42
|
SPECIAL_COLUMN_TYPES.merge(RELATIONS).has_key?(type) ? type : DEFAULT_FORM_ELEMENTS[type] || :unknown
|
43
43
|
end
|
44
44
|
|
@@ -51,7 +51,7 @@ module InlineForms
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def has_many?
|
54
|
-
|
54
|
+
attribute_type == :associated
|
55
55
|
end
|
56
56
|
|
57
57
|
|
@@ -71,7 +71,7 @@ module InlineForms
|
|
71
71
|
@habtm = "\n"
|
72
72
|
@has_attached_files = "\n"
|
73
73
|
@presentation = "\n"
|
74
|
-
@
|
74
|
+
@inline_forms_attribute_list = String.new
|
75
75
|
|
76
76
|
for attribute in attributes
|
77
77
|
if attribute.column_type == :belongs_to # :drop_down, :references and :belongs_to all end up with the column_type :belongs_to
|
@@ -98,20 +98,20 @@ module InlineForms
|
|
98
98
|
"\n"
|
99
99
|
end
|
100
100
|
unless attribute.name == '_presentation' || attribute.relation?
|
101
|
-
attribute.
|
102
|
-
@
|
101
|
+
attribute.attribute_type == :unknown ? commenter = '#' : commenter = ' '
|
102
|
+
@inline_forms_attribute_list << commenter +
|
103
103
|
' [ :' +
|
104
104
|
attribute.name +
|
105
|
-
', "' + attribute.name +
|
106
|
-
'", :' + attribute.
|
105
|
+
' , "' + attribute.name +
|
106
|
+
'", :' + attribute.attribute_type.to_s +
|
107
107
|
" ], \n"
|
108
108
|
end
|
109
109
|
end
|
110
|
-
unless @
|
111
|
-
@
|
112
|
-
" def
|
110
|
+
unless @inline_forms_attribute_list.empty?
|
111
|
+
@inline_forms_attribute_list = "\n" +
|
112
|
+
" def inline_forms_attribute_list\n" +
|
113
113
|
" [\n" +
|
114
|
-
@
|
114
|
+
@inline_forms_attribute_list +
|
115
115
|
" ]\n" +
|
116
116
|
" end\n" +
|
117
117
|
"\n"
|
@@ -138,7 +138,7 @@ module InlineForms
|
|
138
138
|
@columns << ' t.datetime :' + attribute.name + "_updated_at\n"
|
139
139
|
else
|
140
140
|
unless attribute.name == '_presentation' || attribute.special_relation?
|
141
|
-
attribute.
|
141
|
+
attribute.attribute_type == :unknown ? commenter = '#' : commenter = ' '
|
142
142
|
@columns << commenter +
|
143
143
|
' t.' +
|
144
144
|
attribute.column_type.to_s +
|
@@ -1,9 +1,13 @@
|
|
1
1
|
class <%= name %> < ActiveRecord::Base
|
2
|
+
cattr_reader :per_page
|
3
|
+
@@per_page = 10
|
4
|
+
|
2
5
|
<%= @belongs_to if @belongs_to.length > 1 -%>
|
3
6
|
<%= @has_many if @has_many.length > 1 -%>
|
4
7
|
<%= @has_one if @has_one.length > 1 -%>
|
5
8
|
<%= @habtm if @habtm.length > 1 -%>
|
6
9
|
<%= @has_attached_files if @has_attached_files.length > 1 -%>
|
7
10
|
<%= @presentation if @presentation.length > 1 -%>
|
8
|
-
<%= @
|
11
|
+
<%= @inline_forms_attribute_list -%>
|
12
|
+
|
9
13
|
end
|
data/lib/inline_forms.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
puts 'loading inline_forms...'
|
2
2
|
|
3
3
|
module InlineForms
|
4
|
+
|
4
5
|
# ActiveRecord::Migration comes with a set of column types.
|
5
|
-
# They are listed here so they can be
|
6
|
+
# They are listed here so they can be used alongside our Special Column Types.
|
6
7
|
#
|
7
8
|
# These types will override the Special Column Types, so don't declare
|
8
9
|
# types with these names as Special Column Types!
|
@@ -13,7 +14,7 @@ module InlineForms
|
|
13
14
|
# class InlineFormsCreateExamples < ActiveRecord::Migration
|
14
15
|
# def self.up
|
15
16
|
# create_table :examples do |t|
|
16
|
-
# t.string
|
17
|
+
# t.string :name
|
17
18
|
# t.integer :price
|
18
19
|
# t.timestamps
|
19
20
|
# end
|
@@ -24,20 +25,21 @@ module InlineForms
|
|
24
25
|
# end
|
25
26
|
#
|
26
27
|
DEFAULT_COLUMN_TYPES = {
|
27
|
-
:string
|
28
|
-
:text
|
29
|
-
:integer
|
30
|
-
:float
|
31
|
-
:decimal
|
32
|
-
:datetime
|
33
|
-
:timestamp
|
34
|
-
:time
|
35
|
-
:date
|
36
|
-
:binary
|
37
|
-
:boolean
|
38
|
-
#
|
39
|
-
#
|
28
|
+
:string => :string,
|
29
|
+
:text => :text,
|
30
|
+
:integer => :integer,
|
31
|
+
:float => :float,
|
32
|
+
:decimal => :decimal,
|
33
|
+
:datetime => :datetime,
|
34
|
+
:timestamp => :timestamp,
|
35
|
+
:time => :time,
|
36
|
+
:date => :date,
|
37
|
+
:binary => :binary,
|
38
|
+
:boolean => :boolean,
|
39
|
+
# :references => :belongs_to,
|
40
|
+
# :belongs_to => :belongs_to,
|
40
41
|
}
|
42
|
+
|
41
43
|
# For each Default Column Type, we need to specify a Form Element for use in form creation.
|
42
44
|
#
|
43
45
|
# Example:
|
@@ -45,28 +47,29 @@ module InlineForms
|
|
45
47
|
# will result in the following model:
|
46
48
|
#
|
47
49
|
# class Example < ActiveRecord::Base
|
48
|
-
# def
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
50
|
+
# def inline_forms_attribute_list
|
51
|
+
# {
|
52
|
+
# :name => [ "name", :text_field ],
|
53
|
+
# :price => [ "price", :text_field ],
|
54
|
+
# }
|
53
55
|
# end
|
54
56
|
# end
|
55
57
|
# as you see, both :string and :integer are mapped to a :text_field
|
56
58
|
#
|
57
59
|
DEFAULT_FORM_ELEMENTS = {
|
58
|
-
:string
|
59
|
-
:text
|
60
|
-
:integer
|
61
|
-
:float
|
62
|
-
:decimal
|
63
|
-
:datetime
|
64
|
-
:timestamp
|
65
|
-
:time
|
66
|
-
:date
|
67
|
-
:binary
|
68
|
-
:boolean
|
60
|
+
:string => :text_field,
|
61
|
+
:text => :text_area,
|
62
|
+
:integer => :text_field,
|
63
|
+
:float => :text_field,
|
64
|
+
:decimal => :text_field,
|
65
|
+
:datetime => :datetime_select,
|
66
|
+
:timestamp => :datetime_select,
|
67
|
+
:time => :time_select,
|
68
|
+
:date => :date_select,
|
69
|
+
:binary => :text_field,
|
70
|
+
:boolean => :check_box,
|
69
71
|
}
|
72
|
+
|
70
73
|
# This Hash will be used to map our Special Column Types to
|
71
74
|
# ActiveRecord::Migration Column Types.
|
72
75
|
#
|
@@ -80,35 +83,37 @@ module InlineForms
|
|
80
83
|
# t.belongs_to :country
|
81
84
|
# to the migration. (In fact AR will add t.integer :country_id). And
|
82
85
|
# it will add
|
83
|
-
#
|
84
|
-
# to the
|
86
|
+
# :country => [ "country", :dropdown ],
|
87
|
+
# to the inline_forms_attribute_list in the model.
|
85
88
|
#
|
86
89
|
SPECIAL_COLUMN_TYPES = {}
|
90
|
+
|
87
91
|
# When a column has the type of :references or :belongs_to, then
|
88
92
|
# there will be a line in the migration reflecting that, but not in the model.
|
89
93
|
# == Why?
|
90
|
-
# * Let's say we have a customer that has_many
|
91
|
-
# * Let's say that a
|
94
|
+
# * Let's say we have a customer that has_many phone_numbers.
|
95
|
+
# * Let's say that a phone_number belongs_to a customer.
|
92
96
|
# * Let's say that every number has_one type_of_number (like 'private','gsm' etc.)
|
93
97
|
# * Let's say a type_of_number belongs_to a number.
|
94
98
|
#
|
95
99
|
# Wait a minute... thats sounds right... but it ain't!
|
96
100
|
#
|
97
|
-
# In fact, a type_of_number has_many
|
101
|
+
# In fact, a type_of_number has_many phone_numbers and a phone_number belongs_to a type_of_number!
|
98
102
|
#
|
99
103
|
# In a form, it's quite logical to use a dropdown for type_of_number. So, in the generator, use
|
100
104
|
# type_of_number:dropdown
|
101
105
|
# This creates the correct migration (t.integer :type_of_number_id) and the correct model.
|
102
|
-
# (It adds 'belongs_to :type_of_number' and adds a dropdown in the
|
106
|
+
# (It adds 'belongs_to :type_of_number' and adds a dropdown in the inline_forms_attribute_list)
|
103
107
|
#
|
104
108
|
# But, you also want to have a client_id in the migration, and a 'belongs_to :client' in the model.
|
105
109
|
# In such cases, you need to use :belongs_to, like this:
|
106
|
-
# rails g inline_forms Example
|
110
|
+
# rails g inline_forms Example phone_number:string type_of_number:dropdown client:belongs_to
|
107
111
|
#
|
108
112
|
RELATIONS = {
|
109
113
|
:belongs_to => :belongs_to,
|
110
114
|
:references => :belongs_to,
|
111
115
|
}
|
116
|
+
|
112
117
|
# The stuff in this hash will add a line to the model, but little else.
|
113
118
|
SPECIAL_RELATIONS = {
|
114
119
|
:has_many => :has_many,
|
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
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 8
|
9
|
+
- 0
|
10
|
+
version: 0.8.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ace Suares
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-13 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -105,8 +105,8 @@ 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/range.rb
|
109
108
|
- app/helpers/form_elements/scale_with_integers.rb
|
109
|
+
- app/helpers/form_elements/scale_with_values.rb
|
110
110
|
- app/helpers/form_elements/text_area.rb
|
111
111
|
- app/helpers/form_elements/text_field.rb
|
112
112
|
- app/helpers/inline_forms_helper.rb
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module InlineFormsHelper
|
2
|
-
InlineForms::SPECIAL_COLUMN_TYPES[:range]=:integer
|
3
|
-
# range
|
4
|
-
def range_show(object, attribute, values)
|
5
|
-
link_to_inline_edit object, attribute, object.send(attribute), nil
|
6
|
-
end
|
7
|
-
def range_edit(object, attribute, values)
|
8
|
-
# 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!
|
9
|
-
collection_select( ('_' + object.class.to_s.downcase).to_sym, attribute.to_sym, values, 'to_i', 'to_s', :selected => object.send(attribute))
|
10
|
-
end
|
11
|
-
def range_update(object, attribute, values)
|
12
|
-
object[attribute.to_sym] = params[('_' + object.class.to_s.downcase).to_sym][attribute.to_sym]
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|