[Rt-commit] rt branch, 5.0-trunk, updated. rt-5.0.1-28-g10d6eb2037

? sunnavy sunnavy at bestpractical.com
Mon Mar 8 09:44:44 EST 2021


The branch, 5.0-trunk has been updated
       via  10d6eb20375b168edd15d33dab400008bae10641 (commit)
       via  c6b911d1c97ae76e1ab9413e2d3122050664b727 (commit)
      from  0ae4eae458640bc0cd64e8d64467adfbcdf882ce (commit)

Summary of changes:
 share/html/Helpers/Autocomplete/{Articles => Assets} | 19 ++++++++-----------
 share/html/Ticket/Elements/ShowAssets                |  2 +-
 share/static/js/autocomplete.js                      |  3 ++-
 3 files changed, 11 insertions(+), 13 deletions(-)
 copy share/html/Helpers/Autocomplete/{Articles => Assets} (87%)

- Log -----------------------------------------------------------------
commit c6b911d1c97ae76e1ab9413e2d3122050664b727
Author: craig kaiser <craig at bestpractical.com>
Date:   Mon Dec 7 15:33:35 2020 -0500

    Add autocomplete for assets input

diff --git a/share/html/Helpers/Autocomplete/Assets b/share/html/Helpers/Autocomplete/Assets
new file mode 100644
index 0000000000..8015431e10
--- /dev/null
+++ b/share/html/Helpers/Autocomplete/Assets
@@ -0,0 +1,91 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2021 Best Practical Solutions, LLC
+%#                                          <sales at bestpractical.com>
+%#
+%# (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 }}}
+
+% $r->content_type('application/json; charset=utf-8');
+<% JSON( \@suggestions ) |n %>
+% $m->abort;
+
+<%ARGS>
+$term       => undef
+$max        => 10
+$op         => 'STARTSWITH'
+$right      => undef
+$return     => 'id'
+$queue      => undef
+</%ARGS>
+
+<%INIT>
+# Only allow certain return fields
+$return = 'Name'
+    unless $return =~ /^(?:id|Name)$/;
+
+$m->abort unless defined $return
+             and defined $term
+             and length $term;
+
+# Sanity check the operator
+$op = 'STARTSWITH' unless $op =~ /^(?:LIKE|(?:START|END)SWITH|=|!=)$/i;
+
+my $assets = RT::Assets->new( $session{CurrentUser} );
+
+$assets->RowsPerPage( $max );
+$assets->Limit(
+    FIELD           => 'Name',
+    OPERATOR        => $op,
+    VALUE           => $term,
+    ENTRYAGGREGATOR => 'OR',
+    CASESENSITIVE   => 0,
+);
+
+my @suggestions;
+while (my $a = $assets->Next) {
+    next if $right and not $a->CurrentUserHasRight($right);
+    my $value = $a->$return;
+    push @suggestions, { label => $a->Name, value => $value };
+}
+</%INIT>
diff --git a/share/html/Ticket/Elements/ShowAssets b/share/html/Ticket/Elements/ShowAssets
index bebb094ec0..441ccd257e 100644
--- a/share/html/Ticket/Elements/ShowAssets
+++ b/share/html/Ticket/Elements/ShowAssets
@@ -213,7 +213,7 @@ if ($ShowRelatedTickets) {
     <label><&|/l&>Add an asset to this ticket:</&></label>
     <div class="form-row">
       <div class="form-group mx-sm-3 mb-2">
-        <input class="form-control mb-2" size="10" name="<% $Ticket->id %>-RefersTo" placeholder="<&|/l&>Asset #</&>" type="text">
+        <input data-autocomplete="Assets" class="form-control mb-2" size="10" name="<% $Ticket->id %>-RefersTo" placeholder="<&|/l&>Asset #</&>" type="text">
       </div>
       <button type="submit" name="AddAsset" value="Add" class="button btn btn-primary form-control mb-2">Add</button>
     </div>
diff --git a/share/static/js/autocomplete.js b/share/static/js/autocomplete.js
index c56ea33218..7413c4bf81 100644
--- a/share/static/js/autocomplete.js
+++ b/share/static/js/autocomplete.js
@@ -7,7 +7,8 @@ window.RT.Autocomplete.Classes = {
     Groups: 'group',
     Tickets: 'tickets',
     Queues: 'queues',
-    Articles: 'articles'
+    Articles: 'articles',
+    Assets: 'assets'
 };
 
 Selectize.define('rt_drag_drop', function(options) {

commit 10d6eb20375b168edd15d33dab400008bae10641
Merge: 0ae4eae458 c6b911d1c9
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Mon Mar 8 22:25:26 2021 +0800

    Merge branch '5.0/allow-asset-autocomplete' into 5.0-trunk


-----------------------------------------------------------------------


More information about the rt-commit mailing list