diff --git a/include/ajax.tasks.php b/include/ajax.tasks.php index eaf0630fdb4dbee400402f37c4486636e0c255c8..a8237e19fbf8b42921cd927f7aa73ff1d36fc4d3 100644 --- a/include/ajax.tasks.php +++ b/include/ajax.tasks.php @@ -22,6 +22,41 @@ require_once(INCLUDE_DIR.'class.task.php'); class TasksAjaxAPI extends AjaxController { + function lookup() { + global $thisstaff; + + $limit = isset($_REQUEST['limit']) ? (int) $_REQUEST['limit']:25; + $tasks = array(); + + $visibility = Q::any(array( + 'staff_id' => $thisstaff->getId(), + 'team_id__in' => $thisstaff->teams->values_flat('team_id'), + )); + + if (!$thisstaff->showAssignedOnly() && ($depts=$thisstaff->getDepts())) { + $visibility->add(array('dept_id__in' => $depts)); + } + + + $hits = TaskModel::objects() + ->filter(Q::any(array( + 'number__startswith' => $_REQUEST['q'], + ))) + ->filter($visibility) + ->values('number') + ->annotate(array('tasks' => SqlAggregate::COUNT('id'))) + ->order_by('-created') + ->limit($limit); + + foreach ($hits as $T) { + $tasks[] = array('id'=>$T['number'], 'value'=>$T['number'], + 'info'=>"{$T['number']}", + 'matches'=>$_REQUEST['q']); + } + + return $this->json_encode($tasks); + } + function add() { global $thisstaff; diff --git a/include/staff/tasks.inc.php b/include/staff/tasks.inc.php index 7d2c11b191b4a204e85b5a6f9ab6bf97a5fd83c0..6260027a6cc6b3c091cfa7263a8e66420e174eb1 100644 --- a/include/staff/tasks.inc.php +++ b/include/staff/tasks.inc.php @@ -76,12 +76,16 @@ case 'open': // Apply filters $filters = array(); -$SQ = new Q(array('flags__hasbit' => TaskModel::ISOPEN)); -if ($status && !strcasecmp($status, 'closed')) - $SQ->negate(); +if ($status) { + $SQ = new Q(array('flags__hasbit' => TaskModel::ISOPEN)); + if (!strcasecmp($status, 'closed')) + $SQ->negate(); -$filters[] = $SQ; -$tasks->filter($filters); + $filters[] = $SQ; +} + +if ($filters) + $tasks->filter($filters); // Impose visibility constraints // ------------------------------------------------------------ @@ -228,21 +232,22 @@ if ($thisstaff->hasPerm(Task::PERM_DELETE, false)) { </ul> </div> </div> - - <form action="tasks.php" method="get"> + <form action="tasks.php" method="get" onsubmit="javascript: + $.pjax({ + url:$(this).attr('action') + '?' + $(this).serialize(), + container:'#pjax-container', + timeout: 2000 + }); +return false;"> <input type="hidden" name="a" value="search"> - <table> - <tr> - <td><input type="text" id="basic-ticket-search" name="query" - size=30 value="<?php echo Format::htmlchars($_REQUEST['query'], - true); ?>" - autocomplete="off" autocorrect="off" autocapitalize="off"></td> - <td><input type="submit" class="button" value="<?php echo __('Search'); ?>"></td> - <td> <a href="#" onclick="javascript: - $.dialog('ajax.php/tasks/search', 201);" - >[<?php echo __('advanced'); ?>]</a> <i class="help-tip icon-question-sign" href="#advanced"></i></td> - </tr> - </table> + <input type="hidden" name="search-type" value=""/> + <div class="attached input"> + <input type="text" class="basic-search" data-url="ajax.php/tasks/lookup" name="query" + autofocus size="30" value="<?php echo Format::htmlchars($_REQUEST['query'], true); ?>" + autocomplete="off" autocorrect="off" autocapitalize="off"> + <button type="submit" class="attached button"><i class="icon-search"></i> + </button> + </div> </form> </div> <!-- SEARCH FORM END --> @@ -358,7 +363,7 @@ if ($thisstaff->hasPerm(Task::PERM_DELETE, false)) { <?php } //end of foreach if (!$total) - $ferror=__('There are no tickets matching your criteria.'); + $ferror=__('There are no tasks matching your criteria.'); ?> </tbody> <tfoot> diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php index d076ade82a078c0272e5c42a9209f6166bb02216..2aeb8ed118481d5abd0d8f6d863d412f1bad8772 100644 --- a/include/staff/tickets.inc.php +++ b/include/staff/tickets.inc.php @@ -343,7 +343,7 @@ return false;"> <input type="hidden" name="a" value="search"> <input type="hidden" name="search-type" value=""/> <div class="attached input"> - <input type="text" id="basic-ticket-search" name="query" + <input type="text" class="basic-search" data-url="ajax.php/tickets/lookup" name="query" autofocus size="30" value="<?php echo Format::htmlchars($_REQUEST['query'], true); ?>" autocomplete="off" autocorrect="off" autocapitalize="off"> <button type="submit" class="attached button"><i class="icon-search"></i> diff --git a/scp/ajax.php b/scp/ajax.php index be0e7c33db7ca4dfabef4b5f1d5087f164551e00..bdaf0a45483e7548617fd0c3715493f738ba130e 100644 --- a/scp/ajax.php +++ b/scp/ajax.php @@ -181,6 +181,7 @@ $dispatcher = patterns('', url_get('^(?P<tid>\d+)/view$', 'task'), url_post('^(?P<tid>\d+)$', 'task'), url('^add$', 'add'), + url('^lookup', 'lookup'), url_get('^mass/(?P<action>[\w.]+)', 'massProcess'), url_post('^mass/(?P<action>[\w.]+)', 'massProcess') )), diff --git a/scp/js/scp.js b/scp/js/scp.js index 69df220315aa0b8bb03c55099231349ee28aefe1..a97e1ef94ce5ae7e3688b72b97bdc5fd537f79f7 100644 --- a/scp/js/scp.js +++ b/scp/js/scp.js @@ -252,11 +252,13 @@ var scp_prep = function() { /* Typeahead tickets lookup */ var last_req; - $('#basic-ticket-search').typeahead({ + $('input.basic-search').typeahead({ source: function (typeahead, query) { if (last_req) last_req.abort(); + var $el = this.$element; + var url = $el.data('url')+'?q='+query; last_req = $.ajax({ - url: "ajax.php/tickets/lookup?q="+query, + url: url, dataType: 'json', success: function (data) { typeahead.process(data); @@ -264,9 +266,10 @@ var scp_prep = function() { }); }, onselect: function (obj) { - var form = $('#basic-ticket-search').closest('form'); + var $el = this.$element; + var form = $el.closest('form'); form.find('input[name=search-type]').val('typeahead'); - $('#basic-ticket-search').val(obj.value); + $el.val(obj.value); form.submit(); }, property: "matches"