[Rt-commit] rt branch, 4.4/update-owner-menu-on-quickcreate-queue-change, created. rt-4.4.4-190-g31564426c7

Dianne Skoll dianne at bestpractical.com
Thu Dec 10 16:16:15 EST 2020


The branch, 4.4/update-owner-menu-on-quickcreate-queue-change has been created
        at  31564426c7c0a726f0ae5c619a110742a746153c (commit)

- Log -----------------------------------------------------------------
commit 884cc22ce0c3e1ffc444301ed4137adb30d1cc2a
Author: Dianne Skoll <dianne at bestpractical.com>
Date:   Thu Dec 10 15:41:54 2020 -0500

    When the queue pulldown is changed, update the Owner pulldown.
    
    If the current user does not have the OwnTicket right in the newly-selected
    queue, then "Me" must be removed from the Owner pulldown.

diff --git a/share/html/Elements/QuickCreate b/share/html/Elements/QuickCreate
index 36792f004c..80a3577c58 100644
--- a/share/html/Elements/QuickCreate
+++ b/share/html/Elements/QuickCreate
@@ -47,21 +47,63 @@
 %# END BPS TAGGED BLOCK }}}
 <div class="quick-create">
 <&| /Widgets/TitleBox, title => loc('Quick ticket creation') &>
+
+<script type="text/javascript">
+%# This function is called whenever the Queue pulldown is
+%# changed.  It gets a list of possible owners for the ticket,
+%# which can at most include the current user and Nobody.
+%# The back-end helper returns an array of possible users;
+%# each element of the array is a three-element array
+%# [owner_id, owner_name, is_selected]
+function qc_update_owner_options (qselect, default_owner) {
+    var queue_id = qselect.children("option:selected").val();
+    jQuery.post(RT.Config.WebHomePath + '/Helpers/QuickCreatePossibleOwners',
+                {"queue_id": queue_id, "default_owner": default_owner },
+                function (data, status, jq) {
+                    html = '';
+                    data.forEach(function(item, index) {
+                        var val = item[0] + "";  // Convert to string
+                        var txt = item[1] + "";
+                        html = html + '<option value="' +
+                            val.replace(/&/g, '&') .
+                            replace(/>/g, '>')  .
+                            replace(/</g, '<')  .
+                            replace(/"/g, '"') + '"'; // Inside attribute, so escape quotes
+                        if (item[2]) {
+                            html = html + ' selected';
+                        }
+                        html = html + '>' +
+                            txt.replace(/&/g, '&') .
+                            replace(/>/g, '>')  .
+                            replace(/</g, '<') + '</option>';
+                    });
+                    jQuery(qselect).closest("form").find('select[name="Owner"]').html(html);
+                },
+                'json');
+}
+</script>
 <form
     method="post"
     action="<%RT->Config->Get('WebPath')%><% $r->path_info %>"
 % $m->callback(CallbackName => 'InFormElement');
 >
+% my $default_owner = $args->{Owner} || $session{'CurrentUser'}->id;
+
+%# The default owner may not have OwnTicket permission in the default
+%# queue, so update once the DOM is ready
+<script type="text/javascript">
+jQuery(document).ready(function() { qc_update_owner_options(jQuery('select[name="Queue"]'), <% $default_owner %>); });
+</script>
+
 <input type="hidden" class="hidden" name="QuickCreate" value="1" />
 <table>
 <tr class="input-row"><td class="label"><&|/l&>Subject</&>:</td>
     <td colspan="3" class="value"><input type="text" size="50" name="Subject" value="<% $args->{Subject} || '' %>" /></td>
     </tr><tr class="input-row">
-<td class="label"><&|/l&>Queue</&>:</td><td class="value"><& /Elements/SelectNewTicketQueue, Name => 'Queue', Default => $args->{Queue} &>
+<td class="label"><&|/l&>Queue</&>:</td><td class="value"><& /Elements/SelectNewTicketQueue, Name => 'Queue', Default => $args->{Queue}, OnChange => "qc_update_owner_options(jQuery(this), $default_owner);" &>
 </td>
 <td class="label"><&|/l&>Owner</&>:</td><td class="value">
-<select type="select" name="Owner">  
-% my $default_owner = $args->{Owner} || $session{'CurrentUser'}->id;
+<select type="select" name="Owner">
 <option value="<%$session{'CurrentUser'}->id%>" <% $default_owner == $session{'CurrentUser'}->id ? 'selected="selected"' : '' |n %>><&|/l&>Me</&></option>
 <option value="<%RT->Nobody->id%>" <% $default_owner == RT->Nobody->id ? 'selected="selected"' : '' |n %>><%loc('Nobody')%></option>
 </select>
diff --git a/share/html/Elements/QuickCreate b/share/html/Helpers/QuickCreatePossibleOwners
similarity index 52%
copy from share/html/Elements/QuickCreate
copy to share/html/Helpers/QuickCreatePossibleOwners
index 36792f004c..5d66ff2c3c 100644
--- a/share/html/Elements/QuickCreate
+++ b/share/html/Helpers/QuickCreatePossibleOwners
@@ -2,7 +2,7 @@
 %#
 %# COPYRIGHT:
 %#
-%# This software is Copyright (c) 1996-2019 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2020 Best Practical Solutions, LLC
 %#                                          <sales at bestpractical.com>
 %#
 %# (Except where explicitly superseded by other copyright notices)
@@ -45,41 +45,43 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<div class="quick-create">
-<&| /Widgets/TitleBox, title => loc('Quick ticket creation') &>
-<form
-    method="post"
-    action="<%RT->Config->Get('WebPath')%><% $r->path_info %>"
-% $m->callback(CallbackName => 'InFormElement');
->
-<input type="hidden" class="hidden" name="QuickCreate" value="1" />
-<table>
-<tr class="input-row"><td class="label"><&|/l&>Subject</&>:</td>
-    <td colspan="3" class="value"><input type="text" size="50" name="Subject" value="<% $args->{Subject} || '' %>" /></td>
-    </tr><tr class="input-row">
-<td class="label"><&|/l&>Queue</&>:</td><td class="value"><& /Elements/SelectNewTicketQueue, Name => 'Queue', Default => $args->{Queue} &>
-</td>
-<td class="label"><&|/l&>Owner</&>:</td><td class="value">
-<select type="select" name="Owner">  
-% my $default_owner = $args->{Owner} || $session{'CurrentUser'}->id;
-<option value="<%$session{'CurrentUser'}->id%>" <% $default_owner == $session{'CurrentUser'}->id ? 'selected="selected"' : '' |n %>><&|/l&>Me</&></option>
-<option value="<%RT->Nobody->id%>" <% $default_owner == RT->Nobody->id ? 'selected="selected"' : '' |n %>><%loc('Nobody')%></option>
-</select>
-</td>
-</tr>
-<tr class="input-row">
-    <td class="label"><&|/l&>Requestors</&>:</td>
-    <td colspan="3" class="value"><& /Elements/EmailInput, Name => 'Requestors', Size => '40', Default => $args->{Requestors} || $session{CurrentUser}->EmailAddress, AutocompleteMultiple => 1 &></td>
-</tr>
-<tr class="input-row">
-<td class="labeltop"><&|/l&>Content</&>:</td>
-<td colspan="3" class="value"><textarea name="Content" cols="50" rows="3"><% $args->{Content} || ''%></textarea></td></tr>
-</table>
-<& /Elements/Submit, Label => loc('Create') &>
-</form>
-</&>
-</div>
+%
+%# Get a list of possible owners for a ticket in QuickCreate.
+%# Nobody is always a possibility; CurrentUser is a possibility
+%# if and only if the user has OwnTicket rights in the
+%# specified queue.
+%# The output is a JSON array.  Each element of this array
+%# is a three-element array:
+%# [owner_id, owner_name, is_selected]
+%# where owner_id is the user ID of the possible owner, name is either
+%# 'Me' or 'Nobody', and is_selected is true if this should be the
+%# currently-selected owner option.
 
-<%INIT>
-my $args = delete $session{QuickCreate} || {};
-</%INIT>
+<%args>
+$queue_id
+$default_owner
+</%args>
+<%init>
+
+my @possibles;
+
+# "Nobody" is always possible
+my $nobody_id = RT->Nobody->id;
+
+# Each member of the @possibles array is a
+# three-element array: [id, name, selected]
+push(@possibles, [$nobody_id, loc('Nobody'), ($default_owner == $nobody_id ? 1 : 0)]);
+
+# Load the queue
+my $user = $session{'CurrentUser'};
+
+my $Queue = RT::Queue->new($user);
+if ($Queue->Load($queue_id)) {
+   if ($Queue->CurrentUserHasRight('OwnTicket')) {
+      push(@possibles, [$user->Id, loc('Me'), ($default_owner == $user->Id ? 1 : 0)]);
+   }
+}
+$r->content_type('application/json; charset=utf-8');
+$m->out( JSON(\@possibles) );
+$m->abort;
+</%init>

commit 31564426c7c0a726f0ae5c619a110742a746153c
Author: Dianne Skoll <dianne at bestpractical.com>
Date:   Thu Dec 10 16:13:46 2020 -0500

    Make args to Helpers/QuickCreatePossibleOwners optional to avoid test failure in t/web/helpers-http-cache-headers.t
    
    If we do not do this, then we get a warning which fails the test.

diff --git a/share/html/Helpers/QuickCreatePossibleOwners b/share/html/Helpers/QuickCreatePossibleOwners
index 5d66ff2c3c..bdff7994ec 100644
--- a/share/html/Helpers/QuickCreatePossibleOwners
+++ b/share/html/Helpers/QuickCreatePossibleOwners
@@ -57,12 +57,13 @@
 %# 'Me' or 'Nobody', and is_selected is true if this should be the
 %# currently-selected owner option.
 
-<%args>
-$queue_id
-$default_owner
-</%args>
+<%ARGS>
+$default_owner => -1
+$queue_id => -1
+</%ARGS>
 <%init>
 
+
 my @possibles;
 
 # "Nobody" is always possible

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


More information about the rt-commit mailing list