inline_forms 0.7.1 → 0.7.2
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 +30 -25
- data/app/helpers/form_elements/date.rb +10 -5
- data/app/helpers/form_elements/dropdown_with_integers.rb +26 -0
- data/app/helpers/form_elements/dropdown_with_values.rb +9 -1
- data/app/helpers/inline_forms_helper.rb +1 -2
- data/inline_forms.gemspec +3 -3
- metadata +5 -5
- data/app/models/inline_form.rb +0 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.2
|
@@ -1,35 +1,40 @@
|
|
1
|
+
# == Generic controller for the inline_forms plugin.
|
2
|
+
# === Usage
|
3
|
+
# If you have an Example class, make an ExampleController
|
4
|
+
# that is a subclass of InlineFormsController
|
5
|
+
# class ExampleController < InlineFormsController
|
6
|
+
# end
|
7
|
+
# That's it! It'll work. But please read about the InlineForms::InlineFormsGenerator first!
|
8
|
+
#
|
9
|
+
# You can override the methods in your ExampleController
|
10
|
+
# def index
|
11
|
+
# @objects=@Klass.all
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
#
|
15
|
+
# @objects holds the objects (in this case Examples)
|
16
|
+
# and @Klass will be set to Example by the getKlass before filter.
|
17
|
+
#
|
18
|
+
# === How it works
|
19
|
+
# The getKlass before_filter extracts the class and puts it in @Klass
|
20
|
+
#
|
21
|
+
# @Klass is used in the InlineFormsHelper
|
22
|
+
#
|
1
23
|
class InlineFormsController < ApplicationController
|
2
|
-
#unloadable # see http://dev.rubyonrails.org/ticket/6001
|
3
|
-
# == Generic controller for the inline_forms plugin.
|
4
|
-
# === Usage
|
5
|
-
# If you have an Example class, make an ExampleController that is a subclass of InlineFormsController
|
6
|
-
# <tt>class ExampleController < InlineFormsController
|
7
|
-
# # add before filters if you want: before_filter :authenticate_user!, :only => :token
|
8
|
-
# # override methods or make your own, using @Klass instead of Example.
|
9
|
-
# # def index
|
10
|
-
# # @objects=@Klass.all
|
11
|
-
# # end
|
12
|
-
# === How it works
|
13
|
-
# The getKlass before_filter extracts the class and puts it in @Klass
|
14
|
-
# === Limited Access
|
15
24
|
before_filter :getKlass
|
16
|
-
include InlineFormsHelper
|
17
|
-
|
18
|
-
#
|
19
|
-
# The link to 'new' allows you to create a new record.
|
25
|
+
include InlineFormsHelper
|
26
|
+
|
27
|
+
# shows a list of all objects from class @Klass, using will_paginate
|
20
28
|
#
|
21
|
-
#
|
29
|
+
# The link to 'new' allows you to create a new record.
|
22
30
|
#
|
23
31
|
def index
|
24
|
-
#@objects = @Klass.all
|
25
32
|
@objects = @Klass.paginate :page => params[:page], :order => 'created_at DESC'
|
26
|
-
|
27
33
|
update_span = params[:update]
|
28
34
|
respond_to do |format|
|
29
35
|
# found this here: http://www.ruby-forum.com/topic/211467
|
30
36
|
format.html { render 'inline_forms/index', :layout => 'inline_forms' }
|
31
|
-
format.js { render(:update) {|page| page.replace_html update_span, :partial => 'inline_forms/index' }
|
32
|
-
}
|
37
|
+
format.js { render(:update) {|page| page.replace_html update_span, :partial => 'inline_forms/index' } }
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
@@ -98,7 +103,7 @@ class InlineFormsController < ApplicationController
|
|
98
103
|
@values = params[:values]
|
99
104
|
@sub_id = params[:sub_id]
|
100
105
|
@update_span = params[:update]
|
101
|
-
|
106
|
+
#@values = params[@Klass.to_s.downcase].is_a?(Array) ? params[@Klass.to_s.downcase][@field.to_sym] : nil
|
102
107
|
send("#{@form_element.to_s}_update", @object, @field, @values)
|
103
108
|
@object.save
|
104
109
|
respond_to do |format|
|
@@ -133,6 +138,7 @@ class InlineFormsController < ApplicationController
|
|
133
138
|
}
|
134
139
|
end
|
135
140
|
else
|
141
|
+
@values = params[:values]
|
136
142
|
respond_to do |format|
|
137
143
|
# found this here: http://www.ruby-forum.com/topic/211467
|
138
144
|
format.js { render(:update) {|page| page.replace_html @update_span, :inline => '<%= send("#{@form_element}_show", @object, @field, @values) %>' }
|
@@ -153,8 +159,7 @@ class InlineFormsController < ApplicationController
|
|
153
159
|
# end
|
154
160
|
|
155
161
|
private
|
156
|
-
# Get the class
|
157
|
-
# Used in before_filter
|
162
|
+
# Get the class from the controller name.
|
158
163
|
def getKlass #:doc:
|
159
164
|
@Klass = self.controller_name.classify.constantize
|
160
165
|
end
|
@@ -2,14 +2,19 @@ module InlineFormsHelper
|
|
2
2
|
InlineForms::SPECIAL_MIGRATION_TYPES[:date_select]=:date
|
3
3
|
|
4
4
|
# date
|
5
|
-
def
|
5
|
+
def date_select_show(object, attribute, values)
|
6
6
|
link_to_inline_edit object, attribute, object.send(attribute), nil
|
7
7
|
end
|
8
|
-
def
|
9
|
-
|
8
|
+
def date_select_edit(object, attribute, values)
|
9
|
+
out = text_field_tag attribute, object[attribute]
|
10
|
+
out << '<SCRIPT>'.html_safe
|
11
|
+
out << "$(function() { ".html_safe
|
12
|
+
out << '$("#'.html_safe + attribute.to_s.html_safe + '").datepicker();'.html_safe
|
13
|
+
out << '});'.html_safe
|
14
|
+
out << '</SCRIPT>'.html_safe
|
15
|
+
return out
|
10
16
|
end
|
11
|
-
def
|
17
|
+
def date_select_update(object, attribute, values)
|
12
18
|
object[attribute.to_sym] = params[attribute.to_sym]
|
13
19
|
end
|
14
20
|
end
|
15
|
-
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module InlineFormsHelper
|
2
|
+
InlineForms::SPECIAL_MIGRATION_TYPES[:dropdown_with_integers]=:integer
|
3
|
+
# dropdown_with_integers generates a dropdown menu
|
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 dropdown_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 dropdown_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 dropdown_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
|
+
|
@@ -2,10 +2,18 @@ module InlineFormsHelper
|
|
2
2
|
InlineForms::SPECIAL_MIGRATION_TYPES[:dropdown_with_values]=:integer
|
3
3
|
# dropdown_with_values
|
4
4
|
def dropdown_with_values_show(object, attribute, values)
|
5
|
-
|
5
|
+
unless values.is_a?(Hash)
|
6
|
+
options = Array.new
|
7
|
+
values.to_a.each_index do |i|
|
8
|
+
options << [ i.to_s, values.to_a[i] ]
|
9
|
+
end
|
10
|
+
values = Hash[ *options.flatten ]
|
11
|
+
end
|
12
|
+
link_to_inline_edit object, attribute, values[object.send(attribute).to_s], values
|
6
13
|
end
|
7
14
|
def dropdown_with_values_edit(object, attribute, values)
|
8
15
|
# 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!
|
16
|
+
values = values.sort {|a,b| a[1]<=>b[1]}
|
9
17
|
collection_select( ('_' + object.class.to_s.downcase).to_sym, attribute.to_sym, values, 'first', 'last', :selected => object.send(attribute))
|
10
18
|
end
|
11
19
|
def dropdown_with_values_update(object, attribute, values)
|
@@ -6,10 +6,9 @@ end
|
|
6
6
|
|
7
7
|
module InlineFormsHelper
|
8
8
|
def inline_forms_show_record(object, attributes)
|
9
|
-
attributes = [ attributes ]
|
9
|
+
attributes = [ attributes ] unless attributes[0].is_a?(Array) # make sure we have an array of arrays
|
10
10
|
out = String.new
|
11
11
|
attributes.each do | attribute, name, form_element, values |
|
12
|
-
#css_class_id = form_element == :associated ? "subform_#{attribute.to_s}_#{object.id}" : "field_#{attribute.to_s}_#{object.id}"
|
13
12
|
css_class_id = "field_#{attribute.to_s}_#{object.id}"
|
14
13
|
name_cell = content_tag :td, :valign=>'top' do
|
15
14
|
content_tag :div, :class=> "field_name field_#{attribute.to_s} form_element_#{form_element.to_s}" do
|
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.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"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-03-07}
|
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 = [
|
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
"app/helpers/form_elements/checklist.rb",
|
31
31
|
"app/helpers/form_elements/date.rb",
|
32
32
|
"app/helpers/form_elements/dropdown.rb",
|
33
|
+
"app/helpers/form_elements/dropdown_with_integers.rb",
|
33
34
|
"app/helpers/form_elements/dropdown_with_values.rb",
|
34
35
|
"app/helpers/form_elements/geo_code_curacao.rb",
|
35
36
|
"app/helpers/form_elements/image.rb",
|
@@ -38,7 +39,6 @@ Gem::Specification.new do |s|
|
|
38
39
|
"app/helpers/form_elements/text_field.rb",
|
39
40
|
"app/helpers/inline_forms_helper.rb",
|
40
41
|
"app/models/geo_code_curacao.rb",
|
41
|
-
"app/models/inline_form.rb",
|
42
42
|
"app/views/inline_forms/_edit.html.erb",
|
43
43
|
"app/views/inline_forms/_index.html.erb",
|
44
44
|
"app/views/inline_forms/_new.html.erb",
|
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: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
version: 0.7.
|
9
|
+
- 2
|
10
|
+
version: 0.7.2
|
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-
|
18
|
+
date: 2011-03-07 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- app/helpers/form_elements/checklist.rb
|
102
102
|
- app/helpers/form_elements/date.rb
|
103
103
|
- app/helpers/form_elements/dropdown.rb
|
104
|
+
- app/helpers/form_elements/dropdown_with_integers.rb
|
104
105
|
- app/helpers/form_elements/dropdown_with_values.rb
|
105
106
|
- app/helpers/form_elements/geo_code_curacao.rb
|
106
107
|
- app/helpers/form_elements/image.rb
|
@@ -109,7 +110,6 @@ files:
|
|
109
110
|
- app/helpers/form_elements/text_field.rb
|
110
111
|
- app/helpers/inline_forms_helper.rb
|
111
112
|
- app/models/geo_code_curacao.rb
|
112
|
-
- app/models/inline_form.rb
|
113
113
|
- app/views/inline_forms/_edit.html.erb
|
114
114
|
- app/views/inline_forms/_index.html.erb
|
115
115
|
- app/views/inline_forms/_new.html.erb
|
data/app/models/inline_form.rb
DELETED