active_scaffold 3.0.5 → 3.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. data/.document +5 -0
  2. data/Gemfile +11 -2
  3. data/Gemfile.lock +20 -0
  4. data/Rakefile +33 -4
  5. data/active_scaffold.gemspec +378 -17
  6. data/frontends/default/images/config.png +0 -0
  7. data/frontends/default/images/gears.png +0 -0
  8. data/frontends/default/javascripts/jquery/active_scaffold.js +34 -33
  9. data/frontends/default/javascripts/jquery/jquery.editinplace.js +21 -4
  10. data/frontends/default/javascripts/prototype/active_scaffold.js +43 -38
  11. data/frontends/default/stylesheets/stylesheet.css +110 -35
  12. data/frontends/default/views/_action_group.html.erb +20 -0
  13. data/frontends/default/views/_base_form.html.erb +7 -3
  14. data/frontends/default/views/_create_form.html.erb +5 -3
  15. data/frontends/default/views/_create_form_on_list.html.erb +2 -1
  16. data/frontends/default/views/_field_search.html.erb +2 -2
  17. data/frontends/default/views/_form.html.erb +2 -2
  18. data/frontends/default/views/_form_messages.html.erb +1 -1
  19. data/frontends/default/views/_horizontal_subform.html.erb +1 -1
  20. data/frontends/default/views/_list_actions.html.erb +6 -14
  21. data/frontends/default/views/_list_header.html.erb +4 -6
  22. data/frontends/default/views/_list_with_header.html.erb +2 -2
  23. data/frontends/default/views/_messages.html.erb +2 -2
  24. data/frontends/default/views/_search.html.erb +2 -2
  25. data/frontends/default/views/_show.html.erb +1 -1
  26. data/frontends/default/views/_update_form.html.erb +2 -1
  27. data/frontends/default/views/_vertical_subform.html.erb +1 -1
  28. data/frontends/default/views/action_confirmation.html.erb +13 -0
  29. data/frontends/default/views/add_existing.js.rjs +1 -1
  30. data/frontends/default/views/destroy.js.rjs +21 -3
  31. data/frontends/default/views/on_action_update.js.rjs +1 -1
  32. data/frontends/default/views/on_create.js.rjs +30 -13
  33. data/frontends/default/views/on_update.js.rjs +19 -6
  34. data/init.rb +6 -0
  35. data/lib/active_scaffold/actions/core.rb +32 -12
  36. data/lib/active_scaffold/actions/create.rb +4 -11
  37. data/lib/active_scaffold/actions/delete.rb +16 -13
  38. data/lib/active_scaffold/actions/list.rb +58 -2
  39. data/lib/active_scaffold/actions/mark.rb +1 -1
  40. data/lib/active_scaffold/actions/nested.rb +24 -15
  41. data/lib/active_scaffold/actions/show.rb +10 -3
  42. data/lib/active_scaffold/actions/update.rb +10 -3
  43. data/lib/{active_record_permissions.rb → active_scaffold/active_record_permissions.rb} +0 -0
  44. data/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb +9 -8
  45. data/lib/active_scaffold/bridges/bridge.rb +1 -1
  46. data/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +8 -4
  47. data/lib/active_scaffold/bridges/carrierwave/bridge.rb +1 -1
  48. data/lib/active_scaffold/bridges/paperclip/bridge.rb +1 -1
  49. data/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb +1 -1
  50. data/lib/active_scaffold/config/base.rb +8 -0
  51. data/lib/active_scaffold/config/core.rb +2 -15
  52. data/lib/active_scaffold/config/create.rb +8 -0
  53. data/lib/active_scaffold/config/delete.rb +10 -1
  54. data/lib/active_scaffold/config/field_search.rb +1 -0
  55. data/lib/active_scaffold/config/form.rb +2 -1
  56. data/lib/active_scaffold/config/nested.rb +3 -2
  57. data/lib/active_scaffold/config/search.rb +1 -0
  58. data/lib/active_scaffold/config/show.rb +1 -0
  59. data/lib/active_scaffold/config/update.rb +8 -0
  60. data/lib/active_scaffold/constraints.rb +9 -4
  61. data/lib/active_scaffold/data_structures/action_columns.rb +1 -1
  62. data/lib/active_scaffold/data_structures/action_link.rb +10 -1
  63. data/lib/active_scaffold/data_structures/action_links.rb +62 -22
  64. data/lib/active_scaffold/data_structures/column.rb +17 -13
  65. data/lib/active_scaffold/data_structures/nested_info.rb +21 -6
  66. data/lib/active_scaffold/finder.rb +2 -1
  67. data/lib/active_scaffold/helpers/association_helpers.rb +2 -2
  68. data/lib/active_scaffold/helpers/controller_helpers.rb +57 -10
  69. data/lib/active_scaffold/helpers/form_column_helpers.rb +12 -8
  70. data/lib/active_scaffold/helpers/id_helpers.rb +5 -9
  71. data/lib/active_scaffold/helpers/list_column_helpers.rb +26 -28
  72. data/lib/active_scaffold/helpers/search_column_helpers.rb +8 -3
  73. data/lib/active_scaffold/helpers/view_helpers.rb +60 -19
  74. data/lib/active_scaffold/locale/de.rb +13 -6
  75. data/lib/active_scaffold/locale/en.rb +2 -1
  76. data/lib/active_scaffold/locale/es.yml +3 -0
  77. data/lib/active_scaffold/locale/fr.rb +5 -2
  78. data/lib/active_scaffold/locale/ru.yml +77 -20
  79. data/lib/active_scaffold/marked_model.rb +5 -5
  80. data/lib/{paginator.rb → active_scaffold/paginator.rb} +0 -0
  81. data/lib/{responds_to_parent.rb → active_scaffold/responds_to_parent.rb} +0 -0
  82. data/lib/active_scaffold/version.rb +9 -0
  83. data/lib/active_scaffold.rb +60 -84
  84. data/lib/active_scaffold_assets.rb +45 -0
  85. data/lib/active_scaffold_env.rb +14 -0
  86. data/lib/active_scaffold_vho.rb +2 -0
  87. data/lib/extensions/active_association_reflection.rb +13 -0
  88. data/lib/extensions/paginator_extensions.rb +1 -1
  89. data/lib/extensions/routing_mapper.rb +1 -1
  90. data/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +12 -4
  91. metadata +85 -68
  92. data/lib/dhtml_confirm.rb +0 -54
@@ -1,4 +1,4 @@
1
- <div id="<%= active_scaffold_id -%>" class="active-scaffold active-scaffold-<%= controller_id %> <%= "#{params[:controller]}-view" %> <%= active_scaffold_config.theme %>-theme">
1
+ <div id="<%= active_scaffold_id -%>" class="active-scaffold active-scaffold-<%= controller_id %> <%= "#{params[:controller]}-view" %> <%= active_scaffold_config.theme %>-theme" <%= "data-eid=#{id_from_controller(params[:eid])}" if params[:eid]%>>
2
2
  <div class="active-scaffold-header">
3
3
  <%= render :partial => 'list_header' %>
4
4
  </div>
@@ -26,7 +26,7 @@
26
26
  <% end %>
27
27
  </tbody>
28
28
  </table>
29
- <div id="<%= active_scaffold_content_id -%>">
29
+ <div id="<%= active_scaffold_content_id-%>" class="as_content">
30
30
  <%= render :partial => 'list' %>
31
31
  </div>
32
32
  </div>
@@ -1,10 +1,10 @@
1
1
  <% for name in [:info, :warning, :error] %>
2
2
  <% if flash[name] %>
3
- <p class="<%= "#{name}-message message" %>" >
3
+ <div class="<%= "#{name}-message message" %>">
4
4
  <%= h flash[name] %>
5
5
  <% if request.xhr? %>
6
6
  <a href="#" onclick="ActiveScaffold.remove(this.parentNode); return false;" title="<%= as_(:close) %>"><%= as_(:close) %></a>
7
7
  <% end %>
8
- </p>
8
+ </div>
9
9
  <% end %>
10
10
  <% end %>
@@ -1,7 +1,7 @@
1
1
  <% live_search = active_scaffold_config.search.live? -%>
2
2
  <% url_options = params_for(:action => :index, :escape => false).delete_if{|k,v| k == 'search'} -%>
3
3
  <%=
4
- options = {:id => search_form_id,
4
+ options = {:id => element_form_id(:action => 'search'),
5
5
  :class => "as_form search",
6
6
  :remote => true,
7
7
  :method => :get}
@@ -29,6 +29,6 @@ options['data-loading'] = true unless live_search
29
29
  $(<%= "##{search_input_id}".to_json.html_safe %>).delayedObserver(0.5, function() {
30
30
  $(<%= "##{search_input_id}".to_json.html_safe %>).parent().trigger("submit");});
31
31
  <% end -%>
32
- ActiveScaffold.focus_first_element_of_form('<%= search_form_id %>');
32
+ ActiveScaffold.focus_first_element_of_form('<%= element_form_id(:action => 'search') %>');
33
33
  //]]>
34
34
  </script>
@@ -3,6 +3,6 @@
3
3
  <%= render :partial => 'show_columns', :locals => {:columns => active_scaffold_config.show.columns} -%>
4
4
 
5
5
  <p class="form-footer">
6
- <%= link_to as_(:close), main_path_to_return, :class => 'as_cancel', :remote => true, 'data-refresh' => false %>
6
+ <%= link_to as_(:close), main_path_to_return, :class => 'as_cancel', :remote => request.xhr?, 'data-refresh' => false %>
7
7
  <%= loading_indicator_tag(:action => :create, :id => params[:id]) %>
8
8
  </p>
@@ -1,5 +1,6 @@
1
+ <% cancel_link = true if cancel_link.nil? %>
1
2
  <%= render :partial => "base_form", :locals => {:xhr => xhr ||= nil,
2
3
  :form_action => form_action ||= :update,
3
4
  :method => method ||= :put,
4
- :cancel_link => cancel_link ||= true,
5
+ :cancel_link => cancel_link,
5
6
  :headline => headline ||= @record.to_label.nil? ? active_scaffold_config.update.label : as_(:update_model, :model => clean_column_value(@record.to_label))} %>
@@ -3,7 +3,7 @@
3
3
  <% @record = associated[index] -%>
4
4
  <% if @record.errors.count -%>
5
5
  <div class="association-record-errors" id="<%= element_messages_id :action => @record.class.name.underscore, :id => "#{parent_record.id}-#{index}" %>">
6
- <%= error_messages_for :record, :object_name => @record.class.model_name.human.downcase %>
6
+ <%= active_scaffold_error_messages_for :record, :object_name => @record.class.model_name.human.downcase %>
7
7
  </div>
8
8
  <% end %>
9
9
  <%= render :partial => 'vertical_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => @record.new_record? && @record == associated.last} %>
@@ -0,0 +1,13 @@
1
+ <div class="active-scaffold">
2
+ <div class="delete-view view">
3
+ <%= form_tag params_for(:action => link.action, :id => params[:id]), { :method => link.method } %>
4
+ <h4><%= link.confirm(record.try(:to_label)) -%></h4>
5
+
6
+ <p class="form-footer">
7
+ <%= submit_tag as_(link.label), :class => 'submit' %>
8
+ <%= link_to as_(:cancel), main_path_to_return, :class => 'cancel' %>
9
+ </p>
10
+
11
+ </form>
12
+ </div>
13
+ </div>
@@ -1,5 +1,5 @@
1
1
  new_row = render :partial => 'list_record', :locals => {:record => @record}
2
- page << "ActiveScaffold.create_record_row('#{active_scaffold_tbody_id}','#{escape_javascript(new_row)}', #{{:insert_at => :top}.to_json});"
2
+ page << "ActiveScaffold.create_record_row('#{active_scaffold_id}','#{escape_javascript(new_row)}', #{{:insert_at => :top}.to_json});"
3
3
  page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}
4
4
 
5
5
  if (form_stays_open = true)
@@ -1,5 +1,23 @@
1
+ messages_id = active_scaffold_messages_id
1
2
  if controller.send(:successful?)
2
- page << "ActiveScaffold.delete_record_row('#{element_row_id(:action => 'list', :id => params[:id])}','#{url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))}');"
3
- page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}
3
+ if render_parent? && controller.respond_to?(:render_component_into_view)
4
+ render_parent_options
5
+ if render_parent_action == :row
6
+ # TODO: That s not working with delete....
7
+ page << "ActiveScaffold.delete_record_row('#{element_row_id(:controller_id => "as_#{id_from_controller(params[:eid] || params[:parent_sti])}", :action => 'list', :id => params[:id])}','#{url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))}');"
8
+ messages_id = active_scaffold_messages_id(:controller_id => "as_#{id_from_controller(params[:eid] || params[:parent_sti])}")
9
+ elsif render_parent_action == :index
10
+ parent_rendered = controller.send(:render_component_into_view, render_parent_options)
11
+ page << parent_rendered
12
+ end
13
+ #page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}
14
+ elsif (active_scaffold_config.delete.refresh_list)
15
+ page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false)
16
+ else
17
+ page << "ActiveScaffold.delete_record_row('#{element_row_id(:action => 'list', :id => params[:id])}','#{url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))}');"
18
+ page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}
19
+ end
20
+ else
21
+ flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br)
4
22
  end
5
- page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, render(:partial => 'messages')
23
+ page.call 'ActiveScaffold.replace_html', messages_id, render(:partial => 'messages')
@@ -1,6 +1,6 @@
1
1
  page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, render(:partial => 'messages')
2
2
  if controller.send :successful?
3
- page.call 'ActiveScaffold.replace', element_row_id(:action => :list, :id => @record.id), render(:partial => 'list_record', :locals => {:record => @record}) if @record
3
+ page.call 'ActiveScaffold.update_row', element_row_id(:action => :list, :id => @record.id), render(:partial => 'list_record', :locals => {:record => @record}) if @record
4
4
  page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}
5
5
  else
6
6
  page.call 'ActiveScaffold.scroll_to', active_scaffold_messages_id
@@ -1,22 +1,39 @@
1
1
  form_selector = "#{element_form_id(:action => :create)}"
2
-
3
- page << "ActiveScaffold.find_action_link('#{form_selector}').update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');"
2
+ insert_at ||= :top
3
+ page << "var action_link = ActiveScaffold.find_action_link('#{form_selector}');"
4
+ page << "action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');"
4
5
  if controller.send :successful?
5
- if @insert_row
6
+ if render_parent? && controller.respond_to?(:render_component_into_view)
7
+ parent_rendered = controller.send(:render_component_into_view, render_parent_options)
8
+ if nested_singular_association?
9
+ page << "action_link.close('#{escape_javascript(parent_rendered)}');"
10
+ else
11
+ if render_parent_action == :row
12
+ page << "ActiveScaffold.create_record_row(action_link.scaffold(),'#{escape_javascript(parent_rendered)}', #{{:insert_at => insert_at}.to_json});"
13
+ elsif render_parent_action == :index
14
+ page << parent_rendered
15
+ end
16
+ page << "action_link.close();"
17
+ end
18
+ #page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}
19
+ elsif (active_scaffold_config.create.refresh_list)
20
+ page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false)
21
+ elsif params[:parent_controller].nil?
6
22
  new_row = render :partial => 'list_record', :locals => {:record => @record}
7
- insert_at ||= :top
8
- page << "ActiveScaffold.create_record_row('#{active_scaffold_tbody_id}','#{escape_javascript(new_row)}', #{{:insert_at => insert_at}.to_json});"
23
+ page << "ActiveScaffold.create_record_row(action_link.scaffold(),'#{escape_javascript(new_row)}', #{{:insert_at => insert_at}.to_json});"
9
24
  page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}
10
25
  end
11
26
 
12
- if (active_scaffold_config.create.persistent)
13
- page << "ActiveScaffold.find_action_link('#{form_selector}').reload();"
14
- else
15
- page << "ActiveScaffold.find_action_link('#{form_selector}').close();"
16
- end
17
- if (active_scaffold_config.create.edit_after_create)
18
- page << "var link = $('#{action_link_id 'edit', @record.id}');"
19
- page << "if (link) (function() { link.action_link.open() }).defer();"
27
+ unless render_parent?
28
+ if (active_scaffold_config.create.persistent)
29
+ page << "action_link.reload();"
30
+ else
31
+ page << "action_link.close();"
32
+ end
33
+ if (active_scaffold_config.create.edit_after_create)
34
+ page << "var link = $('#{action_link_id 'edit', @record.id}');"
35
+ page << "if (link) (function() { link.action_link.open() }).defer();"
36
+ end
20
37
  end
21
38
  else
22
39
  page.call 'ActiveScaffold.replace', form_selector, render(:partial => 'create_form', :locals => {:xhr => true})
@@ -1,14 +1,27 @@
1
1
  form_selector = "#{element_form_id(:action => :update)}"
2
2
 
3
- page << "ActiveScaffold.find_action_link('#{form_selector}').update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');"
3
+ page << "var action_link = ActiveScaffold.find_action_link('#{form_selector}');"
4
+ page << "action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');"
4
5
  if controller.send :successful?
5
- updated_row = if nested? && nested.belongs_to?
6
- nil
6
+ if render_parent? && controller.respond_to?(:render_component_into_view)
7
+ parent_rendered = controller.send(:render_component_into_view, render_parent_options)
8
+ if nested_singular_association?
9
+ page << "action_link.close('#{escape_javascript(parent_rendered)}');"
10
+ else
11
+ if render_parent_action == :row
12
+ page << "action_link.close('#{escape_javascript(parent_rendered)}');"
13
+ elsif render_parent_action == :index
14
+ page << parent_rendered
15
+ end
16
+ end
17
+ #page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}
18
+ elsif (active_scaffold_config.update.refresh_list)
19
+ page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false)
7
20
  else
8
- render :partial => 'list_record', :locals => {:record => @record}
21
+ updated_row = render :partial => 'list_record', :locals => {:record => @record}
22
+ page << "action_link.close('#{escape_javascript(updated_row)}');"
23
+ page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}
9
24
  end
10
- page << "ActiveScaffold.find_action_link('#{form_selector}').close('#{escape_javascript(updated_row)}');"
11
- page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}
12
25
  else
13
26
  page.call 'ActiveScaffold.replace', form_selector, render(:partial => 'update_form', :locals => {:xhr => true})
14
27
  page.call 'ActiveScaffold.scroll_to', form_selector
data/init.rb CHANGED
@@ -1 +1,7 @@
1
1
  require 'active_scaffold'
2
+
3
+ begin
4
+ ActiveScaffoldAssets.copy_to_public(ActiveScaffold.root, {:clean_up_destination => true})
5
+ rescue
6
+ raise $! unless Rails.env == 'production'
7
+ end
@@ -8,19 +8,10 @@ module ActiveScaffold::Actions
8
8
  base.helper_method :beginning_of_chain
9
9
  end
10
10
  def render_field
11
- @record ||= if params[:in_place_editing]
12
- active_scaffold_config.model.find params[:id]
13
- else
14
- active_scaffold_config.model.new
15
- end
16
- column = active_scaffold_config.columns[params[:column]]
17
11
  if params[:in_place_editing]
18
- render :inline => "<%= active_scaffold_input_for(active_scaffold_config.columns[params[:update_column].to_sym]) %>"
19
- elsif !column.nil?
20
- value = column_value_from_param_value(@record, column, params[:value])
21
- @record.send "#{column.name}=", value
22
- after_render_field(@record, column)
23
- render :partial => "render_field", :collection => Array(params[:update_columns]), :content_type => 'text/javascript'
12
+ render_field_for_inplace_editing
13
+ else
14
+ render_field_for_update_columns
24
15
  end
25
16
  end
26
17
 
@@ -30,6 +21,23 @@ module ActiveScaffold::Actions
30
21
  false
31
22
  end
32
23
 
24
+ def render_field_for_inplace_editing
25
+ register_constraints_with_action_columns(nested.constrained_fields, active_scaffold_config.update.hide_nested_column ? [] : [:update]) if nested?
26
+ @record = find_if_allowed(params[:id], :update)
27
+ render :inline => "<%= active_scaffold_input_for(active_scaffold_config.columns[params[:update_column].to_sym]) %>"
28
+ end
29
+
30
+ def render_field_for_update_columns
31
+ @record = new_model
32
+ column = active_scaffold_config.columns[params[:column]]
33
+ unless column.nil?
34
+ value = column_value_from_param_value(@record, column, params[:value])
35
+ @record.send "#{column.name}=", value
36
+ after_render_field(@record, column)
37
+ render :partial => "render_field", :collection => Array(params[:update_columns]), :content_type => 'text/javascript'
38
+ end
39
+ end
40
+
33
41
  # override this method if you want to do something after render_field
34
42
  def after_render_field(record, column); end
35
43
 
@@ -127,6 +135,18 @@ module ActiveScaffold::Actions
127
135
  end
128
136
  conditions
129
137
  end
138
+
139
+ def new_model
140
+ model = beginning_of_chain
141
+ if model.columns_hash[model.inheritance_column]
142
+ build_options = {model.inheritance_column.to_sym => active_scaffold_config.model_id} if nested? && nested.association && nested.association.collection?
143
+ params = self.params # in new action inheritance_column must be in params
144
+ params = params[:record] || {} unless params[model.inheritance_column] # in create action must be inside record key
145
+ model = params.delete(model.inheritance_column).camelize.constantize if params[model.inheritance_column]
146
+ end
147
+ model.respond_to?(:build) ? model.build(build_options || {}) : model.new
148
+ end
149
+
130
150
  private
131
151
  def respond_to_action(action)
132
152
  respond_to do |type|
@@ -14,7 +14,6 @@ module ActiveScaffold::Actions
14
14
 
15
15
  def create
16
16
  do_create
17
- @insert_row = !(nested? && nested.belongs_to?) && params[:parent_controller].nil?
18
17
  respond_to_action(:create)
19
18
  end
20
19
 
@@ -62,6 +61,10 @@ module ActiveScaffold::Actions
62
61
  end
63
62
 
64
63
  def create_respond_to_js
64
+ if successful? && active_scaffold_config.create.refresh_list && !render_parent?
65
+ do_search if respond_to? :do_search
66
+ do_list
67
+ end
65
68
  render :action => 'on_create'
66
69
  end
67
70
 
@@ -111,16 +114,6 @@ module ActiveScaffold::Actions
111
114
  end
112
115
  end
113
116
 
114
- def new_model
115
- model = beginning_of_chain
116
- if model.columns_hash[model.inheritance_column]
117
- params = self.params # in new action inheritance_column must be in params
118
- params = params[:record] || {} unless params[model.inheritance_column] # in create action must be inside record key
119
- model = params.delete(model.inheritance_column).camelize.constantize if params[model.inheritance_column]
120
- end
121
- model.new
122
- end
123
-
124
117
  # override this method if you want to inject data in the record (or its associated objects) before the save
125
118
  def before_create_save(record); end
126
119
 
@@ -1,29 +1,32 @@
1
1
  module ActiveScaffold::Actions
2
2
  module Delete
3
3
  def self.included(base)
4
- base.before_filter :delete_authorized_filter, :only => [:delete, :destroy]
5
- end
6
-
7
- # this method is for html mode. it provides "the missing action" (http://thelucid.com/articles/2006/07/26/simply-restful-the-missing-action).
8
- # it also gives us delete confirmation for html mode. woo!
9
- def delete
10
- destroy_find_record
11
- render :action => 'delete'
4
+ base.before_filter :delete_authorized_filter, :only => [:destroy]
12
5
  end
13
6
 
14
7
  def destroy
15
- return redirect_to(params.merge(:action => :delete)) if request.get?
16
- do_destroy
17
- respond_to_action(:destroy)
8
+ params.delete :destroy_action
9
+ process_action_link_action(:destroy) do |record|
10
+ do_destroy
11
+ end
18
12
  end
19
13
 
20
14
  protected
21
15
  def destroy_respond_to_html
22
- flash[:info] = as_(:deleted_model, :model => @record.to_label) if self.successful?
16
+ if self.successful?
17
+ flash[:info] = as_(:deleted_model, :model => @record.to_label)
18
+ else
19
+ #error_message_for not available in controller...
20
+ #flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br)
21
+ end
23
22
  return_to_main
24
23
  end
25
24
 
26
25
  def destroy_respond_to_js
26
+ if successful? && active_scaffold_config.delete.refresh_list && !render_parent?
27
+ do_search if respond_to? :do_search
28
+ do_list
29
+ end
27
30
  render(:action => 'destroy')
28
31
  end
29
32
 
@@ -46,7 +49,7 @@ module ActiveScaffold::Actions
46
49
  # A simple method to handle the actual destroying of a record
47
50
  # May be overridden to customize the behavior
48
51
  def do_destroy
49
- destroy_find_record
52
+ @record ||= destroy_find_record
50
53
  begin
51
54
  self.successful = @record.destroy
52
55
  rescue
@@ -11,7 +11,8 @@ module ActiveScaffold::Actions
11
11
 
12
12
  # get just a single row
13
13
  def row
14
- render :partial => 'row', :locals => {:record => find_if_allowed(params[:id], :read)}
14
+ @record = find_if_allowed(params[:id], :read)
15
+ respond_to_action(:row)
15
16
  end
16
17
 
17
18
  def list
@@ -49,6 +50,15 @@ module ActiveScaffold::Actions
49
50
  def list_respond_to_yaml
50
51
  render :text => Hash.from_xml(response_object.to_xml(:only => list_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status
51
52
  end
53
+
54
+ def row_respond_to_html
55
+ render(:partial => 'row', :locals => {:record => @record})
56
+ end
57
+
58
+ def row_respond_to_js
59
+ render(:partial => 'row', :locals => {:record => @record})
60
+ end
61
+
52
62
  # The actual algorithm to prepare for the list view
53
63
  def do_list
54
64
  includes_for_list_columns = active_scaffold_config.list.columns.collect{ |c| c.includes }.flatten.uniq.compact
@@ -75,7 +85,7 @@ module ActiveScaffold::Actions
75
85
 
76
86
  def each_record_in_scope
77
87
  do_search if respond_to? :do_search
78
- finder_options = { :order => "#{active_scaffold_config.model.primary_key} ASC",
88
+ finder_options = { :order => "#{active_scaffold_config.model.connection.quote_table_name(active_scaffold_config.model.table_name)}.#{active_scaffold_config.model.primary_key} ASC",
79
89
  :conditions => all_conditions,
80
90
  :joins => joins_for_finder}
81
91
  finder_options.merge! custom_finder_options
@@ -90,6 +100,45 @@ module ActiveScaffold::Actions
90
100
  authorized_for?(:crud_type => :read)
91
101
  end
92
102
 
103
+ # call this method in your action_link action to simplify processing of actions
104
+ # eg for member action_link :fire
105
+ # process_action_link_action do |record|
106
+ # record.update_attributes(:fired => true)
107
+ # self.successful = true
108
+ # flash[:info] = 'Player fired'
109
+ # end
110
+ def process_action_link_action(render_action = :action_update)
111
+ if request.get?
112
+ # someone has disabled javascript, we have to show confirmation form first
113
+ @record = find_if_allowed(params[:id], :read) if params[:id] && params[:id] && params[:id].to_i > 0
114
+ respond_to_action(:action_confirmation)
115
+ else
116
+ if params[:id] && params[:id] && params[:id].to_i > 0
117
+ @record = find_if_allowed(params[:id], (request.post? || request.put?) ? :update : :delete)
118
+ unless @record.nil?
119
+ yield @record
120
+ else
121
+ self.successful = false
122
+ flash[:error] = as_(:no_authorization_for_action, :action => action_name)
123
+ end
124
+ else
125
+ yield
126
+ end
127
+ respond_to_action(render_action)
128
+ end
129
+ end
130
+
131
+ def action_confirmation_respond_to_html(confirm_action = action_name.to_sym)
132
+ link = active_scaffold_config.action_links[confirm_action]
133
+ render :action => 'action_confirmation', :locals => {:record => @record, :link => link}
134
+ end
135
+
136
+ def action_update_respond_to_html
137
+ do_search if respond_to? :do_search
138
+ do_list
139
+ redirect_to :action => 'index'
140
+ end
141
+
93
142
  def action_update_respond_to_js
94
143
  render(:action => 'on_action_update')
95
144
  end
@@ -110,13 +159,20 @@ module ActiveScaffold::Actions
110
159
  def list_authorized_filter
111
160
  raise ActiveScaffold::ActionNotAllowed unless list_authorized?
112
161
  end
162
+
113
163
  def list_formats
114
164
  (default_formats + active_scaffold_config.formats + active_scaffold_config.list.formats).uniq
115
165
  end
166
+ alias_method :row_formats, :list_formats
167
+
116
168
  def action_update_formats
117
169
  (default_formats + active_scaffold_config.formats).uniq
118
170
  end
119
171
 
172
+ def action_confirmation_formats
173
+ (default_formats + active_scaffold_config.formats).uniq
174
+ end
175
+
120
176
  def list_columns
121
177
  active_scaffold_config.list.columns.collect_visible
122
178
  end
@@ -22,7 +22,7 @@ module ActiveScaffold::Actions
22
22
  # because the object may change. So we give ActiveRecord a proc that ties to the
23
23
  # marked_records_method on this ApplicationController.
24
24
  def assign_marked_records_to_model
25
- active_scaffold_config.model.marked_records_proc = proc {send(:marked_records)}
25
+ active_scaffold_config.model.marked_records = marked_records
26
26
  end
27
27
 
28
28
  def marked_records
@@ -16,6 +16,7 @@ module ActiveScaffold::Actions
16
16
  end
17
17
  base.before_filter :include_habtm_actions
18
18
  base.helper_method :nested
19
+ base.helper_method :nested_parent_record
19
20
  end
20
21
 
21
22
  protected
@@ -23,7 +24,7 @@ module ActiveScaffold::Actions
23
24
  @nested ||= ActiveScaffold::DataStructures::NestedInfo.get(active_scaffold_config.model, active_scaffold_session_storage)
24
25
  if !@nested.nil? && @nested.new_instance?
25
26
  register_constraints_with_action_columns(@nested.constrained_fields)
26
- active_scaffold_constraints[:id] = nested.parent_id if @nested.belongs_to?
27
+ active_scaffold_constraints[:id] = params[:id] if @nested.belongs_to?
27
28
  end
28
29
  @nested
29
30
  end
@@ -33,12 +34,12 @@ module ActiveScaffold::Actions
33
34
  end
34
35
 
35
36
  def set_nested
36
- if params[:parent_model] && ((params[:association] && params[:assoc_id]) || params[:named_scope])
37
+ if params[:parent_scaffold] && ((params[:association] && params[:assoc_id]) || params[:named_scope])
37
38
  @nested = nil
38
- active_scaffold_session_storage[:nested] = {:parent_model => params[:parent_model].camelize.constantize,
39
+ active_scaffold_session_storage[:nested] = {:parent_scaffold => params[:parent_scaffold].to_s,
39
40
  :name => (params[:association] || params[:named_scope]).to_sym,
40
41
  :parent_id => params[:assoc_id]}
41
- params.delete_if {|key, value| [:parent_model, :association, :named_scope, :assoc_id].include? key.to_sym}
42
+ params.delete_if {|key, value| [:parent_scaffold, :association, :named_scope, :assoc_id].include? key.to_sym}
42
43
  end
43
44
  end
44
45
 
@@ -66,7 +67,9 @@ module ActiveScaffold::Actions
66
67
  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']
67
68
  if active_scaffold_config.nested.shallow_delete
68
69
  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']
69
- active_scaffold_config.action_links.delete("delete") if active_scaffold_config.action_links['delete']
70
+ if active_scaffold_config.actions.include?(:delete)
71
+ active_scaffold_config.action_links.delete("delete") if active_scaffold_config.action_links['delete']
72
+ end
70
73
  end
71
74
  else
72
75
  # Production mode is caching this link into a non nested scaffold
@@ -74,7 +77,9 @@ module ActiveScaffold::Actions
74
77
 
75
78
  if active_scaffold_config.nested.shallow_delete
76
79
  active_scaffold_config.action_links.delete("destroy_existing") if active_scaffold_config.action_links['destroy_existing']
77
- active_scaffold_config.action_links.add(ActiveScaffold::Config::Delete.link) unless active_scaffold_config.action_links['delete']
80
+ if active_scaffold_config.actions.include?(:delete)
81
+ active_scaffold_config.action_links.add(ActiveScaffold::Config::Delete.link) unless active_scaffold_config.action_links['delete']
82
+ end
78
83
  end
79
84
  end
80
85
  end
@@ -91,18 +96,22 @@ module ActiveScaffold::Actions
91
96
  end
92
97
 
93
98
  def nested_parent_record(crud = :read)
94
- find_if_allowed(nested.parent_id, crud, nested.parent_model)
99
+ @nested_parent_record ||= find_if_allowed(nested.parent_id, crud, nested.parent_model)
95
100
  end
96
101
 
97
102
  def create_association_with_parent(record)
98
- if nested? && nested.belongs_to? && nested.child_association
99
- parent = nested_parent_record(:read)
100
- case nested.child_association.macro
101
- when :has_one
102
- record.send("#{nested.child_association.name}=", parent)
103
- when :has_many
104
- record.send("#{nested.child_association.name}").send(:<<, parent)
105
- end unless parent.nil?
103
+ if nested?
104
+ if (nested.belongs_to? || nested.has_one? || nested.habtm?) && nested.child_association
105
+ parent = nested_parent_record(:read)
106
+ case nested.child_association.macro
107
+ when :has_one
108
+ record.send("#{nested.child_association.name}=", parent)
109
+ when :belongs_to
110
+ record.send("#{nested.child_association.name}=", parent)
111
+ when :has_many, :has_and_belongs_to_many
112
+ record.send("#{nested.child_association.name}").send(:<<, parent)
113
+ end unless parent.nil?
114
+ end
106
115
  end
107
116
  end
108
117
 
@@ -5,9 +5,16 @@ module ActiveScaffold::Actions
5
5
  end
6
6
 
7
7
  def show
8
- do_show
9
- successful?
10
- respond_to_action(:show)
8
+ # rest destroy falls back to rest show in case of disabled javascript
9
+ # just render action_confirmation message for destroy
10
+ unless params.delete :destroy_action
11
+ do_show
12
+ successful?
13
+ respond_to_action(:show)
14
+ else
15
+ @record = find_if_allowed(params[:id], :read) if params[:id] && params[:id] && params[:id].to_i > 0
16
+ action_confirmation_respond_to_html(:destroy)
17
+ end
11
18
  end
12
19
 
13
20
  protected
@@ -49,6 +49,10 @@ module ActiveScaffold::Actions
49
49
  end
50
50
  end
51
51
  def update_respond_to_js
52
+ if successful? && active_scaffold_config.update.refresh_list && !render_parent?
53
+ do_search if respond_to? :do_search
54
+ do_list
55
+ end
52
56
  render :action => 'on_update'
53
57
  end
54
58
  def update_respond_to_xml
@@ -87,10 +91,10 @@ module ActiveScaffold::Actions
87
91
  end
88
92
  rescue ActiveRecord::RecordInvalid
89
93
  rescue ActiveRecord::StaleObjectError
90
- @record.errors.add_to_base as_(:version_inconsistency)
94
+ @record.errors.add(:base, as_(:version_inconsistency))
91
95
  self.successful=false
92
96
  rescue ActiveRecord::RecordNotSaved
93
- @record.errors.add_to_base as_(:record_not_saved) if @record.errors.empty?
97
+ @record.errors.add(:base, as_(:record_not_saved)) if @record.errors.empty?
94
98
  self.successful = false
95
99
  end
96
100
  end
@@ -100,7 +104,10 @@ module ActiveScaffold::Actions
100
104
  if @record.authorized_for?(:crud_type => :update, :column => params[:column])
101
105
  column = active_scaffold_config.columns[params[:column].to_sym]
102
106
  params[:value] ||= @record.column_for_attribute(params[:column]).default unless @record.column_for_attribute(params[:column]).nil? || @record.column_for_attribute(params[:column]).null
103
- params[:value] = column_value_from_param_value(@record, column, params[:value]) unless column.nil?
107
+ unless column.nil?
108
+ params[:value] = column_value_from_param_value(@record, column, params[:value])
109
+ params[:value] = [] if params[:value].nil? && column.form_ui && column.plural_association?
110
+ end
104
111
  @record.send("#{params[:column]}=", params[:value])
105
112
  before_update_save(@record)
106
113
  @record.save