Skip to content

Commit

Permalink
don't reload after deleting last record if there is no pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
scambra committed Dec 13, 2024
1 parent de7667f commit 0224c9b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions app/assets/javascripts/jquery/active_scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,11 @@
jQuery(tbody).parent().find('tbody.messages p.empty-message').hide();
}
},
show_empty_message: function(tbody) {
if (this.records_for(tbody).length != 0) {
jQuery(tbody).parent().find('tbody.messages p.empty-message').hide();
}
},
reload_if_empty: function(tbody, url) {
if (this.records_for(tbody).length == 0) {
this.reload(url);
Expand Down Expand Up @@ -839,6 +844,7 @@
ActiveScaffold.stripe(tbody);
ActiveScaffold.decrement_record_count(tbody.closest('div.active-scaffold'));
if (page_reload_url) ActiveScaffold.reload_if_empty(tbody, page_reload_url);
else ActiveScaffold.show_empty_message(tbody);
});
},

Expand Down
9 changes: 6 additions & 3 deletions app/views/active_scaffold_overrides/destroy.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
<%= render 'refresh_list', no_history: true %>
<% else %>
<%
url = main_path_to_return
url[:page] = [active_scaffold_config.list.user.page.to_i - 1, 1].max if url.is_a?(Hash) && active_scaffold_config.actions.include?(:list)
if active_scaffold_config.actions.exclude?(:list) || active_scaffold_config.list.pagination
url = main_path_to_return
url[:page] = [active_scaffold_config.list.user.page.to_i - 1, 1].max if url.is_a?(Hash) && active_scaffold_config.actions.include?(:list)
url = url_for(url)
end
%>
ActiveScaffold.delete_record_row('<%= element_row_id(:action => 'list', :id => params[:id]) %>', '<%= url_for(url) %>');
ActiveScaffold.delete_record_row('<%= element_row_id(:action => 'list', :id => params[:id]) %>', '<%= url %>');
<%= render :partial => 'update_calculations', :formats => [:js] %>
<% end %>
<% else %>
Expand Down

0 comments on commit 0224c9b

Please sign in to comment.