[Rt-commit] rt branch, 4.4/queue-autocomplete, created. rt-4.4.0rc2-2-gca98144
Dustin Graves
dustin at bestpractical.com
Wed Dec 2 18:00:32 EST 2015
The branch, 4.4/queue-autocomplete has been created
at ca98144351ed05400bd3be259322d4f85fe44cad (commit)
- Log -----------------------------------------------------------------
commit ca98144351ed05400bd3be259322d4f85fe44cad
Author: Dustin Graves <dustin at bestpractical.com>
Date: Thu Oct 22 20:55:29 2015 +0000
add autocomplete textbox for queue selection
Fixes: I#31291
diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 0125347..ded8e81 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -201,6 +201,16 @@ our %META;
Hints => 'Replaces the owner dropdowns with textboxes' #loc
}
},
+ AutocompleteQueues => {
+ Section => 'General',
+ Overridable => 1,
+ SortOrder => 3.2,
+ Widget => '/Widgets/Form/Boolean',
+ WidgetArguments => {
+ Description => 'Use autocomplete to find queues?', # loc
+ Hints => 'Replaces the queue dropdowns with textboxes' #loc
+ }
+ },
WebDefaultStylesheet => {
Section => 'General', #loc
Overridable => 1,
diff --git a/share/html/Elements/CreateTicket b/share/html/Elements/CreateTicket
index 7dad182..3c58ac9 100644
--- a/share/html/Elements/CreateTicket
+++ b/share/html/Elements/CreateTicket
@@ -50,7 +50,7 @@
>
% my $button_start = '<input type="submit" class="button" value="';
% my $button_end = '" />';
-% my $queue_selector = $m->scomp('/Elements/SelectNewTicketQueue', OnChange => 'document.CreateTicketInQueue.submit()', SendTo => $SendTo );
+% my $queue_selector = $m->scomp('/Elements/SelectNewTicketQueue', AutoSubmit => 1, SendTo => $SendTo, Placeholder => loc('Queue') );
<&|/l_unsafe, $button_start, $button_end, $queue_selector &>[_1]New ticket in[_2] [_3]</&>
% $m->callback(CallbackName => 'BeforeFormEnd');
</form>
diff --git a/share/html/Elements/SelectQueue b/share/html/Elements/SelectQueue
index ae645a7..7034037 100644
--- a/share/html/Elements/SelectQueue
+++ b/share/html/Elements/SelectQueue
@@ -45,14 +45,22 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
+%if (RT->Config->Get("AutocompleteQueues", $session{'CurrentUser'})) {
+<& SelectQueueAutocomplete, %ARGS, &>
+%} else {
<& SelectObject,
%ARGS,
- ObjectType => "Queue",
- CheckRight => $CheckQueueRight,
- ShowAll => $ShowAllQueues,
+ ObjectType => "Queue",
+ CheckRight => $CheckQueueRight,
+ ShowAll => $ShowAllQueues,
CacheNeedsUpdate => RT->System->QueueCacheNeedsUpdate,
&>
+%}
<%args>
$CheckQueueRight => 'CreateTicket'
-$ShowAllQueues => 1
+$ShowAllQueues => 1
+$AutoSubmit => 0
</%args>
+<%init>
+$ARGS{OnChange} = 'jQuery(this).closest("form").submit();' if $AutoSubmit;
+</%init>
diff --git a/share/html/Elements/SelectQueue b/share/html/Elements/SelectQueueAutocomplete
similarity index 71%
copy from share/html/Elements/SelectQueue
copy to share/html/Elements/SelectQueueAutocomplete
index ae645a7..9adf781 100644
--- a/share/html/Elements/SelectQueue
+++ b/share/html/Elements/SelectQueueAutocomplete
@@ -2,7 +2,7 @@
%#
%# COPYRIGHT:
%#
-%# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
%# <sales at bestpractical.com>
%#
%# (Except where explicitly superseded by other copyright notices)
@@ -45,14 +45,30 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
-<& SelectObject,
- %ARGS,
- ObjectType => "Queue",
- CheckRight => $CheckQueueRight,
- ShowAll => $ShowAllQueues,
- CacheNeedsUpdate => RT->System->QueueCacheNeedsUpdate,
- &>
<%args>
+$Name => 'Queue'
+$Default => 0
+$Class => 'select-queue field'
+$Placeholder => ''
+
+$ShowAllQueues => 1
$CheckQueueRight => 'CreateTicket'
-$ShowAllQueues => 1
+$AutoSubmit => 0
+$Return => 'Name'
</%args>
+<%init>
+my $DefaultQueue = RT::Queue->new($session{'CurrentUser'});
+$DefaultQueue->Load( $Default );
+
+undef $CheckQueueRight if $ShowAllQueues;
+</%init>
+<input name="<% $Name %>"
+ size="25"
+ value="<% $DefaultQueue->id ? $DefaultQueue->Name : "" %>"
+ class="<% $Class %>"
+ data-autocomplete="Queues"
+ placeholder="<% $Placeholder %>"
+ data-autocomplete-checkright="<% $CheckQueueRight %>"
+ data-autocomplete-return="<% $Return %>"
+ <% $AutoSubmit ? 'data-autocomplete-autosubmit=1' : '' %>
+/>
diff --git a/share/html/Elements/CreateTicket b/share/html/Helpers/Autocomplete/Queues
similarity index 68%
copy from share/html/Elements/CreateTicket
copy to share/html/Helpers/Autocomplete/Queues
index 7dad182..82a5781 100644
--- a/share/html/Elements/CreateTicket
+++ b/share/html/Helpers/Autocomplete/Queues
@@ -45,15 +45,42 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
-<form action="<% RT->Config->Get('WebPath') %><% $SendTo %>" name="CreateTicketInQueue" id="CreateTicketInQueue" \
-% $m->callback(CallbackName => 'InFormElement');
->
-% my $button_start = '<input type="submit" class="button" value="';
-% my $button_end = '" />';
-% my $queue_selector = $m->scomp('/Elements/SelectNewTicketQueue', OnChange => 'document.CreateTicketInQueue.submit()', SendTo => $SendTo );
-<&|/l_unsafe, $button_start, $button_end, $queue_selector &>[_1]New ticket in[_2] [_3]</&>
-% $m->callback(CallbackName => 'BeforeFormEnd');
-</form>
+% $r->content_type('application/json');
+<% JSON( \@suggestions ) |n %>
+% $m->abort;
<%ARGS>
-$SendTo => '/Ticket/Create.html',
+$term => undef
+$max => 10
+$op => 'STARTSWITH'
+$right => undef
+$return => 'Name';
</%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 $queues = RT::Queues->new( $session{CurrentUser} );
+$queues->RowsPerPage( $max );
+$queues->Limit(
+ FIELD => 'Name',
+ OPERATOR => $op,
+ VALUE => $term,
+ ENTRYAGGREGATOR => 'OR',
+ CASESENSITIVE => 0,
+);
+
+my @suggestions;
+while (my $q = $queues->Next) {
+ next if $right and not $q->CurrentUserHasRight($right);
+ my $value = $q->$return;
+ push @suggestions, { label => $q->Name, value => $value };
+}
+</%INIT>
diff --git a/share/static/css/aileron/nav.css b/share/static/css/aileron/nav.css
index 277187d..0ab3b3a 100644
--- a/share/static/css/aileron/nav.css
+++ b/share/static/css/aileron/nav.css
@@ -67,7 +67,6 @@
top: 6.05em;
right: 0em;
left: auto;
- z-index: 9995;
font-size: 0.9em;
}
@@ -162,9 +161,13 @@
-webkit-border-radius: 0 0 0 5px;
}
-#topactions input[type="search"] {
+#topactions input.field {
border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
}
+#topactions input.select-queue {
+ border: none;
+}
+
diff --git a/share/static/css/ballard/nav.css b/share/static/css/ballard/nav.css
index a24f0a2..e49dfab 100644
--- a/share/static/css/ballard/nav.css
+++ b/share/static/css/ballard/nav.css
@@ -78,7 +78,6 @@
position: absolute;
top: 6em;
right: 0em;
- z-index: 9995;
font-size: 0.9em;
background-color: #eee;
border: 1px solid #ccc;
@@ -146,8 +145,13 @@
color: #000;
}
-#topactions input[type="search"] {
+#topactions input.field {
border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
}
+
+#topactions input.select-queue {
+ border: none;
+}
+
diff --git a/share/static/css/base/nav.css b/share/static/css/base/nav.css
index cb508f5..c7cc7ce 100644
--- a/share/static/css/base/nav.css
+++ b/share/static/css/base/nav.css
@@ -53,4 +53,7 @@
padding-bottom: 0.25em;
height: auto;
}
+
+#page-navigation {
+ z-index: 95;
}
diff --git a/share/static/css/rudder/nav.css b/share/static/css/rudder/nav.css
index a4eca78..d4058f1 100644
--- a/share/static/css/rudder/nav.css
+++ b/share/static/css/rudder/nav.css
@@ -69,7 +69,6 @@
right: 0;
left: 0;
padding-right: 3em;
- z-index: 9995;
font-size: 0.9em;
border-bottom: 1px solid #ccc;
background-color: #eee;
@@ -232,9 +231,13 @@
-webkit-border-radius: 0 0 0 5px;
}
-#topactions input[type="search"] {
+#topactions input.field {
border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
}
+#topactions input.select-queue {
+ border: none;
+}
+
diff --git a/share/static/css/web2/nav.css b/share/static/css/web2/nav.css
index 7ff3ac1..add4899 100644
--- a/share/static/css/web2/nav.css
+++ b/share/static/css/web2/nav.css
@@ -122,7 +122,6 @@
left: 10em;
right: 0em;
height: 2.1em;
- z-index: 9995;
font-size: 0.9em;
background-color: #fff;
border: 1px solid #ccc;
diff --git a/share/static/js/autocomplete.js b/share/static/js/autocomplete.js
index badf128..78bc912 100644
--- a/share/static/js/autocomplete.js
+++ b/share/static/js/autocomplete.js
@@ -5,7 +5,8 @@ window.RT.Autocomplete.bind = function(from) {
var cssClassMap = {
Users: 'user',
Groups: 'group',
- Tickets: 'tickets'
+ Tickets: 'tickets',
+ Queues: 'queues'
};
jQuery("input[data-autocomplete]", from).each(function(){
@@ -13,7 +14,7 @@ window.RT.Autocomplete.bind = function(from) {
var what = input.attr("data-autocomplete");
var wants = input.attr("data-autocomplete-return");
- if (!what || !what.match(/^(Users|Groups|Tickets)$/)) // Did you update cssClassMap above?
+ if (!what || !what.match(/^(Users|Groups|Tickets|Queues)$/)) // Did you update cssClassMap above?
return;
// Don't re-bind the autocompleter
@@ -29,6 +30,11 @@ window.RT.Autocomplete.bind = function(from) {
queryargs.push("return=" + wants);
}
+ if (what == 'Queues') {
+ options.minLength = 2;
+ options.delay = 2;
+ }
+
if (input.is('[data-autocomplete-privileged]')) {
queryargs.push("privileged=1");
}
@@ -65,10 +71,21 @@ window.RT.Autocomplete.bind = function(from) {
terms.push(''); // add trailing delimeter so user can input another value directly
this.value = terms.join(what == 'Tickets' ? ' ' : ", ");
jQuery(this).change();
+
return false;
}
}
+ if (input.attr("data-autocomplete-autosubmit")) {
+ options.select = function( event, ui ) {
+ jQuery(event.target).val(ui.item.value);
+ jQuery(event.target).closest("form").submit();
+ };
+ }
+
+ var checkRight = input.attr("data-autocomplete-checkright");
+ if (checkRight) queryargs.push("right=" + checkRight);
+
var exclude = input.attr('data-autocomplete-exclude');
if (exclude) {
queryargs.push("exclude="+exclude);
-----------------------------------------------------------------------
More information about the rt-commit
mailing list