active_scaffold 3.1.20 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/jquery/active_scaffold.js +4 -1
- data/app/assets/javascripts/prototype/active_scaffold.js +4 -1
- data/app/assets/stylesheets/{active_scaffold.scss~ → active_scaffold.css.scss} +5 -2
- data/app/assets/stylesheets/{active_scaffold_colors.scss → active_scaffold_colors.css.scss} +4 -0
- data/app/assets/stylesheets/active_scaffold_extensions.css.erb +2 -0
- data/app/assets/stylesheets/active_scaffold_images.css.scss +43 -0
- data/lib/active_scaffold/actions/core.rb +1 -0
- data/lib/active_scaffold/actions/nested.rb +0 -1
- data/lib/active_scaffold/extensions/action_view_rendering.rb +1 -1
- data/lib/active_scaffold/helpers/form_column_helpers.rb +1 -0
- data/lib/active_scaffold/version.rb +2 -2
- data/test/mock_app/.gitignore +2 -0
- metadata +86 -164
- data/app/assets/javascripts/active_scaffold.js.erb~ +0 -16
- data/app/assets/javascripts/jquery/active_scaffold.js~ +0 -1053
- data/app/assets/javascripts/jquery/draggable_lists.js~ +0 -27
- data/app/assets/javascripts/prototype/active_scaffold.js~ +0 -1037
- data/app/assets/stylesheets/active_scaffold.css.erb +0 -11
- data/app/assets/stylesheets/active_scaffold.css.erb~ +0 -11
- data/app/assets/stylesheets/active_scaffold.css.scss.erb~ +0 -1120
- data/app/assets/stylesheets/active_scaffold.css.scss~ +0 -11
- data/app/assets/stylesheets/active_scaffold.css~ +0 -11
- data/app/assets/stylesheets/active_scaffold_colors.css +0 -244
- data/app/assets/stylesheets/active_scaffold_colors.css.scss~ +0 -481
- data/app/assets/stylesheets/active_scaffold_default.css.erb +0 -47
- data/app/assets/stylesheets/active_scaffold_default.css.erb~ +0 -57
- data/app/assets/stylesheets/active_scaffold_default.css.scss~ +0 -1092
- data/app/assets/stylesheets/active_scaffold_default.css~ +0 -923
- data/app/assets/stylesheets/active_scaffold_layout.css~ +0 -922
- data/app/assets/stylesheets/blue-theme.css~ +0 -1150
- data/config/locales/es.yml~ +0 -120
- data/frontends/default/views/_action_group.html.erb~ +0 -24
- data/frontends/default/views/_base_form.html.erb~ +0 -42
- data/frontends/default/views/_form.html.erb~ +0 -26
- data/frontends/default/views/_form_association.html.erb~ +0 -19
- data/frontends/default/views/_form_association_footer.html.erb~ +0 -48
- data/frontends/default/views/_horizontal_subform.html.erb~ +0 -32
- data/frontends/default/views/_horizontal_subform_header.html.erb~ +0 -11
- data/frontends/default/views/_horizontal_subform_record.html.erb~ +0 -38
- data/frontends/default/views/_list_actions.html.erb~ +0 -15
- data/frontends/default/views/_list_inline_adapter.html.erb~ +0 -10
- data/frontends/default/views/_list_messages.html.erb~ +0 -30
- data/frontends/default/views/_list_pagination.html.erb~ +0 -11
- data/frontends/default/views/_list_pagination_links.html.erb~ +0 -0
- data/frontends/default/views/_list_with_header.html.erb~ +0 -36
- data/frontends/default/views/_render_field.js.erb~ +0 -23
- data/frontends/default/views/_row.html.erb~ +0 -6
- data/frontends/default/views/_show.html.erb~ +0 -8
- data/frontends/default/views/_update_form.html.erb~ +0 -6
- data/frontends/default/views/_vertical_subform.html.erb~ +0 -12
- data/frontends/default/views/add_existing.js.erb~ +0 -18
- data/frontends/default/views/add_existing_form.html.erb~ +0 -5
- data/frontends/default/views/create.html.erb~ +0 -5
- data/frontends/default/views/edit_associated.js.erb~ +0 -13
- data/frontends/default/views/on_create.js.erb~ +0 -45
- data/frontends/default/views/on_update.js.erb~ +0 -31
- data/frontends/default/views/render_field.js.erb~ +0 -1
- data/frontends/default/views/search.html.erb~ +0 -5
- data/frontends/default/views/show.html.erb~ +0 -5
- data/frontends/default/views/update.html.erb~ +0 -8
- data/frontends/default/views/update_column.js.erb~ +0 -16
- data/lib/active_scaffold.rb~ +0 -373
- data/lib/active_scaffold/actions/core.rb~ +0 -203
- data/lib/active_scaffold/actions/create.rb~ +0 -148
- data/lib/active_scaffold/actions/list.rb~ +0 -196
- data/lib/active_scaffold/actions/nested.rb~ +0 -247
- data/lib/active_scaffold/actions/search.rb~ +0 -49
- data/lib/active_scaffold/actions/subform.rb~ +0 -27
- data/lib/active_scaffold/actions/update.rb~ +0 -150
- data/lib/active_scaffold/attribute_params.rb~ +0 -203
- data/lib/active_scaffold/bridges/date_picker/helper.rb~ +0 -180
- data/lib/active_scaffold/bridges/record_select/helpers.rb~ +0 -86
- data/lib/active_scaffold/bridges/shared/date_bridge.rb~ +0 -209
- data/lib/active_scaffold/config/base.rb~ +0 -72
- data/lib/active_scaffold/config/list.rb~ +0 -195
- data/lib/active_scaffold/config/nested.rb~ +0 -41
- data/lib/active_scaffold/config/search.rb~ +0 -74
- data/lib/active_scaffold/constraints.rb~ +0 -186
- data/lib/active_scaffold/data_structures/action_columns.rb~ +0 -140
- data/lib/active_scaffold/data_structures/action_link.rb~ +0 -179
- data/lib/active_scaffold/data_structures/nested_info.rb~ +0 -147
- data/lib/active_scaffold/extensions/action_controller_rendering.rb~ +0 -22
- data/lib/active_scaffold/extensions/action_view_rendering.rb~ +0 -120
- data/lib/active_scaffold/extensions/active_association_reflection.rb~ +0 -22
- data/lib/active_scaffold/extensions/cache_association.rb~ +0 -12
- data/lib/active_scaffold/extensions/reverse_associations.rb~ +0 -64
- data/lib/active_scaffold/extensions/routing_mapper.rb~ +0 -48
- data/lib/active_scaffold/extensions/unsaved_associated.rb~ +0 -62
- data/lib/active_scaffold/finder.rb~ +0 -370
- data/lib/active_scaffold/helpers/controller_helpers.rb~ +0 -92
- data/lib/active_scaffold/helpers/form_column_helpers.rb~ +0 -320
- data/lib/active_scaffold/helpers/id_helpers.rb~ +0 -123
- data/lib/active_scaffold/helpers/list_column_helpers.rb~ +0 -370
- data/lib/active_scaffold/helpers/search_column_helpers.rb~ +0 -263
- data/lib/active_scaffold/helpers/view_helpers.rb~ +0 -350
@@ -1,247 +0,0 @@
|
|
1
|
-
module ActiveScaffold::Actions
|
2
|
-
# The Nested module basically handles automatically linking controllers together. It does this by creating column links with the right parameters, and by providing any supporting systems (like a /:controller/nested action for returning associated scaffolds).
|
3
|
-
module Nested
|
4
|
-
|
5
|
-
def self.included(base)
|
6
|
-
super
|
7
|
-
base.module_eval do
|
8
|
-
#before_filter :register_constraints_with_action_columns
|
9
|
-
prepend_before_filter :set_nested
|
10
|
-
before_filter :configure_nested
|
11
|
-
debugger
|
12
|
-
include ActiveScaffold::Actions::Nested::ChildMethods if active_scaffold_config.model.reflect_on_all_associations.any? {|a| a.macro == :has_and_belongs_to_many}
|
13
|
-
end
|
14
|
-
base.before_filter :include_habtm_actions
|
15
|
-
base.helper_method :nested
|
16
|
-
base.helper_method :nested_parent_record
|
17
|
-
end
|
18
|
-
|
19
|
-
protected
|
20
|
-
def nested
|
21
|
-
@nested
|
22
|
-
end
|
23
|
-
|
24
|
-
def nested?
|
25
|
-
!nested.nil?
|
26
|
-
end
|
27
|
-
|
28
|
-
def set_nested
|
29
|
-
if params[:parent_scaffold] && (params[:association] || params[:named_scope])
|
30
|
-
@nested = ActiveScaffold::DataStructures::NestedInfo.get(active_scaffold_config.model, params)
|
31
|
-
unless @nested.nil?
|
32
|
-
active_scaffold_constraints[:id] = params[:id] if @nested.belongs_to?
|
33
|
-
register_constraints_with_action_columns(@nested.constrained_fields, active_scaffold_config.list.hide_nested_column ? [] : [:list])
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def configure_nested
|
39
|
-
if nested?
|
40
|
-
active_scaffold_session_storage[:list][:label] = if nested.belongs_to?
|
41
|
-
as_(:nested_of_model, :nested_model => active_scaffold_config.model.model_name.human, :parent_model => nested_parent_record.to_label)
|
42
|
-
else
|
43
|
-
as_(:nested_for_model, :nested_model => active_scaffold_config.list.label, :parent_model => nested_parent_record.to_label)
|
44
|
-
end
|
45
|
-
if nested.sorted?
|
46
|
-
active_scaffold_config.list.user.nested_default_sorting = {:table_name => active_scaffold_config.model.model_name, :default_sorting => nested.default_sorting}
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def nested_authorized?(record = nil)
|
52
|
-
true
|
53
|
-
end
|
54
|
-
|
55
|
-
def include_habtm_actions
|
56
|
-
if nested?
|
57
|
-
if nested.habtm?
|
58
|
-
# Production mode is ok with adding a link everytime the scaffold is nested - we ar not ok with that.
|
59
|
-
active_scaffold_config.action_links.add('new_existing', :label => :add_existing, :type => :collection, :security_method => :add_existing_authorized?) unless active_scaffold_config.action_links['new_existing']
|
60
|
-
if active_scaffold_config.nested.shallow_delete
|
61
|
-
active_scaffold_config.action_links.add('destroy_existing', :label => :remove, :type => :member, :confirm => :are_you_sure_to_delete, :method => :delete, :position => false, :security_method => :delete_existing_authorized?) unless active_scaffold_config.action_links['destroy_existing']
|
62
|
-
if active_scaffold_config.actions.include?(:delete)
|
63
|
-
active_scaffold_config.action_links.delete("delete") if active_scaffold_config.action_links['delete']
|
64
|
-
end
|
65
|
-
end
|
66
|
-
else
|
67
|
-
# Production mode is caching this link into a non nested scaffold
|
68
|
-
active_scaffold_config.action_links.delete('new_existing') if active_scaffold_config.action_links['new_existing']
|
69
|
-
|
70
|
-
if active_scaffold_config.nested.shallow_delete
|
71
|
-
active_scaffold_config.action_links.delete("destroy_existing") if active_scaffold_config.action_links['destroy_existing']
|
72
|
-
if active_scaffold_config.actions.include?(:delete)
|
73
|
-
active_scaffold_config.action_links.add(ActiveScaffold::Config::Delete.link) unless active_scaffold_config.action_links['delete']
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def beginning_of_chain
|
81
|
-
if nested? && nested.association && !nested.association.belongs_to?
|
82
|
-
if nested.association.collection?
|
83
|
-
nested.parent_scope.send(nested.association.name)
|
84
|
-
elsif nested.child_association.belongs_to?
|
85
|
-
active_scaffold_config.model.where(nested.child_association.foreign_key => nested.parent_scope)
|
86
|
-
end
|
87
|
-
elsif nested? && nested.scope
|
88
|
-
nested.parent_scope.send(nested.scope)
|
89
|
-
else
|
90
|
-
active_scaffold_config.model
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def nested_parent_record(crud = :read)
|
95
|
-
@nested_parent_record ||= find_if_allowed(nested.parent_id, crud, nested.parent_model)
|
96
|
-
end
|
97
|
-
|
98
|
-
def create_association_with_parent(record)
|
99
|
-
if nested?
|
100
|
-
if (nested.belongs_to? || nested.has_one? || nested.habtm?) && nested.child_association
|
101
|
-
parent = nested_parent_record(:read)
|
102
|
-
case nested.child_association.macro
|
103
|
-
when :has_one
|
104
|
-
record.send("#{nested.child_association.name}=", parent)
|
105
|
-
when :belongs_to
|
106
|
-
record.send("#{nested.child_association.name}=", parent)
|
107
|
-
when :has_many, :has_and_belongs_to_many
|
108
|
-
record.send("#{nested.child_association.name}").send(:<<, parent)
|
109
|
-
end unless parent.nil?
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
private
|
115
|
-
def nested_formats
|
116
|
-
(default_formats + active_scaffold_config.formats + active_scaffold_config.nested.formats).uniq
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
module ActiveScaffold::Actions::Nested
|
122
|
-
module ChildMethods
|
123
|
-
|
124
|
-
def self.included(base)
|
125
|
-
super
|
126
|
-
end
|
127
|
-
|
128
|
-
def new_existing
|
129
|
-
do_new
|
130
|
-
respond_to_action(:new_existing)
|
131
|
-
end
|
132
|
-
|
133
|
-
def add_existing
|
134
|
-
do_add_existing
|
135
|
-
respond_to_action(:add_existing)
|
136
|
-
end
|
137
|
-
|
138
|
-
def destroy_existing
|
139
|
-
return redirect_to(params.merge(:action => :delete)) if request.get?
|
140
|
-
do_destroy_existing
|
141
|
-
respond_to_action(:destroy_existing)
|
142
|
-
end
|
143
|
-
|
144
|
-
protected
|
145
|
-
def new_existing_respond_to_html
|
146
|
-
if successful?
|
147
|
-
render(:action => 'add_existing_form')
|
148
|
-
else
|
149
|
-
return_to_main
|
150
|
-
end
|
151
|
-
end
|
152
|
-
def new_existing_respond_to_js
|
153
|
-
render(:partial => 'add_existing_form')
|
154
|
-
end
|
155
|
-
def add_existing_respond_to_html
|
156
|
-
if successful?
|
157
|
-
flash[:info] = as_(:created_model, :model => @record.to_label)
|
158
|
-
return_to_main
|
159
|
-
else
|
160
|
-
render(:action => 'add_existing_form')
|
161
|
-
end
|
162
|
-
end
|
163
|
-
def add_existing_respond_to_js
|
164
|
-
if successful?
|
165
|
-
render :action => 'add_existing'
|
166
|
-
else
|
167
|
-
render :action => 'form_messages'
|
168
|
-
end
|
169
|
-
end
|
170
|
-
def add_existing_respond_to_xml
|
171
|
-
render :xml => response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status
|
172
|
-
end
|
173
|
-
def add_existing_respond_to_json
|
174
|
-
render :text => response_object.to_json(:only => active_scaffold_config.list.columns.names), :content_type => Mime::JSON, :status => response_status
|
175
|
-
end
|
176
|
-
def add_existing_respond_to_yaml
|
177
|
-
render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status
|
178
|
-
end
|
179
|
-
def destroy_existing_respond_to_html
|
180
|
-
flash[:info] = as_(:deleted_model, :model => @record.to_label)
|
181
|
-
return_to_main
|
182
|
-
end
|
183
|
-
|
184
|
-
def destroy_existing_respond_to_js
|
185
|
-
render(:action => 'destroy')
|
186
|
-
end
|
187
|
-
|
188
|
-
def destroy_existing_respond_to_xml
|
189
|
-
render :xml => successful? ? "" : response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status
|
190
|
-
end
|
191
|
-
|
192
|
-
def destroy_existing_respond_to_json
|
193
|
-
render :text => successful? ? "" : response_object.to_json(:only => active_scaffold_config.list.columns.names), :content_type => Mime::JSON, :status => response_status
|
194
|
-
end
|
195
|
-
|
196
|
-
def destroy_existing_respond_to_yaml
|
197
|
-
render :text => successful? ? "" : Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status
|
198
|
-
end
|
199
|
-
|
200
|
-
def add_existing_authorized?(record = nil)
|
201
|
-
true
|
202
|
-
end
|
203
|
-
def delete_existing_authorized?(record = nil)
|
204
|
-
true
|
205
|
-
end
|
206
|
-
|
207
|
-
def after_create_save(record)
|
208
|
-
if params[:association_macro] == :has_and_belongs_to_many
|
209
|
-
params[:associated_id] = record
|
210
|
-
do_add_existing
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
# The actual "add_existing" algorithm
|
215
|
-
def do_add_existing
|
216
|
-
parent_record = nested_parent_record(:update)
|
217
|
-
@record = active_scaffold_config.model.find(params[:associated_id])
|
218
|
-
if parent_record && @record
|
219
|
-
parent_record.send(nested.association.name) << @record
|
220
|
-
parent_record.save
|
221
|
-
else
|
222
|
-
false
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
def do_destroy_existing
|
227
|
-
if active_scaffold_config.nested.shallow_delete
|
228
|
-
@record = nested_parent_record(:update)
|
229
|
-
collection = @record.send(nested.association.name)
|
230
|
-
assoc_record = collection.find(params[:id])
|
231
|
-
collection.delete(assoc_record)
|
232
|
-
else
|
233
|
-
do_destroy
|
234
|
-
end
|
235
|
-
end
|
236
|
-
private
|
237
|
-
def new_existing_formats
|
238
|
-
(default_formats + active_scaffold_config.formats).uniq
|
239
|
-
end
|
240
|
-
def add_existing_formats
|
241
|
-
(default_formats + active_scaffold_config.formats).uniq
|
242
|
-
end
|
243
|
-
def destroy_existing_formats
|
244
|
-
(default_formats + active_scaffold_config.formats).uniq
|
245
|
-
end
|
246
|
-
end
|
247
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module ActiveScaffold::Actions
|
2
|
-
module Search
|
3
|
-
include ActiveScaffold::Actions::CommonSearch
|
4
|
-
def self.included(base)
|
5
|
-
base.before_filter :search_authorized_filter, :only => :show_search
|
6
|
-
base.before_filter :store_search_params_into_session, :only => [:index]
|
7
|
-
base.before_filter :do_search, :only => [:index]
|
8
|
-
base.helper_method :search_params
|
9
|
-
end
|
10
|
-
|
11
|
-
def show_search
|
12
|
-
respond_to_action(:search)
|
13
|
-
end
|
14
|
-
|
15
|
-
protected
|
16
|
-
def search_respond_to_html
|
17
|
-
render(:action => "search")
|
18
|
-
end
|
19
|
-
def search_respond_to_js
|
20
|
-
render(:partial => "search")
|
21
|
-
end
|
22
|
-
def do_search
|
23
|
-
query = search_params.to_s.strip rescue ''
|
24
|
-
unless query.empty?
|
25
|
-
columns = active_scaffold_config.search.columns
|
26
|
-
text_search = active_scaffold_config.search.text_search
|
27
|
-
query = query.split(active_scaffold_config.search.split_terms) if active_scaffold_config.search.split_terms
|
28
|
-
debugger
|
29
|
-
search_conditions = self.class.create_conditions_for_columns(query, columns, text_search)
|
30
|
-
self.active_scaffold_conditions = merge_conditions(self.active_scaffold_conditions, search_conditions)
|
31
|
-
@filtered = !search_conditions.blank?
|
32
|
-
|
33
|
-
includes_for_search_columns = columns.collect{ |column| column.includes}.flatten.uniq.compact
|
34
|
-
self.active_scaffold_includes.concat includes_for_search_columns
|
35
|
-
|
36
|
-
active_scaffold_config.list.user.page = nil
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
def search_authorized_filter
|
42
|
-
link = active_scaffold_config.search.link || active_scaffold_config.search.class.link
|
43
|
-
raise ActiveScaffold::ActionNotAllowed unless self.send(link.security_method)
|
44
|
-
end
|
45
|
-
def search_formats
|
46
|
-
(default_formats + active_scaffold_config.formats + active_scaffold_config.search.formats).uniq
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module ActiveScaffold::Actions
|
2
|
-
module Subform
|
3
|
-
def edit_associated
|
4
|
-
do_edit_associated
|
5
|
-
render :action => 'edit_associated.js'
|
6
|
-
end
|
7
|
-
|
8
|
-
protected
|
9
|
-
|
10
|
-
def do_edit_associated
|
11
|
-
@parent_record = params[:id].nil? ? new_model : find_if_allowed(params[:id], :update)
|
12
|
-
@column = active_scaffold_config.columns[params[:association]]
|
13
|
-
|
14
|
-
# NOTE: we don't check whether the user is allowed to update this record, because if not, we'll still let them associate the record. we'll just refuse to do more than associate, is all.
|
15
|
-
@record = @column.association.klass.find(params[:associated_id]) if params[:associated_id]
|
16
|
-
@record ||= if column.singular_association?
|
17
|
-
parent_record.send("build_#{column.name}".to_sym)
|
18
|
-
else
|
19
|
-
parent_record.send(column.name).buildbuild_associated(column, parent_record)
|
20
|
-
end
|
21
|
-
|
22
|
-
@scope = "[#{@column.name}]"
|
23
|
-
@scope += (@record.new_record?) ? "[#{(Time.now.to_f*1000).to_i.to_s}]" : "[#{@record.id}]" if @column.plural_association?
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
@@ -1,150 +0,0 @@
|
|
1
|
-
module ActiveScaffold::Actions
|
2
|
-
module Update
|
3
|
-
def self.included(base)
|
4
|
-
base.before_filter :update_authorized_filter, :only => [:edit, :update]
|
5
|
-
base.helper_method :update_refresh_list?
|
6
|
-
end
|
7
|
-
|
8
|
-
def edit
|
9
|
-
do_edit
|
10
|
-
respond_to_action(:edit)
|
11
|
-
end
|
12
|
-
|
13
|
-
def update
|
14
|
-
do_update
|
15
|
-
respond_to_action(:update)
|
16
|
-
end
|
17
|
-
|
18
|
-
# for inline (inlist) editing
|
19
|
-
def update_column
|
20
|
-
do_update_column
|
21
|
-
@column_span_id = params[:editor_id] || params[:editorId]
|
22
|
-
end
|
23
|
-
|
24
|
-
protected
|
25
|
-
def edit_respond_to_html
|
26
|
-
if successful?
|
27
|
-
render(:action => 'update')
|
28
|
-
else
|
29
|
-
return_to_main
|
30
|
-
end
|
31
|
-
end
|
32
|
-
def edit_respond_to_js
|
33
|
-
render(:partial => 'update_form')
|
34
|
-
end
|
35
|
-
def update_respond_to_html
|
36
|
-
if params[:iframe]=='true' # was this an iframe post ?
|
37
|
-
responds_to_parent do
|
38
|
-
render :action => 'on_update.js', :layout => false
|
39
|
-
end
|
40
|
-
else # just a regular post
|
41
|
-
if successful?
|
42
|
-
flash[:info] = as_(:updated_model, :model => @record.to_label)
|
43
|
-
return_to_main
|
44
|
-
else
|
45
|
-
render(:action => 'update')
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
def update_respond_to_js
|
50
|
-
if successful? && update_refresh_list? && !render_parent?
|
51
|
-
do_search if respond_to? :do_search
|
52
|
-
do_list
|
53
|
-
end
|
54
|
-
render :action => 'on_update'
|
55
|
-
end
|
56
|
-
def update_respond_to_xml
|
57
|
-
render :xml => response_object.to_xml(:only => active_scaffold_config.update.columns.names), :content_type => Mime::XML, :status => response_status
|
58
|
-
end
|
59
|
-
def update_respond_to_json
|
60
|
-
render :text => response_object.to_json(:only => active_scaffold_config.update.columns.names), :content_type => Mime::JSON, :status => response_status
|
61
|
-
end
|
62
|
-
def update_respond_to_yaml
|
63
|
-
render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.update.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status
|
64
|
-
end
|
65
|
-
# A simple method to find and prepare a record for editing
|
66
|
-
# May be overridden to customize the record (set default values, etc.)
|
67
|
-
def do_edit
|
68
|
-
register_constraints_with_action_columns(nested.constrained_fields, active_scaffold_config.update.hide_nested_column ? [] : [:update]) if nested?
|
69
|
-
@record = find_if_allowed(params[:id], :update)
|
70
|
-
end
|
71
|
-
|
72
|
-
# A complex method to update a record. The complexity comes from the support for subforms, and saving associated records.
|
73
|
-
# If you want to customize this algorithm, consider using the +before_update_save+ callback
|
74
|
-
def do_update
|
75
|
-
do_edit
|
76
|
-
update_save
|
77
|
-
end
|
78
|
-
|
79
|
-
def update_save(options = {})
|
80
|
-
begin
|
81
|
-
active_scaffold_config.model.transaction do
|
82
|
-
@record = update_record_from_params(@record, active_scaffold_config.update.columns, params[:record]) unless options[:no_record_param_update]
|
83
|
-
before_update_save(@record)
|
84
|
-
self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit
|
85
|
-
if successful?
|
86
|
-
@record.save! and @record.save_associated!
|
87
|
-
after_update_save(@record)
|
88
|
-
else
|
89
|
-
# some associations such as habtm are saved before saved is called on parent object
|
90
|
-
# we have to revert these changes if validation fails
|
91
|
-
raise ActiveRecord::Rollback, "don't save habtm associations unless record is valid"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
rescue ActiveRecord::RecordInvalid
|
95
|
-
self.successful = false
|
96
|
-
flash[:error] = $!.message
|
97
|
-
rescue ActiveRecord::StaleObjectError
|
98
|
-
@record.errors.add(:base, as_(:version_inconsistency))
|
99
|
-
self.successful = false
|
100
|
-
rescue ActiveRecord::RecordNotSaved
|
101
|
-
@record.errors.add(:base, as_(:record_not_saved)) if @record.errors.empty?
|
102
|
-
self.successful = false
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def do_update_column
|
107
|
-
@record = active_scaffold_config.model.find(params[:id])
|
108
|
-
if @record.authorized_for?(:crud_type => :update, :column => params[:column])
|
109
|
-
column = active_scaffold_config.columns[params[:column].to_sym]
|
110
|
-
params[:value] ||= @record.column_for_attribute(params[:column]).default unless @record.column_for_attribute(params[:column]).nil? || @record.column_for_attribute(params[:column]).null
|
111
|
-
unless column.nil?
|
112
|
-
params[:value] = column_value_from_param_value(@record, column, params[:value])
|
113
|
-
params[:value] = [] if params[:value].nil? && column.form_ui && column.plural_association?
|
114
|
-
end
|
115
|
-
@record.send("#{params[:column]}=", params[:value])
|
116
|
-
before_update_save(@record)
|
117
|
-
@record.save
|
118
|
-
after_update_save(@record)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
# override this method if you want to inject data in the record (or its associated objects) before the save
|
123
|
-
def before_update_save(record); end
|
124
|
-
|
125
|
-
# override this method if you want to do something after the save
|
126
|
-
def after_update_save(record); end
|
127
|
-
|
128
|
-
# should we refresh whole list after update operation
|
129
|
-
def update_refresh_list?
|
130
|
-
active_scaffold_config.update.refresh_list
|
131
|
-
end
|
132
|
-
|
133
|
-
# The default security delegates to ActiveRecordPermissions.
|
134
|
-
# You may override the method to customize.
|
135
|
-
def update_authorized?(record = nil)
|
136
|
-
(!nested? || !nested.readonly?) && authorized_for?(:crud_type => :update)
|
137
|
-
end
|
138
|
-
private
|
139
|
-
def update_authorized_filter
|
140
|
-
link = active_scaffold_config.update.link || active_scaffold_config.update.class.link
|
141
|
-
raise ActiveScaffold::ActionNotAllowed unless self.send(link.security_method)
|
142
|
-
end
|
143
|
-
def edit_formats
|
144
|
-
(default_formats + active_scaffold_config.formats).uniq
|
145
|
-
end
|
146
|
-
def update_formats
|
147
|
-
(default_formats + active_scaffold_config.formats + active_scaffold_config.update.formats).uniq
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|