active_scaffold 3.0.23 → 3.0.24

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.
Files changed (62) hide show
  1. data/frontends/default/views/_action_group.html.erb +1 -1
  2. data/frontends/default/views/_action_group.html.erb~ +24 -0
  3. data/frontends/default/views/_form.html.erb~ +26 -0
  4. data/frontends/default/views/_form_association.html.erb~ +19 -0
  5. data/frontends/default/views/_form_association_footer.html.erb~ +16 -6
  6. data/frontends/default/views/_horizontal_subform.html.erb~ +29 -0
  7. data/frontends/default/views/_horizontal_subform_header.html.erb~ +3 -2
  8. data/frontends/default/views/_list_actions.html.erb~ +15 -0
  9. data/frontends/default/views/_list_inline_adapter.html.erb~ +10 -0
  10. data/frontends/default/views/_list_messages.html.erb~ +30 -0
  11. data/frontends/default/views/_list_pagination.html.erb~ +11 -0
  12. data/frontends/default/views/_list_pagination_links.html.erb~ +0 -0
  13. data/frontends/default/views/_render_field.js.erb~ +23 -0
  14. data/frontends/default/views/_row.html.erb~ +6 -0
  15. data/frontends/default/views/_vertical_subform.html.erb~ +12 -0
  16. data/frontends/default/views/edit_associated.js.erb~ +13 -0
  17. data/frontends/default/views/on_create.js.rjs +2 -2
  18. data/frontends/default/views/render_field.js.erb~ +1 -0
  19. data/lib/active_scaffold/actions/core.rb~ +13 -5
  20. data/lib/active_scaffold/actions/create.rb~ +149 -0
  21. data/lib/active_scaffold/actions/list.rb~ +196 -0
  22. data/lib/active_scaffold/actions/nested.rb +6 -2
  23. data/lib/active_scaffold/actions/nested.rb~ +252 -0
  24. data/lib/active_scaffold/actions/search.rb~ +49 -0
  25. data/lib/active_scaffold/actions/subform.rb~ +27 -0
  26. data/lib/active_scaffold/actions/update.rb~ +149 -0
  27. data/lib/active_scaffold/attribute_params.rb~ +202 -0
  28. data/lib/active_scaffold/bridges/record_select/{lib/record_select_bridge.rb~ → helpers.rb~} +7 -16
  29. data/lib/active_scaffold/bridges/shared/date_bridge.rb~ +209 -0
  30. data/lib/active_scaffold/config/create.rb +4 -4
  31. data/lib/active_scaffold/config/nested.rb +1 -0
  32. data/lib/active_scaffold/config/nested.rb~ +41 -0
  33. data/lib/active_scaffold/config/search.rb~ +74 -0
  34. data/lib/active_scaffold/constraints.rb~ +186 -0
  35. data/lib/active_scaffold/data_structures/action_columns.rb~ +140 -0
  36. data/lib/active_scaffold/data_structures/action_link.rb +4 -4
  37. data/lib/active_scaffold/data_structures/action_link.rb~ +179 -0
  38. data/lib/active_scaffold/data_structures/nested_info.rb~ +124 -0
  39. data/lib/active_scaffold/extensions/action_controller_rendering.rb~ +22 -0
  40. data/lib/active_scaffold/extensions/action_view_rendering.rb~ +108 -0
  41. data/lib/active_scaffold/extensions/cache_association.rb~ +12 -0
  42. data/lib/active_scaffold/extensions/reverse_associations.rb~ +64 -0
  43. data/lib/active_scaffold/extensions/routing_mapper.rb~ +34 -0
  44. data/lib/active_scaffold/extensions/unsaved_associated.rb~ +62 -0
  45. data/lib/active_scaffold/finder.rb~ +370 -0
  46. data/lib/active_scaffold/helpers/controller_helpers.rb~ +101 -0
  47. data/lib/active_scaffold/helpers/form_column_helpers.rb~ +321 -0
  48. data/lib/active_scaffold/helpers/id_helpers.rb~ +123 -0
  49. data/lib/active_scaffold/helpers/list_column_helpers.rb +9 -6
  50. data/lib/active_scaffold/helpers/list_column_helpers.rb~ +368 -0
  51. data/lib/active_scaffold/helpers/search_column_helpers.rb~ +94 -46
  52. data/lib/active_scaffold/helpers/view_helpers.rb +1 -1
  53. data/lib/active_scaffold/helpers/view_helpers.rb~ +353 -0
  54. data/lib/active_scaffold/version.rb +1 -1
  55. data/lib/active_scaffold.rb +1 -1
  56. data/lib/active_scaffold.rb~ +362 -0
  57. metadata +110 -76
  58. data/lib/active_scaffold/bridges/dragonfly/bridge.rb~ +0 -12
  59. data/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge.rb~ +0 -36
  60. data/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge_helpers.rb~ +0 -12
  61. data/lib/active_scaffold/bridges/dragonfly/lib/form_ui.rb~ +0 -27
  62. data/lib/active_scaffold/bridges/dragonfly/lib/list_ui.rb~ +0 -16
@@ -0,0 +1,353 @@
1
+ module ActiveScaffold
2
+ module Helpers
3
+ # All extra helpers that should be included in the View.
4
+ # Also a dumping ground for uncategorized helpers.
5
+ module ViewHelpers
6
+ include ActiveScaffold::Helpers::IdHelpers
7
+ include ActiveScaffold::Helpers::AssociationHelpers
8
+ include ActiveScaffold::Helpers::PaginationHelpers
9
+ include ActiveScaffold::Helpers::ListColumnHelpers
10
+ include ActiveScaffold::Helpers::ShowColumnHelpers
11
+ include ActiveScaffold::Helpers::FormColumnHelpers
12
+ include ActiveScaffold::Helpers::SearchColumnHelpers
13
+ include ActiveScaffold::Helpers::HumanConditionHelpers
14
+
15
+ ##
16
+ ## Delegates
17
+ ##
18
+
19
+ # access to the configuration variable
20
+ def active_scaffold_config
21
+ controller.class.active_scaffold_config
22
+ end
23
+
24
+ def active_scaffold_config_for(*args)
25
+ controller.class.active_scaffold_config_for(*args)
26
+ end
27
+
28
+ def active_scaffold_controller_for(*args)
29
+ controller.class.active_scaffold_controller_for(*args)
30
+ end
31
+
32
+ ##
33
+ ## Uncategorized
34
+ ##
35
+
36
+ def controller_path_for_activerecord(klass)
37
+ begin
38
+ controller = active_scaffold_controller_for(klass)
39
+ controller.controller_path
40
+ rescue ActiveScaffold::ControllerNotFound
41
+ controller = nil
42
+ end
43
+ end
44
+
45
+ # This is the template finder logic, keep it updated with however we find stuff in rails
46
+ # currently this very similar to the logic in ActionBase::Base.render for options file
47
+ def template_exists?(template_name, partial = false)
48
+ lookup_context.exists? template_name, '', partial
49
+ end
50
+
51
+ def generate_temporary_id
52
+ (Time.now.to_f*1000).to_i.to_s
53
+ end
54
+
55
+ # Turns [[label, value]] into <option> tags
56
+ # Takes optional parameter of :include_blank
57
+ def option_tags_for(select_options, options = {})
58
+ select_options.insert(0,[as_(:_select_),nil]) if options[:include_blank]
59
+ select_options.collect do |option|
60
+ label, value = option[0], option[1]
61
+ value.nil? ? "<option value="">#{label}</option>" : "<option value=\"#{value}\">#{label}</option>"
62
+ end
63
+ end
64
+
65
+ # Should this column be displayed in the subform?
66
+ def in_subform?(column, parent_record)
67
+ return true unless column.association
68
+
69
+ # Polymorphic associations can't appear because they *might* be the reverse association, and because you generally don't assign an association from the polymorphic side ... I think.
70
+ return false if column.polymorphic_association?
71
+
72
+ # A column shouldn't be in the subform if it's the reverse association to the parent
73
+ return false if column.association.inverse_for?(parent_record.class)
74
+
75
+ return true
76
+ end
77
+
78
+ def form_remote_upload_tag(url_for_options = {}, options = {})
79
+ options[:target] = action_iframe_id(url_for_options)
80
+ options[:multipart] ||= true
81
+ options[:class] = "#{options[:class]} as_remote_upload".strip
82
+ output=""
83
+ output << form_tag(url_for_options, options)
84
+ (output << "<iframe id='#{action_iframe_id(url_for_options)}' name='#{action_iframe_id(url_for_options)}' style='display:none'></iframe>").html_safe
85
+ end
86
+
87
+ # a general-use loading indicator (the "stuff is happening, please wait" feedback)
88
+ def loading_indicator_tag(options)
89
+ image_tag "indicator.gif", :style => "visibility:hidden;", :id => loading_indicator_id(options), :alt => "loading indicator", :class => "loading-indicator"
90
+ end
91
+
92
+ # Creates a javascript-based link that toggles the visibility of some element on the page.
93
+ # By default, it toggles the visibility of the sibling after the one it's nested in. You may pass custom javascript logic in options[:of] to change that, though. For example, you could say :of => '$("my_div_id")'.
94
+ # You may also flag whether the other element is visible by default or not, and the initial text will adjust accordingly.
95
+ def link_to_visibility_toggle(id, options = {})
96
+ options[:default_visible] = true if options[:default_visible].nil?
97
+ options[:hide_label] = as_(:hide)
98
+ options[:show_label] = as_(:show)
99
+ javascript_tag("ActiveScaffold.create_visibility_toggle('#{id}', #{options.to_json});")
100
+ end
101
+
102
+ def skip_action_link(link, *args)
103
+ (!link.ignore_method.nil? and controller.try(link.ignore_method, *args)) || ((link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method, *args))
104
+ end
105
+
106
+ def render_action_link(link, url_options, record = nil, html_options = {})
107
+ url_options = action_link_url_options(link, url_options, record)
108
+ html_options = action_link_html_options(link, url_options, record, html_options)
109
+ action_link_html(link, url_options, html_options, record)
110
+ end
111
+
112
+ def render_group_action_link(link, url_options, options, record = nil)
113
+ if link.type == :member && !options[:authorized]
114
+ action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"}, record)
115
+ else
116
+ render_action_link(link, url_options, record)
117
+ end
118
+ end
119
+
120
+ def action_link_url_options(link, url_options, record, options = {})
121
+ url_options = url_options.clone
122
+ url_options[:action] = link.action
123
+ 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
+ url_options.merge! link.parameters if link.parameters
126
+ @link_record = record
127
+ url_options.merge! self.instance_eval(&(link.dynamic_parameters)) if link.dynamic_parameters.is_a?(Proc)
128
+ @link_record = nil
129
+ url_options_for_nested_link(link.column, record, link, url_options, options) if link.nested_link?
130
+ url_options_for_sti_link(link.column, record, link, url_options, options) unless record.nil? || active_scaffold_config.sti_children.nil?
131
+ url_options[:_method] = link.method if !link.confirm? && link.inline? && link.method != :get
132
+ url_options
133
+ end
134
+
135
+ def action_link_html_options(link, url_options, record, html_options)
136
+ link_id = get_action_link_id(url_options, record, link.column)
137
+ html_options.reverse_merge! link.html_options.merge(:class => link.action.to_s)
138
+
139
+ # Needs to be in html_options to as the adding _method to the url is no longer supported by Rails
140
+ html_options[:method] = link.method if link.method != :get
141
+
142
+ html_options[:class] += ' as_action' if link.inline?
143
+ html_options[:data] = {}
144
+ html_options[:data][:confirm] = link.confirm(record.try(:to_label)) if link.confirm?
145
+ html_options[:data][:position] = link.position if link.position and link.inline?
146
+ html_options[:data][:action] = link.action if link.inline?
147
+ if link.popup?
148
+ html_options[:data][:popup] = true
149
+ html_options[:target] = '_blank'
150
+ end
151
+ html_options[:id] = link_id
152
+ html_options[:remote] = true unless link.page? || link.popup?
153
+ if link.dhtml_confirm?
154
+ html_options[:class] += ' as_action' if !link.inline?
155
+ html_options[:page_link] = 'true' if !link.inline?
156
+ html_options[:dhtml_confirm] = link.dhtml_confirm.value
157
+ html_options[:onclick] = link.dhtml_confirm.onclick_function(controller, link_id)
158
+ end
159
+ html_options[:class] += " #{link.html_options[:class]}" unless link.html_options[:class].blank?
160
+ html_options
161
+ end
162
+
163
+ def get_action_link_id(url_options, record = nil, column = nil)
164
+ id = url_options[:id] || url_options[:parent_id]
165
+ id = "#{column.association.name}-#{record.id}" if column && column.plural_association?
166
+ if record.try(column.association.name.to_sym).present?
167
+ id = "#{column.association.name}-#{record.send(column.association.name).id}-#{record.id}"
168
+ else
169
+ id = "#{column.association.name}-#{record.id}" unless record.nil?
170
+ end if column && column.singular_association?
171
+ id = "#{id}-#{url_options[:batch_scope].downcase}" if url_options[:batch_scope]
172
+ action_id = "#{id_from_controller(url_options[:controller]) + '-' if url_options[:parent_controller]}#{url_options[:action].to_s}"
173
+ action_link_id(action_id, id)
174
+ end
175
+
176
+ def action_link_html(link, url, html_options, record)
177
+ # issue 260, use url_options[:link] if it exists. This prevents DB data from being localized.
178
+ label = url.delete(:link) if url.is_a?(Hash)
179
+ label ||= link.label
180
+ if link.image.nil?
181
+ html = link_to(label, url, html_options)
182
+ else
183
+ html = link_to(image_tag(link.image[:name] , :size => link.image[:size], :alt => label), url, html_options)
184
+ end
185
+ # if url is nil we would like to generate an anchor without href attribute
186
+ url.nil? ? html.sub(/href=".*?"/, '').html_safe : html.html_safe
187
+ end
188
+
189
+ def url_options_for_nested_link(column, record, link, url_options, options = {})
190
+ if column && column.association
191
+ url_options[:assoc_id] = url_options.delete(:id)
192
+ url_options[:id] = record.send(column.association.name).id if column.singular_association? && record.send(column.association.name).present?
193
+ link.eid = "#{controller_id.from(3)}_#{record.id}_#{column.association.name}" unless options.has_key?(:reuse_eid)
194
+ url_options[:eid] = link.eid
195
+ elsif link.parameters && link.parameters[:named_scope]
196
+ url_options[:assoc_id] = url_options.delete(:id)
197
+ link.eid = "#{controller_id.from(3)}_#{record.id}_#{link.parameters[:named_scope]}" unless record.nil? || options.has_key?(:reuse_eid)
198
+ url_options[:eid] = link.eid
199
+ end
200
+ end
201
+
202
+ def url_options_for_sti_link(column, record, link, url_options, options = {})
203
+ #need to find out controller of current record type
204
+ #and set parameters
205
+ # its quite difficult to detect an sti link
206
+ # if link.column.nil? we are sure that it is nt an singular association inline autolink
207
+ # howver that will not work if a sti parent is an singular association inline autolink
208
+ if link.column.nil?
209
+ sti_controller_path = controller_path_for_activerecord(record.class)
210
+ if sti_controller_path
211
+ url_options[:controller] = sti_controller_path
212
+ url_options[:parent_sti] = controller_path
213
+ end
214
+ end
215
+ end
216
+
217
+ def column_class(column, column_value, record)
218
+ classes = []
219
+ classes << "#{column.name}-column"
220
+ if column.css_class.is_a?(Proc)
221
+ css_class = column.css_class.call(column_value, record)
222
+ classes << css_class unless css_class.nil?
223
+ else
224
+ classes << column.css_class
225
+ end unless column.css_class.nil?
226
+
227
+ classes << 'empty' if column_empty? column_value
228
+ classes << 'sorted' if active_scaffold_config.list.user.sorting.sorts_on?(column)
229
+ classes << 'numeric' if column.column and [:decimal, :float, :integer].include?(column.column.type)
230
+ classes.join(' ').rstrip
231
+ end
232
+
233
+ def column_heading_class(column, sorting)
234
+ classes = []
235
+ classes << "#{column.name}-column_heading"
236
+ classes << "sorted #{sorting.direction_of(column).downcase}" if sorting.sorts_on? column
237
+ classes << column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc)
238
+ classes.join(' ')
239
+ end
240
+
241
+ def as_main_div_class
242
+ classes = ["active-scaffold", "active-scaffold-#{controller_id}", "#{params[:controller]}-view", "#{active_scaffold_config.theme}-theme"]
243
+ classes << "as_touch" if touch_device?
244
+ classes.join(' ')
245
+ end
246
+
247
+ def column_empty?(column_value)
248
+ empty = column_value.nil?
249
+ empty ||= column_value.blank? if column_value.respond_to? :blank?
250
+ empty ||= ['&nbsp;', active_scaffold_config.list.empty_field_text].include? column_value if String === column_value
251
+ return empty
252
+ end
253
+
254
+ def column_calculation(column)
255
+ unless column.calculate.instance_of? Proc
256
+ conditions = controller.send(:all_conditions)
257
+ includes = active_scaffold_config.list.count_includes
258
+ includes ||= controller.send(:active_scaffold_includes) unless conditions.nil?
259
+ calculation = beginning_of_chain.calculate(column.calculate, column.name, :conditions => conditions,
260
+ :joins => controller.send(:joins_for_collection), :include => includes)
261
+ else
262
+ column.calculate.call(@records)
263
+ end
264
+ end
265
+
266
+ def render_column_calculation(column)
267
+ calculation = column_calculation(column)
268
+ override_formatter = "render_#{column.name}_#{column.calculate}"
269
+ calculation = send(override_formatter, calculation) if respond_to? override_formatter
270
+
271
+ "#{"#{as_(column.calculate)}: " unless column.calculate.is_a? Proc}#{format_column_value nil, column, calculation}"
272
+ end
273
+
274
+ def column_show_add_existing(column)
275
+ (column.allow_add_existing and options_for_association_count(column.association) > 0)
276
+ end
277
+
278
+ def column_show_add_new(column, associated, record)
279
+ value = (column.plural_association? && !column.readonly_association?) || (column.singular_association? and not associated.empty?)
280
+ value = false unless column.association.klass.authorized_for?(:crud_type => :create)
281
+ value
282
+ end
283
+
284
+ def clean_column_name(name)
285
+ name.to_s.gsub('?', '')
286
+ end
287
+
288
+ def clean_class_name(name)
289
+ name.underscore.gsub('/', '_')
290
+ end
291
+
292
+ def active_scaffold_error_messages_for(*params)
293
+ options = params.extract_options!.symbolize_keys
294
+ options.reverse_merge!(:container_tag => :div, :list_type => :ul)
295
+
296
+ objects = Array.wrap(options.delete(:object) || params).map do |object|
297
+ object = instance_variable_get("@#{object}") unless object.respond_to?(:to_model)
298
+ object = convert_to_model(object)
299
+
300
+ if object.class.respond_to?(:model_name)
301
+ options[:object_name] ||= object.class.model_name.human.downcase
302
+ end
303
+
304
+ object
305
+ end
306
+
307
+ objects.compact!
308
+ count = objects.inject(0) {|sum, object| sum + object.errors.count }
309
+
310
+ unless count.zero?
311
+ html = {}
312
+ [:id, :class].each do |key|
313
+ if options.include?(key)
314
+ value = options[key]
315
+ html[key] = value unless value.blank?
316
+ else
317
+ html[key] = 'errorExplanation'
318
+ end
319
+ end
320
+ options[:object_name] ||= params.first
321
+
322
+ header_message = if options.include?(:header_message)
323
+ options[:header_message]
324
+ else
325
+ as_('errors.template.header', :count => count, :model => options[:object_name].to_s.gsub('_', ' '))
326
+ end
327
+
328
+ message = options.include?(:message) ? options[:message] : as_('errors.template.body')
329
+
330
+ error_messages = objects.sum do |object|
331
+ object.errors.full_messages.map do |msg|
332
+ options[:list_type] != :br ? content_tag(:li, msg) : msg
333
+ end
334
+ end
335
+ error_messages = if options[:list_type] == :br
336
+ error_messages.join('<br/>').html_safe
337
+ else
338
+ content_tag(options[:list_type], error_messages.join.html_safe)
339
+ end
340
+
341
+ contents = []
342
+ contents << content_tag(options[:header_tag] || :h2, header_message) unless header_message.blank?
343
+ contents << content_tag(:p, message) unless message.blank?
344
+ contents << error_messages
345
+ contents = contents.join.html_safe
346
+ options[:container_tag] ? content_tag(options[:container_tag], contents, html) : contents
347
+ else
348
+ ''
349
+ end
350
+ end
351
+ end
352
+ end
353
+ end
@@ -2,7 +2,7 @@ module ActiveScaffold
2
2
  module Version
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
- PATCH = 23
5
+ PATCH = 24
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
@@ -268,7 +268,7 @@ module ActiveScaffold
268
268
  column.actions_for_association_links.delete :new unless actions.include? :create
269
269
  column.actions_for_association_links.delete :edit unless actions.include? :update
270
270
  column.actions_for_association_links.delete :show unless actions.include? :show
271
- ActiveScaffold::DataStructures::ActionLink.new(:none, options.merge({:crud_type => nil, :html_options => {:class => column.name}}))
271
+ ActiveScaffold::DataStructures::ActionLink.new(nil, options.merge(:html_options => {:class => column.name}))
272
272
  end
273
273
  end
274
274
  end