Skip to content

Commit

Permalink
Support changing the view partial used to render a record, default to…
Browse files Browse the repository at this point in the history
… 'list_record'

better support refreshing a record when list view is replaced with other way to render records
  • Loading branch information
scambra committed Dec 14, 2024
1 parent 628d63f commit 6d6384f
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/active_scaffold_overrides/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<%= render :partial => 'list_messages', :locals => {:columns => columns} %>
<tbody class="records" id="<%= active_scaffold_tbody_id %>" data-refresh-record="<%= url_for(params_for(:action => :index, :id => '--ID--')) %>">
<% 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 -%>
</tbody>
<% if columns.any? {|c| c.calculation?} -%>
Expand Down
2 changes: 1 addition & 1 deletion app/views/active_scaffold_overrides/_new_record.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
2 changes: 1 addition & 1 deletion app/views/active_scaffold_overrides/_refresh_list.js.erb
Original file line number Diff line number Diff line change
@@ -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 %>});
Expand Down
2 changes: 1 addition & 1 deletion app/views/active_scaffold_overrides/_row.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= render :partial => 'list_record', :locals => {:record => record} %>
<%= render :partial => list_record_view, :locals => {:record => record} %>
2 changes: 1 addition & 1 deletion app/views/active_scaffold_overrides/add_existing.js.erb
Original file line number Diff line number Diff line change
@@ -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] %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/active_scaffold_overrides/on_update.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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' %>
Expand All @@ -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]) %>');
Expand Down
2 changes: 1 addition & 1 deletion app/views/active_scaffold_overrides/row.js.erb
Original file line number Diff line number Diff line change
@@ -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] %>
2 changes: 1 addition & 1 deletion app/views/active_scaffold_overrides/update_row.js.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ActiveScaffold.update_row('<%=element_row_id(:action => 'list', :id => @record.id)%>','<%=escape_javascript(render(:partial => 'list_record', :locals => {:record => @record}))%>');
ActiveScaffold.update_row('<%=element_row_id(:action => 'list', :id => @record.id)%>','<%=escape_javascript(render(:partial => list_record_view, :locals => {:record => @record}))%>');
4 changes: 4 additions & 0 deletions lib/active_scaffold/helpers/list_column_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6d6384f

Please sign in to comment.