active_scaffold 3.2.11 → 3.2.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/CHANGELOG +23 -2
  2. data/app/assets/javascripts/jquery/active_scaffold.js +55 -46
  3. data/app/assets/javascripts/prototype/active_scaffold.js +54 -35
  4. data/app/assets/stylesheets/active_scaffold_layout.css +4 -0
  5. data/config/locales/de.yml +5 -0
  6. data/config/locales/en.yml +5 -0
  7. data/config/locales/es.yml +5 -0
  8. data/config/locales/fr.yml +5 -0
  9. data/config/locales/hu.yml +5 -0
  10. data/config/locales/ja.yml +5 -0
  11. data/config/locales/ru.yml +5 -0
  12. data/frontends/default/views/_form_association.html.erb +2 -2
  13. data/frontends/default/views/_form_association_footer.html.erb +2 -2
  14. data/frontends/default/views/_horizontal_subform.html.erb +3 -3
  15. data/frontends/default/views/_list_inline_adapter.html.erb +7 -4
  16. data/frontends/default/views/_list_messages.html.erb +2 -1
  17. data/frontends/default/views/_messages.html.erb +1 -1
  18. data/frontends/default/views/_row.html.erb +1 -6
  19. data/frontends/default/views/_vertical_subform.html.erb +2 -2
  20. data/frontends/default/views/add_existing.js.erb +1 -1
  21. data/frontends/default/views/destroy.js.erb +2 -2
  22. data/frontends/default/views/on_action_update.js.erb +1 -1
  23. data/frontends/default/views/on_create.js.erb +3 -17
  24. data/frontends/default/views/on_mark.js.erb +6 -0
  25. data/frontends/default/views/on_update.js.erb +4 -13
  26. data/frontends/default/views/row.js.erb +1 -0
  27. data/lib/active_scaffold.rb +1 -0
  28. data/lib/active_scaffold/actions/core.rb +9 -7
  29. data/lib/active_scaffold/actions/create.rb +1 -1
  30. data/lib/active_scaffold/actions/delete.rb +1 -1
  31. data/lib/active_scaffold/actions/list.rb +11 -4
  32. data/lib/active_scaffold/actions/mark.rb +35 -24
  33. data/lib/active_scaffold/actions/nested.rb +3 -1
  34. data/lib/active_scaffold/actions/subform.rb +2 -2
  35. data/lib/active_scaffold/config/core.rb +17 -1
  36. data/lib/active_scaffold/config/form.rb +1 -1
  37. data/lib/active_scaffold/config/list.rb +0 -8
  38. data/lib/active_scaffold/config/mark.rb +7 -12
  39. data/lib/active_scaffold/data_structures/action_columns.rb +19 -15
  40. data/lib/active_scaffold/data_structures/nested_info.rb +27 -7
  41. data/lib/active_scaffold/extensions/routing_mapper.rb +2 -2
  42. data/lib/active_scaffold/finder.rb +12 -11
  43. data/lib/active_scaffold/helpers/controller_helpers.rb +5 -9
  44. data/lib/active_scaffold/helpers/form_column_helpers.rb +3 -3
  45. data/lib/active_scaffold/helpers/id_helpers.rb +5 -1
  46. data/lib/active_scaffold/helpers/list_column_helpers.rb +55 -40
  47. data/lib/active_scaffold/helpers/view_helpers.rb +22 -6
  48. data/lib/active_scaffold/marked_model.rb +4 -4
  49. data/lib/active_scaffold/tableless.rb +18 -0
  50. data/lib/active_scaffold/version.rb +1 -1
  51. data/test/config/list_test.rb +0 -6
  52. metadata +18 -18
  53. data/frontends/default/views/on_mark_all.js.erb +0 -12
@@ -31,8 +31,10 @@ fr:
31
31
  filtered: '(Filtré)'
32
32
  found: 'Trouvé'
33
33
  hide: 'Cacher'
34
+ inplace_edit_handle: '--'
34
35
  live_search: 'Recherche en temps réel'
35
36
  loading: 'Chargement…'
37
+ mark_all_records: "Mark all"
36
38
  next: 'Suivant'
37
39
  no_entries: "Pas d'entrée"
38
40
  no_options: "pas d'option"
@@ -41,6 +43,9 @@ fr:
41
43
  pdf: 'PDF'
42
44
  previous: 'Précédent'
43
45
  print: 'Imprimer'
46
+ records_marked:
47
+ one: "1 marked %{model}"
48
+ other: "%{count} marked %{model}"
44
49
  refresh: 'Rafraîchir'
45
50
  remove: 'Supprimer'
46
51
  remove_file: 'Supprimer et remplacer le fichier'
@@ -31,8 +31,10 @@ hu:
31
31
  filtered: '(Szűrt)'
32
32
  found: 'Találat'
33
33
  hide: 'Elrejtés'
34
+ inplace_edit_handle: '--'
34
35
  live_search: 'Élő keresés'
35
36
  loading: 'Betöltés…'
37
+ mark_all_records: "Mark all"
36
38
  next: 'Következő'
37
39
  no_entries: 'Nincs elem'
38
40
  no_options: 'nincsenek opciók'
@@ -41,6 +43,9 @@ hu:
41
43
  pdf: 'PDF'
42
44
  previous: 'Előző'
43
45
  print: 'Nyomtatás'
46
+ records_marked:
47
+ one: "1 marked %{model}"
48
+ other: "%{count} marked %{model}"
44
49
  refresh: 'Frissítés'
45
50
  remove: 'Törlés'
46
51
  remove_file: 'Fájl törlése, vagy cseréje'
@@ -31,8 +31,10 @@ ja:
31
31
  filtered: '(フィルタ中)'
32
32
  found: '個ありました'
33
33
  hide: '隠す'
34
+ inplace_edit_handle: '--'
34
35
  live_search: 'その場で検索'
35
36
  loading: '読み込み中…'
37
+ mark_all_records: "Mark all"
36
38
  next: '次'
37
39
  no_entries: '見つかりませんでした'
38
40
  no_options: 'オプション無し'
@@ -41,6 +43,9 @@ ja:
41
43
  pdf: 'PDF'
42
44
  previous: '前'
43
45
  print: '印刷'
46
+ records_marked:
47
+ one: "1 marked %{model}"
48
+ other: "%{count} marked %{model}"
44
49
  refresh: 'Refresh' # needed?
45
50
  remove: '削除'
46
51
  remove_file: 'ファイルを削除または置換'
@@ -35,8 +35,10 @@ ru:
35
35
  many: 'записей'
36
36
  other: 'записи'
37
37
  hide: 'Скрыть'
38
+ inplace_edit_handle: '--'
38
39
  live_search: 'Поиск'
39
40
  loading: 'Загрузка…'
41
+ mark_all_records: "Mark all"
40
42
  next: 'Следующее'
41
43
  no_entries: 'Нет записей'
42
44
  no_options: 'Нет вариантов'
@@ -45,6 +47,9 @@ ru:
45
47
  pdf: 'PDF'
46
48
  previous: 'Предыдущее'
47
49
  print: 'Печать'
50
+ records_marked:
51
+ one: "1 marked %{model}"
52
+ other: "%{count} marked %{model}"
48
53
  refresh: 'Обновить'
49
54
  remove: 'Удалить'
50
55
  remove_file: 'Удалить или заменить файл'
@@ -10,8 +10,8 @@ subform_div_id = "#{sub_form_id({:association => column.name, :id => parent_reco
10
10
  <h5><%= column.label -%></h5>
11
11
  <div id ="<%= subform_div_id %>" <%= 'style="display: none;"'.html_safe if column.collapsed -%>>
12
12
  <%# HACK to be able to delete all associated records %>
13
- <%= hidden_field_tag "#{active_scaffold_input_options(column)[:name]}[0]", '' if column.plural_association? %>
14
- <%= render :partial => subform_partial_for_column(column), :locals => {:column => column, :parent_record => parent_record, :associated => associated, :show_blank_record => show_blank_record} %>
13
+ <%= hidden_field_tag "#{active_scaffold_input_options(column, scope)[:name]}[0]", '' if column.plural_association? %>
14
+ <%= render :partial => subform_partial_for_column(column), :locals => {:column => column, :parent_record => parent_record, :associated => associated, :show_blank_record => show_blank_record, :scope => scope} %>
15
15
  </div>
16
16
  <%= link_to_visibility_toggle(subform_div_id, {:default_visible => !column.collapsed}) -%>
17
17
  <% @record = parent_record -%>
@@ -11,8 +11,8 @@ show_add_new = column_show_add_new(column, associated, @record)
11
11
 
12
12
  return unless show_add_new or show_add_existing
13
13
 
14
- edit_associated_url = url_for(:action => 'edit_associated', :id => parent_record.id, :association => column.name, :associated_id => '--ID--', :eid => params[:eid], :parent_controller => params[:parent_controller], :parent_id => params[:parent_id]) if show_add_existing
15
- add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :association => column.name, :eid => params[:eid], :parent_controller => params[:parent_controller], :parent_id => params[:parent_id]) if show_add_new
14
+ edit_associated_url = params_for(:action => 'edit_associated', :child_association => column.name, :associated_id => '--ID--', :scope => scope) if show_add_existing
15
+ add_new_url = params_for(:action => 'edit_associated', :child_association => column.name, :scope => scope) if show_add_new
16
16
 
17
17
  -%>
18
18
  <div class="footer-wrapper">
@@ -12,11 +12,11 @@
12
12
  </td>
13
13
  </tr>
14
14
  <% end %>
15
- <%= 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} %>
15
+ <%= render :partial => 'horizontal_subform_record', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %>
16
16
  <% end -%>
17
17
  </tbody>
18
18
  <tfoot>
19
- <%= render :partial => 'horizontal_subform_footer', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column} %>
19
+ <%= render :partial => 'horizontal_subform_footer', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column} %>
20
20
  </tfoot>
21
21
  </table>
22
- <%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated} -%>
22
+ <%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated, :scope => scope} -%>
@@ -1,8 +1,11 @@
1
1
  <%
2
- column_count = if nested? and action_name == 'index'
3
- active_scaffold_config_for(nested.parent_model).list.columns.count + 1
4
- else
5
- active_scaffold_config.list.columns.count + 1
2
+ column_count ||= begin
3
+ config = if nested? and (nested.singular_association? || action_name == 'index')
4
+ active_scaffold_config_for(nested.parent_model)
5
+ else
6
+ active_scaffold_config
7
+ end
8
+ config.list.columns.count + 1
6
9
  end
7
10
  %>
8
11
  <%# nested_id, allows us to remove a nested scaffold programmatically %>
@@ -1,6 +1,7 @@
1
+ <% column_count ||= columns.length + 1 -%>
1
2
  <tbody class="messages">
2
3
  <tr class="record even-record">
3
- <td colspan="<%= columns.length + 1 -%>" class="messages-container">
4
+ <td colspan="<%= column_count -%>" class="messages-container">
4
5
  <p class="error-message message server-error" style="display:none;">
5
6
  <%= as_(:internal_error).html_safe %>
6
7
  <a href="#" class="close" title="<%= as_(:close).html_safe %>"><%= as_(:close).html_safe %></a>
@@ -1,7 +1,7 @@
1
1
  <% for name in [:info, :warning, :error] %>
2
2
  <% if flash[name] %>
3
3
  <div class="<%= "#{name}-message message" %>">
4
- <%= h flash[name] %>
4
+ <%= display_message flash[name] %>
5
5
  <% if request.xhr? %>
6
6
  <a href="#" class="close" title="<%= as_(:close) %>"><%= as_(:close) %></a>
7
7
  <% end %>
@@ -1,6 +1 @@
1
- <%= render :partial => 'list_record', :locals => {:record => record}%>
2
- <%= javascript_tag do %>
3
- <%= render :partial => 'update_calculations', :formats => [:js] %>
4
- <% end %>
5
-
6
-
1
+ <%= render :partial => 'list_record', :locals => {:record => record} %>
@@ -6,7 +6,7 @@
6
6
  <%= active_scaffold_error_messages_for :record, :object_name => @record.class.model_name.human.downcase %>
7
7
  </div>
8
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} %>
9
+ <%= render :partial => 'vertical_subform_record', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %>
10
10
  <% end -%>
11
11
  </div>
12
- <%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated} -%>
12
+ <%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated, :scope => scope} -%>
@@ -1,7 +1,7 @@
1
1
  <% new_row = render :partial => 'list_record', :locals => {:record => @record} %>
2
2
  ActiveScaffold.create_record_row('<%= active_scaffold_id %>', '<%= escape_javascript(new_row) %>', <%= {:insert_at => :top}.to_json.html_safe %>);
3
3
 
4
- <%= render :partial => 'update_calculations' %>
4
+ <%= render :partial => 'update_calculations', :formats => [:js] %>
5
5
 
6
6
  <% if form_stays_open ||= true %>
7
7
  <%# why not just re-render the form? that wouldn't utilize a possible do_new override which sets default values.%>
@@ -6,7 +6,7 @@
6
6
  <% current_id = controller_id(params[:eid] || params[:parent_sti]) -%>
7
7
  ActiveScaffold.delete_record_row('<%= element_row_id(:controller_id => current_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)) %>');
8
8
  <% messages_id = active_scaffold_messages_id(:controller_id => current_id) %>
9
- <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => current_id)} %>
9
+ <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => current_id)}, :formats => [:js] %>
10
10
  <% elsif render_parent_action == :index %>
11
11
  <% if controller.respond_to?(:render_component_into_view) %>
12
12
  <%= escape_javascript(controller.send(:render_component_into_view, render_parent_options)) %>
@@ -18,7 +18,7 @@
18
18
  <%= render :partial => 'refresh_list' %>
19
19
  <% else %>
20
20
  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)) %>');
21
- <%= render :partial => 'update_calculations' %>
21
+ <%= render :partial => 'update_calculations', :formats => [:js] %>
22
22
  <% end %>
23
23
  <% else %>
24
24
  <% 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) %>
@@ -8,7 +8,7 @@
8
8
  ActiveScaffold.update_row('<%= element_row_id(:action => :list, :id => @record.id) %>', '<%= row %>');
9
9
  ActiveScaffold.scroll_to('<%= element_row_id(:action => :list, :id => @record.id) %>', true);
10
10
  <% end %>
11
- <%= render :partial => 'update_calculations' %>
11
+ <%= render :partial => 'update_calculations', :formats => [:js] %>
12
12
  <% else %>
13
13
  <% if @action_link.nil? || @action_link.position %>
14
14
  ActiveScaffold.find_action_link('<%= element_row_id(:action => action_name) %>').close();
@@ -5,23 +5,9 @@ var action_link = ActiveScaffold.find_action_link('<%= form_selector%>');
5
5
  action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'messages'))%>');
6
6
  <% if controller.send :successful? %>
7
7
  <% if render_parent? %>
8
- <% if controller.respond_to?(:render_component_into_view) %>
9
- <% parent_rendered = controller.send(:render_component_into_view, render_parent_options) %>
10
- <% if nested_singular_association? %>
11
- action_link.close('<%= escape_javascript(parent_rendered)%>');
12
- <% else %>
13
- <% if render_parent_action == :row %>
14
- ActiveScaffold.create_record_row(action_link.scaffold(),'<%= escape_javascript(parent_rendered) %>', <%= {:insert_at => insert_at}.to_json.html_safe %>);
15
- <% elsif render_parent_action == :index %>
16
- <%= escape_javascript(parent_rendered) %>
17
- <% end %>
18
- action_link.close();
19
- <% end %>
20
- <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => render_parent_controller)} unless render_parent_action == :index %>
8
+ <% if nested_singular_association? || render_parent_action == :row %>
9
+ action_link.close(true);
21
10
  <% else %>
22
- <% if nested_singular_association? || render_parent_action == :row %>
23
- action_link.close();
24
- <% end %>
25
11
  ActiveScaffold.reload('<%= url_for render_parent_options %>');
26
12
  <% end %>
27
13
  <% elsif (active_scaffold_config.create.refresh_list) %>
@@ -29,7 +15,7 @@ action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'mess
29
15
  <% elsif params[:parent_controller].nil? %>
30
16
  <% new_row = render :partial => 'list_record', :locals => {:record => @record} %>
31
17
  ActiveScaffold.create_record_row(action_link.scaffold(),'<%= escape_javascript(new_row) %>', <%= {:insert_at => insert_at}.to_json.html_safe %>);
32
- <%= render :partial => 'update_calculations' %>
18
+ <%= render :partial => 'update_calculations', :formats => [:js] %>
33
19
  <% end %>
34
20
 
35
21
  <% unless render_parent? %>
@@ -0,0 +1,6 @@
1
+ <%
2
+ checked = all_marked? unless local_assigns.has_key? :checked
3
+ options = {:checked => checked, :include_mark_all => true, :include_checkboxes => params[:id].nil?}
4
+ %>
5
+ ActiveScaffold.mark_records('<%= active_scaffold_tbody_id %>',<%= options.to_json.html_safe %>);
6
+ <%= render :partial => 'update_messages' %>
@@ -5,26 +5,17 @@ action_link.update_flash_messages('<%= escape_javascript(render(:partial => 'mes
5
5
  <% if controller.send :successful? %>
6
6
  <% if !active_scaffold_config.update.persistent %>
7
7
  <% if render_parent? %>
8
- <% if controller.respond_to?(:render_component_into_view) %>
9
- <% parent_rendered = controller.send(:render_component_into_view, render_parent_options) %>
10
- <% if nested_singular_association? || render_parent_action == :row %>
11
- action_link.close('<%= escape_javascript(parent_rendered) %>');
12
- <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => render_parent_controller)} %>
13
- <% elsif render_parent_action == :index %>
14
- <%= escape_javascript(parent_rendered) %>
15
- <% end %>
8
+ <% if nested_singular_association? || render_parent_action == :row %>
9
+ action_link.close(true);
16
10
  <% else %>
17
- <% if nested_singular_association? || render_parent_action == :row %>
18
- action_link.close();
19
- <% end %>
20
- ActiveScaffold.reload('<%= url_for render_parent_options %>');
11
+ ActiveScaffold.reload('<%= url_for render_parent_options %>');
21
12
  <% end %>
22
13
  <% elsif update_refresh_list? %>
23
14
  <%= render :partial => 'refresh_list' %>
24
15
  <% else %>
25
16
  <% updated_row = render :partial => 'list_record', :locals => {:record => @record} %>
26
17
  action_link.close('<%= escape_javascript(updated_row) %>');
27
- <%= render :partial => 'update_calculations' %>
18
+ <%= render :partial => 'update_calculations', :formats => [:js] %>
28
19
  <% end %>
29
20
  <% end %>
30
21
  <% else %>
@@ -1 +1,2 @@
1
1
  ActiveScaffold.update_row('<%= element_row_id(:action => :list) %>', '<%= escape_javascript render(:partial => 'row', :locals => {:record => @record}) %>');
2
+ <%= render :partial => 'update_calculations', :formats => [:js] %>
@@ -70,6 +70,7 @@ module ActiveScaffold
70
70
 
71
71
  base.helper_method :touch_device?
72
72
  base.helper_method :hover_via_click?
73
+ base.helper_method :active_scaffold_constraints
73
74
  end
74
75
 
75
76
  def self.set_defaults(&block)
@@ -150,14 +150,16 @@ module ActiveScaffold::Actions
150
150
 
151
151
  # Builds search conditions by search params for column names. This allows urls like "contacts/list?company_id=5".
152
152
  def conditions_from_params
153
- conditions = {}
154
- params.reject {|key, value| [:controller, :action, :id, :page, :sort, :sort_direction].include?(key.to_sym)}.each do |key, value|
155
- next unless active_scaffold_config.model.columns_hash[key.to_s]
156
- next if active_scaffold_constraints[key.to_sym]
157
- next if nested? and nested.constrained_fields.include? key.to_sym
158
- conditions[key] = value
153
+ @conditions_from_params ||= begin
154
+ conditions = {}
155
+ params.reject {|key, value| [:controller, :action, :id, :page, :sort, :sort_direction].include?(key.to_sym)}.each do |key, value|
156
+ next unless active_scaffold_config.model.columns_hash[key.to_s]
157
+ next if active_scaffold_constraints[key.to_sym]
158
+ next if nested? and nested.constrained_fields.include? key.to_sym
159
+ conditions[key.to_sym] = value
160
+ end
161
+ conditions
159
162
  end
160
- conditions
161
163
  end
162
164
 
163
165
  def new_model
@@ -122,7 +122,7 @@ module ActiveScaffold::Actions
122
122
  end
123
123
 
124
124
  def create_authorized?
125
- (!nested? || !nested.readonly?) && authorized_for?(:crud_type => :create)
125
+ (!nested? || !nested.readonly? || !nested.through?) && authorized_for?(:crud_type => :create)
126
126
  end
127
127
  private
128
128
  def create_authorized_filter
@@ -49,7 +49,7 @@ module ActiveScaffold::Actions
49
49
  @record ||= destroy_find_record
50
50
  begin
51
51
  self.successful = @record.destroy
52
- marked_records.delete @record.id.to_s if successful?
52
+ @record.as_marked = false if successful?
53
53
  rescue Exception => ex
54
54
  flash[:warning] = as_(:cant_destroy_record, :record => @record.to_label)
55
55
  self.successful = false
@@ -11,7 +11,7 @@ module ActiveScaffold::Actions
11
11
 
12
12
  # get just a single row
13
13
  def row
14
- @record = find_if_allowed(params[:id], :read)
14
+ get_row
15
15
  respond_to_action(:row)
16
16
  end
17
17
 
@@ -50,8 +50,8 @@ module ActiveScaffold::Actions
50
50
  render :text => Hash.from_xml(response_object.to_xml(:only => list_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status
51
51
  end
52
52
 
53
- def row_respond_to_html
54
- render(:partial => 'row', :locals => {:record => @record})
53
+ def row_respond_to_js
54
+ render
55
55
  end
56
56
 
57
57
  # The actual algorithm to prepare for the list view
@@ -59,6 +59,12 @@ module ActiveScaffold::Actions
59
59
  includes_for_list_columns = active_scaffold_config.list.columns.collect{ |c| c.includes }.flatten.uniq.compact
60
60
  self.active_scaffold_includes.concat includes_for_list_columns
61
61
  end
62
+
63
+ def get_row
64
+ set_includes_for_list_columns
65
+ klass = beginning_of_chain.includes(active_scaffold_includes)
66
+ @record = find_if_allowed(params[:id], :read, klass)
67
+ end
62
68
 
63
69
  # The actual algorithm to prepare for the list view
64
70
  def do_list
@@ -76,7 +82,8 @@ module ActiveScaffold::Actions
76
82
  end
77
83
 
78
84
  page = find_page(options)
79
- if page.items.blank? && !page.pager.infinite?
85
+ total_pages = page.pager.number_of_pages
86
+ if !page.pager.infinite? && !total_pages.zero? && page.number > total_pages
80
87
  page = page.pager.last
81
88
  active_scaffold_config.list.user.page = page.number
82
89
  end
@@ -3,58 +3,69 @@ module ActiveScaffold::Actions
3
3
 
4
4
  def self.included(base)
5
5
  base.before_filter :mark_authorized?, :only => :mark
6
- #base.prepend_before_filter :assign_marked_records_to_model
6
+ base.prepend_before_filter :assign_marked_records_to_model
7
7
  base.helper_method :marked_records
8
8
  end
9
9
 
10
- def mark_all
11
- if mark_all? || mark_all_scope_forced?
12
- do_mark_all
10
+ def mark
11
+ if mark? || mark_all_scope_forced?
12
+ do_mark
13
13
  else
14
- do_unmark
14
+ do_demark
15
15
  end
16
- do_list
17
- respond_to_action(:mark_all)
16
+ if marked_records.length > 0
17
+ link = "<a href=\"#{url_for(:action=>:mark, :id=>'', :mark_target => :scope)}\" data-method=\"post\" data-remote=\"true\">#{as_ :mark_all_records}</a>"
18
+ count = marked_records.length
19
+ flash[:info] = as_(:records_marked, :count => count, :model => active_scaffold_config.label(:count => count), :link => link)
20
+ end
21
+ respond_to_action(:mark)
18
22
  end
19
23
  protected
20
24
 
21
- def mark_all_respond_to_html
25
+ def mark_respond_to_html
26
+ do_list
22
27
  list_respond_to_html
23
28
  end
24
29
 
25
- def mark_all_respond_to_js
26
- render :action => 'on_mark_all', :locals => {:mark_all => mark_all?}
30
+ def mark_respond_to_js
31
+ if params[:id]
32
+ do_search if respond_to? :do_search
33
+ set_includes_for_list_columns
34
+ @page = find_page(:pagination => active_scaffold_config.mark.mark_all_mode != :page)
35
+ render :action => 'on_mark'
36
+ else
37
+ render :action => 'on_mark', :locals => {:checked => mark?}
38
+ end
27
39
  end
28
40
 
29
41
  # We need to give the ActiveRecord classes a handle to currently marked records. We don't want to just pass the object,
30
- # because the object may change. So we give ActiveRecord a proc that ties to the
31
- # marked_records_method on this ApplicationController.
42
+ # because the object may change. So we give ActiveRecord a proc that ties to the marked_records_method on this ApplicationController.
32
43
  def assign_marked_records_to_model
33
44
  active_scaffold_config.model.marked_records = marked_records
34
45
  end
35
46
 
36
47
  def mark?
37
- params[:value] == 'true'
38
- end
39
-
40
- def mark_all?
41
- @mark_all ||= [true, 'true', 1, '1', 'T', 't'].include?(params[:value].class == String ? params[:value].downcase : params[:value])
48
+ @mark ||= [true, 'true', 1, '1', 'T', 't'].include?(params[:value].class == String ? params[:value].downcase : params[:value])
42
49
  end
43
50
 
44
51
  def mark_all_scope_forced?
45
- !params[:mark_target].nil? && params[:mark_target]=='scope'
52
+ params[:mark_target] == 'scope' unless params[:id]
46
53
  end
47
-
48
- def do_mark_all
49
- if active_scaffold_config.mark.mark_all_mode == :page && !mark_all_scope_forced? then
54
+
55
+ def do_mark
56
+ if params[:id]
57
+ find_if_allowed(params[:id], :read).as_marked = true
58
+ elsif active_scaffold_config.mark.mark_all_mode == :page && !mark_all_scope_forced?
50
59
  each_record_in_page {|record| marked_records << record.id}
51
60
  else
52
61
  each_record_in_scope {|record| marked_records << record.id}
53
62
  end
54
63
  end
55
64
 
56
- def do_demark_all
57
- if active_scaffold_config.mark.mark_all_mode == :page then
65
+ def do_demark
66
+ if params[:id]
67
+ find_if_allowed(params[:id], :read).as_marked = false
68
+ elsif active_scaffold_config.mark.mark_all_mode == :page
58
69
  each_record_in_page {|record| marked_records.delete(record.id)}
59
70
  else
60
71
  each_record_in_scope {|record| marked_records.delete(record.id)}
@@ -67,7 +78,7 @@ module ActiveScaffold::Actions
67
78
  authorized_for?(:crud_type => :read)
68
79
  end
69
80
 
70
- def mark_all_formats
81
+ def mark_formats
71
82
  (default_formats + active_scaffold_config.formats).uniq
72
83
  end
73
84
  end