Skip to content

Commit

Permalink
Merge branch '3-7-stable'
Browse files Browse the repository at this point in the history
  • Loading branch information
scambra committed Dec 14, 2024
2 parents 6a87ffb + 6d6384f commit 9d59808
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 26 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
= 3.7.11 (not released yet)
- Add partial list_messages_content to reduce code duplication, and better support replacing list view with other way to render records
- 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
36 changes: 20 additions & 16 deletions app/assets/javascripts/jquery/active_scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -1285,18 +1285,15 @@
if (element.length > 0) {
element.data(); // $ 1.4.2 workaround
if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) {
var parent = element.closest('.actions');
if (parent.length === 0 || parent.is('td')) {
// maybe an column action_link
parent = element.closest('tr.record');
}
if (parent.is('tr')) {
var parent = element.closest('.record');
if (parent.length === 0) parent = element.closest('.actions');
if (parent.is('.record')) {
// record action
var target = parent.find('a.as_action');
var loading_indicator = parent.find('td.actions .loading-indicator');
var loading_indicator = parent.find('.actions .loading-indicator');
if (!loading_indicator.length) loading_indicator = element.parent().find('.loading-indicator');
new ActiveScaffold.Actions.Record(target, parent, loading_indicator);
} else if (parent && parent.is('div')) {
} else if (parent.is('.active-scaffold-header .actions')) {
//table action
new ActiveScaffold.Actions.Table(parent.find('a.as_action'), parent.closest('div.active-scaffold').find('tbody.before-header').first(), parent.find('.loading-indicator').first());
}
Expand Down Expand Up @@ -1339,7 +1336,9 @@
link.enable();
if (link.hide_target) link.target.show();
if (link.hide_content) link.content.show();
if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(link.target.attr('id'), ActiveScaffold.config.scroll_on_close == 'checkInViewport');
if (ActiveScaffold.config.scroll_on_close) {
ActiveScaffold.scroll_to(link.target.attr('id'), ActiveScaffold.config.scroll_on_close === 'checkInViewport');
}
});
}
},
Expand Down Expand Up @@ -1422,25 +1421,30 @@
insert: function(content) {
this.close_previous_adapter();

if (this.position == 'replace') {
if (this.position === 'replace') {
this.position = 'after';
this.hide_target = true;
} else if (this.position === 'table') {
this.hide_content = true;
}

var colspan = this.target.children().length;
if (content && this.position) {
content = jQuery(content);
content.find('.inline-adapter-cell:first').attr('colspan', colspan);
}
if (this.position == 'after') {
if (this.position === 'after') {
this.target.after(content);
this.set_adapter(this.target.next());
}
else if (this.position == 'before') {
else if (this.position === 'before') {
this.target.before(content);
this.set_adapter(this.target.prev());
}
else {
} else if (this.position === 'table') {
var content_parent = this.target.closest('div.active-scaffold').find('tbody.before-header').first()
content_parent.prepend(content);
this.set_adapter(content_parent.children().first())
} else {
return false;
}
ActiveScaffold.highlight(this.adapter.find('td'));
Expand Down Expand Up @@ -1478,10 +1482,10 @@
},

set_opened: function() {
if (this.position == 'after') {
if (this.position === 'after') {
this.set_adapter(this.target.next());
}
else if (this.position == 'before') {
else if (this.position === 'before') {
this.set_adapter(this.target.prev());
}
this.disable();
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 'list_messages', 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?(&: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 'list_record', record: record %>
<%= render list_record_view, 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 'list_record', record: @record %>
<% new_row = render list_record_view, record: @record %>
ActiveScaffold.create_record_row('<%= active_scaffold_id %>', '<%= escape_javascript(new_row) %>', <%= {insert_at: :top}.to_json.html_safe %>);

<%= render 'update_calculations' %>
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_name)
<% if successful? %>
<% if @record %>
<%= render 'update_messages' %>
<% row = escape_javascript(render('list_record', record: @record)) -%>
<% row = escape_javascript(render(list_record_view, 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('list_record', record: @record)) %>');
ActiveScaffold.update_row('<%= row_selector %>', '<%= escape_javascript(render(list_record_view, record: @record)) %>');
if (action_link) action_link.target = $('#<%= row_selector %>');
<%= render 'update_calculations' %>
<% 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('list_record', record: @record)) %>');
if (action_link) action_link.close('<%= escape_javascript(render(list_record_view, 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 'update_calculations' %>
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('list_record', record: @record))%>');
ActiveScaffold.update_row('<%=element_row_id(action: 'list', id: @record.id)%>','<%=escape_javascript(render(list_record_view, record: @record))%>');
1 change: 1 addition & 0 deletions lib/active_scaffold/data_structures/action_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def page?
# :before
# :replace
# :after
# :table
# false (no attempt at positioning)
attr_writer :position

Expand Down
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 9d59808

Please sign in to comment.