diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index ea32c529a..bb5a967bf 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -3,6 +3,7 @@ - Support selector for records body in create_record_row JS method, better support replacing list view with other way to render records - Improve detection of member action links when list view is replaced with other structure, based on 'record' html class, instead of tags - Support :table position for member action links, replacing the whole table +- Support changing the view partial used to render a record, default to 'list_record', better support refreshing a record when list view is replaced with other way to render records = 3.7.10 - Move code from on_create.js.erb to partials, so it's easier to change parts, e.g. how new record is rendered diff --git a/app/views/active_scaffold_overrides/_list.html.erb b/app/views/active_scaffold_overrides/_list.html.erb index c0df1b8e6..572c70d3a 100644 --- a/app/views/active_scaffold_overrides/_list.html.erb +++ b/app/views/active_scaffold_overrides/_list.html.erb @@ -19,7 +19,7 @@ <%= render :partial => 'list_messages', :locals => {:columns => columns} %>
<% if !@page.empty? -%> - <%= render :partial => 'list_record', :collection => @page.items, :locals => {:hidden => false, :columns => columns, :action_links => active_scaffold_config.action_links.member} %> + <%= render :partial => list_record_view, :collection => @page.items, :locals => {:hidden => false, :columns => columns, :action_links => active_scaffold_config.action_links.member} %> <% end -%> <% if columns.any? {|c| c.calculation?} -%> diff --git a/app/views/active_scaffold_overrides/_new_record.js.erb b/app/views/active_scaffold_overrides/_new_record.js.erb index 70a41d419..4041bea25 100644 --- a/app/views/active_scaffold_overrides/_new_record.js.erb +++ b/app/views/active_scaffold_overrides/_new_record.js.erb @@ -9,7 +9,7 @@ <% elsif active_scaffold_config.create.refresh_list %> <%= render 'refresh_list', no_history: true %> <% elsif params[:parent_controller].nil? %> - <% new_row = render 'list_record', record: @saved_record || @record %> + <% new_row = render list_record_view, record: @saved_record || @record %> ActiveScaffold.create_record_row(action_link ? action_link.scaffold() : '<%= active_scaffold_id %>', '<%= escape_javascript(new_row) %>', <%= {insert_at: insert_at}.to_json.html_safe %>); <%= render 'update_calculations' %> <% end %> \ No newline at end of file diff --git a/app/views/active_scaffold_overrides/_refresh_list.js.erb b/app/views/active_scaffold_overrides/_refresh_list.js.erb index 8aa5d4908..f08a6b5f3 100644 --- a/app/views/active_scaffold_overrides/_refresh_list.js.erb +++ b/app/views/active_scaffold_overrides/_refresh_list.js.erb @@ -1,6 +1,6 @@ <% if @auto_pagination -%> <% if @page.items.present? -%> - ActiveScaffold.append('<%= active_scaffold_tbody_id %>', '<%= escape_javascript(render(:partial => 'list_record', :collection => @page.items, :locals => {:hidden => false, :columns => list_columns, :action_links => active_scaffold_config.action_links.member})) %>'); + ActiveScaffold.append('<%= active_scaffold_tbody_id %>', '<%= escape_javascript(render(:partial => list_record_view, :collection => @page.items, :locals => {:hidden => false, :columns => list_columns, :action_links => active_scaffold_config.action_links.member})) %>'); <% if @page.pager.infinite? || @page.number < @page.pager.number_of_pages -%> ActiveScaffold.auto_load_page('<%= url_for main_path_to_return %>', {auto_pagination: true, page: <%= @page.number + 1 %>}); diff --git a/app/views/active_scaffold_overrides/_row.html.erb b/app/views/active_scaffold_overrides/_row.html.erb index 79475acb5..ae26e975c 100644 --- a/app/views/active_scaffold_overrides/_row.html.erb +++ b/app/views/active_scaffold_overrides/_row.html.erb @@ -1 +1 @@ -<%= render :partial => 'list_record', :locals => {:record => record} %> +<%= render :partial => list_record_view, :locals => {:record => record} %> diff --git a/app/views/active_scaffold_overrides/add_existing.js.erb b/app/views/active_scaffold_overrides/add_existing.js.erb index ea16f7e50..dba03bf5b 100644 --- a/app/views/active_scaffold_overrides/add_existing.js.erb +++ b/app/views/active_scaffold_overrides/add_existing.js.erb @@ -1,4 +1,4 @@ -<% new_row = render :partial => 'list_record', :locals => {:record => @record} %> +<% new_row = render :partial => list_record_view, :locals => {:record => @record} %> ActiveScaffold.create_record_row('<%= active_scaffold_id %>', '<%= escape_javascript(new_row) %>', <%= {:insert_at => :top}.to_json.html_safe %>); <%= render :partial => 'update_calculations', :formats => [:js] %> diff --git a/app/views/active_scaffold_overrides/on_action_update.js.erb b/app/views/active_scaffold_overrides/on_action_update.js.erb index 5264b96a4..a0ac1ffe9 100644 --- a/app/views/active_scaffold_overrides/on_action_update.js.erb +++ b/app/views/active_scaffold_overrides/on_action_update.js.erb @@ -5,7 +5,7 @@ link = ActiveScaffold.find_action_link('<%= element_form_id(:action => action_na <% if successful? %> <% if @record %> <%= render :partial => 'update_messages' %> - <% row = escape_javascript(render(:partial => 'list_record', :locals => {:record => @record})) -%> + <% row = escape_javascript(render(:partial => list_record_view, :locals => {:record => @record})) -%> <% if @action_link&.position %> if (link) link.close('<%= row %>'); <% else %> diff --git a/app/views/active_scaffold_overrides/on_update.js.erb b/app/views/active_scaffold_overrides/on_update.js.erb index 994018345..fb9af2392 100644 --- a/app/views/active_scaffold_overrides/on_update.js.erb +++ b/app/views/active_scaffold_overrides/on_update.js.erb @@ -5,7 +5,7 @@ if (action_link) action_link.update_flash_messages('<%= escape_javascript(render <% if successful? %> <% if params[:dont_close] %> <% row_selector = element_row_id(:action => :list, :id => @record.id) %> - ActiveScaffold.update_row('<%= row_selector %>', '<%= escape_javascript(render(:partial => 'list_record', :locals => {:record => @record})) %>'); + ActiveScaffold.update_row('<%= row_selector %>', '<%= escape_javascript(render(:partial => list_record_view, :locals => {:record => @record})) %>'); if (action_link) action_link.target = $('#<%= row_selector %>'); <%= render :partial => 'update_calculations', :formats => [:js] %> <% if params[:iframe] == 'true' %> @@ -22,7 +22,7 @@ if (action_link) action_link.update_flash_messages('<%= escape_javascript(render <%= render 'refresh_list', no_history: true %> <% else %> <% if @record %> - if (action_link) action_link.close('<%= escape_javascript(render(:partial => 'list_record', :locals => {:record => @record})) %>'); + if (action_link) action_link.close('<%= escape_javascript(render(:partial => list_record_view, :locals => {:record => @record})) %>'); <% else %> if (action_link) action_link.close(); ActiveScaffold.delete_record_row('<%= element_row_id(:action => :list, :id => params[:id]) %>'); diff --git a/app/views/active_scaffold_overrides/row.js.erb b/app/views/active_scaffold_overrides/row.js.erb index 6cb0dd3d9..f51f3a0d9 100644 --- a/app/views/active_scaffold_overrides/row.js.erb +++ b/app/views/active_scaffold_overrides/row.js.erb @@ -1,2 +1,2 @@ -ActiveScaffold.update_row('<%= element_row_id(action: :list, id: @record&.id) %>', '<%= escape_javascript render('list_record', record: @record) %>'); +ActiveScaffold.update_row('<%= element_row_id(action: :list, id: @record&.id) %>', '<%= escape_javascript render(list_record_view, record: @record) %>'); <%= render :partial => 'update_calculations', :formats => [:js] %> diff --git a/app/views/active_scaffold_overrides/update_row.js.erb b/app/views/active_scaffold_overrides/update_row.js.erb index 177d86f7b..ebe56180c 100644 --- a/app/views/active_scaffold_overrides/update_row.js.erb +++ b/app/views/active_scaffold_overrides/update_row.js.erb @@ -1 +1 @@ -ActiveScaffold.update_row('<%=element_row_id(:action => 'list', :id => @record.id)%>','<%=escape_javascript(render(:partial => 'list_record', :locals => {:record => @record}))%>'); \ No newline at end of file +ActiveScaffold.update_row('<%=element_row_id(:action => 'list', :id => @record.id)%>','<%=escape_javascript(render(:partial => list_record_view, :locals => {:record => @record}))%>'); \ No newline at end of file diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index d578eb610..83d7fb8bc 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -2,6 +2,10 @@ module ActiveScaffold module Helpers # Helpers that assist with the rendering of a List Column module ListColumnHelpers + def list_record_view + 'list_record' + end + def get_column_value(record, column) record = record.send(column.delegated_association.name) if column.delegated_association if record