active_scaffold 3.0.23 → 3.0.24

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -16,7 +16,7 @@
16
16
  <% end %>
17
17
  <% else -%>
18
18
  <% if options[:level] == 0 %>
19
- <%= "#{start_level_0_tag}#{h(render_group_action_link(link, url_options, options, record))}#{end_level_0_tag}".html_safe %>
19
+ <%= "#{start_level_0_tag}#{render_group_action_link(link, url_options, options, record)}#{end_level_0_tag}".html_safe %>
20
20
  <% else %>
21
21
  <%= content_tag('li', render_group_action_link(link, url_options, options, record), options[:first_action] ? {:class => 'top'}: {}) %>
22
22
  <% end %>
@@ -0,0 +1,24 @@
1
+ <% record ||= nil
2
+ start_level_0_tag ||= ''
3
+ end_level_0_tag ||= ''%>
4
+ <% action_links.traverse(controller, traverse_options) do |parent, link, options| -%>
5
+ <% if (options[:node] == :finished_traversing) -%>
6
+ <%= "</ul>#{(options[:level] == 0 ? "</div>#{end_level_0_tag}": '</li>')}".html_safe %>
7
+ <% elsif (options[:node] == :start_traversing) -%>
8
+ <% html_classes = []
9
+ html_classes << 'hover_click' if hover_via_click? %>
10
+ <% if options[:level] == 0 %>
11
+ <% html_classes << 'action_group' %>
12
+ <%= "#{start_level_0_tag}<div class=\"#{html_classes.join(' ')}\" #{"onclick=\"\"" if hover_via_click?}> #{content_tag(:div, as_(parent.name), :class => (parent.name.to_s).downcase)}<ul>".html_safe %>
13
+ <% else %>
14
+ <% html_classes << 'top' if options[:first_action] %>
15
+ <%= "<li #{"class=\"#{html_classes.join(' ')}\"" unless html_classes.empty?} #{"onclick=\"\"" if hover_via_click?}>#{content_tag(:div, as_(parent.name), :class => (parent.name.to_s).downcase)}<ul>".html_safe %>
16
+ <% end %>
17
+ <% else debugger-%>
18
+ <% if options[:level] == 0 %>
19
+ <%= "#{start_level_0_tag}#{render_group_action_link(link, url_options, options, record)}#{end_level_0_tag}".html_safe %>
20
+ <% else %>
21
+ <%= content_tag('li', render_group_action_link(link, url_options, options, record), options[:first_action] ? {:class => 'top'}: {}) %>
22
+ <% end %>
23
+ <% end -%>
24
+ <% end -%>
@@ -0,0 +1,26 @@
1
+ <% subsection_id ||= nil %>
2
+ <% show_unauthorized_columns = active_scaffold_config.send(form_action).show_unauthorized_columns %>
3
+ <ol class="form" <%= "id=#{subsection_id}" unless subsection_id.nil? %> <%= "style=\"display: none;\"" if columns.collapsed %>>
4
+ <% columns.each :for => @record, :crud_type => (:read if show_unauthorized_columns) do |column| %>
5
+ <% authorized = show_unauthorized_columns ? @record.authorized_for?(:crud_type => form_action, :column => column.name) : true %>
6
+ <% renders_as = column_renders_as(column) %>
7
+ <% if renders_as == :subsection -%>
8
+ <% subsection_id = sub_section_id(:sub_section => column.label) %>
9
+ <li class="sub-section">
10
+ <h5><%= column.label %></h5>
11
+ <%= render :partial => 'form', :locals => { :columns => column, :subsection_id => subsection_id, :form_action => form_action } %>
12
+ <%= link_to_visibility_toggle(subsection_id, {:default_visible => !column.collapsed}) -%>
13
+ </li>
14
+ <% elsif column.readonly_association?
15
+ next %>
16
+ <% elsif renders_as == :subform and !override_form_field?(column) and authorized -%>
17
+ <li class="sub-form <%= active_scaffold_config_for(column.association.klass).subform.layout %>-sub-form <%= column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %> <%=column.name%>-sub-form" id="<%= sub_form_id(:association => column.name) %>">
18
+ <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column } -%>
19
+ </li>
20
+ <% else -%>
21
+ <li class="form-element <%= 'required' if column.required? %> <%= column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %>">
22
+ <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column, :only_value => !authorized } -%>
23
+ </li>
24
+ <% end -%>
25
+ <% end -%>
26
+ </ol>
@@ -0,0 +1,19 @@
1
+ <%
2
+ parent_record = @record
3
+ associated = column.singular_association? ? [parent_record.send(column.name)].compact : parent_record.send(column.name).to_a
4
+ associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless column.association.options.has_key?(:order)
5
+ if show_blank_record = column.show_blank_record?(associated)
6
+ associated << if column.singular_association?
7
+ parent_record.send("build_#{column.name}".to_sym)
8
+ else
9
+ parent_record.send(column.name).buildbuild_associated(column, parent_record)
10
+ end
11
+ end
12
+ subform_div_id = "#{sub_form_id({:association => column.name, :id => parent_record.id || 99999999999})}-div"
13
+ -%>
14
+ <h5><%= column.label -%></h5>
15
+ <div id ="<%= subform_div_id %>" <%= 'style="display: none;"'.html_safe if column.collapsed -%>>
16
+ <%= render :partial => subform_partial_for_column(column), :locals => {:column => column, :parent_record => parent_record, :associated => associated, :show_blank_record => show_blank_record} %>
17
+ </div>
18
+ <%= link_to_visibility_toggle(subform_div_id, {:default_visible => !column.collapsed}) -%>
19
+ <% @record = parent_record -%>
@@ -1,4 +1,10 @@
1
1
  <%
2
+ debugger
3
+ begin
4
+ remote_controller = active_scaffold_controller_for(column.association.klass)
5
+ rescue ActiveScaffold::ControllerNotFound
6
+ remote_controller = nil
7
+ end
2
8
  @record = parent_record
3
9
 
4
10
  show_add_existing = column_show_add_existing(column)
@@ -21,18 +27,22 @@ add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :as
21
27
  add_class = 'as_replace_with_new'
22
28
  end
23
29
  create_another_id = "#{sub_form_id(:association => column.name)}-create-another" %>
24
- <%= tag(:input, {:id => create_another_id, :type => 'button', :value => add_label, :href => add_new_url.html_safe, 'data-remote' => true, :class => add_class, :style=> "display: none;"}) %>
30
+ <%= link_to add_label, add_new_url, :id => create_another_id, :remote => true, :class => add_class, :style=> "display: none;" %>
25
31
  <%= javascript_tag("ActiveScaffold.show('#{create_another_id}');") %>
26
32
  <% end -%>
27
33
 
28
34
  <%= '|' if show_add_new and show_add_existing %>
29
35
 
30
36
  <% if show_add_existing -%>
31
- <% select_options = options_for_select(options_for_association(column.association))
32
- add_existing_id = "#{sub_form_id(:association => column.name)}-add-existing" %>
33
- <%= select_tag 'associated_id', '<option value="">'.html_safe + as_(:_select_) + '</option>'.html_safe + select_options %>
34
- <%= tag(:input, {:id => add_existing_id, :type => 'button', :value => as_(:add_existing), :href => edit_associated_url.html_safe, 'data-remote' => true, :class=> column.plural_association? ? 'as_add_existing' : 'as_replace_existing', :style => "display: none;"}) %>
35
- <%= javascript_tag("ActiveScaffold.show('#{add_existing_id}');") %>
37
+ <% if remote_controller and remote_controller.respond_to? :uses_record_select? and remote_controller.uses_record_select? -%>
38
+ <%= link_to_record_select as_(:add_existing), remote_controller.controller_path, :onselect => "ActiveScaffold.record_select_onselect(#{edit_associated_url.to_json}, #{active_scaffold_id.to_json}, id);" -%>
39
+ <% else -%>
40
+ <% select_options = options_for_select(options_for_association(column.association))
41
+ add_existing_id = "#{sub_form_id(:association => column.name)}-add-existing" %>
42
+ <%= select_tag 'associated_id', '<option value="">'.html_safe + as_(:_select_) + '</option>'.html_safe + select_options %>
43
+ <%= link_to as_(:add_existing), edit_associated_url, :id => add_existing_id, :remote => true, :class=> column.plural_association? ? 'as_add_existing' : 'as_replace_existing', :style => "display: none;" %>
44
+ <%= javascript_tag("ActiveScaffold.show('#{add_existing_id}');") %>
45
+ <% end -%>
36
46
  <% end -%>
37
47
  </div>
38
48
  </div>
@@ -0,0 +1,29 @@
1
+ <table cellpadding="0" cellspacing="0">
2
+ <%
3
+ record = if associated.empty?
4
+ if column.singular_association?
5
+ parent_record.send("build_#{column.name}".to_sym)
6
+ else
7
+ parent_record.send(column.name).build
8
+ end
9
+ else
10
+ associated.last
11
+ end
12
+ -%>
13
+ <%= render :partial => 'horizontal_subform_header', :locals => {:parent_record => parent_record, :record => record} %>
14
+
15
+ <tbody id="<%= sub_form_list_id(:association => column.name) %>">
16
+ <% associated.each_index do |index| %>
17
+ <% @record = associated[index] -%>
18
+ <% if @record.errors.count -%>
19
+ <tr class="association-record-errors">
20
+ <td colspan="<%= active_scaffold_config_for(@record.class).subform.columns.length + 1 %>" id="<%= element_messages_id :action => @record.class.name.underscore, :id => "#{parent_record.id}-#{index}" %>">
21
+ <%= active_scaffold_error_messages_for :record, :object_name => @record.class.model_name.human.downcase %>
22
+ </td>
23
+ </tr>
24
+ <% end %>
25
+ <%= render :partial => 'horizontal_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %>
26
+ <% end -%>
27
+ </tbody>
28
+ </table>
29
+ <%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated} -%>
@@ -2,9 +2,10 @@
2
2
  <tr>
3
3
  <%
4
4
  active_scaffold_config_for(@record.class).subform.columns.each :for => @record.class, :flatten => true do |column|
5
- next unless in_subform?(column, parent_record) and column_renders_as(column) != :hidden
5
+ hidden = column_renders_as(column) == :hidden
6
+ next unless in_subform?(column, parent_record)
6
7
  -%>
7
- <th<%= ' class="required"' if column.required? %>><label><%= column.label %></label></th>
8
+ <th class="<%= "#{'required' if column.required?} #{'hidden' if hidden}" %>"><label><%= column.label unless hidden %></label></th>
8
9
  <% end -%>
9
10
  </tr>
10
11
  </thead>
@@ -0,0 +1,15 @@
1
+ <td class="actions"><table cellpadding="0" cellspacing="0">
2
+ <tr>
3
+ <td class="indicator-container">
4
+ <%= loading_indicator_tag(:action => :record, :id => record.id) %>
5
+ </td>
6
+ <%= render :partial => 'action_group', :locals => {:action_links => action_links || active_scaffold_config.action_links.member,
7
+ :url_options => url_options,
8
+ :record => record,
9
+ :traverse_options => {:for => record},
10
+ :start_level_0_tag => '<td>',
11
+ :end_level_0_tag => '</td>'} %>
12
+ </tr>
13
+ </table>
14
+ </td>
15
+
@@ -0,0 +1,10 @@
1
+ <%# nested_id, allows us to remove a nested scaffold programmatically %>
2
+ <tr class="inline-adapter" id="<%= element_row_id :action => :nested %>">
3
+ <td colspan="99" class="inline-adapter-cell">
4
+ <div class="<%= "#{params[:action]}-view" if params[:action] %> <%= "#{params[:associations] ? params[:associations] : params[:controller]}-view" %> view">
5
+ <%= link_to(as_(:close), '', :class => 'inline-adapter-close as_cancel', :remote => true, :title => as_(:close), 'data-refresh' => (action_name == 'index' ? true : false)) -%>
6
+ <%= payload -%>
7
+ </div>
8
+ </td>
9
+ </tr>
10
+ <%= javascript_tag("var action_link = ActiveScaffold.ActionLink.get('#{element_row_id(:action => :nested)}'); if (action_link) action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');") %>
@@ -0,0 +1,30 @@
1
+ <tbody class="messages">
2
+ <tr class="record even-record">
3
+ <td colspan="<%= columns.length -%>" class="messages-container">
4
+ <p class="error-message message server-error" style="display:none;">
5
+ <%= as_(:internal_error).html_safe %>
6
+ <a href="#" onclick="ActiveScaffold.hide(this.parentNode); return false;" title="<%= as_(:close).html_safe %>"><%= as_(:close).html_safe %></a>
7
+ </p>
8
+ <div id="<%= active_scaffold_messages_id -%>">
9
+ <%= render :partial => 'messages' %>
10
+ </div>
11
+ <p class="filtered-message" <%= ' style="display:none;" '.html_safe unless @filtered %>>
12
+ <%= @filtered.is_a?(Array) ? render(:partial => 'human_conditions', :locals => {:columns => @filtered}) : as_(active_scaffold_config.list.filtered_message) %>
13
+ </p>
14
+ <p id="<%= empty_message_id %>" class="empty-message" <%= ' style="display:none;" '.html_safe unless @page.items.empty? %>>
15
+ <%= as_(active_scaffold_config.list.no_entries_message) %>
16
+ </p>
17
+ </td>
18
+ <% if active_scaffold_config.list.show_search_reset && @filtered -%>
19
+ <% search_link = ActiveScaffold::DataStructures::ActionLink.new('index', :label => :click_to_reset, :type => :member, :position => false)
20
+ action_links = ActiveScaffold::DataStructures::ActionLinks.new
21
+ action_links.add(search_link) -%>
22
+ <%= render :partial => 'list_actions', :locals => {:record => active_scaffold_config.model, :url_options => params_for(:escape => false, :search => ''), :action_links => action_links.member} %>
23
+ <% else %>
24
+ <td class='actions'><%= '<p class="empty-message">&nbsp;</p>'.html_safe if @page.items.empty? %></td>
25
+ <% end -%>
26
+
27
+ </tr>
28
+ </tbody>
29
+
30
+
@@ -0,0 +1,11 @@
1
+ <% if active_scaffold_config.list.pagination -%>
2
+ <div class="active-scaffold-footer">
3
+ <% unless @page.pager.infinite? -%>
4
+ <div class="active-scaffold-found"><span class="active-scaffold-records"><%= @page.pager.count -%></span> <%=as_(:found, :count => @page.pager.count) %></div>
5
+ <% end -%>
6
+ <div class="active-scaffold-pagination">
7
+ <%= render :partial => 'list_pagination_links', :locals => { :current_page => @page } if true || @page.pager.infinite? || @page.pager.number_of_pages > 1 %>
8
+ </div>
9
+ <br clear="both" /><%# a hack for the Rico Corner problem %>
10
+ </div>
11
+ <% end -%>
@@ -0,0 +1,23 @@
1
+ <%
2
+ column = if render_field.is_a? ActiveScaffold::DataStructures::Column
3
+ render_field
4
+ else
5
+ active_scaffold_config.columns[render_field.to_sym] unless render_field.is_a? ActiveScaffold::DataStructures::Column
6
+ end
7
+ @rendered ||= Set.new
8
+ return if @rendered.include? column.name
9
+ @rendered << column.name
10
+ if column_renders_as(column) == :subform
11
+ options = {:is_subform => true, :field_class => "#{column.name}-sub-form"}
12
+ else
13
+ options = {:is_subform => false, :field_class => "#{column.name}-input"}
14
+ end
15
+ -%>
16
+
17
+ ActiveScaffold.render_form_field('<%= source_id %>','<%= escape_javascript(render(:partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope })) %>', <%= options.to_json.html_safe %>);
18
+ <%if column.update_columns && !column.update_columns.empty?%>
19
+ <%= render(:partial => "render_field", :collection => column.update_columns, :locals => {:source_id => source_id, :scope => scope})%>
20
+ <%end%>
21
+
22
+
23
+
@@ -0,0 +1,6 @@
1
+ <%= render :partial => 'list_record', :locals => {:record => record}%>
2
+ <%= javascript_tag do %>
3
+ ActiveScaffold.replace('<%= active_scaffold_calculations_id %>', '<%= escape_javascript render(:partial => 'list_calculations') %>');
4
+ <% end if active_scaffold_config.list.columns.any? {|c| c.calculation?} %>
5
+
6
+
@@ -0,0 +1,12 @@
1
+ <div id="<%= sub_form_list_id(:association => column.name) %>">
2
+ <% associated.each_index do |index| %>
3
+ <% @record = associated[index] -%>
4
+ <% if @record.errors.count -%>
5
+ <div class="association-record-errors" id="<%= element_messages_id :action => @record.class.name.underscore, :id => "#{parent_record.id}-#{index}" %>">
6
+ <%= active_scaffold_error_messages_for :record, :object_name => @record.class.model_name.human.downcase %>
7
+ </div>
8
+ <% end %>
9
+ <%= render :partial => 'vertical_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %>
10
+ <% end -%>
11
+ </div>
12
+ <%#= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated} -%>
@@ -0,0 +1,13 @@
1
+ <%
2
+ associated_form = render :partial => "#{subform_partial_for_column(@column)}_record", :locals => {:scope => @scope, :parent_record => @parent_record, :column => @column, :locked => @record.new_record? && @column.singular_association?}
3
+ options = {:singular => false}
4
+ if @column.singular_association?
5
+ options[:singular] = true
6
+ else
7
+ unless @record.new_record?
8
+ column = active_scaffold_config_for(@record.class).columns[@record.class.primary_key]
9
+ options[:id] = active_scaffold_input_options(column, @scope)[:id]
10
+ end
11
+ end %>
12
+ alert("probando");
13
+ ActiveScaffold.create_associated_record_form('<%=sub_form_list_id(:association => @column.name)%>','<%=escape_javascript(associated_form)%>', <%= options.to_json.html_safe %>);
@@ -30,8 +30,8 @@ if controller.send :successful?
30
30
  else
31
31
  page << "action_link.close();"
32
32
  end
33
- if (active_scaffold_config.create.edit_after_create)
34
- page << "var link = $('#{action_link_id 'edit', @record.id}');"
33
+ if (active_scaffold_config.create.action_after_create)
34
+ page << "var link = $('#{action_link_id active_scaffold_config.create.action_after_create, @record.id}');"
35
35
  page << "if (link) (function() { link.action_link.open() }).defer();"
36
36
  end
37
37
  end
@@ -0,0 +1 @@
1
+ <%= render :partial => "render_field", :collection => columns, :locals => {:source_id => source_id, :scope => scope} %>
@@ -29,25 +29,29 @@ module ActiveScaffold::Actions
29
29
  end
30
30
 
31
31
  def render_field_for_update_columns
32
- @record = new_model
33
32
  column = active_scaffold_config.columns[params[:column]]
34
33
  unless column.nil?
34
+ @source_id = params.delete(:source_id)
35
+ @columns = column.update_columns
36
+ @scope = params[:scope]
37
+
35
38
  if column.send_form_on_update_column
36
39
  hash = if params[:scope]
37
- hash = params[:scope].gsub('[','').split(']').inject(params[:record]) do |hash, index|
40
+ params[:scope].gsub('[','').split(']').inject(params[:record]) do |hash, index|
38
41
  hash[index]
39
42
  end
40
43
  else
41
44
  params[:record]
42
45
  end
43
- @record = update_record_from_params(@record, active_scaffold_config.send(params[:id] ? :update : :create).columns, hash)
46
+ @record = hash[:id] ? find_if_allowed(hash[:id], :update) : new_model
47
+ @record = update_record_from_params(@record, active_scaffold_config.send(@scope ? :subform : (params[:id] ? :update : :create)).columns, hash)
44
48
  else
49
+ @record = new_model
45
50
  value = column_value_from_param_value(@record, column, params[:value])
46
51
  @record.send "#{column.name}=", value
47
52
  end
53
+
48
54
  after_render_field(@record, column)
49
- source_id = params.delete(:source_id)
50
- render :locals => {:source_id => source_id, :columns => column.update_columns, :scope => params[:scope]}
51
55
  end
52
56
  end
53
57
 
@@ -66,6 +70,10 @@ module ActiveScaffold::Actions
66
70
  end
67
71
  end
68
72
 
73
+ def marked_records
74
+ active_scaffold_session_storage[:marked_records] ||= Set.new
75
+ end
76
+
69
77
  def default_formats
70
78
  [:html, :js, :json, :xml, :yaml]
71
79
  end
@@ -0,0 +1,149 @@
1
+ module ActiveScaffold::Actions
2
+ module Create
3
+ def self.included(base)
4
+ base.before_filter :create_authorized_filter, :only => [:new, :create]
5
+ base.verify :method => :post,
6
+ :only => :create,
7
+ :redirect_to => { :action => :index }
8
+ end
9
+
10
+ def new
11
+ do_new
12
+ respond_to_action(:new)
13
+ end
14
+
15
+ def create
16
+ do_create
17
+ respond_to_action(:create)
18
+ end
19
+
20
+ protected
21
+ def response_location
22
+ url_for(params_for(:action => "show", :id => @record.id)) if successful?
23
+ end
24
+
25
+ def new_respond_to_html
26
+ if successful?
27
+ render(:action => 'create')
28
+ else
29
+ return_to_main
30
+ end
31
+ end
32
+
33
+ def new_respond_to_js
34
+ render(:partial => 'create_form')
35
+ end
36
+
37
+ def create_respond_to_html
38
+ if params[:iframe]=='true' # was this an iframe post ?
39
+ responds_to_parent do
40
+ render :action => 'on_create.js', :layout => false
41
+ end
42
+ else
43
+ if successful?
44
+ flash[:info] = as_(:created_model, :model => @record.to_label)
45
+ if action = active_scaffold_config.create.action_after_create
46
+ redirect_to params_for(:action => action, :id => @record.id)
47
+ elsif active_scaffold_config.create.persistent
48
+ redirect_to params_for(:action => "new")
49
+ else
50
+ return_to_main
51
+ end
52
+ else
53
+ if !nested? && active_scaffold_config.actions.include?(:list) && active_scaffold_config.list.always_show_create
54
+ do_list
55
+ render(:action => 'list')
56
+ else
57
+ render(:action => 'create')
58
+ end
59
+ end
60
+ end
61
+ end
62
+
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
68
+ render :action => 'on_create'
69
+ end
70
+
71
+ def create_respond_to_xml
72
+ render :xml => response_object.to_xml(:only => active_scaffold_config.create.columns.names), :content_type => Mime::XML, :status => response_status, :location => response_location
73
+ end
74
+
75
+ def create_respond_to_json
76
+ render :text => response_object.to_json(:only => active_scaffold_config.create.columns.names), :content_type => Mime::JSON, :status => response_status, :location => response_location
77
+ end
78
+
79
+ def create_respond_to_yaml
80
+ 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
81
+ end
82
+
83
+ # A simple method to find and prepare an example new record for the form
84
+ # May be overridden to customize the behavior (add default values, for instance)
85
+ def do_new
86
+ @record = new_model
87
+ apply_constraints_to_record(@record)
88
+ if nested?
89
+ create_association_with_parent(@record)
90
+ register_constraints_with_action_columns(nested.constrained_fields)
91
+ end
92
+ @record
93
+ end
94
+
95
+ # A somewhat complex method to actually create a new record. The complexity is from support for subforms and associated records.
96
+ # If you want to customize this behavior, consider using the +before_create_save+ and +after_create_save+ callbacks.
97
+ def do_create
98
+ begin
99
+ active_scaffold_config.model.transaction do
100
+ @record = update_record_from_params(new_model, active_scaffold_config.create.columns, params[:record])
101
+ apply_constraints_to_record(@record, :allow_autosave => true)
102
+ if nested?
103
+ create_association_with_parent(@record)
104
+ register_constraints_with_action_columns(nested.constrained_fields)
105
+ end
106
+ create_save
107
+ end
108
+ rescue ActiveRecord::RecordInvalid
109
+ end
110
+ end
111
+
112
+ def create_save
113
+ before_create_save(@record)
114
+ self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit
115
+ if successful?
116
+ @record.save! and @record.save_associated!
117
+ after_create_save(@record)
118
+ end
119
+ end
120
+
121
+ # override this method if you want to inject data in the record (or its associated objects) before the save
122
+ def before_create_save(record); end
123
+
124
+ # override this method if you want to do something after the save
125
+ def after_create_save(record); end
126
+
127
+ # The default security delegates to ActiveRecordPermissions.
128
+ # You may override the method to customize.
129
+
130
+ def create_ignore?
131
+ nested? && active_scaffold_config.list.always_show_create
132
+ end
133
+
134
+ def create_authorized?
135
+ (!nested? || !nested.readonly?) && authorized_for?(:crud_type => :create)
136
+ end
137
+ private
138
+ def create_authorized_filter
139
+ link = active_scaffold_config.create.link || active_scaffold_config.create.class.link
140
+ raise ActiveScaffold::ActionNotAllowed unless self.send(link.security_method)
141
+ end
142
+ def new_formats
143
+ (default_formats + active_scaffold_config.formats).uniq
144
+ end
145
+ def create_formats
146
+ (default_formats + active_scaffold_config.formats + active_scaffold_config.create.formats).uniq
147
+ end
148
+ end
149
+ end