Skip to content

Commit fd3bd06

Browse files
Merge branch '6.0/htmx-user-warnings' into 6.0-trunk
2 parents 9360f50 + 768bd4f commit fd3bd06

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

lib/RT/Interface/Web.pm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,15 @@ sub HandleRequest {
481481
if ( $HTML::Mason::Commands::m->request_path !~ /^(?:\/SelfService)?\/Views/ ) {
482482
$HTML::Mason::Commands::m->comp( '/Elements/Footer', %$ARGS );
483483
}
484+
485+
if ( RT::Interface::Web::RequestENV('HTTP_HX_REQUEST') && $HTML::Mason::Commands::m->notes('HXUserWarnings') ) {
486+
my $data;
487+
if ( my $old_trigger = $HTML::Mason::Commands::r->headers_out->{'HX-Trigger'} ) {
488+
$data = JSON::decode_json($old_trigger);
489+
}
490+
push @{ $data->{userWarnings} ||= [] }, @{ $HTML::Mason::Commands::m->notes('HXUserWarnings') };
491+
$HTML::Mason::Commands::r->headers_out->{'HX-Trigger'} = EncodeJSON( $data, ascii => 1 );
492+
}
484493
}
485494

486495
sub _ForceLogout {

share/html/Elements/ShowCustomFieldCustomGroupings

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,19 @@ if ( my $config = RT->Config->Get('InlineEditPanelBehavior') ) {
141141
my $edit_label = $m->interp->apply_escapes( loc("Edit"), 'h' );
142142
my $cancel_label = $m->interp->apply_escapes( loc("Cancel"), 'h' );
143143

144-
@Groupings = (RT::CustomField->CustomGroupings( $Object ), '') unless @Groupings;
144+
if ( @Groupings ) {
145+
my %valid = map { $_ => 1 } RT::CustomField->Groupings( $Object ), '';
146+
if ( my @invalid_groups = grep { !$valid{$_} } @Groupings ) {
147+
RT->Logger->warning(
148+
"Invalid custom field groupings for " . ref($Object) . '#' . $Object->Id . ': ' . join ', ',
149+
@invalid_groups );
150+
push @{ $m->notes->{'HXUserWarnings'} ||= [] },
151+
loc( "Some custom field groupings were not found: [_1]" , join ', ', @invalid_groups )
152+
. ". " . loc("Contact your RT administrator.");
153+
}
154+
@Groupings = grep { $valid{$_} } @Groupings;
155+
}
156+
else {
157+
@Groupings = ( RT::CustomField->CustomGroupings( $Object ), '' );
158+
}
145159
</%INIT>

share/static/js/util.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,14 @@ jQuery(function() {
10221022
}
10231023
});
10241024

1025+
document.body.addEventListener('userWarnings', function(evt) {
1026+
if ( evt.detail.value ) {
1027+
for ( const item of evt.detail.value ) {
1028+
alertWarning(escapeHTML(item));
1029+
}
1030+
}
1031+
});
1032+
10251033
document.body.addEventListener('actionsChanged', function(evt) {
10261034
jQuery.jGrowl('close');
10271035
evt.detail.messages ||= evt.detail.value; // .value contains messages if it's passed as "actionsChanged => [$msg]"

0 commit comments

Comments
 (0)