inline_forms 1.1.13 → 1.1.15
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/Gemfile.lock +1 -64
- data/{app → lib/app}/assets/images/close.png +0 -0
- data/{app → lib/app}/assets/images/glass_plate.gif +0 -0
- data/{app → lib/app}/assets/images/trash.png +0 -0
- data/{app → lib/app}/assets/images/ui-bg_diagonals-medium_20_d34d17_40x40.png +0 -0
- data/{app → lib/app}/assets/images/ui-bg_flat_30_cccccc_40x100.png +0 -0
- data/{app → lib/app}/assets/images/ui-bg_flat_50_5c5c5c_40x100.png +0 -0
- data/{app → lib/app}/assets/images/ui-bg_gloss-wave_45_817865_500x100.png +0 -0
- data/{app → lib/app}/assets/images/ui-bg_gloss-wave_60_fece2f_500x100.png +0 -0
- data/{app → lib/app}/assets/images/ui-bg_gloss-wave_70_ffdd57_500x100.png +0 -0
- data/{app → lib/app}/assets/images/ui-bg_gloss-wave_90_fff9e5_500x100.png +0 -0
- data/{app → lib/app}/assets/images/ui-bg_highlight-soft_100_feeebd_1x100.png +0 -0
- data/{app → lib/app}/assets/images/ui-bg_inset-soft_30_ffffff_1x100.png +0 -0
- data/{app → lib/app}/assets/images/ui-icons_3d3d3d_256x240.png +0 -0
- data/{app → lib/app}/assets/images/ui-icons_bd7b00_256x240.png +0 -0
- data/{app → lib/app}/assets/images/ui-icons_d19405_256x240.png +0 -0
- data/{app → lib/app}/assets/images/ui-icons_eb990f_256x240.png +0 -0
- data/{app → lib/app}/assets/images/ui-icons_ed9f26_256x240.png +0 -0
- data/{app → lib/app}/assets/images/ui-icons_fadc7a_256x240.png +0 -0
- data/{app → lib/app}/assets/images/ui-icons_ffe180_256x240.png +0 -0
- data/{app → lib/app}/assets/javascripts/ckeditor/config.js +0 -0
- data/{app → lib/app}/assets/stylesheets/application.css +0 -0
- data/{app → lib/app}/assets/stylesheets/devise.css +0 -0
- data/{app → lib/app}/assets/stylesheets/inline_forms.css +0 -0
- data/{app → lib/app}/assets/stylesheets/jquery-ui-sunny.css +0 -0
- data/lib/app/controllers/inline_forms_controller.rb +219 -0
- data/{app → lib/app}/helpers/form_elements/check_box.rb +0 -0
- data/{app → lib/app}/helpers/form_elements/check_list.rb +0 -0
- data/{app → lib/app}/helpers/form_elements/date.rb +0 -0
- data/{app → lib/app}/helpers/form_elements/datetime.rb +0 -0
- data/{app → lib/app}/helpers/form_elements/dropdown.rb +0 -0
- data/{app → lib/app}/helpers/form_elements/dropdown_with_integers.rb +0 -0
- data/{app → lib/app}/helpers/form_elements/dropdown_with_values.rb +0 -0
- data/{app → lib/app}/helpers/form_elements/file_field.rb +0 -0
- data/{app → lib/app}/helpers/form_elements/geo_code_curacao.rb +0 -0
- data/{app → lib/app}/helpers/form_elements/image_field.rb +0 -0
- data/{app → lib/app}/helpers/form_elements/info.rb +0 -0
- data/{app → lib/app}/helpers/form_elements/infoadmin.rb +0 -0
- data/{app → lib/app}/helpers/form_elements/question_list.rb +0 -0
- data/{app → lib/app}/helpers/form_elements/scale_with_integers.rb +0 -0
- data/{app → lib/app}/helpers/form_elements/scale_with_values.rb +0 -0
- data/{app → lib/app}/helpers/form_elements/slider_with_values.rb +0 -0
- data/{app → lib/app}/helpers/form_elements/text_area.rb +0 -0
- data/{app → lib/app}/helpers/form_elements/text_field.rb +0 -0
- data/{app → lib/app}/helpers/inline_forms_helper.rb +8 -3
- data/{app → lib/app}/models/geo_code_curacao.rb +0 -0
- data/{app → lib/app}/views/devise/confirmations/new.html.erb +0 -0
- data/{app → lib/app}/views/devise/mailer/confirmation_instructions.html.erb +0 -0
- data/{app → lib/app}/views/devise/mailer/reset_password_instructions.html.erb +0 -0
- data/{app → lib/app}/views/devise/mailer/unlock_instructions.html.erb +0 -0
- data/{app → lib/app}/views/devise/passwords/edit.html.erb +0 -0
- data/{app → lib/app}/views/devise/passwords/new.html.erb +0 -0
- data/{app → lib/app}/views/devise/registrations/edit.html.erb +0 -0
- data/{app → lib/app}/views/devise/registrations/new.html.erb +0 -0
- data/{app → lib/app}/views/devise/sessions/new.html.erb +0 -0
- data/{app → lib/app}/views/devise/shared/_links.erb +0 -0
- data/{app → lib/app}/views/devise/unlocks/new.html.erb +0 -0
- data/{app → lib/app}/views/inline_forms/_close.html.erb +0 -0
- data/{app → lib/app}/views/inline_forms/_edit.html.erb +0 -0
- data/{app → lib/app}/views/inline_forms/_header.html.erb +0 -0
- data/{app → lib/app}/views/inline_forms/_list.html.erb +2 -2
- data/{app → lib/app}/views/inline_forms/_new.html.erb +0 -0
- data/{app → lib/app}/views/inline_forms/_show.html.erb +0 -0
- data/{app → lib/app}/views/inline_forms/_show_undo.html.erb +0 -0
- data/{app → lib/app}/views/inline_forms/close.js.erb +0 -0
- data/{app → lib/app}/views/inline_forms/edit.js.erb +0 -0
- data/{app → lib/app}/views/inline_forms/list.js.erb +0 -0
- data/{app → lib/app}/views/inline_forms/new.js.erb +0 -0
- data/{app → lib/app}/views/inline_forms/show.js.erb +0 -0
- data/{app → lib/app}/views/inline_forms/show_element.js.erb +0 -0
- data/{app → lib/app}/views/inline_forms/show_undo.js.erb +0 -0
- data/{app → lib/app}/views/inline_forms/update.js.erb +0 -0
- data/{app → lib/app}/views/layouts/devise.html.erb +0 -0
- data/{app → lib/app}/views/layouts/inline_forms.html.erb +0 -0
- data/lib/generators/inline_forms/inline_forms_generator.rb +2 -2
- data/lib/inline_forms.rb +26 -3
- data/lib/inline_forms/version.rb +1 -1
- metadata +76 -76
- data/app/controllers/inline_forms_controller.rb +0 -221
data/Gemfile.lock
CHANGED
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
inline_forms (1.
|
|
5
|
-
capistrano
|
|
6
|
-
carrierwave
|
|
7
|
-
jquery-rails
|
|
8
|
-
mysql2
|
|
9
|
-
paper_trail
|
|
10
|
-
rails (~> 3.1.0)
|
|
11
|
-
rake
|
|
12
|
-
remotipart (~> 1.0)
|
|
13
|
-
tabs_on_rails
|
|
4
|
+
inline_forms (1.1.13)
|
|
14
5
|
|
|
15
6
|
GEM
|
|
16
7
|
remote: http://rubygems.org/
|
|
17
8
|
specs:
|
|
18
|
-
actionmailer (3.1.1)
|
|
19
|
-
actionpack (= 3.1.1)
|
|
20
|
-
mail (~> 2.3.0)
|
|
21
9
|
actionpack (3.1.1)
|
|
22
10
|
activemodel (= 3.1.1)
|
|
23
11
|
activesupport (= 3.1.1)
|
|
@@ -33,57 +21,20 @@ GEM
|
|
|
33
21
|
activesupport (= 3.1.1)
|
|
34
22
|
builder (~> 3.0.0)
|
|
35
23
|
i18n (~> 0.6)
|
|
36
|
-
activerecord (3.1.1)
|
|
37
|
-
activemodel (= 3.1.1)
|
|
38
|
-
activesupport (= 3.1.1)
|
|
39
|
-
arel (~> 2.2.1)
|
|
40
|
-
tzinfo (~> 0.3.29)
|
|
41
|
-
activeresource (3.1.1)
|
|
42
|
-
activemodel (= 3.1.1)
|
|
43
|
-
activesupport (= 3.1.1)
|
|
44
24
|
activesupport (3.1.1)
|
|
45
25
|
multi_json (~> 1.0)
|
|
46
|
-
arel (2.2.1)
|
|
47
26
|
builder (3.0.0)
|
|
48
|
-
capistrano (2.9.0)
|
|
49
|
-
highline
|
|
50
|
-
net-scp (>= 1.0.0)
|
|
51
|
-
net-sftp (>= 2.0.0)
|
|
52
|
-
net-ssh (>= 2.0.14)
|
|
53
|
-
net-ssh-gateway (>= 1.1.0)
|
|
54
|
-
carrierwave (0.5.7)
|
|
55
|
-
activesupport (~> 3.0)
|
|
56
27
|
diff-lcs (1.1.3)
|
|
57
28
|
erubis (2.7.0)
|
|
58
29
|
git (1.2.5)
|
|
59
|
-
highline (1.6.2)
|
|
60
30
|
hike (1.2.1)
|
|
61
31
|
i18n (0.6.0)
|
|
62
32
|
jeweler (1.5.2)
|
|
63
33
|
bundler (~> 1.0.0)
|
|
64
34
|
git (>= 1.2.5)
|
|
65
35
|
rake
|
|
66
|
-
jquery-rails (1.0.14)
|
|
67
|
-
railties (~> 3.0)
|
|
68
|
-
thor (~> 0.14)
|
|
69
36
|
json (1.6.1)
|
|
70
|
-
mail (2.3.0)
|
|
71
|
-
i18n (>= 0.4.0)
|
|
72
|
-
mime-types (~> 1.16)
|
|
73
|
-
treetop (~> 1.4.8)
|
|
74
|
-
mime-types (1.16)
|
|
75
37
|
multi_json (1.0.3)
|
|
76
|
-
mysql2 (0.3.7)
|
|
77
|
-
net-scp (1.0.4)
|
|
78
|
-
net-ssh (>= 1.99.1)
|
|
79
|
-
net-sftp (2.0.5)
|
|
80
|
-
net-ssh (>= 2.0.9)
|
|
81
|
-
net-ssh (2.2.1)
|
|
82
|
-
net-ssh-gateway (1.1.0)
|
|
83
|
-
net-ssh (>= 1.99.1)
|
|
84
|
-
paper_trail (2.4.0)
|
|
85
|
-
rails (~> 3)
|
|
86
|
-
polyglot (0.3.2)
|
|
87
38
|
rack (1.3.4)
|
|
88
39
|
rack-cache (1.1)
|
|
89
40
|
rack (>= 0.4)
|
|
@@ -93,14 +44,6 @@ GEM
|
|
|
93
44
|
rack
|
|
94
45
|
rack-test (0.6.1)
|
|
95
46
|
rack (>= 1.0)
|
|
96
|
-
rails (3.1.1)
|
|
97
|
-
actionmailer (= 3.1.1)
|
|
98
|
-
actionpack (= 3.1.1)
|
|
99
|
-
activerecord (= 3.1.1)
|
|
100
|
-
activeresource (= 3.1.1)
|
|
101
|
-
activesupport (= 3.1.1)
|
|
102
|
-
bundler (~> 1.0)
|
|
103
|
-
railties (= 3.1.1)
|
|
104
47
|
railties (3.1.1)
|
|
105
48
|
actionpack (= 3.1.1)
|
|
106
49
|
activesupport (= 3.1.1)
|
|
@@ -112,7 +55,6 @@ GEM
|
|
|
112
55
|
rcov (0.9.10)
|
|
113
56
|
rdoc (3.10)
|
|
114
57
|
json (~> 1.4)
|
|
115
|
-
remotipart (1.0)
|
|
116
58
|
rspec (2.6.0)
|
|
117
59
|
rspec-core (~> 2.6.0)
|
|
118
60
|
rspec-expectations (~> 2.6.0)
|
|
@@ -131,13 +73,8 @@ GEM
|
|
|
131
73
|
hike (~> 1.2)
|
|
132
74
|
rack (~> 1.0)
|
|
133
75
|
tilt (~> 1.1, != 1.3.0)
|
|
134
|
-
tabs_on_rails (2.0.2)
|
|
135
76
|
thor (0.14.6)
|
|
136
77
|
tilt (1.3.3)
|
|
137
|
-
treetop (1.4.10)
|
|
138
|
-
polyglot
|
|
139
|
-
polyglot (>= 0.3.1)
|
|
140
|
-
tzinfo (0.3.30)
|
|
141
78
|
|
|
142
79
|
PLATFORMS
|
|
143
80
|
ruby
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,219 @@
|
|
|
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
|
+
#
|
|
23
|
+
class InlineFormsController < ApplicationController
|
|
24
|
+
before_filter :getKlass
|
|
25
|
+
|
|
26
|
+
def self.cancan_enabled?
|
|
27
|
+
begin
|
|
28
|
+
::Ability && true
|
|
29
|
+
rescue NameError
|
|
30
|
+
false
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def cancan_enabled?
|
|
35
|
+
self.class.cancan_enabled?
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def cancan_disabled?
|
|
39
|
+
! self.class.cancan_enabled?
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
helper_method :cancan_disabled?, :cancan_enabled?
|
|
43
|
+
|
|
44
|
+
load_and_authorize_resource if cancan_enabled?
|
|
45
|
+
|
|
46
|
+
# :index shows a list of all objects from class @Klass, using will_paginate,
|
|
47
|
+
# including a link to 'new', that allows you to create a new record.
|
|
48
|
+
def index
|
|
49
|
+
@update_span = params[:update]
|
|
50
|
+
@parent_class = params[:parent_class]
|
|
51
|
+
@parent_id = params[:parent_id]
|
|
52
|
+
@ul_needed = params[:ul_needed]
|
|
53
|
+
@PER_PAGE = 5 unless @parent_class.nil?
|
|
54
|
+
# if the parent_class is not nill, we are in associated list and we don't search there.
|
|
55
|
+
# also, make sure the Model that you want to do a search on has a :name attribute. TODO
|
|
56
|
+
if @parent_class.nil?
|
|
57
|
+
conditions = [ @Klass.order_by_clause.to_s + " like ?", "%#{params[:search]}%" ]
|
|
58
|
+
else
|
|
59
|
+
conditions = [ "#{@parent_class.foreign_key} = ?", @parent_id ]
|
|
60
|
+
end
|
|
61
|
+
# if we are using cancan, then make sure to select only accessible records
|
|
62
|
+
if cancan_enabled?
|
|
63
|
+
@objects = @Klass.accessible_by(current_ability).order(@Klass.order_by_clause).paginate(
|
|
64
|
+
:page => params[:page],
|
|
65
|
+
:per_page => @PER_PAGE || 12,
|
|
66
|
+
:conditions => conditions )
|
|
67
|
+
else
|
|
68
|
+
@objects = @Klass.order(@Klass.order_by_clause).paginate(
|
|
69
|
+
:page => params[:page],
|
|
70
|
+
:per_page => @PER_PAGE || 12,
|
|
71
|
+
:conditions => conditions )
|
|
72
|
+
end
|
|
73
|
+
respond_to do |format|
|
|
74
|
+
format.html { render 'inline_forms/_list', :layout => 'inline_forms' } unless @Klass.not_accessible_through_html?
|
|
75
|
+
format.js { render :list }
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# :new prepares a new object, updates the list of objects and replaces it with
|
|
80
|
+
# an empty form. After pressing OK or Cancel, the list of objects is retrieved
|
|
81
|
+
# in the same way as :index
|
|
82
|
+
def new
|
|
83
|
+
@object = @Klass.new
|
|
84
|
+
@update_span = params[:update]
|
|
85
|
+
@parent_class = params[:parent_class]
|
|
86
|
+
unless @parent_class.nil?
|
|
87
|
+
@parent_id = params[:parent_id]
|
|
88
|
+
@object[@parent_class.foreign_key] = @parent_id
|
|
89
|
+
end
|
|
90
|
+
respond_to do |format|
|
|
91
|
+
format.js { }
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# :edit presents a form to edit one specific attribute from an object
|
|
96
|
+
def edit
|
|
97
|
+
@object = @Klass.find(params[:id])
|
|
98
|
+
@attribute = params[:attribute]
|
|
99
|
+
@form_element = params[:form_element]
|
|
100
|
+
@sub_id = params[:sub_id]
|
|
101
|
+
@update_span = params[:update]
|
|
102
|
+
respond_to do |format|
|
|
103
|
+
format.js { }
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# :create creates the object made with :new.
|
|
108
|
+
# It then presents the list of objects.
|
|
109
|
+
def create
|
|
110
|
+
object = @Klass.new
|
|
111
|
+
@update_span = params[:update]
|
|
112
|
+
attributes = object.inline_forms_attribute_list
|
|
113
|
+
attributes.each do | attribute, name, form_element |
|
|
114
|
+
send("#{form_element.to_s}_update", object, attribute) unless form_element == :associated
|
|
115
|
+
end
|
|
116
|
+
@parent_class = params[:parent_class]
|
|
117
|
+
@parent_id = params[:parent_id]
|
|
118
|
+
@PER_PAGE = 5 unless @parent_class.nil?
|
|
119
|
+
# for the logic behind the :conditions see the #index method.
|
|
120
|
+
@parent_class.nil? ? conditions = [ @Klass.order_by_clause.to_s + " like ?", "%#{params[:search]}%" ] : conditions = [ "#{@parent_class.foreign_key} = ?", @parent_id ]
|
|
121
|
+
object[@parent_class.foreign_key] = @parent_id unless @parent_class.nil?
|
|
122
|
+
if object.save
|
|
123
|
+
flash.now[:success] = "Successfully created #{object.class.to_s.underscore}."
|
|
124
|
+
if cancan_enabled?
|
|
125
|
+
@objects = @Klass.accessible_by(current_ability).order(@Klass.order_by_clause).paginate :page => params[:page], :per_page => @PER_PAGE || 12, :conditions => conditions
|
|
126
|
+
else
|
|
127
|
+
@objects = @Klass.order(@Klass.order_by_clause).paginate :page => params[:page], :per_page => @PER_PAGE || 12, :conditions => conditions
|
|
128
|
+
end
|
|
129
|
+
respond_to do |format|
|
|
130
|
+
format.js { render :list }
|
|
131
|
+
end
|
|
132
|
+
else
|
|
133
|
+
flash.now[:error] = "Failed to create #{object.class.to_s.underscore}.".html_safe
|
|
134
|
+
object.errors.each do |e|
|
|
135
|
+
flash.now[:error] << '<br />'.html_safe + e[0].to_s + ": " + e[1]
|
|
136
|
+
end
|
|
137
|
+
respond_to do |format|
|
|
138
|
+
@object = object
|
|
139
|
+
format.js { render :new}
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# :update updates a specific attribute from an object.
|
|
145
|
+
def update
|
|
146
|
+
@object = @Klass.find(params[:id])
|
|
147
|
+
@attribute = params[:attribute]
|
|
148
|
+
@form_element = params[:form_element]
|
|
149
|
+
@sub_id = params[:sub_id]
|
|
150
|
+
@update_span = params[:update]
|
|
151
|
+
send("#{@form_element.to_s}_update", @object, @attribute)
|
|
152
|
+
@object.save
|
|
153
|
+
#puts "Requested #{request.format}"
|
|
154
|
+
respond_to do |format|
|
|
155
|
+
format.js { }
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# :show shows one attribute (attribute) from a record (object).
|
|
160
|
+
# It includes the link to 'edit'
|
|
161
|
+
def show
|
|
162
|
+
@object = @Klass.find(params[:id])
|
|
163
|
+
@attribute = params[:attribute]
|
|
164
|
+
@form_element = params[:form_element]
|
|
165
|
+
close = params[:close] || false
|
|
166
|
+
if @form_element == "associated"
|
|
167
|
+
@sub_id = params[:sub_id]
|
|
168
|
+
if @sub_id.to_i > 0
|
|
169
|
+
@associated_record_id = @object.send(@attribute.to_s.singularize + "_ids").index(@sub_id.to_i)
|
|
170
|
+
@associated_record = @object.send(@attribute)[@associated_record_id]
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
@update_span = params[:update]
|
|
174
|
+
if @attribute.nil?
|
|
175
|
+
respond_to do |format|
|
|
176
|
+
@attributes = @object.inline_forms_attribute_list
|
|
177
|
+
if close
|
|
178
|
+
format.js { render :close }
|
|
179
|
+
else
|
|
180
|
+
format.js { }
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
else
|
|
184
|
+
respond_to do |format|
|
|
185
|
+
format.js { render :show_element }
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# :destroy destroys the record, but also shows an undo link (with paper_trail)
|
|
191
|
+
def destroy
|
|
192
|
+
@update_span = params[:update]
|
|
193
|
+
@object = @Klass.find(params[:id])
|
|
194
|
+
@object.destroy
|
|
195
|
+
respond_to do |format|
|
|
196
|
+
format.js { render :show_undo }
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# :revert works like undo.
|
|
201
|
+
# Thanks Ryan Bates: http://railscasts.com/episodes/255-undo-with-paper-trail
|
|
202
|
+
def revert
|
|
203
|
+
@update_span = params[:update]
|
|
204
|
+
@version = Version.find(params[:id])
|
|
205
|
+
@version.reify.save!
|
|
206
|
+
@object = @Klass.find(@version.item_id)
|
|
207
|
+
respond_to do |format|
|
|
208
|
+
format.js { render :close }
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
private
|
|
213
|
+
# Get the class from the controller name.
|
|
214
|
+
# CountryController < InlineFormsController, so what class are we?
|
|
215
|
+
def getKlass #:doc:
|
|
216
|
+
@Klass = self.controller_name.classify.constantize
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -39,6 +39,7 @@ module InlineFormsHelper
|
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
# undo link
|
|
42
43
|
def link_to_undo_destroy(msg, object, update_span )
|
|
43
44
|
link_to("undo", revert_version_path(object.versions.scoped.last), :method => :post)
|
|
44
45
|
end
|
|
@@ -64,6 +65,7 @@ module InlineFormsHelper
|
|
|
64
65
|
end
|
|
65
66
|
end
|
|
66
67
|
|
|
68
|
+
# link to new record
|
|
67
69
|
def link_to_new_record(text, model, path_to_new, update_span, parent_class, parent_id)
|
|
68
70
|
out = ""
|
|
69
71
|
out << "<li class='new_record_link'>"
|
|
@@ -117,14 +119,17 @@ module InlineFormsHelper
|
|
|
117
119
|
|
|
118
120
|
end
|
|
119
121
|
|
|
120
|
-
# make the current method and the calling method available
|
|
121
|
-
# http://www.ruby-forum.com/topic/75258
|
|
122
|
-
# supposedly, this is fixed in 1.9
|
|
123
122
|
module Kernel
|
|
124
123
|
private
|
|
124
|
+
# make the current method available
|
|
125
|
+
# http://www.ruby-forum.com/topic/75258
|
|
126
|
+
# supposedly, this is fixed in 1.9
|
|
125
127
|
def this_method
|
|
126
128
|
caller[0] =~ /`([^']*)'/ and $1
|
|
127
129
|
end
|
|
130
|
+
# make the calling method available
|
|
131
|
+
# http://www.ruby-forum.com/topic/75258
|
|
132
|
+
# supposedly, this is fixed in 1.9
|
|
128
133
|
def calling_method
|
|
129
134
|
caller[1] =~ /`([^']*)'/ and $1
|
|
130
135
|
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -52,7 +52,7 @@ they are @object. We need this magic here to rewrite all the @variables to varia
|
|
|
52
52
|
|
|
53
53
|
<% end %>
|
|
54
54
|
|
|
55
|
-
<%= "<ul id=\"#{update_span}\" class=\"inline_forms_list\">" if ul_needed -%>
|
|
55
|
+
<%= raw "<ul id=\"#{update_span}\" class=\"inline_forms_list\">" if ul_needed -%>
|
|
56
56
|
<!-- # link to new -->
|
|
57
57
|
<%= link_to_new_record("Add a new #{human_readable_class}", model_name, path_to_new, update_span, parent_class, parent_id) -%>
|
|
58
58
|
<!-- # list of objects -->
|
|
@@ -79,4 +79,4 @@ they are @object. We need this magic here to rewrite all the @variables to varia
|
|
|
79
79
|
<%= will_paginate objects, :ajax => true, :params => {:controller => attribute, :action => :index, :id => nil, :parent_class => parent_class, :parent_id => parent_id, :update => "#{parent_class.to_s.underscore}_#{parent_id}_#{attribute}", :ul_needed => true } -%>
|
|
80
80
|
<% end %>
|
|
81
81
|
</li>
|
|
82
|
-
<%= "</ul>" if ul_needed -%>
|
|
82
|
+
<%= raw "</ul>" if ul_needed -%>
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -6,7 +6,7 @@ module InlineForms
|
|
|
6
6
|
#
|
|
7
7
|
# Read more about the possible types below.
|
|
8
8
|
#
|
|
9
|
-
#
|
|
9
|
+
# == Overriding Rails::Generators::GeneratedAttribute
|
|
10
10
|
# When using a generator in the form
|
|
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.
|
|
@@ -15,7 +15,7 @@ module InlineForms
|
|
|
15
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
|
-
class
|
|
18
|
+
class Generator < Rails::Generators::NamedBase
|
|
19
19
|
Rails::Generators::GeneratedAttribute.class_eval do #:doc:
|
|
20
20
|
# Deducts the column_type for migrations from the type.
|
|
21
21
|
#
|
data/lib/inline_forms.rb
CHANGED
|
@@ -130,11 +130,34 @@ module InlineForms
|
|
|
130
130
|
:habtm => :no_migration,
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
# load form elements. Each element goes into a separate file
|
|
134
|
+
# and defines a _show, _edit and _update method.
|
|
135
|
+
#
|
|
136
|
+
|
|
133
137
|
# Declare as a Rails::Engine, see http://www.ruby-forum.com/topic/211017#927932
|
|
134
138
|
class Engine < Rails::Engine
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
139
|
+
paths["app"] << "lib/app"
|
|
140
|
+
paths["app/controllers"] << "lib/app/controllers"
|
|
141
|
+
paths["app/helpers"] << "lib/app/helpers"
|
|
142
|
+
paths["app/models"] << "lib/app/models"
|
|
143
|
+
paths["app/views"] << "lib/app/views"
|
|
144
|
+
paths["app/assets"] << "lib/app/assets"
|
|
138
145
|
end
|
|
146
|
+
|
|
139
147
|
end
|
|
140
148
|
|
|
149
|
+
# make the current method and the calling method available
|
|
150
|
+
# http://www.ruby-forum.com/topic/75258
|
|
151
|
+
# supposedly, this is fixed in 1.9
|
|
152
|
+
module Kernel
|
|
153
|
+
private
|
|
154
|
+
def this_method
|
|
155
|
+
caller[0] =~ /`([^']*)'/ and $1
|
|
156
|
+
end
|
|
157
|
+
def calling_method
|
|
158
|
+
caller[1] =~ /`([^']*)'/ and $1
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
data/lib/inline_forms/version.rb
CHANGED
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: 13
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 1
|
|
8
8
|
- 1
|
|
9
|
-
-
|
|
10
|
-
version: 1.1.
|
|
9
|
+
- 15
|
|
10
|
+
version: 1.1.15
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Ace Suares
|
|
@@ -108,81 +108,81 @@ files:
|
|
|
108
108
|
- LICENSE.txt
|
|
109
109
|
- README.rdoc
|
|
110
110
|
- Rakefile
|
|
111
|
-
- app/assets/images/close.png
|
|
112
|
-
- app/assets/images/glass_plate.gif
|
|
113
|
-
- app/assets/images/trash.png
|
|
114
|
-
- app/assets/images/ui-bg_diagonals-medium_20_d34d17_40x40.png
|
|
115
|
-
- app/assets/images/ui-bg_flat_30_cccccc_40x100.png
|
|
116
|
-
- app/assets/images/ui-bg_flat_50_5c5c5c_40x100.png
|
|
117
|
-
- app/assets/images/ui-bg_gloss-wave_45_817865_500x100.png
|
|
118
|
-
- app/assets/images/ui-bg_gloss-wave_60_fece2f_500x100.png
|
|
119
|
-
- app/assets/images/ui-bg_gloss-wave_70_ffdd57_500x100.png
|
|
120
|
-
- app/assets/images/ui-bg_gloss-wave_90_fff9e5_500x100.png
|
|
121
|
-
- app/assets/images/ui-bg_highlight-soft_100_feeebd_1x100.png
|
|
122
|
-
- app/assets/images/ui-bg_inset-soft_30_ffffff_1x100.png
|
|
123
|
-
- app/assets/images/ui-icons_3d3d3d_256x240.png
|
|
124
|
-
- app/assets/images/ui-icons_bd7b00_256x240.png
|
|
125
|
-
- app/assets/images/ui-icons_d19405_256x240.png
|
|
126
|
-
- app/assets/images/ui-icons_eb990f_256x240.png
|
|
127
|
-
- app/assets/images/ui-icons_ed9f26_256x240.png
|
|
128
|
-
- app/assets/images/ui-icons_fadc7a_256x240.png
|
|
129
|
-
- app/assets/images/ui-icons_ffe180_256x240.png
|
|
130
|
-
- app/assets/javascripts/ckeditor/config.js
|
|
131
|
-
- app/assets/stylesheets/application.css
|
|
132
|
-
- app/assets/stylesheets/devise.css
|
|
133
|
-
- app/assets/stylesheets/inline_forms.css
|
|
134
|
-
- app/assets/stylesheets/jquery-ui-sunny.css
|
|
135
|
-
- app/controllers/inline_forms_controller.rb
|
|
136
|
-
- app/helpers/form_elements/check_box.rb
|
|
137
|
-
- app/helpers/form_elements/check_list.rb
|
|
138
|
-
- app/helpers/form_elements/date.rb
|
|
139
|
-
- app/helpers/form_elements/datetime.rb
|
|
140
|
-
- app/helpers/form_elements/dropdown.rb
|
|
141
|
-
- app/helpers/form_elements/dropdown_with_integers.rb
|
|
142
|
-
- app/helpers/form_elements/dropdown_with_values.rb
|
|
143
|
-
- app/helpers/form_elements/file_field.rb
|
|
144
|
-
- app/helpers/form_elements/geo_code_curacao.rb
|
|
145
|
-
- app/helpers/form_elements/image_field.rb
|
|
146
|
-
- app/helpers/form_elements/info.rb
|
|
147
|
-
- app/helpers/form_elements/infoadmin.rb
|
|
148
|
-
- app/helpers/form_elements/question_list.rb
|
|
149
|
-
- app/helpers/form_elements/scale_with_integers.rb
|
|
150
|
-
- app/helpers/form_elements/scale_with_values.rb
|
|
151
|
-
- app/helpers/form_elements/slider_with_values.rb
|
|
152
|
-
- app/helpers/form_elements/text_area.rb
|
|
153
|
-
- app/helpers/form_elements/text_field.rb
|
|
154
|
-
- app/helpers/inline_forms_helper.rb
|
|
155
|
-
- app/models/geo_code_curacao.rb
|
|
156
|
-
- app/views/devise/confirmations/new.html.erb
|
|
157
|
-
- app/views/devise/mailer/confirmation_instructions.html.erb
|
|
158
|
-
- app/views/devise/mailer/reset_password_instructions.html.erb
|
|
159
|
-
- app/views/devise/mailer/unlock_instructions.html.erb
|
|
160
|
-
- app/views/devise/passwords/edit.html.erb
|
|
161
|
-
- app/views/devise/passwords/new.html.erb
|
|
162
|
-
- app/views/devise/registrations/edit.html.erb
|
|
163
|
-
- app/views/devise/registrations/new.html.erb
|
|
164
|
-
- app/views/devise/sessions/new.html.erb
|
|
165
|
-
- app/views/devise/shared/_links.erb
|
|
166
|
-
- app/views/devise/unlocks/new.html.erb
|
|
167
|
-
- app/views/inline_forms/_close.html.erb
|
|
168
|
-
- app/views/inline_forms/_edit.html.erb
|
|
169
|
-
- app/views/inline_forms/_header.html.erb
|
|
170
|
-
- app/views/inline_forms/_list.html.erb
|
|
171
|
-
- app/views/inline_forms/_new.html.erb
|
|
172
|
-
- app/views/inline_forms/_show.html.erb
|
|
173
|
-
- app/views/inline_forms/_show_undo.html.erb
|
|
174
|
-
- app/views/inline_forms/close.js.erb
|
|
175
|
-
- app/views/inline_forms/edit.js.erb
|
|
176
|
-
- app/views/inline_forms/list.js.erb
|
|
177
|
-
- app/views/inline_forms/new.js.erb
|
|
178
|
-
- app/views/inline_forms/show.js.erb
|
|
179
|
-
- app/views/inline_forms/show_element.js.erb
|
|
180
|
-
- app/views/inline_forms/show_undo.js.erb
|
|
181
|
-
- app/views/inline_forms/update.js.erb
|
|
182
|
-
- app/views/layouts/devise.html.erb
|
|
183
|
-
- app/views/layouts/inline_forms.html.erb
|
|
184
111
|
- bin/inline_forms
|
|
185
112
|
- inline_forms.gemspec
|
|
113
|
+
- lib/app/assets/images/close.png
|
|
114
|
+
- lib/app/assets/images/glass_plate.gif
|
|
115
|
+
- lib/app/assets/images/trash.png
|
|
116
|
+
- lib/app/assets/images/ui-bg_diagonals-medium_20_d34d17_40x40.png
|
|
117
|
+
- lib/app/assets/images/ui-bg_flat_30_cccccc_40x100.png
|
|
118
|
+
- lib/app/assets/images/ui-bg_flat_50_5c5c5c_40x100.png
|
|
119
|
+
- lib/app/assets/images/ui-bg_gloss-wave_45_817865_500x100.png
|
|
120
|
+
- lib/app/assets/images/ui-bg_gloss-wave_60_fece2f_500x100.png
|
|
121
|
+
- lib/app/assets/images/ui-bg_gloss-wave_70_ffdd57_500x100.png
|
|
122
|
+
- lib/app/assets/images/ui-bg_gloss-wave_90_fff9e5_500x100.png
|
|
123
|
+
- lib/app/assets/images/ui-bg_highlight-soft_100_feeebd_1x100.png
|
|
124
|
+
- lib/app/assets/images/ui-bg_inset-soft_30_ffffff_1x100.png
|
|
125
|
+
- lib/app/assets/images/ui-icons_3d3d3d_256x240.png
|
|
126
|
+
- lib/app/assets/images/ui-icons_bd7b00_256x240.png
|
|
127
|
+
- lib/app/assets/images/ui-icons_d19405_256x240.png
|
|
128
|
+
- lib/app/assets/images/ui-icons_eb990f_256x240.png
|
|
129
|
+
- lib/app/assets/images/ui-icons_ed9f26_256x240.png
|
|
130
|
+
- lib/app/assets/images/ui-icons_fadc7a_256x240.png
|
|
131
|
+
- lib/app/assets/images/ui-icons_ffe180_256x240.png
|
|
132
|
+
- lib/app/assets/javascripts/ckeditor/config.js
|
|
133
|
+
- lib/app/assets/stylesheets/application.css
|
|
134
|
+
- lib/app/assets/stylesheets/devise.css
|
|
135
|
+
- lib/app/assets/stylesheets/inline_forms.css
|
|
136
|
+
- lib/app/assets/stylesheets/jquery-ui-sunny.css
|
|
137
|
+
- lib/app/controllers/inline_forms_controller.rb
|
|
138
|
+
- lib/app/helpers/form_elements/check_box.rb
|
|
139
|
+
- lib/app/helpers/form_elements/check_list.rb
|
|
140
|
+
- lib/app/helpers/form_elements/date.rb
|
|
141
|
+
- lib/app/helpers/form_elements/datetime.rb
|
|
142
|
+
- lib/app/helpers/form_elements/dropdown.rb
|
|
143
|
+
- lib/app/helpers/form_elements/dropdown_with_integers.rb
|
|
144
|
+
- lib/app/helpers/form_elements/dropdown_with_values.rb
|
|
145
|
+
- lib/app/helpers/form_elements/file_field.rb
|
|
146
|
+
- lib/app/helpers/form_elements/geo_code_curacao.rb
|
|
147
|
+
- lib/app/helpers/form_elements/image_field.rb
|
|
148
|
+
- lib/app/helpers/form_elements/info.rb
|
|
149
|
+
- lib/app/helpers/form_elements/infoadmin.rb
|
|
150
|
+
- lib/app/helpers/form_elements/question_list.rb
|
|
151
|
+
- lib/app/helpers/form_elements/scale_with_integers.rb
|
|
152
|
+
- lib/app/helpers/form_elements/scale_with_values.rb
|
|
153
|
+
- lib/app/helpers/form_elements/slider_with_values.rb
|
|
154
|
+
- lib/app/helpers/form_elements/text_area.rb
|
|
155
|
+
- lib/app/helpers/form_elements/text_field.rb
|
|
156
|
+
- lib/app/helpers/inline_forms_helper.rb
|
|
157
|
+
- lib/app/models/geo_code_curacao.rb
|
|
158
|
+
- lib/app/views/devise/confirmations/new.html.erb
|
|
159
|
+
- lib/app/views/devise/mailer/confirmation_instructions.html.erb
|
|
160
|
+
- lib/app/views/devise/mailer/reset_password_instructions.html.erb
|
|
161
|
+
- lib/app/views/devise/mailer/unlock_instructions.html.erb
|
|
162
|
+
- lib/app/views/devise/passwords/edit.html.erb
|
|
163
|
+
- lib/app/views/devise/passwords/new.html.erb
|
|
164
|
+
- lib/app/views/devise/registrations/edit.html.erb
|
|
165
|
+
- lib/app/views/devise/registrations/new.html.erb
|
|
166
|
+
- lib/app/views/devise/sessions/new.html.erb
|
|
167
|
+
- lib/app/views/devise/shared/_links.erb
|
|
168
|
+
- lib/app/views/devise/unlocks/new.html.erb
|
|
169
|
+
- lib/app/views/inline_forms/_close.html.erb
|
|
170
|
+
- lib/app/views/inline_forms/_edit.html.erb
|
|
171
|
+
- lib/app/views/inline_forms/_header.html.erb
|
|
172
|
+
- lib/app/views/inline_forms/_list.html.erb
|
|
173
|
+
- lib/app/views/inline_forms/_new.html.erb
|
|
174
|
+
- lib/app/views/inline_forms/_show.html.erb
|
|
175
|
+
- lib/app/views/inline_forms/_show_undo.html.erb
|
|
176
|
+
- lib/app/views/inline_forms/close.js.erb
|
|
177
|
+
- lib/app/views/inline_forms/edit.js.erb
|
|
178
|
+
- lib/app/views/inline_forms/list.js.erb
|
|
179
|
+
- lib/app/views/inline_forms/new.js.erb
|
|
180
|
+
- lib/app/views/inline_forms/show.js.erb
|
|
181
|
+
- lib/app/views/inline_forms/show_element.js.erb
|
|
182
|
+
- lib/app/views/inline_forms/show_undo.js.erb
|
|
183
|
+
- lib/app/views/inline_forms/update.js.erb
|
|
184
|
+
- lib/app/views/layouts/devise.html.erb
|
|
185
|
+
- lib/app/views/layouts/inline_forms.html.erb
|
|
186
186
|
- lib/generators/inline_forms/USAGE
|
|
187
187
|
- lib/generators/inline_forms/inline_forms_generator.rb
|
|
188
188
|
- lib/generators/inline_forms/templates/_inline_forms_tabs.html.erb
|
|
@@ -1,221 +0,0 @@
|
|
|
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
|
-
#
|
|
23
|
-
class InlineFormsController < ApplicationController
|
|
24
|
-
before_filter :getKlass
|
|
25
|
-
|
|
26
|
-
def self.cancan_enabled?
|
|
27
|
-
begin
|
|
28
|
-
::Ability && true
|
|
29
|
-
rescue NameError
|
|
30
|
-
false
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def cancan_enabled?
|
|
35
|
-
self.class.cancan_enabled?
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def cancan_disabled?
|
|
39
|
-
! self.class.cancan_enabled?
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
helper_method :cancan_disabled?, :cancan_enabled?
|
|
43
|
-
|
|
44
|
-
load_and_authorize_resource if cancan_enabled?
|
|
45
|
-
|
|
46
|
-
include InlineFormsHelper
|
|
47
|
-
|
|
48
|
-
# :index shows a list of all objects from class @Klass, using will_paginate,
|
|
49
|
-
# including a link to 'new', that allows you to create a new record.
|
|
50
|
-
def index
|
|
51
|
-
@update_span = params[:update]
|
|
52
|
-
@parent_class = params[:parent_class]
|
|
53
|
-
@parent_id = params[:parent_id]
|
|
54
|
-
@ul_needed = params[:ul_needed]
|
|
55
|
-
@PER_PAGE = 5 unless @parent_class.nil?
|
|
56
|
-
# if the parent_class is not nill, we are in associated list and we don't search there.
|
|
57
|
-
# also, make sure the Model that you want to do a search on has a :name attribute. TODO
|
|
58
|
-
if @parent_class.nil?
|
|
59
|
-
conditions = [ @Klass.order_by_clause.to_s + " like ?", "%#{params[:search]}%" ]
|
|
60
|
-
else
|
|
61
|
-
conditions = [ "#{@parent_class.foreign_key} = ?", @parent_id ]
|
|
62
|
-
end
|
|
63
|
-
# if we are using cancan, then make sure to select only accessible records
|
|
64
|
-
if cancan_enabled?
|
|
65
|
-
@objects = @Klass.accessible_by(current_ability).order(@Klass.order_by_clause).paginate(
|
|
66
|
-
:page => params[:page],
|
|
67
|
-
:per_page => @PER_PAGE || 12,
|
|
68
|
-
:conditions => conditions )
|
|
69
|
-
else
|
|
70
|
-
@objects = @Klass.order(@Klass.order_by_clause).paginate(
|
|
71
|
-
:page => params[:page],
|
|
72
|
-
:per_page => @PER_PAGE || 12,
|
|
73
|
-
:conditions => conditions )
|
|
74
|
-
end
|
|
75
|
-
respond_to do |format|
|
|
76
|
-
format.html { render 'inline_forms/_list', :layout => 'inline_forms' } unless @Klass.not_accessible_through_html?
|
|
77
|
-
format.js { render :list }
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
# :new prepares a new object, updates the list of objects and replaces it with
|
|
82
|
-
# an empty form. After pressing OK or Cancel, the list of objects is retrieved
|
|
83
|
-
# in the same way as :index
|
|
84
|
-
def new
|
|
85
|
-
@object = @Klass.new
|
|
86
|
-
@update_span = params[:update]
|
|
87
|
-
@parent_class = params[:parent_class]
|
|
88
|
-
unless @parent_class.nil?
|
|
89
|
-
@parent_id = params[:parent_id]
|
|
90
|
-
@object[@parent_class.foreign_key] = @parent_id
|
|
91
|
-
end
|
|
92
|
-
respond_to do |format|
|
|
93
|
-
format.js { }
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
# :edit presents a form to edit one specific attribute from an object
|
|
98
|
-
def edit
|
|
99
|
-
@object = @Klass.find(params[:id])
|
|
100
|
-
@attribute = params[:attribute]
|
|
101
|
-
@form_element = params[:form_element]
|
|
102
|
-
@sub_id = params[:sub_id]
|
|
103
|
-
@update_span = params[:update]
|
|
104
|
-
respond_to do |format|
|
|
105
|
-
format.js { }
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
# :create creates the object made with :new.
|
|
110
|
-
# It then presents the list of objects.
|
|
111
|
-
def create
|
|
112
|
-
object = @Klass.new
|
|
113
|
-
@update_span = params[:update]
|
|
114
|
-
attributes = object.inline_forms_attribute_list
|
|
115
|
-
attributes.each do | attribute, name, form_element |
|
|
116
|
-
send("#{form_element.to_s}_update", object, attribute) unless form_element == :associated
|
|
117
|
-
end
|
|
118
|
-
@parent_class = params[:parent_class]
|
|
119
|
-
@parent_id = params[:parent_id]
|
|
120
|
-
@PER_PAGE = 5 unless @parent_class.nil?
|
|
121
|
-
# for the logic behind the :conditions see the #index method.
|
|
122
|
-
@parent_class.nil? ? conditions = [ @Klass.order_by_clause.to_s + " like ?", "%#{params[:search]}%" ] : conditions = [ "#{@parent_class.foreign_key} = ?", @parent_id ]
|
|
123
|
-
object[@parent_class.foreign_key] = @parent_id unless @parent_class.nil?
|
|
124
|
-
if object.save
|
|
125
|
-
flash.now[:success] = "Successfully created #{object.class.to_s.underscore}."
|
|
126
|
-
if cancan_enabled?
|
|
127
|
-
@objects = @Klass.accessible_by(current_ability).order(@Klass.order_by_clause).paginate :page => params[:page], :per_page => @PER_PAGE || 12, :conditions => conditions
|
|
128
|
-
else
|
|
129
|
-
@objects = @Klass.order(@Klass.order_by_clause).paginate :page => params[:page], :per_page => @PER_PAGE || 12, :conditions => conditions
|
|
130
|
-
end
|
|
131
|
-
respond_to do |format|
|
|
132
|
-
format.js { render :list }
|
|
133
|
-
end
|
|
134
|
-
else
|
|
135
|
-
flash.now[:error] = "Failed to create #{object.class.to_s.underscore}.".html_safe
|
|
136
|
-
object.errors.each do |e|
|
|
137
|
-
flash.now[:error] << '<br />'.html_safe + e[0].to_s + ": " + e[1]
|
|
138
|
-
end
|
|
139
|
-
respond_to do |format|
|
|
140
|
-
@object = object
|
|
141
|
-
format.js { render :new}
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
# :update updates a specific attribute from an object.
|
|
147
|
-
def update
|
|
148
|
-
@object = @Klass.find(params[:id])
|
|
149
|
-
@attribute = params[:attribute]
|
|
150
|
-
@form_element = params[:form_element]
|
|
151
|
-
@sub_id = params[:sub_id]
|
|
152
|
-
@update_span = params[:update]
|
|
153
|
-
send("#{@form_element.to_s}_update", @object, @attribute)
|
|
154
|
-
@object.save
|
|
155
|
-
#puts "Requested #{request.format}"
|
|
156
|
-
respond_to do |format|
|
|
157
|
-
format.js { }
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
# :show shows one attribute (attribute) from a record (object).
|
|
162
|
-
# It includes the link to 'edit'
|
|
163
|
-
def show
|
|
164
|
-
@object = @Klass.find(params[:id])
|
|
165
|
-
@attribute = params[:attribute]
|
|
166
|
-
@form_element = params[:form_element]
|
|
167
|
-
close = params[:close] || false
|
|
168
|
-
if @form_element == "associated"
|
|
169
|
-
@sub_id = params[:sub_id]
|
|
170
|
-
if @sub_id.to_i > 0
|
|
171
|
-
@associated_record_id = @object.send(@attribute.to_s.singularize + "_ids").index(@sub_id.to_i)
|
|
172
|
-
@associated_record = @object.send(@attribute)[@associated_record_id]
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
@update_span = params[:update]
|
|
176
|
-
if @attribute.nil?
|
|
177
|
-
respond_to do |format|
|
|
178
|
-
@attributes = @object.inline_forms_attribute_list
|
|
179
|
-
if close
|
|
180
|
-
format.js { render :close }
|
|
181
|
-
else
|
|
182
|
-
format.js { }
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
else
|
|
186
|
-
respond_to do |format|
|
|
187
|
-
format.js { render :show_element }
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
# :destroy destroys the record, but also shows an undo link (with paper_trail)
|
|
193
|
-
def destroy
|
|
194
|
-
@update_span = params[:update]
|
|
195
|
-
@object = @Klass.find(params[:id])
|
|
196
|
-
@object.destroy
|
|
197
|
-
respond_to do |format|
|
|
198
|
-
format.js { render :show_undo }
|
|
199
|
-
end
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
# :revert works like undo.
|
|
203
|
-
# Thanks Ryan Bates: http://railscasts.com/episodes/255-undo-with-paper-trail
|
|
204
|
-
def revert
|
|
205
|
-
@update_span = params[:update]
|
|
206
|
-
@version = Version.find(params[:id])
|
|
207
|
-
@version.reify.save!
|
|
208
|
-
@object = @Klass.find(@version.item_id)
|
|
209
|
-
respond_to do |format|
|
|
210
|
-
format.js { render :close }
|
|
211
|
-
end
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
private
|
|
215
|
-
# Get the class from the controller name.
|
|
216
|
-
# CountryController < InlineFormsController, so what class are we?
|
|
217
|
-
def getKlass #:doc:
|
|
218
|
-
@Klass = self.controller_name.classify.constantize
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
end
|