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,203 +0,0 @@
|
|
1
|
-
module ActiveScaffold::Actions
|
2
|
-
module Core
|
3
|
-
def self.included(base)
|
4
|
-
base.class_eval do
|
5
|
-
after_filter :clean_up_session
|
6
|
-
after_filter :clear_flashes
|
7
|
-
end
|
8
|
-
base.helper_method :nested?
|
9
|
-
base.helper_method :beginning_of_chain
|
10
|
-
base.helper_method :new_model
|
11
|
-
end
|
12
|
-
def render_field
|
13
|
-
if params[:in_place_editing]
|
14
|
-
render_field_for_inplace_editing
|
15
|
-
else
|
16
|
-
render_field_for_update_columns
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
protected
|
21
|
-
def clean_up_session
|
22
|
-
backup = session.reject! { |k, v| k.is_a?(String) && v != active_scaffold_session_storage && k.start_with?('as:')}
|
23
|
-
end
|
24
|
-
|
25
|
-
def nested?
|
26
|
-
false
|
27
|
-
end
|
28
|
-
|
29
|
-
def render_field_for_inplace_editing
|
30
|
-
register_constraints_with_action_columns(nested.constrained_fields, active_scaffold_config.update.hide_nested_column ? [] : [:update]) if nested?
|
31
|
-
@record = find_if_allowed(params[:id], :update)
|
32
|
-
render :inline => "<%= active_scaffold_input_for(active_scaffold_config.columns[params[:update_column].to_sym]) %>"
|
33
|
-
end
|
34
|
-
|
35
|
-
def render_field_for_update_columns
|
36
|
-
column = active_scaffold_config.columns[params[:column]]
|
37
|
-
unless column.nil?
|
38
|
-
@source_id = params.delete(:source_id)
|
39
|
-
@columns = column.update_columns
|
40
|
-
@scope = params[:scope]
|
41
|
-
|
42
|
-
if column.send_form_on_update_column
|
43
|
-
hash = if @scope
|
44
|
-
@scope.gsub('[','').split(']').inject(params[:record]) do |hash, index|
|
45
|
-
hash[index]
|
46
|
-
end
|
47
|
-
else
|
48
|
-
params[:record]
|
49
|
-
end
|
50
|
-
@record = hash[:id] ? find_if_allowed(hash[:id], :update) : new_model
|
51
|
-
@record = update_record_from_params(@record, active_scaffold_config.send(@scope ? :subform : (params[:id] ? :update : :create)).columns, hash)
|
52
|
-
else
|
53
|
-
@record = new_model
|
54
|
-
value = column_value_from_param_value(@record, column, params[:value])
|
55
|
-
@record.send "#{column.name}=", value
|
56
|
-
end
|
57
|
-
|
58
|
-
after_render_field(@record, column)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# override this method if you want to do something after render_field
|
63
|
-
def after_render_field(record, column); end
|
64
|
-
|
65
|
-
def authorized_for?(options = {})
|
66
|
-
active_scaffold_config.model.authorized_for?(options)
|
67
|
-
end
|
68
|
-
|
69
|
-
def clear_flashes
|
70
|
-
if request.xhr?
|
71
|
-
flash.keys.each do |flash_key|
|
72
|
-
flash[flash_key] = nil
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def marked_records
|
78
|
-
active_scaffold_session_storage[:marked_records] ||= Set.new
|
79
|
-
end
|
80
|
-
|
81
|
-
def default_formats
|
82
|
-
[:html, :js, :json, :xml, :yaml]
|
83
|
-
end
|
84
|
-
# Returns true if the client accepts one of the MIME types passed to it
|
85
|
-
# ex: accepts? :html, :xml
|
86
|
-
def accepts?(*types)
|
87
|
-
for priority in request.accepts.compact
|
88
|
-
if priority == Mime::ALL
|
89
|
-
# Because IE always sends */* in the accepts header and we assume
|
90
|
-
# that if you really wanted XML or something else you would say so
|
91
|
-
# explicitly, we will assume */* to only ask for :html
|
92
|
-
return types.include?(:html)
|
93
|
-
elsif types.include?(priority.to_sym)
|
94
|
-
return true
|
95
|
-
end
|
96
|
-
end
|
97
|
-
false
|
98
|
-
end
|
99
|
-
|
100
|
-
def response_status
|
101
|
-
if successful?
|
102
|
-
action_name == 'create' ? 201 : 200
|
103
|
-
else
|
104
|
-
422
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
# API response object that will be converted to XML/YAML/JSON using to_xxx
|
109
|
-
def response_object
|
110
|
-
@response_object = successful? ? (@record || @records) : @record.errors
|
111
|
-
end
|
112
|
-
|
113
|
-
# Success is the existence of certain variables and the absence of errors (when applicable).
|
114
|
-
# Success can also be defined.
|
115
|
-
def successful?
|
116
|
-
if @successful.nil?
|
117
|
-
@records or (@record and @record.errors.count == 0 and @record.no_errors_in_associated?)
|
118
|
-
else
|
119
|
-
@successful
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def successful=(val)
|
124
|
-
@successful = (val) ? true : false
|
125
|
-
end
|
126
|
-
|
127
|
-
# Redirect to the main page (override if the ActiveScaffold is used as a component on another controllers page) for Javascript degradation
|
128
|
-
def return_to_main
|
129
|
-
redirect_to main_path_to_return
|
130
|
-
end
|
131
|
-
|
132
|
-
# Override this method on your controller to define conditions to be used when querying a recordset (e.g. for List). The return of this method should be any format compatible with the :conditions clause of ActiveRecord::Base's find.
|
133
|
-
def conditions_for_collection
|
134
|
-
end
|
135
|
-
|
136
|
-
# Override this method on your controller to define joins to be used when querying a recordset (e.g. for List). The return of this method should be any format compatible with the :joins clause of ActiveRecord::Base's find.
|
137
|
-
def joins_for_collection
|
138
|
-
end
|
139
|
-
|
140
|
-
# Override this method on your controller to provide custom finder options to the find() call. The return of this method should be a hash.
|
141
|
-
def custom_finder_options
|
142
|
-
{}
|
143
|
-
end
|
144
|
-
|
145
|
-
#Overide this method on your controller to provide model with named scopes
|
146
|
-
def beginning_of_chain
|
147
|
-
active_scaffold_config.model
|
148
|
-
end
|
149
|
-
|
150
|
-
# Builds search conditions by search params for column names. This allows urls like "contacts/list?company_id=5".
|
151
|
-
def conditions_from_params
|
152
|
-
conditions = nil
|
153
|
-
params.reject {|key, value| [:controller, :action, :id, :page, :sort, :sort_direction].include?(key.to_sym)}.each do |key, value|
|
154
|
-
next unless active_scaffold_config.model.column_names.include?(key)
|
155
|
-
if value.is_a?(Array)
|
156
|
-
conditions = merge_conditions(conditions, ["#{active_scaffold_config.model.table_name}.#{key.to_s} in (?)", value])
|
157
|
-
else
|
158
|
-
conditions = merge_conditions(conditions, ["#{active_scaffold_config.model.table_name}.#{key.to_s} = ?", value])
|
159
|
-
end
|
160
|
-
end
|
161
|
-
conditions
|
162
|
-
end
|
163
|
-
|
164
|
-
def new_model
|
165
|
-
model = beginning_of_chain
|
166
|
-
if model.columns_hash[model.inheritance_column]
|
167
|
-
build_options = {model.inheritance_column.to_sym => active_scaffold_config.model_id} if nested? && nested.association && nested.association.collection?
|
168
|
-
params = self.params # in new action inheritance_column must be in params
|
169
|
-
params = params[:record] || {} unless params[model.inheritance_column] # in create action must be inside record key
|
170
|
-
model = params.delete(model.inheritance_column).camelize.constantize if params[model.inheritance_column]
|
171
|
-
end
|
172
|
-
model.respond_to?(:build) ? model.build(build_options || {}) : model.new
|
173
|
-
end
|
174
|
-
|
175
|
-
private
|
176
|
-
def respond_to_action(action)
|
177
|
-
respond_to do |type|
|
178
|
-
action_formats.each do |format|
|
179
|
-
type.send(format){ send("#{action}_respond_to_#{format}") }
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
def action_formats
|
185
|
-
@action_formats ||= if respond_to? "#{action_name}_formats", true
|
186
|
-
send("#{action_name}_formats")
|
187
|
-
else
|
188
|
-
(default_formats + active_scaffold_config.formats).uniq
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
def response_code_for_rescue(exception)
|
193
|
-
case exception
|
194
|
-
when ActiveScaffold::RecordNotAllowed
|
195
|
-
"403 Record Not Allowed"
|
196
|
-
when ActiveScaffold::ActionNotAllowed
|
197
|
-
"403 Action Not Allowed"
|
198
|
-
else
|
199
|
-
super
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
@@ -1,148 +0,0 @@
|
|
1
|
-
module ActiveScaffold::Actions
|
2
|
-
module Create
|
3
|
-
def self.included(base)
|
4
|
-
base.before_filter :create_authorized_filter, :only => [:new, :create]
|
5
|
-
end
|
6
|
-
|
7
|
-
def new
|
8
|
-
do_new
|
9
|
-
respond_to_action(:new)
|
10
|
-
end
|
11
|
-
|
12
|
-
def create
|
13
|
-
do_create
|
14
|
-
respond_to_action(:create)
|
15
|
-
end
|
16
|
-
|
17
|
-
protected
|
18
|
-
def response_location
|
19
|
-
url_for(params_for(:action => "show", :id => @record.id)) if successful?
|
20
|
-
end
|
21
|
-
|
22
|
-
def new_respond_to_html
|
23
|
-
if successful?
|
24
|
-
render(:action => 'create')
|
25
|
-
else
|
26
|
-
return_to_main
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def new_respond_to_js
|
31
|
-
render(:partial => 'create_form')
|
32
|
-
end
|
33
|
-
|
34
|
-
def create_respond_to_html
|
35
|
-
if params[:iframe]=='true' # was this an iframe post ?
|
36
|
-
responds_to_parent do
|
37
|
-
render :action => 'on_create.js', :layout => false
|
38
|
-
end
|
39
|
-
else
|
40
|
-
if successful?
|
41
|
-
flash[:info] = as_(:created_model, :model => @record.to_label)
|
42
|
-
if action = active_scaffold_config.create.action_after_create
|
43
|
-
redirect_to params_for(:action => action, :id => @record.id)
|
44
|
-
elsif active_scaffold_config.create.persistent
|
45
|
-
redirect_to params_for(:action => "new")
|
46
|
-
else
|
47
|
-
return_to_main
|
48
|
-
end
|
49
|
-
else
|
50
|
-
if !nested? && active_scaffold_config.actions.include?(:list) && active_scaffold_config.list.always_show_create
|
51
|
-
do_list
|
52
|
-
render(:action => 'list')
|
53
|
-
else
|
54
|
-
render(:action => 'create')
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def create_respond_to_js
|
61
|
-
if successful? && active_scaffold_config.create.refresh_list && !render_parent?
|
62
|
-
do_search if respond_to? :do_search
|
63
|
-
do_list
|
64
|
-
end
|
65
|
-
render :action => 'on_create'
|
66
|
-
end
|
67
|
-
|
68
|
-
def create_respond_to_xml
|
69
|
-
render :xml => response_object.to_xml(:only => active_scaffold_config.create.columns.names), :content_type => Mime::XML, :status => response_status, :location => response_location
|
70
|
-
end
|
71
|
-
|
72
|
-
def create_respond_to_json
|
73
|
-
render :text => response_object.to_json(:only => active_scaffold_config.create.columns.names), :content_type => Mime::JSON, :status => response_status, :location => response_location
|
74
|
-
end
|
75
|
-
|
76
|
-
def create_respond_to_yaml
|
77
|
-
render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.create.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status, :location => response_location
|
78
|
-
end
|
79
|
-
|
80
|
-
# A simple method to find and prepare an example new record for the form
|
81
|
-
# May be overridden to customize the behavior (add default values, for instance)
|
82
|
-
def do_new
|
83
|
-
@record = new_model
|
84
|
-
apply_constraints_to_record(@record)
|
85
|
-
if nested?
|
86
|
-
create_association_with_parent(@record)
|
87
|
-
register_constraints_with_action_columns(nested.constrained_fields)
|
88
|
-
end
|
89
|
-
@record
|
90
|
-
end
|
91
|
-
|
92
|
-
# A somewhat complex method to actually create a new record. The complexity is from support for subforms and associated records.
|
93
|
-
# If you want to customize this behavior, consider using the +before_create_save+ and +after_create_save+ callbacks.
|
94
|
-
def do_create
|
95
|
-
begin
|
96
|
-
active_scaffold_config.model.transaction do
|
97
|
-
@record = update_record_from_params(new_model, active_scaffold_config.create.columns, params[:record])
|
98
|
-
apply_constraints_to_record(@record, :allow_autosave => true)
|
99
|
-
if nested?
|
100
|
-
create_association_with_parent(@record)
|
101
|
-
register_constraints_with_action_columns(nested.constrained_fields)
|
102
|
-
end
|
103
|
-
create_save
|
104
|
-
end
|
105
|
-
rescue ActiveRecord::RecordInvalid
|
106
|
-
self.successful = false
|
107
|
-
flash[:error] = $!.messages
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def create_save
|
112
|
-
before_create_save(@record)
|
113
|
-
self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit
|
114
|
-
if successful?
|
115
|
-
@record.save! and @record.save_associated!
|
116
|
-
after_create_save(@record)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
# override this method if you want to inject data in the record (or its associated objects) before the save
|
121
|
-
def before_create_save(record); end
|
122
|
-
|
123
|
-
# override this method if you want to do something after the save
|
124
|
-
def after_create_save(record); end
|
125
|
-
|
126
|
-
# The default security delegates to ActiveRecordPermissions.
|
127
|
-
# You may override the method to customize.
|
128
|
-
|
129
|
-
def create_ignore?
|
130
|
-
nested? && active_scaffold_config.list.always_show_create
|
131
|
-
end
|
132
|
-
|
133
|
-
def create_authorized?
|
134
|
-
(!nested? || !nested.readonly?) && authorized_for?(:crud_type => :create)
|
135
|
-
end
|
136
|
-
private
|
137
|
-
def create_authorized_filter
|
138
|
-
link = active_scaffold_config.create.link || active_scaffold_config.create.class.link
|
139
|
-
raise ActiveScaffold::ActionNotAllowed unless self.send(link.security_method)
|
140
|
-
end
|
141
|
-
def new_formats
|
142
|
-
(default_formats + active_scaffold_config.formats).uniq
|
143
|
-
end
|
144
|
-
def create_formats
|
145
|
-
(default_formats + active_scaffold_config.formats + active_scaffold_config.create.formats).uniq
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
@@ -1,196 +0,0 @@
|
|
1
|
-
module ActiveScaffold::Actions
|
2
|
-
module List
|
3
|
-
def self.included(base)
|
4
|
-
base.before_filter :list_authorized_filter, :only => [:index, :row]
|
5
|
-
base.helper_method :list_columns
|
6
|
-
end
|
7
|
-
|
8
|
-
def index
|
9
|
-
list
|
10
|
-
end
|
11
|
-
|
12
|
-
# get just a single row
|
13
|
-
def row
|
14
|
-
@record = find_if_allowed(params[:id], :read)
|
15
|
-
respond_to_action(:row)
|
16
|
-
end
|
17
|
-
|
18
|
-
def list
|
19
|
-
do_list
|
20
|
-
@nested_auto_open = active_scaffold_config.list.nested_auto_open
|
21
|
-
respond_to_action(:list)
|
22
|
-
end
|
23
|
-
|
24
|
-
protected
|
25
|
-
def list_respond_to_html
|
26
|
-
if params.delete(:embedded)
|
27
|
-
render :action => 'list', :layout => false
|
28
|
-
else
|
29
|
-
render :action => 'list'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
def list_respond_to_js
|
33
|
-
if params[:adapter]
|
34
|
-
render(:partial => 'list_with_header')
|
35
|
-
elsif params[:embedded]
|
36
|
-
params.delete(:embedded)
|
37
|
-
render(:partial => 'list_with_header')
|
38
|
-
else
|
39
|
-
render :action => 'list.js'
|
40
|
-
end
|
41
|
-
end
|
42
|
-
def list_respond_to_xml
|
43
|
-
render :xml => response_object.to_xml(:only => list_columns_names), :content_type => Mime::XML, :status => response_status
|
44
|
-
end
|
45
|
-
def list_respond_to_json
|
46
|
-
render :text => response_object.to_json(:only => list_columns_names), :content_type => Mime::JSON, :status => response_status
|
47
|
-
end
|
48
|
-
def list_respond_to_yaml
|
49
|
-
render :text => Hash.from_xml(response_object.to_xml(:only => list_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status
|
50
|
-
end
|
51
|
-
|
52
|
-
def row_respond_to_html
|
53
|
-
render(:partial => 'row', :locals => {:record => @record})
|
54
|
-
end
|
55
|
-
|
56
|
-
# The actual algorithm to prepare for the list view
|
57
|
-
def set_includes_for_list_columns
|
58
|
-
includes_for_list_columns = active_scaffold_config.list.columns.collect{ |c| c.includes }.flatten.uniq.compact
|
59
|
-
self.active_scaffold_includes.concat includes_for_list_columns
|
60
|
-
end
|
61
|
-
|
62
|
-
# The actual algorithm to prepare for the list view
|
63
|
-
def do_list
|
64
|
-
set_includes_for_list_columns
|
65
|
-
|
66
|
-
options = { :sorting => active_scaffold_config.list.user.sorting,
|
67
|
-
:count_includes => active_scaffold_config.list.user.count_includes }
|
68
|
-
paginate = (params[:format].nil?) ? (accepts? :html, :js) : ['html', 'js'].include?(params[:format])
|
69
|
-
if paginate
|
70
|
-
options.merge!({
|
71
|
-
:per_page => active_scaffold_config.list.user.per_page,
|
72
|
-
:page => active_scaffold_config.list.user.page,
|
73
|
-
:pagination => active_scaffold_config.list.pagination
|
74
|
-
})
|
75
|
-
end
|
76
|
-
|
77
|
-
page = find_page(options)
|
78
|
-
if page.items.blank? && !page.pager.infinite?
|
79
|
-
page = page.pager.last
|
80
|
-
active_scaffold_config.list.user.page = page.number
|
81
|
-
end
|
82
|
-
@page, @records = page, page.items
|
83
|
-
end
|
84
|
-
|
85
|
-
def each_record_in_page
|
86
|
-
_page = active_scaffold_config.list.user.page
|
87
|
-
do_search if respond_to? :do_search
|
88
|
-
active_scaffold_config.list.user.page = _page
|
89
|
-
do_list
|
90
|
-
@page.items.each {|record| yield record}
|
91
|
-
end
|
92
|
-
|
93
|
-
def each_record_in_scope
|
94
|
-
do_search if respond_to? :do_search
|
95
|
-
finder_options = { :order => "#{active_scaffold_config.model.connection.quote_table_name(active_scaffold_config.model.table_name)}.#{active_scaffold_config.model.primary_key} ASC",
|
96
|
-
:conditions => all_conditions,
|
97
|
-
:joins => joins_for_finder}
|
98
|
-
finder_options.merge! custom_finder_options
|
99
|
-
finder_options.merge! :include => (active_scaffold_includes.blank? ? nil : active_scaffold_includes)
|
100
|
-
klass = beginning_of_chain
|
101
|
-
klass.all(finder_options).each {|record| yield record}
|
102
|
-
end
|
103
|
-
|
104
|
-
# The default security delegates to ActiveRecordPermissions.
|
105
|
-
# You may override the method to customize.
|
106
|
-
def list_authorized?
|
107
|
-
authorized_for?(:crud_type => :read)
|
108
|
-
end
|
109
|
-
|
110
|
-
# call this method in your action_link action to simplify processing of actions
|
111
|
-
# eg for member action_link :fire
|
112
|
-
# process_action_link_action do |record|
|
113
|
-
# record.update_attributes(:fired => true)
|
114
|
-
# self.successful = true
|
115
|
-
# flash[:info] = 'Player fired'
|
116
|
-
# end
|
117
|
-
def process_action_link_action(render_action = :action_update, crud_type = nil)
|
118
|
-
if request.get?
|
119
|
-
# someone has disabled javascript, we have to show confirmation form first
|
120
|
-
@record = find_if_allowed(params[:id], :read) if params[:id] && params[:id] && params[:id].to_i > 0
|
121
|
-
respond_to_action(:action_confirmation)
|
122
|
-
else
|
123
|
-
if params[:id] && params[:id] && params[:id].to_i > 0
|
124
|
-
crud_type ||= (request.post? || request.put?) ? :update : :delete
|
125
|
-
@record = find_if_allowed(params[:id], crud_type)
|
126
|
-
unless @record.nil?
|
127
|
-
yield @record
|
128
|
-
else
|
129
|
-
self.successful = false
|
130
|
-
flash[:error] = as_(:no_authorization_for_action, :action => action_name)
|
131
|
-
end
|
132
|
-
else
|
133
|
-
yield
|
134
|
-
end
|
135
|
-
respond_to_action(render_action)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
def action_confirmation_respond_to_html(confirm_action = action_name.to_sym)
|
140
|
-
link = active_scaffold_config.action_links[confirm_action]
|
141
|
-
render :action => 'action_confirmation', :locals => {:record => @record, :link => link}
|
142
|
-
end
|
143
|
-
|
144
|
-
def action_update_respond_to_html
|
145
|
-
do_search if respond_to? :do_search
|
146
|
-
do_list
|
147
|
-
redirect_to :action => 'index'
|
148
|
-
end
|
149
|
-
|
150
|
-
def action_update_respond_to_js
|
151
|
-
render(:action => 'on_action_update')
|
152
|
-
end
|
153
|
-
|
154
|
-
def action_update_respond_to_xml
|
155
|
-
render :xml => successful? ? "" : response_object.to_xml(:only => list_columns_names), :content_type => Mime::XML, :status => response_status
|
156
|
-
end
|
157
|
-
|
158
|
-
def action_update_respond_to_json
|
159
|
-
render :text => successful? ? "" : response_object.to_json(:only => list_columns_names), :content_type => Mime::JSON, :status => response_status
|
160
|
-
end
|
161
|
-
|
162
|
-
def action_update_respond_to_yaml
|
163
|
-
render :text => successful? ? "" : Hash.from_xml(response_object.to_xml(:only => list_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status
|
164
|
-
end
|
165
|
-
|
166
|
-
private
|
167
|
-
def list_authorized_filter
|
168
|
-
raise ActiveScaffold::ActionNotAllowed unless list_authorized?
|
169
|
-
end
|
170
|
-
|
171
|
-
def list_formats
|
172
|
-
(default_formats + active_scaffold_config.formats + active_scaffold_config.list.formats).uniq
|
173
|
-
end
|
174
|
-
alias_method :index_formats, :list_formats
|
175
|
-
|
176
|
-
def row_formats
|
177
|
-
([:html] + active_scaffold_config.formats + active_scaffold_config.list.formats).uniq
|
178
|
-
end
|
179
|
-
|
180
|
-
def action_update_formats
|
181
|
-
(default_formats + active_scaffold_config.formats).uniq
|
182
|
-
end
|
183
|
-
|
184
|
-
def action_confirmation_formats
|
185
|
-
(default_formats + active_scaffold_config.formats).uniq
|
186
|
-
end
|
187
|
-
|
188
|
-
def list_columns
|
189
|
-
active_scaffold_config.list.columns.collect_visible
|
190
|
-
end
|
191
|
-
|
192
|
-
def list_columns_names
|
193
|
-
list_columns.collect(&:name)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|