Skip to content

Commit 44db682

Browse files
committed
Merge branch 'master' into framework-ui
# Conflicts: # gemfiles/Gemfile.rails-8.1.x.lock
2 parents f895630 + 812afd4 commit 44db682

File tree

5 files changed

+68
-52
lines changed

5 files changed

+68
-52
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,16 @@ jobs:
9191
strategy:
9292
fail-fast: false
9393
matrix:
94-
ruby: [ "4.0", "3.4", "3.3", "3.2", "jruby-10.0" ]
94+
#ruby: [ "4.0", "3.4", "3.3", "3.2", "jruby-10.0" ]
95+
ruby: [ "3.4", "3.3", "3.2", "jruby-10.0" ]
9596
rails: [ "8.1", "8.0", "7.2" ]
9697
exclude:
9798
- ruby: 'jruby-10.0'
9899
rails: '8.1'
100+
- ruby: '4.0'
101+
rails: '8.0'
102+
- ruby: '4.0'
103+
rails: '7.2'
99104
include:
100105
- ruby: '3.4'
101106
rails: '7.2'

CHANGELOG.rdoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
- Fix replacing tinymce fields with update_columns
2+
- Support refresh_link in radio form UI
3+
- Rewrite refresh_link JS event handler to find the field without relying in the html structure
24

35
= 4.2.0
46
- Integrate LogicalQueryParser, supporting full logical search, or simplified searches with 'all keywords' and 'any keyword' operators.

app/assets/javascripts/jquery/active_scaffold.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,15 @@
334334
});
335335
jQuery(document).on('click', 'a.refresh-link', function(event) {
336336
event.preventDefault();
337-
var element = jQuery(this);
338-
var form_element = element.prev();
339-
var value;
337+
var element = jQuery(this), selector = element.data('field-selector'), value, form_element;
338+
form_element = selector.startsWith('#') ? jQuery(selector) : element.closest('.form-element').find(selector);
339+
if (form_element.is('.draggable-list')) form_element = form_element.closest('.draggable-lists-container');
340340
if (form_element.is(".field_with_errors")) form_element = form_element.children().last();
341341
if (form_element.is(".checkbox-list")) {
342342
value = form_element.find(':checked').map(function(item) { return jQuery(this).val(); }).toArray();
343343
form_element = form_element.parent().find("input:checkbox"); // parent is needed for draggable-list, checked list may be empty
344-
} else value = form_element.is("input:checkbox:not(:checked)") ? null : form_element.val();
344+
} else if (form_element.is(':radio, :checkbox')) value = form_element.filter(':checked').val() || null;
345+
else value = form_element.val();
345346
ActiveScaffold.update_column(form_element, element.attr('href'), element.data('update_send_form'), form_element.attr('id'), value);
346347
});
347348
jQuery(document).on('click', 'a.visibility-toggle', function(e) {

gemfiles/Gemfile.rails-8.1.x.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ GEM
126126
ostruct
127127
globalid (1.3.0)
128128
activesupport (>= 6.1)
129-
google-protobuf (4.33.4-x86_64-linux-gnu)
129+
google-protobuf (4.33.5-x86_64-linux-gnu)
130130
bigdecimal
131131
rake (>= 13)
132132
highline (3.1.2)

lib/active_scaffold/helpers/form_column_helpers.rb

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ def active_scaffold_file_with_remove_link(content, options, controls_class, link
511511
end
512512

513513
def active_scaffold_refresh_link(column, html_options, record, ui_options = {})
514-
link_options = {object: record}
514+
link_options = {object: record, data: {field_selector: ui_options[:field_selector] || "##{html_options[:id]}"}}
515515
if html_options['data-update_url']
516516
link_options['data-update_send_form'] = html_options['data-update_send_form']
517517
link_options['data-update_send_form_selector'] = html_options['data-update_send_form_selector']
@@ -651,6 +651,54 @@ def active_scaffold_radio_option(option, selected, column, radio_options, ui_opt
651651
content_tag(:label, radio_button(:record, column.name, value, radio_options) + text)
652652
end
653653

654+
def active_scaffold_input_radio_content(column, record, options, html_options, ui_options)
655+
if ui_options[:add_new]
656+
add_new_subform = ui_options[:add_new] == true || ui_options[:add_new][:mode].in?([nil, :subform])
657+
if add_new_subform
658+
html_options[:data] ||= {}
659+
html_options[:data][:subform_id] = active_scaffold_subform_attributes(column, ui_options: ui_options)[:id]
660+
end
661+
radio_html_options = html_options.merge(class: "#{html_options[:class]} hide-new-subform")
662+
else
663+
radio_html_options = html_options
664+
end
665+
666+
selected = record.send(column.association.name) if column.association
667+
radios = options.map do |option|
668+
active_scaffold_radio_option(option, selected&.id, column, radio_html_options, ui_options: ui_options)
669+
end
670+
671+
if ui_options[:include_blank]
672+
label = ui_options[:include_blank]
673+
label = as_(ui_options[:include_blank]) if ui_options[:include_blank].is_a?(Symbol)
674+
radio_id = "#{html_options[:id]}-"
675+
radios.prepend content_tag(:label, radio_button(:record, column.name, '', html_options.merge(id: radio_id)) + label)
676+
end
677+
if ui_options[:add_new]
678+
if add_new_subform
679+
create_new = content_tag(:label) do
680+
radio_button_tag(html_options[:name], '', selected&.new_record?, html_options.merge(
681+
id: "#{html_options[:id]}-create_new", class: "#{html_options[:class]} show-new-subform"
682+
).except(:object)) <<
683+
active_scaffold_add_new_text(ui_options[:add_new], :add_new_text, :create_new)
684+
end
685+
radios << create_new
686+
skip_link = true
687+
else
688+
ui_options = ui_options.merge(add_new: ui_options[:add_new].merge(
689+
url_options: {
690+
parent_scope: html_options[:name].gsub(/^record|\[[^\]]*\]$/, '').presence,
691+
radio_data: html_options.slice(*html_options.keys.grep(/^data-update_/))
692+
}
693+
))
694+
radios << content_tag(:span, '', class: 'new-radio-container', id: html_options[:id])
695+
end
696+
radios << active_scaffold_add_new(column, record, html_options, ui_options: ui_options, skip_link: skip_link)
697+
end
698+
699+
safe_join radios
700+
end
701+
654702
def active_scaffold_input_radio(column, html_options, ui_options: column.options)
655703
record = html_options[:object]
656704
html_options.merge!(ui_options[:html_options] || {})
@@ -663,59 +711,19 @@ def active_scaffold_input_radio(column, html_options, ui_options: column.options
663711
send(enum_options_method, column, record, ui_options: ui_options)
664712
end
665713

666-
selected = record.send(column.association.name) if column.association
667-
selected_id = selected&.id
668714
if options.present?
669-
if ui_options[:add_new]
670-
add_new_subform = ui_options[:add_new] == true || ui_options[:add_new][:mode].in?([nil, :subform])
671-
if add_new_subform
672-
html_options[:data] ||= {}
673-
html_options[:data][:subform_id] = active_scaffold_subform_attributes(column, ui_options: ui_options)[:id]
674-
end
675-
radio_html_options = html_options.merge(class: "#{html_options[:class]} hide-new-subform")
676-
else
677-
radio_html_options = html_options
678-
end
679-
radios = options.map do |option|
680-
active_scaffold_radio_option(option, selected_id, column, radio_html_options, ui_options: ui_options)
681-
end
682-
if ui_options[:include_blank]
683-
label = ui_options[:include_blank]
684-
label = as_(ui_options[:include_blank]) if ui_options[:include_blank].is_a?(Symbol)
685-
radio_id = "#{html_options[:id]}-"
686-
radios.prepend content_tag(:label, radio_button(:record, column.name, '', html_options.merge(id: radio_id)) + label)
687-
end
688-
if ui_options[:add_new]
689-
if add_new_subform
690-
create_new = content_tag(:label) do
691-
radio_button_tag(html_options[:name], '', selected&.new_record?, html_options.merge(
692-
id: "#{html_options[:id]}-create_new", class: "#{html_options[:class]} show-new-subform"
693-
).except(:object)) <<
694-
active_scaffold_add_new_text(ui_options[:add_new], :add_new_text, :create_new)
695-
end
696-
radios << create_new
697-
skip_link = true
698-
else
699-
ui_options = ui_options.merge(add_new: ui_options[:add_new].merge(
700-
url_options: {
701-
parent_scope: html_options[:name].gsub(/^record|\[[^\]]*\]$/, '').presence,
702-
radio_data: html_options.slice(*html_options.keys.grep(/^data-update_/))
703-
}
704-
))
705-
radios << content_tag(:span, '', class: 'new-radio-container', id: html_options[:id])
706-
end
707-
radios << active_scaffold_add_new(column, record, html_options, ui_options: ui_options, skip_link: skip_link)
708-
end
709-
safe_join radios
715+
html = active_scaffold_input_radio_content(column, record, options, html_options, ui_options)
710716
else
711-
html = content_tag(:span, as_(:no_options), class: "#{html_options[:class]} no-options", id: html_options[:id])
712-
html << hidden_field_tag(html_options[:name], '', id: nil)
717+
html = content_tag(:span, as_(:no_options), class: "#{html_options[:class]} no-options")
718+
html << hidden_field_tag(html_options[:name], '', id: html_options[:id])
713719
if ui_options[:add_new]
714720
html = content_tag(:div, html, class: 'select-field') <<
715721
active_scaffold_add_new(column, record, html_options, ui_options: ui_options)
716722
end
717723
html
718724
end
725+
html << active_scaffold_refresh_link(column, html_options, record, ui_options.merge(field_selector: "[name=\"#{html_options[:name]}\"]")) if ui_options[:refresh_link]
726+
html
719727
end
720728

721729
def active_scaffold_input_checkbox(column, options, ui_options: column.options)

0 commit comments

Comments
 (0)