active_scaffold 3.2.20 → 3.3.0.rc
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +19 -13
- data/README +66 -0
- data/app/assets/javascripts/jquery/active_scaffold.js +156 -113
- data/app/assets/javascripts/jquery/active_scaffold_chosen.js +11 -0
- data/app/assets/javascripts/jquery/date_picker_bridge.js.erb +0 -1
- data/app/assets/javascripts/jquery/jquery.editinplace.js +132 -128
- data/app/assets/javascripts/prototype/active_scaffold.js +68 -25
- data/{frontends/default/views/_horizontal_subform_footer.html.erb → app/assets/javascripts/prototype/active_scaffold_chosen.js} +0 -0
- data/app/assets/stylesheets/active_scaffold_colors.css.scss +8 -1
- data/app/assets/stylesheets/active_scaffold_layout.css +14 -8
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_add_existing_form.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_base_form.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_create_form.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_create_form_on_list.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_field_search.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_form.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_form_association.html.erb +8 -3
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_form_association_footer.html.erb +5 -4
- data/app/views/active_scaffold_overrides/_form_association_record.html.erb +85 -0
- data/app/views/active_scaffold_overrides/_form_attribute.html.erb +23 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_form_hidden_attribute.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_form_messages.html.erb +0 -0
- data/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +12 -0
- data/app/views/active_scaffold_overrides/_horizontal_subform_footer.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_horizontal_subform_header.html.erb +3 -2
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_human_conditions.html.erb +0 -0
- data/app/views/active_scaffold_overrides/_list.html.erb +35 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_list_calculations.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_list_column_headings.html.erb +0 -0
- data/app/views/active_scaffold_overrides/_list_header.html.erb +8 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_list_inline_adapter.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_list_messages.html.erb +4 -4
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_list_pagination.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_list_pagination_links.html.erb +0 -0
- data/app/views/active_scaffold_overrides/_list_record.html.erb +30 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_list_with_header.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_messages.html.erb +0 -0
- data/app/views/active_scaffold_overrides/_refresh_list.js.erb +1 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_render_field.js.erb +9 -1
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_row.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_search.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_search_attribute.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_show.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_show_columns.html.erb +0 -0
- data/app/views/active_scaffold_overrides/_update_actions.html.erb +9 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_update_calculations.js.erb +0 -0
- data/app/views/active_scaffold_overrides/_update_column.js.erb +16 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_update_form.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/_update_messages.js.erb +0 -0
- data/app/views/active_scaffold_overrides/_vertical_subform.html.erb +8 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/action_confirmation.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/add_existing.js.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/add_existing_form.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/create.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/delete.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/destroy.js.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/edit_associated.js.erb +1 -1
- data/{frontends/default/views → app/views/active_scaffold_overrides}/field_search.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/form_messages.js.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/list.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/on_action_update.js.erb +3 -3
- data/{frontends/default/views → app/views/active_scaffold_overrides}/on_create.js.erb +1 -1
- data/{frontends/default/views → app/views/active_scaffold_overrides}/on_mark.js.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/on_update.js.erb +4 -4
- data/{frontends/default/views → app/views/active_scaffold_overrides}/render_field.js.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/row.js.erb +1 -1
- data/{frontends/default/views → app/views/active_scaffold_overrides}/search.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/show.html.erb +0 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/update.html.erb +1 -1
- data/app/views/active_scaffold_overrides/update_column.js.erb +26 -0
- data/{frontends/default/views → app/views/active_scaffold_overrides}/update_row.js.erb +0 -0
- data/config/locales/de.yml +1 -0
- data/config/locales/en.yml +1 -0
- data/config/locales/es.yml +1 -0
- data/config/locales/fr.yml +1 -0
- data/config/locales/hu.yml +1 -0
- data/config/locales/ja.yml +1 -0
- data/config/locales/ru.yml +1 -0
- data/lib/active_scaffold.rb +14 -26
- data/lib/active_scaffold/actions/core.rb +14 -11
- data/lib/active_scaffold/actions/create.rb +3 -3
- data/lib/active_scaffold/actions/delete.rb +3 -0
- data/lib/active_scaffold/actions/list.rb +9 -6
- data/lib/active_scaffold/actions/mark.rb +1 -1
- data/lib/active_scaffold/actions/nested.rb +8 -6
- data/lib/active_scaffold/actions/show.rb +6 -1
- data/lib/active_scaffold/actions/update.rb +39 -19
- data/lib/active_scaffold/active_record_permissions.rb +29 -12
- data/lib/active_scaffold/attribute_params.rb +14 -7
- data/lib/active_scaffold/bridges/calendar_date_select.rb +1 -1
- data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +1 -2
- data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +1 -1
- data/lib/active_scaffold/bridges/chosen.rb +14 -0
- data/lib/active_scaffold/bridges/chosen/helpers.rb +48 -0
- data/lib/active_scaffold/bridges/date_picker/helper.rb +7 -6
- data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +1 -1
- data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +1 -1
- data/lib/active_scaffold/bridges/file_column.rb +1 -1
- data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +2 -2
- data/lib/active_scaffold/bridges/file_column/list_ui.rb +4 -4
- data/lib/active_scaffold/bridges/paperclip.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/form_ui.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/list_ui.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +1 -1
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +1 -1
- data/lib/active_scaffold/config/core.rb +9 -2
- data/lib/active_scaffold/config/list.rb +9 -13
- data/lib/active_scaffold/config/nested.rb +11 -2
- data/lib/active_scaffold/data_structures/action_columns.rb +19 -5
- data/lib/active_scaffold/data_structures/action_link.rb +9 -2
- data/lib/active_scaffold/data_structures/action_links.rb +5 -36
- data/lib/active_scaffold/data_structures/column.rb +21 -21
- data/lib/active_scaffold/data_structures/nested_info.rb +31 -44
- data/lib/active_scaffold/extensions/action_controller_rescueing.rb +1 -0
- data/lib/active_scaffold/extensions/action_view_rendering.rb +30 -36
- data/lib/active_scaffold/extensions/reverse_associations.rb +10 -6
- data/lib/active_scaffold/extensions/routing_mapper.rb +6 -5
- data/lib/active_scaffold/extensions/unsaved_associated.rb +1 -1
- data/lib/active_scaffold/finder.rb +18 -10
- data/lib/active_scaffold/helpers/association_helpers.rb +21 -2
- data/lib/active_scaffold/helpers/controller_helpers.rb +14 -16
- data/lib/active_scaffold/helpers/form_column_helpers.rb +161 -21
- data/lib/active_scaffold/helpers/id_helpers.rb +7 -7
- data/lib/active_scaffold/helpers/list_column_helpers.rb +42 -92
- data/lib/active_scaffold/helpers/search_column_helpers.rb +10 -3
- data/lib/active_scaffold/helpers/show_column_helpers.rb +4 -9
- data/lib/active_scaffold/helpers/view_helpers.rb +278 -78
- data/lib/active_scaffold/version.rb +2 -2
- data/lib/generators/active_scaffold_controller/templates/controller.rb +1 -1
- data/test/bridges/paperclip_test.rb +2 -2
- data/vendor/assets/javascripts/jquery-ui-timepicker-addon.js +1882 -1276
- metadata +79 -80
- data/README.md +0 -67
- data/frontends/default/views/_action_group.html.erb +0 -24
- data/frontends/default/views/_form_attribute.html.erb +0 -23
- data/frontends/default/views/_horizontal_subform.html.erb +0 -22
- data/frontends/default/views/_horizontal_subform_record.html.erb +0 -43
- data/frontends/default/views/_list.html.erb +0 -18
- data/frontends/default/views/_list_actions.html.erb +0 -15
- data/frontends/default/views/_list_header.html.erb +0 -10
- data/frontends/default/views/_list_record.html.erb +0 -13
- data/frontends/default/views/_list_record_columns.html.erb +0 -8
- data/frontends/default/views/_refresh_list.js.erb +0 -1
- data/frontends/default/views/_update_actions.html.erb +0 -9
- data/frontends/default/views/_vertical_subform.html.erb +0 -12
- data/frontends/default/views/_vertical_subform_record.html.erb +0 -43
- data/frontends/default/views/refresh_list.js.erb +0 -2
- data/frontends/default/views/update_column.js.erb +0 -15
- data/lib/active_scaffold/extensions/active_record_offset.rb +0 -12
- data/lib/active_scaffold/extensions/nil_id_in_url_params.rb +0 -7
@@ -61,7 +61,7 @@ module ActiveScaffold
|
|
61
61
|
associated.collect!(&:to_i)
|
62
62
|
|
63
63
|
if column.association
|
64
|
-
select_options =
|
64
|
+
select_options = sorted_association_options_find(column.association).collect {|r| [r.to_label, r.id]}
|
65
65
|
else
|
66
66
|
select_options = column.options[:options].collect do |text, value|
|
67
67
|
active_scaffold_translated_option(column, text, value)
|
@@ -77,7 +77,7 @@ module ActiveScaffold
|
|
77
77
|
if column.association
|
78
78
|
associated = associated.is_a?(Array) ? associated.map(&:to_i) : associated.to_i unless associated.nil?
|
79
79
|
method = column.association.macro == :belongs_to ? column.association.foreign_key : column.name
|
80
|
-
select_options =
|
80
|
+
select_options = sorted_association_options_find(column.association, false)
|
81
81
|
else
|
82
82
|
method = column.name
|
83
83
|
select_options = column.options[:options].collect do |text, value|
|
@@ -92,7 +92,14 @@ module ActiveScaffold
|
|
92
92
|
else
|
93
93
|
options[:include_blank] ||= as_(:_select_)
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
|
+
if optgroup = options.delete(:optgroup)
|
97
|
+
select(:record, method, grouped_options_for_select(column, select_options, optgroup), options, html_options)
|
98
|
+
elsif column.association
|
99
|
+
collection_select(:record, method, select_options, :id, :to_label, options, html_options)
|
100
|
+
else
|
101
|
+
select(:record, method, select_options, options, html_options)
|
102
|
+
end
|
96
103
|
end
|
97
104
|
|
98
105
|
def active_scaffold_search_text(column, options)
|
@@ -8,25 +8,20 @@ module ActiveScaffold
|
|
8
8
|
# we only pass the record as the argument. we previously also passed the formatted_value,
|
9
9
|
# but mike perham pointed out that prohibited the usage of overrides to improve on the
|
10
10
|
# performance of our default formatting. see issue #138.
|
11
|
-
|
12
|
-
ActiveSupport::Deprecation.warn("Add column argument to field override, signature is unified with list_ui")
|
13
|
-
send(method, record)
|
14
|
-
else
|
15
|
-
send(method, record, column)
|
16
|
-
end
|
11
|
+
send(method, record, column)
|
17
12
|
# second, check if the dev has specified a valid list_ui for this column
|
18
13
|
elsif column.list_ui and (method = override_show_column_ui(column.list_ui))
|
19
|
-
send(method,
|
14
|
+
send(method, record, column)
|
20
15
|
else
|
21
16
|
if column.column and (method = override_show_column_ui(column.column.type))
|
22
|
-
send(method,
|
17
|
+
send(method, record, column)
|
23
18
|
else
|
24
19
|
get_column_value(record, column)
|
25
20
|
end
|
26
21
|
end
|
27
22
|
end
|
28
23
|
|
29
|
-
def active_scaffold_show_text(
|
24
|
+
def active_scaffold_show_text(record, column)
|
30
25
|
simple_format(clean_column_value(record.send(column.name)))
|
31
26
|
end
|
32
27
|
|
@@ -3,6 +3,7 @@ module ActiveScaffold
|
|
3
3
|
# All extra helpers that should be included in the View.
|
4
4
|
# Also a dumping ground for uncategorized helpers.
|
5
5
|
module ViewHelpers
|
6
|
+
NESTED_PARAMS = [:eid, :association, :parent_scaffold]
|
6
7
|
include ActiveScaffold::Helpers::IdHelpers
|
7
8
|
include ActiveScaffold::Helpers::AssociationHelpers
|
8
9
|
include ActiveScaffold::Helpers::PaginationHelpers
|
@@ -99,61 +100,243 @@ module ActiveScaffold
|
|
99
100
|
javascript_tag("ActiveScaffold.create_visibility_toggle('#{id}', #{options.to_json});")
|
100
101
|
end
|
101
102
|
|
102
|
-
def skip_action_link(link, *args)
|
103
|
-
|
103
|
+
def skip_action_link?(link, *args)
|
104
|
+
!link.ignore_method.nil? && controller.respond_to?(link.ignore_method) && controller.send(link.ignore_method, *args)
|
104
105
|
end
|
105
106
|
|
106
|
-
def
|
107
|
-
|
108
|
-
|
109
|
-
|
107
|
+
def action_link_authorized?(link, *args)
|
108
|
+
security_method = link.security_method_set? || controller.respond_to?(link.security_method)
|
109
|
+
authorized = if security_method
|
110
|
+
controller.send(link.security_method, *args)
|
111
|
+
else
|
112
|
+
args.empty? ? true : args.first.authorized_for?(:crud_type => link.crud_type, :action => link.action)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def display_action_links(action_links, record, options, &block)
|
117
|
+
options[:level_0_tag] ||= nil
|
118
|
+
options[:options_level_0_tag] ||= nil
|
119
|
+
options[:level] ||= 0
|
120
|
+
options[:first_action] = true
|
121
|
+
output = ActiveSupport::SafeBuffer.new
|
122
|
+
|
123
|
+
action_links.each(:reverse => options.delete(:reverse), :groups => true) do |link|
|
124
|
+
if link.is_a? ActiveScaffold::DataStructures::ActionLinks
|
125
|
+
unless link.empty?
|
126
|
+
options[:level] += 1
|
127
|
+
content = display_action_links(link, record, options, &block)
|
128
|
+
options[:level] -= 1
|
129
|
+
if content.present?
|
130
|
+
output << display_action_link(link, content, record, options)
|
131
|
+
options[:first_action] = false
|
132
|
+
end
|
133
|
+
end
|
134
|
+
elsif !skip_action_link?(link, *Array(options[:for]))
|
135
|
+
authorized = action_link_authorized?(link, *Array(options[:for]))
|
136
|
+
next if !authorized && options[:skip_unauthorized]
|
137
|
+
output << display_action_link(link, nil, record, options.merge(:authorized => authorized))
|
138
|
+
options[:first_action] = false
|
139
|
+
end
|
140
|
+
end
|
141
|
+
output
|
142
|
+
end
|
143
|
+
|
144
|
+
def display_action_link(link, content, record, options)
|
145
|
+
if content
|
146
|
+
html_classes = hover_via_click? ? 'hover_click ' : ''
|
147
|
+
if options[:level] == 0
|
148
|
+
html_classes << 'action_group'
|
149
|
+
group_tag = :div
|
150
|
+
else
|
151
|
+
html_classes << 'top' if options[:first_action]
|
152
|
+
group_tag = :li
|
153
|
+
end
|
154
|
+
content = content_tag(group_tag, :class => (html_classes if html_classes.present?), :onclick => ('' if hover_via_click?)) do
|
155
|
+
content_tag(:div, as_(link.name), :class => link.name.to_s.downcase) << content_tag(:ul, content)
|
156
|
+
end
|
157
|
+
else
|
158
|
+
content = render_action_link(link, record, options)
|
159
|
+
content = content_tag(:li, content, :class => ('top' if options[:first_action])) unless options[:level] == 0
|
160
|
+
end
|
161
|
+
content = content_tag(options[:level_0_tag], content, options[:options_level_0_tag]) if options[:level] == 0 && options[:level_0_tag]
|
162
|
+
content
|
163
|
+
end
|
164
|
+
|
165
|
+
def render_action_link(link, record = nil, options = {})
|
166
|
+
if link.action.nil? || link.column.try(:polymorphic_association?)
|
167
|
+
link = action_link_to_inline_form(link, record)
|
168
|
+
options[:authorized] = false if link.action.nil? || link.controller.nil?
|
169
|
+
options.delete :link if link.crud_type == :create
|
170
|
+
end
|
171
|
+
if link.action.nil? || (link.type == :member && options.has_key?(:authorized) && !options[:authorized])
|
172
|
+
action_link_html(link, nil, options.merge(:class => "disabled #{link.action}#{" #{link.html_options[:class]}" unless link.html_options[:class].blank?}"), record)
|
173
|
+
else
|
174
|
+
url = action_link_url(link, record)
|
175
|
+
html_options = action_link_html_options(link, record, options)
|
176
|
+
action_link_html(link, url, html_options, record)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# setup the action link to inline form
|
181
|
+
def action_link_to_inline_form(link, record)
|
182
|
+
link = link.clone
|
183
|
+
associated = record.send(link.column.association.name)
|
184
|
+
if link.column.polymorphic_association?
|
185
|
+
link.controller = controller_path_for_activerecord(associated.class)
|
186
|
+
return link if link.controller.nil?
|
187
|
+
end
|
188
|
+
link = configure_column_link(link, record, associated) if link.action.nil?
|
189
|
+
link
|
110
190
|
end
|
111
191
|
|
112
|
-
def
|
113
|
-
|
114
|
-
|
192
|
+
def configure_column_link(link, record, associated, actions = nil)
|
193
|
+
actions ||= link.column.actions_for_association_links
|
194
|
+
if column_empty?(associated) # if association is empty, we only can link to create form
|
195
|
+
if actions.include?(:new)
|
196
|
+
link.action = 'new'
|
197
|
+
link.crud_type = :create
|
198
|
+
link.label ||= as_(:create_new)
|
199
|
+
end
|
200
|
+
elsif actions.include?(:edit)
|
201
|
+
link.action = 'edit'
|
202
|
+
link.crud_type = :update
|
203
|
+
elsif actions.include?(:show)
|
204
|
+
link.action = 'show'
|
205
|
+
link.crud_type = :read
|
206
|
+
elsif actions.include?(:list)
|
207
|
+
link.action = 'index'
|
208
|
+
link.crud_type = :read
|
209
|
+
end
|
210
|
+
|
211
|
+
unless column_link_authorized?(link, link.column, record, associated)
|
212
|
+
link.action = nil
|
213
|
+
# if action is edit and is not authorized, fallback to show if it's enabled
|
214
|
+
if link.crud_type == :update && actions.include?(:show)
|
215
|
+
link = configure_column_link(link, record, associated, [:show])
|
216
|
+
end
|
217
|
+
end
|
218
|
+
link
|
219
|
+
end
|
220
|
+
|
221
|
+
def column_link_authorized?(link, column, record, associated)
|
222
|
+
if column.association
|
223
|
+
associated_for_authorized = if column.plural_association? || (associated.respond_to?(:blank?) && associated.blank?)
|
224
|
+
column.association.klass
|
225
|
+
else
|
226
|
+
associated
|
227
|
+
end
|
228
|
+
authorized = associated_for_authorized.authorized_for?(:crud_type => link.crud_type)
|
229
|
+
authorized = authorized and record.authorized_for?(:crud_type => :update, :column => column.name) if link.crud_type == :create
|
230
|
+
authorized
|
115
231
|
else
|
116
|
-
|
232
|
+
record.authorized_for?(:crud_type => link.crud_type)
|
117
233
|
end
|
118
234
|
end
|
235
|
+
|
236
|
+
def action_link_url(link, record)
|
237
|
+
url = (@action_links_urls ||= {})[link.name_to_cache_link_url]
|
238
|
+
url ||= begin
|
239
|
+
url_options = action_link_url_options(link, record)
|
240
|
+
if active_scaffold_config.cache_action_link_urls
|
241
|
+
url = url_for(url_options)
|
242
|
+
@action_links_urls[link.name_to_cache_link_url] = url unless link.dynamic_parameters.is_a?(Proc)
|
243
|
+
url
|
244
|
+
else
|
245
|
+
url_for(params_for(url_options))
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
url = record ? url.sub('--ID--', record.id.to_s) : url.clone
|
250
|
+
if link.column.try(:singular_association?)
|
251
|
+
url = url.sub('--CHILD_ID--', record.send(link.column.association.name).try(:id).to_s)
|
252
|
+
elsif nested?
|
253
|
+
url = url.sub('--CHILD_ID--', params[nested.param_name].to_s)
|
254
|
+
end
|
255
|
+
|
256
|
+
if active_scaffold_config.cache_action_link_urls
|
257
|
+
query_string, non_nested_query_string = query_string_for_action_links(link)
|
258
|
+
if query_string || (!link.nested_link? && non_nested_query_string)
|
259
|
+
url << (url.include?('?') ? '&' : '?')
|
260
|
+
url << query_string if query_string
|
261
|
+
url << non_nested_query_string if !link.nested_link? && non_nested_query_string
|
262
|
+
end
|
263
|
+
end
|
264
|
+
url
|
265
|
+
end
|
266
|
+
|
267
|
+
def query_string_for_action_links(link)
|
268
|
+
if defined?(@query_string) && link.parameters.none? { |k, v| @query_string_params.include? k }
|
269
|
+
return [@query_string, @non_nested_query_string]
|
270
|
+
end
|
271
|
+
keep = true
|
272
|
+
@query_string_params ||= Set.new
|
273
|
+
query_string_for_all = nil
|
274
|
+
query_string_options = []
|
275
|
+
non_nested_query_string_options = []
|
276
|
+
|
277
|
+
params_for.except(:controller, :action, :id).each do |key, value|
|
278
|
+
@query_string_params << key
|
279
|
+
if link.parameters.include? key
|
280
|
+
keep = false
|
281
|
+
next
|
282
|
+
end
|
283
|
+
qs = "#{key}=#{value}"
|
284
|
+
if NESTED_PARAMS.include?(key) || conditions_from_params.include?(key) || (nested? && nested.param_name == key)
|
285
|
+
non_nested_query_string_options << qs
|
286
|
+
else
|
287
|
+
query_string_options << qs
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
query_string = URI.escape(query_string_options.join('&')) if query_string_options.present?
|
292
|
+
if non_nested_query_string_options.present?
|
293
|
+
non_nested_query_string = "#{'&' if query_string}#{URI.escape(non_nested_query_string_options.join('&'))}"
|
294
|
+
end
|
295
|
+
if keep
|
296
|
+
@query_string = query_string
|
297
|
+
@non_nested_query_string = non_nested_query_string
|
298
|
+
end
|
299
|
+
[query_string, non_nested_query_string]
|
300
|
+
end
|
119
301
|
|
120
|
-
def action_link_url_options(link,
|
121
|
-
url_options =
|
122
|
-
url_options[:
|
302
|
+
def action_link_url_options(link, record)
|
303
|
+
url_options = {:action => link.action}
|
304
|
+
url_options[:id] = '--ID--' unless record.nil?
|
123
305
|
url_options[:controller] = link.controller.to_s if link.controller
|
124
|
-
url_options.delete(:search) if link.controller and link.controller.to_s != params[:controller]
|
125
306
|
url_options.merge! link.parameters if link.parameters
|
126
307
|
if link.dynamic_parameters.is_a?(Proc)
|
127
308
|
if record.nil?
|
128
309
|
url_options.merge! link.dynamic_parameters.call
|
129
|
-
elsif link.dynamic_parameters.arity == 0
|
130
|
-
ActiveSupport::Deprecation.warn("dynamic_parameters must be a block with an argument for member action links, instead of using @link_record")
|
131
|
-
@link_record = record
|
132
|
-
url_options.merge! self.instance_eval(&(link.dynamic_parameters))
|
133
|
-
@link_record = nil
|
134
310
|
else
|
135
311
|
url_options.merge! link.dynamic_parameters.call(record)
|
136
312
|
end
|
137
313
|
end
|
138
|
-
|
139
|
-
|
314
|
+
if link.nested_link?
|
315
|
+
url_options_for_nested_link(link.column, record, link, url_options)
|
316
|
+
elsif nested?
|
317
|
+
url_options[nested.param_name] = '--CHILD_ID--'
|
318
|
+
end
|
319
|
+
url_options_for_sti_link(link.column, record, link, url_options) unless record.nil? || active_scaffold_config.sti_children.nil?
|
140
320
|
url_options[:_method] = link.method if !link.confirm? && link.inline? && link.method != :get
|
141
321
|
url_options
|
142
322
|
end
|
143
323
|
|
144
|
-
def action_link_html_options(link,
|
145
|
-
link_id = get_action_link_id(
|
324
|
+
def action_link_html_options(link, record, html_options)
|
325
|
+
link_id = get_action_link_id(link, record)
|
146
326
|
html_options.reverse_merge! link.html_options.merge(:class => link.action.to_s)
|
147
327
|
|
148
328
|
# Needs to be in html_options to as the adding _method to the url is no longer supported by Rails
|
149
329
|
html_options[:method] = link.method if link.method != :get
|
150
330
|
|
151
|
-
html_options[:class] += ' as_action' if link.inline?
|
152
331
|
html_options[:data] = {}
|
153
332
|
html_options[:data][:confirm] = link.confirm(record.try(:to_label)) if link.confirm?
|
154
|
-
|
155
|
-
|
156
|
-
|
333
|
+
if link.inline?
|
334
|
+
html_options[:class] += ' as_action'
|
335
|
+
html_options[:data][:position] = link.position if link.position
|
336
|
+
html_options[:data][:action] = link.action
|
337
|
+
html_options[:data][:cancel_refresh] = true if link.refresh_on_close
|
338
|
+
html_options[:data][:keep_open] = true if link.keep_open?
|
339
|
+
end
|
157
340
|
if link.popup?
|
158
341
|
html_options[:data][:popup] = true
|
159
342
|
html_options[:target] = '_blank'
|
@@ -161,8 +344,10 @@ module ActiveScaffold
|
|
161
344
|
html_options[:id] = link_id
|
162
345
|
html_options[:remote] = true unless link.page? || link.popup?
|
163
346
|
if link.dhtml_confirm?
|
164
|
-
|
165
|
-
|
347
|
+
unless link.inline?
|
348
|
+
html_options[:class] += ' as_action'
|
349
|
+
html_options[:page_link] = 'true'
|
350
|
+
end
|
166
351
|
html_options[:dhtml_confirm] = link.dhtml_confirm.value
|
167
352
|
html_options[:onclick] = link.dhtml_confirm.onclick_function(controller, link_id)
|
168
353
|
end
|
@@ -170,48 +355,49 @@ module ActiveScaffold
|
|
170
355
|
html_options
|
171
356
|
end
|
172
357
|
|
173
|
-
def get_action_link_id(
|
174
|
-
|
175
|
-
id =
|
176
|
-
if
|
177
|
-
id = "#{column.association.name}-#{record.
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
358
|
+
def get_action_link_id(link, record = nil, column = nil)
|
359
|
+
column ||= link.column
|
360
|
+
id = record ? record.id.to_s : (nested? ? nested.parent_id : '')
|
361
|
+
if column && column.plural_association?
|
362
|
+
id = "#{column.association.name}-#{record.id}"
|
363
|
+
elsif column && column.singular_association?
|
364
|
+
if record.try(column.association.name.to_sym).present?
|
365
|
+
id = "#{column.association.name}-#{record.send(column.association.name).id}-#{record.id}"
|
366
|
+
else
|
367
|
+
id = "#{column.association.name}-#{record.id}" unless record.nil?
|
368
|
+
end
|
369
|
+
end
|
370
|
+
action_id = "#{id_from_controller("#{link.controller}-") if params[:parent_controller] || link.controller != controller.controller_path}#{link.action}"
|
183
371
|
action_link_id(action_id, id)
|
184
372
|
end
|
185
373
|
|
186
374
|
def action_link_html(link, url, html_options, record)
|
187
|
-
|
188
|
-
label = url.delete(:link) if url.is_a?(Hash)
|
375
|
+
label = html_options.delete(:link)
|
189
376
|
label ||= link.label
|
190
|
-
if link.image
|
191
|
-
|
377
|
+
label = image_tag(link.image[:name], :size => link.image[:size], :alt => label, :title => label) if link.image
|
378
|
+
if url.nil?
|
379
|
+
content_tag(:a, label, html_options)
|
192
380
|
else
|
193
|
-
|
381
|
+
link_to(label, url, html_options)
|
194
382
|
end
|
195
|
-
# if url is nil we would like to generate an anchor without href attribute
|
196
|
-
url.nil? ? html.sub(/href=".*?"/, '').html_safe : html.html_safe
|
197
383
|
end
|
198
384
|
|
199
|
-
def url_options_for_nested_link(column, record, link, url_options
|
385
|
+
def url_options_for_nested_link(column, record, link, url_options)
|
200
386
|
if column && column.association
|
201
387
|
url_options[:parent_scaffold] = controller_path
|
202
388
|
url_options[column.association.active_record.name.foreign_key.to_sym] = url_options.delete(:id)
|
203
|
-
|
204
|
-
|
389
|
+
if column.singular_association? && url_options[:action].to_sym != :index
|
390
|
+
url_options[:id] = '--CHILD_ID--'
|
391
|
+
else
|
392
|
+
url_options[:id] = nil
|
393
|
+
end
|
205
394
|
elsif link.parameters && link.parameters[:named_scope]
|
206
395
|
url_options[:parent_scaffold] = controller_path
|
207
396
|
url_options[active_scaffold_config.model.name.foreign_key.to_sym] = url_options.delete(:id)
|
208
|
-
url_options[:eid] = nil # needed for nested scaffolds open from an embedded scaffold
|
209
397
|
end
|
210
|
-
url_options.except! *params_conditions
|
211
|
-
url_options.except! *nested.constrained_fields if nested?
|
212
398
|
end
|
213
399
|
|
214
|
-
def url_options_for_sti_link(column, record, link, url_options
|
400
|
+
def url_options_for_sti_link(column, record, link, url_options)
|
215
401
|
#need to find out controller of current record type
|
216
402
|
#and set parameters
|
217
403
|
# its quite difficult to detect an sti link
|
@@ -226,9 +412,15 @@ module ActiveScaffold
|
|
226
412
|
end
|
227
413
|
end
|
228
414
|
|
229
|
-
def
|
415
|
+
def list_row_class_method(record)
|
416
|
+
return @_list_row_class_method if defined? @_list_row_class_method
|
230
417
|
class_override_helper = :"#{clean_class_name(record.class.name)}_list_row_class"
|
231
|
-
|
418
|
+
@_list_row_class_method = (class_override_helper if respond_to?(class_override_helper))
|
419
|
+
end
|
420
|
+
|
421
|
+
def list_row_class(record)
|
422
|
+
class_override_helper = list_row_class_method(record)
|
423
|
+
class_override_helper ? send(class_override_helper, record) : ''
|
232
424
|
end
|
233
425
|
|
234
426
|
def column_attributes(column, record)
|
@@ -238,39 +430,39 @@ module ActiveScaffold
|
|
238
430
|
end
|
239
431
|
|
240
432
|
def column_class(column, column_value, record)
|
241
|
-
|
242
|
-
|
433
|
+
@_column_classes ||= {}
|
434
|
+
@_column_classes[column.name] ||= begin
|
435
|
+
classes = "#{column.name}-column "
|
436
|
+
classes << 'sorted ' if active_scaffold_config.list.user.sorting.sorts_on?(column)
|
437
|
+
classes << 'numeric ' if column.column and [:decimal, :float, :integer].include?(column.column.type)
|
438
|
+
classes << column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc)
|
439
|
+
end
|
440
|
+
classes = "#{@_column_classes[column.name]} "
|
441
|
+
classes << 'empty ' if column_empty? column_value
|
442
|
+
classes << 'in_place_editor_field ' if inplace_edit?(record, column) or column.list_ui == :marked
|
243
443
|
if column.css_class.is_a?(Proc)
|
244
444
|
css_class = column.css_class.call(column_value, record)
|
245
445
|
classes << css_class unless css_class.nil?
|
246
|
-
|
247
|
-
|
248
|
-
end unless column.css_class.nil?
|
249
|
-
|
250
|
-
classes << 'empty' if column_empty? column_value
|
251
|
-
classes << 'sorted' if active_scaffold_config.list.user.sorting.sorts_on?(column)
|
252
|
-
classes << 'numeric' if column.column and [:decimal, :float, :integer].include?(column.column.type)
|
253
|
-
classes << 'in_place_editor_field' if inplace_edit?(record, column) or column.list_ui == :marked
|
254
|
-
classes.join(' ').rstrip
|
446
|
+
end
|
447
|
+
classes
|
255
448
|
end
|
256
449
|
|
257
450
|
def column_heading_class(column, sorting)
|
258
|
-
classes =
|
259
|
-
classes << "#{column.
|
260
|
-
classes << "sorted #{sorting.direction_of(column).downcase}" if sorting.sorts_on? column
|
451
|
+
classes = "#{column.name}-column_heading "
|
452
|
+
classes << "sorted #{sorting.direction_of(column).downcase} " if sorting.sorts_on? column
|
261
453
|
classes << column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc)
|
262
|
-
classes
|
454
|
+
classes
|
263
455
|
end
|
264
456
|
|
265
457
|
def as_main_div_class
|
266
|
-
classes =
|
267
|
-
classes << "as_touch" if touch_device?
|
268
|
-
classes
|
458
|
+
classes = "active-scaffold active-scaffold-#{controller_id} #{id_from_controller params[:controller]}-view #{active_scaffold_config.theme}-theme"
|
459
|
+
classes << " as_touch" if touch_device?
|
460
|
+
classes
|
269
461
|
end
|
270
462
|
|
271
463
|
def column_empty?(column_value)
|
272
464
|
empty = column_value.nil?
|
273
|
-
empty ||= column_value.blank?
|
465
|
+
empty ||= column_value.blank?
|
274
466
|
empty ||= [' ', active_scaffold_config.list.empty_field_text].include? column_value if String === column_value
|
275
467
|
return empty
|
276
468
|
end
|
@@ -315,10 +507,18 @@ module ActiveScaffold
|
|
315
507
|
end
|
316
508
|
|
317
509
|
def override_helper(column, suffix)
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
510
|
+
@_override_helpers ||= {}
|
511
|
+
@_override_helpers[suffix] ||= {}
|
512
|
+
return @_override_helpers[suffix][column.name] if @_override_helpers[suffix].include? column.name
|
513
|
+
@_override_helpers[suffix][column.name] = begin
|
514
|
+
method_with_class = override_helper_name(column, suffix, true)
|
515
|
+
if respond_to?(method_with_class)
|
516
|
+
method_with_class
|
517
|
+
else
|
518
|
+
method = override_helper_name(column, suffix)
|
519
|
+
method if respond_to?(method)
|
520
|
+
end
|
521
|
+
end
|
322
522
|
end
|
323
523
|
|
324
524
|
def display_message(message)
|