active_scaffold_vho 3.0.31 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. data/Gemfile +9 -1
  2. data/Gemfile.lock +8 -79
  3. data/Rakefile +17 -20
  4. data/active_scaffold_vho.gemspec +374 -15
  5. data/{frontends/default → app/assets}/images/add.gif +0 -0
  6. data/{frontends/default → app/assets}/images/arrow_down.gif +0 -0
  7. data/{frontends/default → app/assets}/images/arrow_up.gif +0 -0
  8. data/{frontends/default → app/assets}/images/close.gif +0 -0
  9. data/{frontends/default → app/assets}/images/close_touch.png +0 -0
  10. data/{frontends/default → app/assets}/images/config.png +0 -0
  11. data/{frontends/default → app/assets}/images/cross.png +0 -0
  12. data/{frontends/default → app/assets}/images/gears.png +0 -0
  13. data/{frontends/default → app/assets}/images/indicator-small.gif +0 -0
  14. data/{frontends/default → app/assets}/images/indicator.gif +0 -0
  15. data/{frontends/default → app/assets}/images/magnifier.png +0 -0
  16. data/app/assets/javascripts/active_scaffold.js.erb +12 -0
  17. data/{frontends/default → app/assets}/javascripts/jquery/active_scaffold.js +73 -245
  18. data/app/assets/javascripts/jquery/date_picker_bridge.js.erb +24 -0
  19. data/app/assets/javascripts/jquery/jquery-ui-timepicker-addon.js +1060 -0
  20. data/{frontends/default → app/assets}/javascripts/jquery/jquery.editinplace.js +1 -1
  21. data/{lib/active_scaffold/bridges/tiny_mce/public → app/assets}/javascripts/jquery/tiny_mce_bridge.js +4 -3
  22. data/{frontends/default → app/assets}/javascripts/prototype/active_scaffold.js +36 -122
  23. data/{frontends/default → app/assets}/javascripts/prototype/dhtml_history.js +0 -0
  24. data/{frontends/default → app/assets}/javascripts/prototype/form_enhancements.js +0 -0
  25. data/{frontends/default → app/assets}/javascripts/prototype/rico_corner.js +0 -0
  26. data/{frontends/default/stylesheets/stylesheet-ie.css → app/assets/stylesheets/active_scaffold-ie.css} +0 -0
  27. data/{frontends/default/stylesheets/stylesheet.css → app/assets/stylesheets/active_scaffold.css.erb} +24 -22
  28. data/app/assets/stylesheets/jquery-ui-timepicker-addon.css +6 -0
  29. data/frontends/default/views/_action_group.html.erb +1 -1
  30. data/frontends/default/views/_base_form.html.erb +1 -1
  31. data/frontends/default/views/_form_association_footer.html.erb +11 -7
  32. data/frontends/default/views/_horizontal_subform_record.html.erb +5 -9
  33. data/frontends/default/views/_list.html.erb +1 -2
  34. data/frontends/default/views/_list_inline_adapter.html.erb +10 -0
  35. data/frontends/default/views/_list_messages.html.erb +2 -2
  36. data/frontends/default/views/_list_pagination.html.erb +6 -3
  37. data/frontends/default/views/_list_pagination_links.html.erb +9 -0
  38. data/frontends/default/views/_list_record.html.erb +2 -1
  39. data/frontends/default/views/_list_record_columns.html.erb +2 -1
  40. data/frontends/default/views/_list_with_header.html.erb +1 -1
  41. data/frontends/default/views/_messages.html.erb +0 -1
  42. data/frontends/default/views/_render_field.js.erb +13 -0
  43. data/frontends/default/views/_vertical_subform_record.html.erb +5 -9
  44. data/frontends/default/views/add_existing.js.erb +20 -0
  45. data/frontends/default/views/destroy.js.erb +24 -0
  46. data/frontends/default/views/{edit_associated.js.rjs → edit_associated.js.erb} +3 -2
  47. data/frontends/default/views/form_messages.js.erb +1 -0
  48. data/frontends/default/views/list.js.erb +1 -0
  49. data/frontends/default/views/on_action_update.js.erb +13 -0
  50. data/frontends/default/views/on_create.js.erb +45 -0
  51. data/frontends/default/views/on_mark_all.js.erb +12 -0
  52. data/frontends/default/views/on_update.js.erb +31 -0
  53. data/frontends/default/views/update_column.js.erb +16 -0
  54. data/frontends/default/views/update_row.js.erb +1 -0
  55. data/init.rb +1 -7
  56. data/lib/active_scaffold/actions/delete.rb +3 -5
  57. data/lib/active_scaffold/actions/field_search.rb +2 -6
  58. data/lib/active_scaffold/actions/list.rb +16 -14
  59. data/lib/active_scaffold/actions/search.rb +3 -3
  60. data/lib/active_scaffold/active_record_permissions.rb +2 -25
  61. data/lib/active_scaffold/attribute_params.rb +21 -44
  62. data/lib/active_scaffold/bridges/calendar_date_select/bridge.rb +1 -1
  63. data/lib/active_scaffold/bridges/date_picker/bridge.rb +2 -16
  64. data/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +86 -56
  65. data/lib/active_scaffold/bridges/file_column/bridge.rb +1 -1
  66. data/lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb +1 -1
  67. data/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb +1 -1
  68. data/lib/active_scaffold/bridges/paperclip/bridge.rb +1 -1
  69. data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb +2 -2
  70. data/lib/active_scaffold/bridges/shared/date_bridge.rb +3 -3
  71. data/lib/active_scaffold/bridges/tiny_mce/bridge.rb +0 -12
  72. data/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb +1 -1
  73. data/lib/active_scaffold/config/base.rb +1 -1
  74. data/lib/active_scaffold/config/core.rb +1 -8
  75. data/lib/active_scaffold/config/delete.rb +1 -1
  76. data/lib/active_scaffold/config/field_search.rb +1 -22
  77. data/lib/active_scaffold/config/list.rb +10 -18
  78. data/lib/active_scaffold/data_structures/action_link.rb +9 -0
  79. data/lib/active_scaffold/data_structures/action_links.rb +1 -1
  80. data/lib/active_scaffold/data_structures/column.rb +4 -30
  81. data/lib/active_scaffold/data_structures/nested_info.rb +3 -3
  82. data/lib/active_scaffold/data_structures/sorting.rb +1 -1
  83. data/lib/active_scaffold/engine.rb +8 -0
  84. data/lib/active_scaffold/extensions/action_controller_rendering.rb +22 -0
  85. data/lib/active_scaffold/extensions/action_view_rendering.rb +79 -59
  86. data/lib/active_scaffold/extensions/action_view_resolver.rb +4 -2
  87. data/lib/active_scaffold/extensions/active_association_reflection.rb +3 -3
  88. data/lib/active_scaffold/extensions/reverse_associations.rb +3 -3
  89. data/lib/active_scaffold/finder.rb +27 -39
  90. data/lib/active_scaffold/helpers/association_helpers.rb +3 -3
  91. data/lib/active_scaffold/helpers/form_column_helpers.rb +3 -3
  92. data/lib/active_scaffold/helpers/human_condition_helpers.rb +2 -4
  93. data/lib/active_scaffold/helpers/list_column_helpers.rb +16 -22
  94. data/lib/active_scaffold/helpers/search_column_helpers.rb +1 -1
  95. data/lib/active_scaffold/helpers/view_helpers.rb +35 -13
  96. data/lib/active_scaffold/locale/de.rb +120 -0
  97. data/lib/active_scaffold/locale/en.rb +119 -0
  98. data/lib/active_scaffold/version.rb +2 -2
  99. data/lib/active_scaffold.rb +12 -27
  100. data/lib/active_scaffold_env.rb +3 -3
  101. data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +1 -1
  102. metadata +84 -86
  103. data/.gitignore +0 -42
  104. data/frontends/default/views/_render_field.js.rjs +0 -10
  105. data/frontends/default/views/add_existing.js.rjs +0 -17
  106. data/frontends/default/views/destroy.js.rjs +0 -23
  107. data/frontends/default/views/form_messages.js.rjs +0 -1
  108. data/frontends/default/views/list.js.rjs +0 -1
  109. data/frontends/default/views/on_action_update.js.rjs +0 -10
  110. data/frontends/default/views/on_create.js.rjs +0 -41
  111. data/frontends/default/views/on_mark_all.js.rjs +0 -12
  112. data/frontends/default/views/on_update.js.rjs +0 -28
  113. data/frontends/default/views/update_column.js.rjs +0 -13
  114. data/frontends/default/views/update_row.js.rjs +0 -1
  115. data/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js +0 -36
  116. data/lib/active_scaffold/bridges/tiny_mce/public/javascripts/prototype/tiny_mce_bridge.js +0 -21
  117. data/lib/active_scaffold/locale/de.yml +0 -120
  118. data/lib/active_scaffold/locale/en.yml +0 -115
  119. data/lib/active_scaffold_assets.rb +0 -45
@@ -1,8 +1,11 @@
1
1
  <% if active_scaffold_config.list.pagination -%>
2
2
  <div class="active-scaffold-footer">
3
- <% unless active_scaffold_config.list.pagination == :infinite -%>
4
- <div class="active-scaffold-found"><span class="active-scaffold-records"><%= @records.total_count -%></span> <%=as_(:found, :count => @records.total_count) %></div>
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
5
  <% end -%>
6
- <%= paginate @records, :window => active_scaffold_config.list.page_links_window, :params => params_for(:action => :index), :remote => true %>
6
+ <div class="active-scaffold-pagination">
7
+ <%= render :partial => 'list_pagination_links', :locals => { :current_page => @page } if @page.pager.infinite? || @page.pager.number_of_pages > 1 %>
8
+ </div>
9
+ <br clear="both" /><%# a hack for the Rico Corner problem %>
7
10
  </div>
8
11
  <% end -%>
@@ -0,0 +1,9 @@
1
+ <% unless current_page.nil? -%>
2
+ <% url_options = params_for(:action => :index) -%>
3
+ <% options = {'data-page-history' => controller_id, :remote => true, :method => :get} -%>
4
+
5
+ <%= loading_indicator_tag :action => :pagination %>
6
+ <%= link_to as_(:previous), url_options.merge(:page => current_page.number - 1), options.merge(:class => "as_paginate previous") if current_page.prev? %>
7
+ <%= pagination_ajax_links current_page, url_options, options, active_scaffold_config.list.page_links_window %>
8
+ <%= link_to as_(:next), url_options.merge(:page => current_page.number + 1), options.merge(:class => "as_paginate next") if current_page.next? %>
9
+ <% end -%>
@@ -6,8 +6,9 @@ tr_class += " #{list_row_class(record)}" if respond_to? :list_row_class
6
6
  url_options = params_for(:action => :list, :id => record.id)
7
7
  action_links ||= active_scaffold_config.action_links.member
8
8
  -%>
9
+
9
10
  <tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>" data-refresh="<%= url_for(params_for(:action => :row, :id => record.id, :_method => :get, :escape => false)).html_safe %>" data-as_load="tr">
10
11
  <%= render :partial => 'list_record_columns', :locals => {:record => record, :columns => columns} %>
11
12
  <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options, :action_links => action_links} unless action_links.empty? %>
13
+ <%= render_nested_view(action_links, url_options, record) unless @nested_auto_open.nil? %>
12
14
  </tr>
13
- <%= render_nested_view(action_links, url_options, record) unless @nested_auto_open.nil? %>
@@ -1,6 +1,7 @@
1
1
  <% columns.each do |column| %>
2
- <% authorized = record.authorized_for_read_column?(column.name) -%>
2
+ <% authorized = record.authorized_for?(:crud_type => :read, :column => column.name) -%>
3
3
  <% column_value = authorized ? get_column_value(record, column) : active_scaffold_config.list.empty_field_text -%>
4
+
4
5
  <td class="<%= column_class(column, column_value, record) %>" >
5
6
  <%= authorized ? render_list_column(column_value, column, record) : column_value %>
6
7
  </td>
@@ -1,4 +1,4 @@
1
- <div id="<%= active_scaffold_id -%>" class="<%= as_main_div_class %>" <%= "data-eid=#{id_from_controller(params[:eid])}" if params[:eid]%> data-closelabel="<%=as_(:close).html_safe%>" data-controller=<%="#{params[:controller]}"%>>
1
+ <div id="<%= active_scaffold_id -%>" class="<%= as_main_div_class %>" <%= "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>
@@ -5,7 +5,6 @@
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
- <% flash[name] = nil %>
9
8
  </div>
10
9
  <% end %>
11
10
  <% end %>
@@ -0,0 +1,13 @@
1
+ <%column = active_scaffold_config.columns[render_field.to_sym]
2
+ options = {:is_subform => false, :field_class => "#{column.name}-input"}
3
+ if column_renders_as(column) == :subform
4
+ options[:is_subform] = true
5
+ end %>
6
+
7
+ ActiveScaffold.render_form_field('<%=source_id%>','<%=escape_javascript(render(:partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] }))%>', <%=options.to_json.html_safe%>);
8
+ <%if column.update_columns && !column.update_columns.empty?%>
9
+ <%= render(:partial => "render_field", :collection => column.update_columns)%>
10
+ <%end%>
11
+
12
+
13
+
@@ -6,7 +6,6 @@
6
6
  config = active_scaffold_config_for(@record.class)
7
7
  options = active_scaffold_input_options(config.columns[@record.class.primary_key], scope)
8
8
  tr_id = "association-#{options[:id]}"
9
- associated_action = @record.new_record? ? :create_or_empty : :update
10
9
  -%>
11
10
  <ol id="<%= tr_id %>" class="association-record <%= 'association-record-new' if @record.new_record? -%> <%= 'locked' if locked -%>">
12
11
  <% config.subform.columns.each :for => @record, :crud_type => crud_type, :flatten => true do |column| %>
@@ -27,16 +26,13 @@
27
26
  <% if show_actions -%>
28
27
  <li class="actions">
29
28
  <% if record_column.plural_association? and (@record.authorized_for?(:crud_type => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %>
30
- <% link_classes = ['destroy', 'as_destroy_existing']
31
- link_classes << 'as_associated_form_link' if !locked %>
32
- <%= link_to as_(:remove), '#', :class => link_classes.join(' '), :style=> "display: none;" %>
29
+ <% destroy_id = "#{options[:id]}-destroy" %>
30
+ <%= link_to as_(:remove), '#', :class => 'destroy', :id => destroy_id , :onclick => "ActiveScaffold.delete_subform_record(\"#{tr_id}\"); return false;", :style=> "display: none;" %>
31
+ <%= javascript_tag("ActiveScaffold.show('#{destroy_id}');") if !locked %>
33
32
  <% end %>
34
- </li>
35
- <% end -%>
36
- <li>
37
33
  <% unless @record.new_record? %>
38
- <input type="hidden" name="<%= options[:name] -%>" id="<%= options[:id] -%>" value="<%= @record.id -%>" />
34
+ <input type="hidden" name="<%= options[:name] -%>" id="<%= options[:id] -%>" value="<%= @record.id -%>" />
39
35
  <% end -%>
40
- <input type="hidden" name="<%= scope ? "record#{scope}[associated_action]" : "record[associated_action]" -%>" class="associated_action" value="<%= associated_action -%>" />
41
36
  </li>
37
+ <% end -%>
42
38
  </ol>
@@ -0,0 +1,20 @@
1
+ <% new_row = render :partial => 'list_record', :locals => {:record => @record}%>
2
+ ActiveScaffold.create_record_row('<%=active_scaffold_id%>','<%=escape_javascript(new_row)%>', <%={:insert_at => :top}.to_json.html_safe%>);
3
+
4
+ <% if active_scaffold_config.list.columns.any? {|c| c.calculation?} %>
5
+ ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>');
6
+ <% end %>
7
+
8
+ <% if(form_stays_open = true)%>
9
+ <%# why not just re-render the form? that wouldn't utilize a possible do_new override which sets default values.%>
10
+ ActiveScaffold.reset_form('<%=element_form_id%>');
11
+ ActiveScaffold.replace_html('<%=element_messages_id(:action => :add_existing)%>', '<%=escape_javascript(render(:partial => 'form_messages'))%>');
12
+ <%# have to delay the focus, because there's no "firstElement" in prototype until at least one element is not disabled%>
13
+ <% if ActiveScaffold.js_framework == :prototype %>
14
+ page.delay 0.1 do
15
+ page << "ActiveScaffold.focus_first_element_of_form('<%=element_form_id%>');"
16
+ end
17
+ <% end %>
18
+ <% else %>
19
+ ActiveScaffold.find_action_link('<%=element_form_id(:action => :new_existing)%>').close();
20
+ <% end %>
@@ -0,0 +1,24 @@
1
+ <%messages_id = active_scaffold_messages_id%>
2
+ <%if controller.send(:successful?)%>
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
+ 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
+ <%= escape_javascript(controller.send(:render_component_into_view, render_parent_options))%>
11
+ <%end%>
12
+ <%#page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}%>
13
+ <%elsif (active_scaffold_config.delete.refresh_list)%>
14
+ ActiveScaffold.replace('<%=active_scaffold_content_id%>', '<%=escape_javascript(render(:partial => 'list', :layout => false))%>');
15
+ <%else%>
16
+ 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))%>');
17
+ <% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%>
18
+ ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>');
19
+ <% end %>
20
+ <%end%>
21
+ <%else%>
22
+ <%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)%>
23
+ <%end%>
24
+ ActiveScaffold.replace_html('<%=messages_id%>', '<%=escape_javascript(render(:partial => 'messages'))%>');
@@ -1,3 +1,4 @@
1
+ <%
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?}
2
3
  options = {:singular => false}
3
4
  if @column.singular_association?
@@ -7,5 +8,5 @@ else
7
8
  column = active_scaffold_config_for(@record.class).columns[@record.class.primary_key]
8
9
  options[:id] = active_scaffold_input_options(column, @scope)[:id]
9
10
  end
10
- end
11
- page.call 'ActiveScaffold.create_associated_record_form', sub_form_list_id(:association => @column.name), associated_form, options
11
+ end %>
12
+ ActiveScaffold.create_associated_record_form('<%=sub_form_list_id(:association => @column.name)%>','<%=escape_javascript(associated_form)%>', <%=options.to_json.html_safe%>);
@@ -0,0 +1 @@
1
+ ActiveScaffold.replace_html('<%=element_messages_id%>','<%=escape_javascript(render(:partial => 'form_messages'))%>');
@@ -0,0 +1 @@
1
+ ActiveScaffold.replace_html('<%=active_scaffold_content_id%>','<%=escape_javascript(render(:partial => 'list', :layout => false))%>');
@@ -0,0 +1,13 @@
1
+ <%if controller.send :successful?%>
2
+ ActiveScaffold.replace_html('<%=active_scaffold_messages_id%>','<%=escape_javascript(render(:partial => 'messages'))%>');
3
+ <%if @record%>
4
+ ActiveScaffold.update_row('<%=element_row_id(:action => :list, :id => @record.id)%>','<%=escape_javascript(render(:partial => 'list_record', :locals => {:record => @record}))%>');
5
+ <%end%>
6
+ <% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%>
7
+ ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>');
8
+ <% end %>
9
+ <%else%>
10
+ <%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)%>
11
+ ActiveScaffold.replace_html('<%=active_scaffold_messages_id%>','<%=escape_javascript(render(:partial => 'messages'))%>');
12
+ ActiveScaffold.scroll_to('<%=active_scaffold_messages_id%>');
13
+ <%end%>
@@ -0,0 +1,45 @@
1
+ try {
2
+ <% form_selector = "#{element_form_id(:action => :create)}"
3
+ insert_at ||= :top %>
4
+ var action_link = ActiveScaffold.find_action_link('<%= form_selector%>');
5
+ action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'messages').strip)%>');
6
+ <% if controller.send :successful? %>
7
+ <% if render_parent? && controller.respond_to?(:render_component_into_view) %>
8
+ <% parent_rendered = controller.send(:render_component_into_view, render_parent_options) %>
9
+ <% if nested_singular_association? %>
10
+ action_link.close('<%= escape_javascript(parent_rendered)%>');
11
+ <% else %>
12
+ <% if render_parent_action == :row %>
13
+ ActiveScaffold.create_record_row(action_link.scaffold(),'<%= escape_javascript(parent_rendered)%>', <%= {:insert_at => insert_at}.to_json.html_safe %>);
14
+ <% elsif render_parent_action == :index %>
15
+ <%= escape_javascript(parent_rendered) %>
16
+ <% end %>
17
+ action_link.close();
18
+ <% end %>
19
+ <%#page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}%>
20
+ <% elsif (active_scaffold_config.create.refresh_list) %>
21
+ ActiveScaffold.replace_html('<%= active_scaffold_content_id%>', '<%= escape_javascript(render(:partial => 'list', :layout => false)) %>');
22
+ <% elsif params[:parent_controller].nil? %>
23
+ <% new_row = render :partial => 'list_record', :locals => {:record => @record} %>
24
+ ActiveScaffold.create_record_row(action_link.scaffold(),'<%=escape_javascript(new_row)%>', <%={:insert_at => insert_at}.to_json.html_safe%>);
25
+ <% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%>
26
+ ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>');
27
+ <% end %>
28
+ <% end %>
29
+
30
+ <% unless render_parent? %>
31
+ <% if (active_scaffold_config.create.persistent) %>
32
+ action_link.reload();
33
+ <% else %>
34
+ action_link.close();
35
+ <% end %>
36
+ <% if (active_scaffold_config.create.edit_after_create) %>
37
+ var link = $('<%=action_link_id 'edit', @record.id%>');
38
+ if (link) (function() { link.action_link.open() }).defer();
39
+ <% end %>
40
+ <% end %>
41
+ <% else %>
42
+ ActiveScaffold.replace('<%=form_selector%>','<%=escape_javascript(render(:partial => 'create_form', :locals => {:xhr => true}))%>');
43
+ ActiveScaffold.scroll_to('<%=form_selector%>');
44
+ <% end %>
45
+ } catch (e) { alert('RJS error:\n\n' + e.toString());}
@@ -0,0 +1,12 @@
1
+ <%options = {:checked => mark_all,
2
+ :include_mark_all => true}%>
3
+ ActiveScaffold.mark_records('<%=active_scaffold_tbody_id%>',<%=options.to_json.html_safe%>);
4
+ <%if active_scaffold_config.model.marked.length>0 then %>
5
+ <%if active_scaffold_config.model.marked.length < @page.pager.count then%>
6
+ ActiveScaffold.replace_html('<%=active_scaffold_messages_id%>','<%="#{active_scaffold_config.model.marked.length.to_s} records marked. Press <a href=\"#{url_for(:action=>"mark_all",:mark_target=>"scope")}\">here</a> to select all #{@page.pager.count} records.".html_safe%>');
7
+ <%else%>
8
+ ActiveScaffold.replace_html('<%=active_scaffold_messages_id%>','<%="All #{@page.pager.count} records marked".html_safe%>');
9
+ <%end%>
10
+ <%else%>
11
+ ActiveScaffold.replace_html('<%=active_scaffold_messages_id%>','');
12
+ <%end%>
@@ -0,0 +1,31 @@
1
+ try {
2
+ <% form_selector = "#{element_form_id(:action => :update)}" %>
3
+ var action_link = ActiveScaffold.find_action_link('<%= form_selector%>');
4
+ action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'messages').strip)%>');
5
+ <% if controller.send :successful? %>
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
+ action_link.close('<%= escape_javascript(parent_rendered)%>');
10
+ <% else %>
11
+ <% if render_parent_action == :row %>
12
+ action_link.close('<%= escape_javascript(parent_rendered)%>');
13
+ <% elsif render_parent_action == :index %>
14
+ <%= escape_javascript(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 update_refresh_list? %>
19
+ ActiveScaffold.replace_html('<%= active_scaffold_content_id%>', '<%= escape_javascript(render(:partial => 'list', :layout => false))%>');
20
+ <% else %>
21
+ <% updated_row = render :partial => 'list_record', :locals => {:record => @record}%>
22
+ action_link.close('<%= escape_javascript(updated_row)%>');
23
+ <% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%>
24
+ ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>');
25
+ <% end %>
26
+ <% end %>
27
+ <% else %>
28
+ ActiveScaffold.replace('<%=form_selector%>','<%=escape_javascript(render(:partial => 'update_form', :locals => {:xhr => true}))%>');
29
+ ActiveScaffold.scroll_to('<%=form_selector%>');
30
+ <% end %>
31
+ } catch (e) { alert('RJS error:\n\n' + e.toString());}
@@ -0,0 +1,16 @@
1
+ <% column_span_id ||= element_cell_id(:id => @record.id.to_s, :action => 'update_column', :name => params[:column])%>
2
+ <% unless controller.send :successful?%>
3
+ alert('<%= escape_javascript(@record.errors.full_messages.join("\n"))%>');
4
+ <% @record.reload%>
5
+ <% end%>
6
+ <% column = active_scaffold_config.columns[params[:column]]%>
7
+ <% if column.inplace_edit%>
8
+ ActiveScaffold.replace_html('<%=column_span_id%>','<%=escape_javascript(format_inplace_edit_column(@record, column))%>');
9
+ <% else%>
10
+ <% formatted_value = get_column_value(@record, column)%>
11
+ ActiveScaffold.replace_html('<%=column_span_id%>','<%=escape_javascript(formatted_value)%>');
12
+ <% end%>
13
+ <% if column.calculation?%>
14
+ ActiveScaffold.replace_html('<%=active_scaffold_calculations_id(column)%>', '<%=escape_javascript(render_column_calculation(column))%>');
15
+ <% end%>
16
+
@@ -0,0 +1 @@
1
+ ActiveScaffold.update_row('<%=element_row_id(:action => 'list', :id => @record.id)%>','<%=escape_javascript(render(:partial => 'list_record', :locals => {:record => @record}))%>');
data/init.rb CHANGED
@@ -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
1
+ require 'active_scaffold'
@@ -63,15 +63,13 @@ module ActiveScaffold::Actions
63
63
  def delete_authorized?(record = nil)
64
64
  (!nested? || !nested.readonly?) && authorized_for?(:crud_type => :delete)
65
65
  end
66
-
67
- def destroy_formats
68
- (default_formats + active_scaffold_config.formats + active_scaffold_config.delete.formats).uniq
69
- end
70
66
  private
71
67
  def delete_authorized_filter
72
68
  link = active_scaffold_config.delete.link || active_scaffold_config.delete.class.link
73
69
  raise ActiveScaffold::ActionNotAllowed unless self.send(link.security_method)
74
70
  end
75
-
71
+ def destroy_formats
72
+ (default_formats + active_scaffold_config.formats + active_scaffold_config.delete.formats).uniq
73
+ end
76
74
  end
77
75
  end
@@ -43,16 +43,12 @@ module ActiveScaffold::Actions
43
43
  end
44
44
 
45
45
  def do_search
46
- prepare_search_conditions(search_params)
47
- end
48
-
49
- def prepare_search_conditions(params)
50
- unless params.nil?
46
+ unless search_params.nil?
51
47
  text_search = active_scaffold_config.field_search.text_search
52
48
  search_conditions = []
53
49
  human_condition_columns = [] if active_scaffold_config.field_search.human_conditions
54
50
  columns = field_search_columns
55
- params.each do |key, value|
51
+ search_params.each do |key, value|
56
52
  next unless columns.include? key
57
53
  search_condition = self.class.condition_for_column(active_scaffold_config.columns[key], value, text_search)
58
54
  unless search_condition.blank?
@@ -3,7 +3,6 @@ module ActiveScaffold::Actions
3
3
  def self.included(base)
4
4
  base.before_filter :list_authorized_filter, :only => [:index, :row]
5
5
  base.helper_method :list_columns
6
- base.helper_method :save_current_page_num
7
6
  end
8
7
 
9
8
  def index
@@ -33,7 +32,10 @@ module ActiveScaffold::Actions
33
32
  end
34
33
  end
35
34
  def list_respond_to_js
36
- if params.delete(:embedded)
35
+ if params[:adapter]
36
+ render(:partial => 'list_with_header')
37
+ elsif params[:embedded]
38
+ params.delete(:embedded)
37
39
  render(:partial => 'list_with_header')
38
40
  else
39
41
  render :action => 'list.js'
@@ -64,7 +66,7 @@ module ActiveScaffold::Actions
64
66
 
65
67
  options = { :sorting => active_scaffold_config.list.user.sorting,
66
68
  :count_includes => active_scaffold_config.list.user.count_includes }
67
- paginate = (params[:format].nil?) ? (accepts? :html, :js) : ['html', 'js'].include?(params[:format].to_s)
69
+ paginate = (params[:format].nil?) ? (accepts? :html, :js) : ['html', 'js'].include?(params[:format])
68
70
  if paginate
69
71
  options.merge!({
70
72
  :per_page => active_scaffold_config.list.user.per_page,
@@ -73,8 +75,12 @@ module ActiveScaffold::Actions
73
75
  })
74
76
  end
75
77
 
76
- @records = find_page(options);
77
- @records
78
+ page = find_page(options);
79
+ if page.items.blank? && !page.pager.infinite?
80
+ page = page.pager.last
81
+ active_scaffold_config.list.user.page = page.number
82
+ end
83
+ @page, @records = page, page.items
78
84
  end
79
85
 
80
86
  def each_record_in_page
@@ -156,6 +162,11 @@ module ActiveScaffold::Actions
156
162
  def action_update_respond_to_yaml
157
163
  render :text => successful? ? "" : Hash.from_xml(response_object.to_xml(:only => list_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status
158
164
  end
165
+
166
+ private
167
+ def list_authorized_filter
168
+ raise ActiveScaffold::ActionNotAllowed unless list_authorized?
169
+ end
159
170
 
160
171
  def list_formats
161
172
  (default_formats + active_scaffold_config.formats + active_scaffold_config.list.formats).uniq
@@ -170,15 +181,6 @@ module ActiveScaffold::Actions
170
181
  (default_formats + active_scaffold_config.formats).uniq
171
182
  end
172
183
 
173
- def save_current_page_num
174
- active_scaffold_config.list.user.page = @records.current_page unless active_scaffold_config.list.pagination == false
175
- end
176
-
177
- private
178
- def list_authorized_filter
179
- raise ActiveScaffold::ActionNotAllowed unless list_authorized?
180
- end
181
-
182
184
  def list_columns
183
185
  active_scaffold_config.list.columns.collect_visible
184
186
  end
@@ -35,13 +35,13 @@ module ActiveScaffold::Actions
35
35
  end
36
36
  end
37
37
 
38
- def search_formats
39
- (default_formats + active_scaffold_config.formats + active_scaffold_config.search.formats).uniq
40
- end
41
38
  private
42
39
  def search_authorized_filter
43
40
  link = active_scaffold_config.search.link || active_scaffold_config.search.class.link
44
41
  raise ActiveScaffold::ActionNotAllowed unless self.send(link.security_method)
45
42
  end
43
+ def search_formats
44
+ (default_formats + active_scaffold_config.formats + active_scaffold_config.search.formats).uniq
45
+ end
46
46
  end
47
47
  end
@@ -64,7 +64,6 @@ module ActiveRecordPermissions
64
64
  def self.included(base)
65
65
  base.extend SecurityMethods
66
66
  base.send :include, SecurityMethods
67
- base.class_attribute :auth_column_read_methods
68
67
  end
69
68
 
70
69
  # Because any class-level queries get delegated to the instance level via a new record,
@@ -83,6 +82,8 @@ module ActiveRecordPermissions
83
82
  # options[:column] should be the name of a model attribute
84
83
  # options[:action] is the name of a method
85
84
  def authorized_for?(options = {})
85
+ raise ArgumentError, "unknown crud type #{options[:crud_type]}" if options[:crud_type] and ![:create, :read, :update, :delete].include?(options[:crud_type])
86
+
86
87
  # column_authorized_for_crud_type? has the highest priority over other methods,
87
88
  # you can disable a crud verb and enable that verb for a column
88
89
  # (for example, disable update and enable inplace_edit in a column)
@@ -111,30 +112,6 @@ module ActiveRecordPermissions
111
112
  return ActiveRecordPermissions.default_permission
112
113
  end
113
114
 
114
- def authorized_for_read_column?(column)
115
- self.class.auth_column_read_methods ||= {}
116
- methods = self.class.auth_column_read_methods[column]
117
- if methods.nil?
118
- method = column_and_crud_type_security_method(column, :read)
119
- methods = if method && respond_to?(method)
120
- [method]
121
- else
122
- [column_security_method(column),
123
- crud_type_security_method(:read)].compact.select {|m| respond_to?(m)}
124
- end
125
- self.class.auth_column_read_methods[column] = methods
126
- end
127
-
128
- # if any method returns false, then return false
129
- return false if methods.any? {|m| !send(m)}
130
-
131
- # if any method actually exists then it must've returned true, so return true
132
- return true unless methods.empty?
133
-
134
- # if no method exists, return the default permission
135
- return ActiveRecordPermissions.default_permission
136
- end
137
-
138
115
  private
139
116
 
140
117
  def column_security_method(column)
@@ -39,7 +39,6 @@ module ActiveScaffold
39
39
  crud_type = parent_record.new_record? ? :create : :update
40
40
  return parent_record unless parent_record.authorized_for?(:crud_type => crud_type)
41
41
 
42
- attributes = {} unless attributes.is_a?(Hash)
43
42
  multi_parameter_attributes = {}
44
43
  attributes.each do |k, v|
45
44
  next unless k.include? '('
@@ -88,7 +87,7 @@ module ActiveScaffold
88
87
  end
89
88
 
90
89
  def manage_nested_record_from_params(parent_record, column, attributes)
91
- record = nested_record_for_action(parent_record, column, attributes)
90
+ record = find_or_create_for_params(attributes, column, parent_record)
92
91
  if record
93
92
  record_columns = active_scaffold_config_for(column.association.klass).subform.columns
94
93
  update_record_from_params(record, record_columns, attributes)
@@ -96,23 +95,6 @@ module ActiveScaffold
96
95
  end
97
96
  record
98
97
  end
99
-
100
- def nested_record_for_action(parent_record, column, attributes)
101
- associated_action = attributes.delete(:associated_action)
102
-
103
- case associated_action.to_sym
104
- when :create then create_nested_record(column, parent_record)
105
- when :update then find_nested_record(attributes[:id], column, parent_record)
106
- when :empty then nil
107
- when :delete then nil
108
- when :create_or_empty then
109
- if column.show_blank_record && attributes_hash_is_empty?(attributes, column.association.klass)
110
- nil
111
- else
112
- create_nested_record(column, parent_record)
113
- end
114
- end
115
- end
116
98
 
117
99
  def column_value_from_param_value(parent_record, column, value)
118
100
  # convert the value, possibly by instantiating associated objects
@@ -135,11 +117,8 @@ module ActiveScaffold
135
117
  # convert empty strings into nil. this works better with 'null => true' columns (and validations),
136
118
  # and 'null => false' columns should just convert back to an empty string.
137
119
  # ... but we can at least check the ConnectionAdapter::Column object to see if nulls are allowed
138
- if value.is_a? String and value.empty? and !column.column.nil? and column.column.null
139
- nil
140
- else
141
- column.stripped_value(value)
142
- end
120
+ value = nil if value.is_a? String and value.empty? and !column.column.nil? and column.column.null
121
+ value
143
122
  end
144
123
  end
145
124
 
@@ -170,35 +149,33 @@ module ActiveScaffold
170
149
  end
171
150
  end
172
151
 
173
- def create_nested_record(parent_column, parent_record)
152
+ # Attempts to create or find an instance of klass (which must be an ActiveRecord object) from the
153
+ # request parameters given. If params[:id] exists it will attempt to find an existing object
154
+ # otherwise it will build a new one.
155
+ def find_or_create_for_params(params, parent_column, parent_record)
156
+ current = parent_record.send(parent_column.name)
174
157
  klass = parent_column.association.klass
175
-
176
- if klass.authorized_for?(:crud_type => :create)
177
- if parent_column.singular_association?
178
- return parent_record.send("build_#{parent_column.name}")
179
- else
180
- return parent_record.send(parent_column.name).build
181
- end
182
- end
183
- end
158
+ return nil if parent_column.show_blank_record and attributes_hash_is_empty?(params, klass)
184
159
 
185
- def find_nested_record(id, parent_column, parent_record)
186
- klass = parent_column.association.klass
187
- if id
188
- current = parent_record.send(parent_column.name)
189
- Rails.logger.info("find_nested_record: id: #{id}, curent: #{current.inspect}")
160
+ if params.has_key? :id
190
161
  # modifying the current object of a singular association
191
- if current && current.is_a?(ActiveRecord::Base) && current.id.to_s == id
162
+ if current and current.is_a? ActiveRecord::Base and current.id.to_s == params[:id]
192
163
  return current
193
164
  # modifying one of the current objects in a plural association
194
- elsif current && current.respond_to?(:any?) && current.any? {|o| o.id.to_s == id}
195
- return current.detect {|o| o.id.to_s == id}
165
+ elsif current and current.respond_to?(:any?) and current.any? {|o| o.id.to_s == params[:id]}
166
+ return current.detect {|o| o.id.to_s == params[:id]}
196
167
  # attaching an existing but not-current object
197
168
  else
198
- return klass.find(id)
169
+ return klass.find(params[:id])
199
170
  end
200
171
  else
201
- Rails.logger.info("Activescaffold find_nested_record missing id")
172
+ if klass.authorized_for?(:crud_type => :create)
173
+ if parent_column.singular_association?
174
+ return parent_record.send("build_#{parent_column.name}")
175
+ else
176
+ return parent_record.send(parent_column.name).build
177
+ end
178
+ end
202
179
  end
203
180
  end
204
181
 
@@ -3,7 +3,7 @@ ActiveScaffold::Bridges.bridge "CalendarDateSelect" do
3
3
  # check to see if the old bridge was installed. If so, warn them
4
4
  # we can detect this by checking to see if the bridge was installed before calling this code
5
5
 
6
- if ActiveScaffold::Config::Core.instance_method_names.include?("initialize_with_calendar_date_select")
6
+ if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_calendar_date_select")
7
7
  raise RuntimeError, "We've detected that you have active_scaffold_calendar_date_select_bridge installed. This plugin has been moved to core. Please remove active_scaffold_calendar_date_select_bridge to prevent any conflicts"
8
8
  end
9
9