[Rt-commit] rt branch, 4.4/queue-autocomplete, created. rt-4.2.12-353-ga055b0b
Dustin Graves
dustin at bestpractical.com
Thu Oct 29 11:31:45 EDT 2015
The branch, 4.4/queue-autocomplete has been created
at a055b0b592e78bc043cc5eb75dc253678aea784d (commit)
- Log -----------------------------------------------------------------
commit a055b0b592e78bc043cc5eb75dc253678aea784d
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 bcf4189..a7723bc 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..19b586e 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 => '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..69e55c5 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} = 'document.CreateTicketInQueue.submit()' if $AutoSubmit;
+</%init>
diff --git a/share/html/Elements/SelectQueue b/share/html/Elements/SelectQueueAutocomplete
similarity index 70%
copy from share/html/Elements/SelectQueue
copy to share/html/Elements/SelectQueueAutocomplete
index ae645a7..79b4714 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
</%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 %>"
+ <% $AutoSubmit ? 'data-autocomplete-autosubmit=1' : '' %>
+
+%# valuefield should be id for create ticket, name for query builder
+ data-autocomplete-params="right=<% $CheckQueueRight || '' |u %>&valuefield=<% $ARGS{OnChange} ? 'Id' : 'Name' %>"
+/>
diff --git a/share/html/Elements/CreateTicket b/share/html/Helpers/Autocomplete/Queues
similarity index 70%
copy from share/html/Elements/CreateTicket
copy to share/html/Helpers/Autocomplete/Queues
index 7dad182..a7841c8 100644
--- a/share/html/Elements/CreateTicket
+++ b/share/html/Helpers/Autocomplete/Queues
@@ -45,15 +45,37 @@
%# 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
+$valuefield => 'Name';
</%ARGS>
+<%INIT>
+$m->abort unless 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 = lc($valuefield) eq 'id' ? $q->Id : $q->Name;
+ 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 795ff6a..a4080e3 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;
}
@@ -158,9 +157,13 @@
-webkit-border-radius: 0 0 0 5px;
}
-#simple-search input.field {
+#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 b2ec4b2..b25b718 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;
@@ -142,8 +141,13 @@
color: #000;
}
-#simple-search input.field {
+#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 e21b0f2..2b238ad 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 ad48366..4c113dc 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;
@@ -226,9 +225,13 @@
-webkit-border-radius: 0 0 0 5px;
}
-#simple-search input.field {
+#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 957d6f2..2383aa2 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");
}
@@ -57,10 +63,18 @@ 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 exclude = input.attr('data-autocomplete-exclude');
if (exclude) {
queryargs.push("exclude="+exclude);
-----------------------------------------------------------------------
More information about the rt-commit
mailing list