From 427cfeccf17b302001582b3390cd3e50f121a6f3 Mon Sep 17 00:00:00 2001 From: sunnavy Date: Wed, 8 Nov 2023 16:48:55 -0500 Subject: [PATCH] Load owner dropdown via AJAX for inline edit on list to speed up page load --- share/html/Elements/RT__Ticket/ColumnMap | 2 +- share/html/Elements/SelectOwner | 2 + share/html/Elements/SelectOwnerDropdown | 1 + share/html/Elements/SelectOwnerDropdownDelay | 63 +++++++++++++++ share/html/Helpers/SelectOwnerDropdown | 79 +++++++++++++++++++ .../SelfService/Helpers/SelectOwnerDropdown | 48 +++++++++++ share/static/js/util.js | 20 +++++ 7 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 share/html/Elements/SelectOwnerDropdownDelay create mode 100644 share/html/Helpers/SelectOwnerDropdown create mode 100644 share/html/SelfService/Helpers/SelectOwnerDropdown diff --git a/share/html/Elements/RT__Ticket/ColumnMap b/share/html/Elements/RT__Ticket/ColumnMap index 1c43d501fb6..99a75454f94 100644 --- a/share/html/Elements/RT__Ticket/ColumnMap +++ b/share/html/Elements/RT__Ticket/ColumnMap @@ -114,7 +114,7 @@ $COLUMN_MAP = { title => 'Owner', # loc attribute => 'Owner', value => sub { return $_[0]->OwnerObj->Name }, - edit => sub { return \($m->scomp('/Elements/SelectOwner', TicketObj => $_[0], Name => 'Owner', Default => $_[0]->OwnerObj->Id, DefaultValue => 0)) }, + edit => sub { return \($m->scomp('/Elements/SelectOwner', TicketObj => $_[0], Name => 'Owner', Default => $_[0]->OwnerObj->Id, DefaultValue => 0, Delay => 1)) }, }, Status => { title => 'Status', # loc diff --git a/share/html/Elements/SelectOwner b/share/html/Elements/SelectOwner index 6342257a892..7edd34b0826 100644 --- a/share/html/Elements/SelectOwner +++ b/share/html/Elements/SelectOwner @@ -54,6 +54,7 @@ if ( !$QueueObj && !$TicketObj && RT->Config->Get('AutocompleteOwnersForSearch') $Widget ||= RT->Config->Get('AutocompleteOwners', $session{'CurrentUser'}) ? 'Autocomplete' : 'Dropdown'; +$Widget = 'DropdownDelay' if $Delay; my @objects; if ($TicketObj) { @objects = ($TicketObj); @@ -82,4 +83,5 @@ $m->callback( $TicketObj => undef $QueueObj => undef %Queues => () +$Delay => 0 diff --git a/share/html/Elements/SelectOwnerDropdown b/share/html/Elements/SelectOwnerDropdown index 44dcee0f84f..9e8fcf0f89c 100644 --- a/share/html/Elements/SelectOwnerDropdown +++ b/share/html/Elements/SelectOwnerDropdown @@ -113,6 +113,7 @@ unshift @formatednames, $nobody; $m->callback( CallbackName => 'ModifyOwnerListSorted', ARGSRef => \%ARGS, NamesRef => \@formatednames, DefaultRef => \$Default, Objects => $Objects ); +$ValueAttribute = 'id' unless ( $ValueAttribute // '' ) =~ /^(?:id|Name)$/; <%ARGS> diff --git a/share/html/Elements/SelectOwnerDropdownDelay b/share/html/Elements/SelectOwnerDropdownDelay new file mode 100644 index 00000000000..41847f7b859 --- /dev/null +++ b/share/html/Elements/SelectOwnerDropdownDelay @@ -0,0 +1,63 @@ +%# BEGIN BPS TAGGED BLOCK {{{ +%# +%# COPYRIGHT: +%# +%# This software is Copyright (c) 1996-2023 Best Practical Solutions, LLC +%# +%# +%# (Except where explicitly superseded by other copyright notices) +%# +%# +%# LICENSE: +%# +%# This work is made available to you under the terms of Version 2 of +%# the GNU General Public License. A copy of that license should have +%# been provided with this software, but in any event can be snarfed +%# from www.gnu.org. +%# +%# This work is distributed in the hope that it will be useful, but +%# WITHOUT ANY WARRANTY; without even the implied warranty of +%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +%# General Public License for more details. +%# +%# You should have received a copy of the GNU General Public License +%# along with this program; if not, write to the Free Software +%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +%# 02110-1301 or visit their web page on the internet at +%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. +%# +%# +%# CONTRIBUTION SUBMISSION POLICY: +%# +%# (The following paragraph is not intended to limit the rights granted +%# to you to modify and distribute this software under the terms of +%# the GNU General Public License and is only of importance to you if +%# you choose to contribute your changes and enhancements to the +%# community by submitting them to Best Practical Solutions, LLC.) +%# +%# By intentionally submitting any modifications, corrections or +%# derivatives to this work, or any other work intended for use with +%# Request Tracker, to Best Practical Solutions, LLC, you confirm that +%# you are the copyright holder for those contributions and you grant +%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, +%# royalty-free, perpetual, license to use, copy, create derivative +%# works based on those contributions, and sublicense and distribute +%# those contributions and any derivatives thereof. +%# +%# END BPS TAGGED BLOCK }}} +
+
Loading...
+
+ +<%ARGS> +$Name => undef +$Objects => [] +$Default => 0 +$DefaultValue => 1 +$DefaultLabel => "-" +$ValueAttribute => '' +$Size => 0 + diff --git a/share/html/Helpers/SelectOwnerDropdown b/share/html/Helpers/SelectOwnerDropdown new file mode 100644 index 00000000000..b925f05ae61 --- /dev/null +++ b/share/html/Helpers/SelectOwnerDropdown @@ -0,0 +1,79 @@ +%# BEGIN BPS TAGGED BLOCK {{{ +%# +%# COPYRIGHT: +%# +%# This software is Copyright (c) 1996-2023 Best Practical Solutions, LLC +%# +%# +%# (Except where explicitly superseded by other copyright notices) +%# +%# +%# LICENSE: +%# +%# This work is made available to you under the terms of Version 2 of +%# the GNU General Public License. A copy of that license should have +%# been provided with this software, but in any event can be snarfed +%# from www.gnu.org. +%# +%# This work is distributed in the hope that it will be useful, but +%# WITHOUT ANY WARRANTY; without even the implied warranty of +%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +%# General Public License for more details. +%# +%# You should have received a copy of the GNU General Public License +%# along with this program; if not, write to the Free Software +%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +%# 02110-1301 or visit their web page on the internet at +%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. +%# +%# +%# CONTRIBUTION SUBMISSION POLICY: +%# +%# (The following paragraph is not intended to limit the rights granted +%# to you to modify and distribute this software under the terms of +%# the GNU General Public License and is only of importance to you if +%# you choose to contribute your changes and enhancements to the +%# community by submitting them to Best Practical Solutions, LLC.) +%# +%# By intentionally submitting any modifications, corrections or +%# derivatives to this work, or any other work intended for use with +%# Request Tracker, to Best Practical Solutions, LLC, you confirm that +%# you are the copyright holder for those contributions and you grant +%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, +%# royalty-free, perpetual, license to use, copy, create derivative +%# works based on those contributions, and sublicense and distribute +%# those contributions and any derivatives thereof. +%# +%# END BPS TAGGED BLOCK }}} +<& /Elements/SelectOwnerDropdown, %ARGS, Objects => \@objects &> +% $m->abort; +<%INIT> +my @objects; +for my $item ( @{ JSON::from_json($Objects) || [] } ) { + my ( $class, $id ) = split /-/, $item, 2; + if ( $class && $id && $class =~ /^RT::(?:Ticket|Queue)/ ) { + my $object = $class->new( $session{CurrentUser} ); + $object->Load($id); + if ( $object->Id ) { + if ( $object->CurrentUserCanSee ) { + push @objects, $object; + } + else { + $m->abort; + } + } + else { + RT->Logger->info("Couldn't load $item"); + $m->abort; + } + } + else { + RT->Logger->info("Invalid object: $item"); + $m->abort; + } +} + + +<%ARGS> +$Objects => '' + diff --git a/share/html/SelfService/Helpers/SelectOwnerDropdown b/share/html/SelfService/Helpers/SelectOwnerDropdown new file mode 100644 index 00000000000..2c7dbda6d0e --- /dev/null +++ b/share/html/SelfService/Helpers/SelectOwnerDropdown @@ -0,0 +1,48 @@ +%# BEGIN BPS TAGGED BLOCK {{{ +%# +%# COPYRIGHT: +%# +%# This software is Copyright (c) 1996-2023 Best Practical Solutions, LLC +%# +%# +%# (Except where explicitly superseded by other copyright notices) +%# +%# +%# LICENSE: +%# +%# This work is made available to you under the terms of Version 2 of +%# the GNU General Public License. A copy of that license should have +%# been provided with this software, but in any event can be snarfed +%# from www.gnu.org. +%# +%# This work is distributed in the hope that it will be useful, but +%# WITHOUT ANY WARRANTY; without even the implied warranty of +%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +%# General Public License for more details. +%# +%# You should have received a copy of the GNU General Public License +%# along with this program; if not, write to the Free Software +%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +%# 02110-1301 or visit their web page on the internet at +%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. +%# +%# +%# CONTRIBUTION SUBMISSION POLICY: +%# +%# (The following paragraph is not intended to limit the rights granted +%# to you to modify and distribute this software under the terms of +%# the GNU General Public License and is only of importance to you if +%# you choose to contribute your changes and enhancements to the +%# community by submitting them to Best Practical Solutions, LLC.) +%# +%# By intentionally submitting any modifications, corrections or +%# derivatives to this work, or any other work intended for use with +%# Request Tracker, to Best Practical Solutions, LLC, you confirm that +%# you are the copyright holder for those contributions and you grant +%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, +%# royalty-free, perpetual, license to use, copy, create derivative +%# works based on those contributions, and sublicense and distribute +%# those contributions and any derivatives thereof. +%# +%# END BPS TAGGED BLOCK }}} +% $m->comp('/Helpers/SelectOwnerDropdown', %ARGS); diff --git a/share/static/js/util.js b/share/static/js/util.js index 6d8ddf76c38..d349bd6dcc9 100644 --- a/share/static/js/util.js +++ b/share/static/js/util.js @@ -1323,6 +1323,26 @@ jQuery(function () { beginInlineEdit(cell); }); + + jQuery(document).on('mouseenter', 'table.inline-edit td.editable .edit-icon', function (e) { + const owner_dropdown_delay = jQuery(this).closest('.editable').find('div.select-owner-dropdown-delay:not(.loaded)'); + if ( owner_dropdown_delay.length ) { + owner_dropdown_delay.load(RT.Config.WebHomePath + '/Helpers/SelectOwnerDropdown', { + Name: owner_dropdown_delay.attr('data-name'), + Default: owner_dropdown_delay.attr('data-default'), + DefaultValue: owner_dropdown_delay.attr('data-default-value'), + DefaultLabel: owner_dropdown_delay.attr('data-default-label'), + ValueAttribute: owner_dropdown_delay.attr('data-value-attribute'), + Size: owner_dropdown_delay.attr('data-size'), + Objects: owner_dropdown_delay.attr('data-objects') + }, function () { + owner_dropdown_delay.addClass('loaded'); + refreshSelectpicker(owner_dropdown_delay.find('.selectpicker')); + RT.Autocomplete.bind(owner_dropdown_delay); + }); + } + }); + jQuery(document).on('change', 'td.editable.editing form :input', function () { jQuery(this).closest('form').data('changed', true); });