inline_forms 0.7.3 → 0.7.4
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
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.4
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module InlineFormsHelper
|
2
|
+
InlineForms::SPECIAL_COLUMN_TYPES[:scale_with_integers]=:integer
|
3
|
+
# scale_with_integers generates a sacle
|
4
|
+
# with the given list of integers as options
|
5
|
+
#
|
6
|
+
# values must be a Range or a one-dimensional array of Integers
|
7
|
+
def scale_with_integers_show(object, attribute, values)
|
8
|
+
unless values.is_a?(Hash)
|
9
|
+
options = Array.new
|
10
|
+
values.to_a.each_index do |i|
|
11
|
+
options << [ i.to_s, values.to_a[i] ]
|
12
|
+
end
|
13
|
+
values = Hash[ *options.flatten ]
|
14
|
+
end
|
15
|
+
link_to_inline_edit object, attribute, values[object.send(attribute).to_s], values
|
16
|
+
end
|
17
|
+
def scale_with_integers_edit(object, attribute, values)
|
18
|
+
# 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!
|
19
|
+
values = values.sort {|a,b| a[1].to_i<=>b[1].to_i}
|
20
|
+
collection_select( ('_' + object.class.to_s.downcase).to_sym, attribute.to_sym, values, 'first', 'last', :selected => object.send(attribute))
|
21
|
+
end
|
22
|
+
def scale_with_integers_update(object, attribute, values)
|
23
|
+
object[attribute.to_sym] = params[('_' + object.class.to_s.downcase).to_sym][attribute.to_sym]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
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.7.
|
8
|
+
s.version = "0.7.4"
|
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-09}
|
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 = [
|
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
|
|
35
35
|
"app/helpers/form_elements/geo_code_curacao.rb",
|
36
36
|
"app/helpers/form_elements/image.rb",
|
37
37
|
"app/helpers/form_elements/range.rb",
|
38
|
+
"app/helpers/form_elements/scale_with_integers.rb",
|
38
39
|
"app/helpers/form_elements/text_area.rb",
|
39
40
|
"app/helpers/form_elements/text_field.rb",
|
40
41
|
"app/helpers/inline_forms_helper.rb",
|
@@ -29,7 +29,7 @@ module InlineForms
|
|
29
29
|
# typo in the generator command line or you need to add a Form Element!
|
30
30
|
#
|
31
31
|
def column_type
|
32
|
-
SPECIAL_COLUMN_TYPES.merge(DEFAULT_COLUMN_TYPES).merge(RELATIONS)[type] || :unknown
|
32
|
+
SPECIAL_COLUMN_TYPES.merge(DEFAULT_COLUMN_TYPES).merge(RELATIONS).merge(SPECIAL_RELATIONS)[type] || :unknown
|
33
33
|
end
|
34
34
|
|
35
35
|
# Override the field_type to include our special column types.
|
@@ -39,17 +39,17 @@ module InlineForms
|
|
39
39
|
# will be :unknown. Make sure to check your models for the :unknown.
|
40
40
|
#
|
41
41
|
def field_type
|
42
|
-
SPECIAL_COLUMN_TYPES.merge(RELATIONS).has_key?(type) ? type :
|
42
|
+
SPECIAL_COLUMN_TYPES.merge(RELATIONS).has_key?(type) ? type : DEFAULT_FORM_ELEMENTS[type] || :unknown
|
43
43
|
end
|
44
44
|
|
45
|
-
def relation?
|
46
|
-
RELATIONS.has_key?(type) || special_relation?
|
47
|
-
end
|
48
|
-
|
49
45
|
def special_relation?
|
50
46
|
SPECIAL_RELATIONS.has_key?(type)
|
51
47
|
end
|
52
48
|
|
49
|
+
def relation?
|
50
|
+
RELATIONS.has_key?(type) || special_relation?
|
51
|
+
end
|
52
|
+
|
53
53
|
def has_many?
|
54
54
|
field_type == :associated
|
55
55
|
end
|
@@ -65,20 +65,29 @@ module InlineForms
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def generate_model
|
68
|
-
@belongs_to
|
69
|
-
@has_many
|
70
|
-
@
|
71
|
-
@
|
72
|
-
@
|
68
|
+
@belongs_to = "\n"
|
69
|
+
@has_many = "\n"
|
70
|
+
@has_one = "\n"
|
71
|
+
@habtm = "\n"
|
72
|
+
@has_attached_files = "\n"
|
73
|
+
@presentation = "\n"
|
74
|
+
@inline_forms_field_list = String.new
|
73
75
|
|
74
76
|
for attribute in attributes
|
75
|
-
if attribute.column_type
|
76
|
-
@belongs_to << ' belongs_to :'
|
77
|
+
if attribute.column_type == :belongs_to # :drop_down, :references and :belongs_to all end up with the column_type :belongs_to
|
78
|
+
@belongs_to << ' belongs_to :' + attribute.name + "\n"
|
79
|
+
end
|
80
|
+
if attribute.type == :has_many
|
81
|
+
@has_many << ' has_many :' + attribute.name + "\n"
|
82
|
+
end
|
83
|
+
if attribute.type == :has_one
|
84
|
+
@has_one << ' has_one :' + attribute.name + "\n"
|
77
85
|
end
|
78
|
-
if attribute.type
|
79
|
-
|
86
|
+
if attribute.type == :habtm ||
|
87
|
+
attribute.type == :has_and_belongs_to_many
|
88
|
+
@habtm << ' has_and_belongs_to_many :' + attribute.name + "\n"
|
80
89
|
end
|
81
|
-
if attribute.type
|
90
|
+
if attribute.type == :image
|
82
91
|
@has_attached_files << " has_attached_file :#{attribute.name},
|
83
92
|
:styles => { :medium => \"300x300>\", :thumb => \"100x100>\" }\n"
|
84
93
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
class <%= name %> < ActiveRecord::Base
|
2
2
|
<%= @belongs_to if @belongs_to.length > 1 -%>
|
3
|
-
<%= @has_many if @
|
4
|
-
<%= @
|
5
|
-
<%= @
|
3
|
+
<%= @has_many if @has_many.length > 1 -%>
|
4
|
+
<%= @has_one if @has_one.length > 1 -%>
|
5
|
+
<%= @habtm if @habtm.length > 1 -%>
|
6
|
+
<%= @has_attached_files if @has_attached_files.length > 1 -%>
|
7
|
+
<%= @presentation if @presentation.length > 1 -%>
|
6
8
|
<%= @inline_forms_field_list -%>
|
7
9
|
end
|
data/lib/inline_forms.rb
CHANGED
@@ -81,23 +81,42 @@ module InlineForms
|
|
81
81
|
# to the migration. (In fact AR will add t.integer :country_id). And
|
82
82
|
# it will add
|
83
83
|
# [ :country, "country", :dropdown ],
|
84
|
-
# to the model.
|
84
|
+
# to the inline_forms_field_list in the model.
|
85
85
|
#
|
86
86
|
SPECIAL_COLUMN_TYPES = {}
|
87
|
-
#
|
87
|
+
# When a column has the type of :references or :belongs_to, then
|
88
|
+
# there will be a line in the migration reflecting that, but not in the model.
|
89
|
+
# == Why?
|
90
|
+
# * Let's say we have a customer that has_many numbers.
|
91
|
+
# * Let's say that a number belongs_to a customer.
|
92
|
+
# * Let's say that every number has_one type_of_number (like 'private','gsm' etc.)
|
93
|
+
# * Let's say a type_of_number belongs_to a number.
|
94
|
+
#
|
95
|
+
# Wait a minute... thats sounds right... but it ain't!
|
96
|
+
#
|
97
|
+
# In fact, a type_of_number has_many numbers and a number belongs_to a type_of_number!
|
98
|
+
#
|
99
|
+
# In a form, it's quite logical to use a dropdown for type_of_number. So, in the generator, use
|
100
|
+
# type_of_number:dropdown
|
101
|
+
# 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 inline_forms_field_list)
|
103
|
+
#
|
104
|
+
# But, you also want to have a client_id in the migration, and a 'belongs_to :client' in the model.
|
105
|
+
# In such cases, you need to use :belongs_to, like this:
|
106
|
+
# rails g inline_forms Example number:string type_of_number:dropdown client:belongs_to
|
107
|
+
#
|
88
108
|
RELATIONS = {
|
89
109
|
:belongs_to => :belongs_to,
|
90
110
|
:references => :belongs_to,
|
91
111
|
}
|
92
|
-
#
|
112
|
+
# The stuff in this hash will add a line to the model, but little else.
|
93
113
|
SPECIAL_RELATIONS = {
|
94
|
-
:has_many
|
95
|
-
:
|
114
|
+
:has_many => :has_many,
|
115
|
+
:has_one => :has_one,
|
116
|
+
:has_and_belongs_to_many => :has_and_belongs_to_many,
|
117
|
+
:habtm => :has_and_belongs_to_many,
|
118
|
+
:associated => :associated,
|
96
119
|
}
|
97
|
-
# has_and_belongs_to_many :clients
|
98
|
-
# def <=>(other)
|
99
|
-
# self.name <=> other.name
|
100
|
-
# end
|
101
120
|
|
102
121
|
# Declare as a Rails::Engine, see http://www.ruby-forum.com/topic/211017#927932
|
103
122
|
class InlineFormsEngine < Rails::Engine
|
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: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
version: 0.7.
|
9
|
+
- 4
|
10
|
+
version: 0.7.4
|
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-09 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- app/helpers/form_elements/geo_code_curacao.rb
|
107
107
|
- app/helpers/form_elements/image.rb
|
108
108
|
- app/helpers/form_elements/range.rb
|
109
|
+
- app/helpers/form_elements/scale_with_integers.rb
|
109
110
|
- app/helpers/form_elements/text_area.rb
|
110
111
|
- app/helpers/form_elements/text_field.rb
|
111
112
|
- app/helpers/inline_forms_helper.rb
|