[Rt-commit] rt branch 5.0/cf-sort-order-inputs created. rt-5.0.3-220-g4dc03f6fb0
BPS Git Server
git at git.bestpractical.com
Tue Jan 3 20:52:51 UTC 2023
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".
The branch, 5.0/cf-sort-order-inputs has been created
at 4dc03f6fb0335f7edb7e68880d0a96a3ab966889 (commit)
- Log -----------------------------------------------------------------
commit 4dc03f6fb0335f7edb7e68880d0a96a3ab966889
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri Jan 26 06:45:37 2018 +0800
Support SortOrder edit on ocf admin pages
Since we don't support move up/down for global cfs on queue-specific
pages, global cfs' SortOrder inputs are disabled there accordingly.
diff --git a/lib/RT/ObjectCustomField.pm b/lib/RT/ObjectCustomField.pm
index 38ae9aa9aa..33569f4b8c 100644
--- a/lib/RT/ObjectCustomField.pm
+++ b/lib/RT/ObjectCustomField.pm
@@ -102,6 +102,19 @@ sub Neighbors {
return $res;
}
+sub SetSortOrder {
+ my $self = shift;
+ my $value = shift;
+ my $old_value = $self->SortOrder;
+ my ( $ret, $msg ) = $self->_Set( Field => 'SortOrder', Value => $value );
+ if ($ret) {
+ return ( $ret, $self->loc( 'SortOrder changed from [_1] to [_2]', $old_value, $value ) );
+ }
+ else {
+ return ( $ret, $msg );
+ }
+}
+
=head2 id
Returns the current value of id.
diff --git a/share/html/Admin/Elements/EditCustomFields b/share/html/Admin/Elements/EditCustomFields
index f1c54118f2..65a0547621 100644
--- a/share/html/Admin/Elements/EditCustomFields
+++ b/share/html/Admin/Elements/EditCustomFields
@@ -152,6 +152,33 @@ if ( $UpdateCFs ) {
my ($status, $msg) = $CF->RemoveFromObject( $Object );
push @results, $msg;
}
+
+ my %sort = map { /CustomField-(\d+)-SortOrder/ ? ( $1 => $ARGS{$_} ) : () } keys %ARGS;
+ for my $cf_id ( sort keys %sort ) {
+ my $sort_order = $sort{$cf_id};
+ $sort_order =~ s/^\s+//;
+ $sort_order =~ s/\s+$//;
+ next unless $sort_order =~ /^-?\d+$/;
+
+ my $record = RT::ObjectCustomField->new( $session{'CurrentUser'} );
+ $record->LoadByCols( ObjectId => $id, CustomField => $cf_id );
+ unless ( $record->id ) {
+ push @results,
+ loc("Custom field #[_1] is not applied to object #[_2]", $cf_id, $id);
+ next;
+ }
+
+ if ( $record->SortOrder != $sort_order ) {
+ if ( $id && !$record->ObjectId ) {
+ # just in case, global inputs are disabled on non-global pages
+ push @results, loc("Only global pages can update SortOrder of global objects");
+ next;
+ }
+ my ( $status, $msg ) = $record->SetSortOrder( $sort_order );
+ push @results, loc( '[_1]: [_2]', $record->CustomFieldObj->Name, $msg );
+ }
+ }
+
}
$m->callback(CallbackName => 'UpdateExtraFields', Results => \@results, Object => $Object, %ARGS);
@@ -170,8 +197,8 @@ my $format = RT->Config->Get('AdminSearchResultFormat')->{'CustomFields'};
my $rows = RT->Config->Get('AdminSearchResultRows')->{'CustomFields'} || 50;
my $display_format = $id
- ? ("'__RemoveCheckBox.{$id}__',". $format .", '__MoveCF.{$id}__'")
- : ("'__CheckBox.{RemoveCustomField}__',". $format .", '__MoveCF.{$id}__'");
+ ? ("'__RemoveCheckBox__', ". $format .", '__SortOrder.{$id}__', '__MoveCF.{$id}__'")
+ : ("'__CheckBox.{RemoveCustomField}__', ". $format .", '__SortOrder__', '__MoveCF.{$id}__'");
$m->callback(CallbackName => 'EditDisplayFormat', DisplayFormat => \$display_format, id => $id);
</%INIT>
diff --git a/share/html/Elements/RT__CustomField/ColumnMap b/share/html/Elements/RT__CustomField/ColumnMap
index 4c47e106a7..b8a8df108d 100644
--- a/share/html/Elements/RT__CustomField/ColumnMap
+++ b/share/html/Elements/RT__CustomField/ColumnMap
@@ -181,6 +181,28 @@ my $COLUMN_MAP = {
return @res;
},
},
+ SortOrder => {
+ title => 'Sort',
+ value => sub {
+ my $id = $_[0]->id;
+ my $queue_id = $_[2] || 0;
+
+ my $record = RT::ObjectCustomField->new( $session{CurrentUser} );
+ my $applied_id = $_[0]->IsGlobal ? 0 : $queue_id;
+ my $disabled = $applied_id == $queue_id ? '' : 'disabled="disabled"';
+
+ $record->LoadByCols( CustomField => $id, ObjectId => $applied_id );
+ if ( $record->id ) {
+ my $name = "CustomField-$id-SortOrder";
+ my $value = $record->SortOrder;
+ return \qq{<input name="}, $name, \qq{" size="5" value="$value" $disabled />};
+ }
+ else {
+ RT->Logger->warning("Custom field #$id is not applied to object #$applied_id");
+ return '';
+ }
+ },
+ },
};
$COLUMN_MAP->{'AppliedTo'} = $COLUMN_MAP->{'AddedTo'};
-----------------------------------------------------------------------
hooks/post-receive
--
rt
More information about the rt-commit
mailing list