From 1ff49a6af716d2c9ced675d0e557f268c0836b95 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Mon, 17 Aug 2015 15:31:04 +0000 Subject: [PATCH] Make Tickets/Tasks Queues sticky Redirect to recent queue / listing on transfer or assign --- include/class.thread.php | 5 ++++- include/staff/tasks.inc.php | 16 +++++++++++---- .../staff/templates/status-options.tmpl.php | 2 +- include/staff/templates/task-view.tmpl.php | 13 ++++++++---- .../staff/templates/tasks-actions.tmpl.php | 1 + include/staff/ticket-view.inc.php | 19 +++++++++++++----- include/staff/tickets.inc.php | 9 +++++---- scp/js/ticket.js | 7 +++++-- scp/tasks.php | 18 +++++++++++++++++ scp/tickets.php | 20 +++++++++++++++---- 10 files changed, 85 insertions(+), 25 deletions(-) diff --git a/include/class.thread.php b/include/class.thread.php index 0636df348..7e94e08d7 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -1818,7 +1818,10 @@ class CloseEvent extends ThreadEvent { static $state = 'closed'; function getDescription($mode=self::MODE_STAFF) { - return $this->template(__('Closed by <b>{somebody}</b> with status of {<TicketStatus>data.status} {timestamp}')); + if ($this->getData('status')) + return $this->template(__('Closed by <b>{somebody}</b> with status of {<TicketStatus>data.status} {timestamp}')); + else + return $this->template(__('Closed by <b>{somebody}</b> {timestamp}')); } } diff --git a/include/staff/tasks.inc.php b/include/staff/tasks.inc.php index 49cdd5e22..f5406c5c5 100644 --- a/include/staff/tasks.inc.php +++ b/include/staff/tasks.inc.php @@ -24,11 +24,14 @@ $sort_options = array( 'relevance' => __('Relevance'), ); -$queue_name = strtolower($_GET['status'] ?: $_GET['a']); //Status is overloaded +// Queue we're viewing +$queue_key = sprintf('::Q:%s', ObjectModel::OBJECT_TYPE_TASK); +$queue_name = $_SESSION[$queue_key] ?: ''; + switch ($queue_name) { case 'closed': $status='closed'; - $results_type=__('Closed Tasks'); + $results_type=__('Completed Tasks'); $showassigned=true; //closed by. $queue_sort_options = array('closed', 'updated', 'created', 'number', 'hot'); @@ -56,6 +59,7 @@ case 'search': 'number__startswith' => $_REQUEST['query'], 'cdata__title__contains' => $_REQUEST['query'], ))); + unset($_SESSION[$queue_key]); break; } elseif (isset($_SESSION['advsearch:tasks'])) { // XXX: De-duplicate and simplify this code @@ -430,8 +434,12 @@ $(function() { +$(this).attr('href').substr(1) +'?count='+count +'&_uid='+new Date().getTime(); + var $redirect = $(this).data('redirect'); $.dialog(url, [201], function (xhr) { - $.pjax.reload('#pjax-container'); + if (!!$redirect) + $.pjax({url: $redirect, container:'#pjax-container'}); + else + $.pjax.reload('#pjax-container'); }); } return false; @@ -445,7 +453,7 @@ $(function() { var $options = $(this).data('dialogConfig'); var $redirect = $(this).data('redirect'); $.dialog(url, [201], function (xhr) { - if ($redirect) + if (!!$redirect) window.location.href = $redirect; else $.pjax.reload('#pjax-container'); diff --git a/include/staff/templates/status-options.tmpl.php b/include/staff/templates/status-options.tmpl.php index 71e05981f..1f9918f26 100644 --- a/include/staff/templates/status-options.tmpl.php +++ b/include/staff/templates/status-options.tmpl.php @@ -55,7 +55,7 @@ if (!$nextStatuses) $status->getId()); ?>" <?php if (isset($actions[$status->getState()]['href'])) - echo sprintf('data-href="%s"', + echo sprintf('data-redirect="%s"', $actions[$status->getState()]['href']); ?> diff --git a/include/staff/templates/task-view.tmpl.php b/include/staff/templates/task-view.tmpl.php index 326576acf..7130c655d 100644 --- a/include/staff/templates/task-view.tmpl.php +++ b/include/staff/templates/task-view.tmpl.php @@ -32,7 +32,8 @@ if ($role->hasPerm(Task::PERM_ASSIGN)) { 'assign' => array( 'href' => sprintf('#tasks/%d/assign', $task->getId()), 'icon' => 'icon-user', - 'label' => $task->isAssigned() ? __('Reassign') : __('Assign') + 'label' => $task->isAssigned() ? __('Reassign') : __('Assign'), + 'redirect' => 'tasks.php' )); } @@ -41,7 +42,8 @@ if ($role->hasPerm(Task::PERM_TRANSFER)) { 'transfer' => array( 'href' => sprintf('#tasks/%d/transfer', $task->getId()), 'icon' => 'icon-share', - 'label' => __('Transfer') + 'label' => __('Transfer'), + 'redirect' => 'tasks.php' )); } @@ -52,7 +54,8 @@ if ($role->hasPerm(Task::PERM_DELETE)) { 'href' => sprintf('#tasks/%d/delete', $task->getId()), 'icon' => 'icon-trash', 'class' => 'red button task-action', - 'label' => __('Delete') + 'label' => __('Delete'), + 'redirect' => 'tasks.php' )); } @@ -152,6 +155,8 @@ if ($task->isOverdue()) <?php if ($action['dialog']) echo sprintf("data-dialog-config='%s'", $action['dialog']); + if ($action['redirect']) + echo sprintf("data-redirect='%s'", $action['redirect']); ?> href="<?php echo $action['href']; ?>"><i class="<?php @@ -504,7 +509,7 @@ $(function() { var $options = $(this).data('dialogConfig'); var $redirect = $(this).data('redirect'); $.dialog(url, [201], function (xhr) { - if ($redirect) + if (!!$redirect) window.location.href = $redirect; else $.pjax.reload('#pjax-container'); diff --git a/include/staff/templates/tasks-actions.tmpl.php b/include/staff/templates/tasks-actions.tmpl.php index fcf6192a4..04696a771 100644 --- a/include/staff/templates/tasks-actions.tmpl.php +++ b/include/staff/templates/tasks-actions.tmpl.php @@ -71,6 +71,7 @@ if ($agent->hasPerm(Task::PERM_TRANSFER, false)) { $actions += array( 'transfer' => array( 'icon' => 'icon-share', + 'redirect' => 'tickets.php', 'action' => __('Transfer') )); } diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php index ea79bc6c1..5bf1a6e5c 100644 --- a/include/staff/ticket-view.inc.php +++ b/include/staff/ticket-view.inc.php @@ -76,6 +76,7 @@ if($ticket->isOverdue()) // Transfer if ($role->hasPerm(TicketModel::PERM_TRANSFER)) {?> <a class="ticket-action action-button pull-right" id="ticket-transfer" + data-redirect="tickets.php" href="#tickets/<?php echo $ticket->getId(); ?>/transfer"><i class="icon-share"></i> <?php echo __('Transfer'); ?></a> <?php @@ -86,16 +87,24 @@ if($ticket->isOverdue()) if ($role->hasPerm(TicketModel::PERM_ASSIGN)) {?> <span class="action-button pull-right" data-dropdown="#action-dropdown-assign"> <i class="icon-caret-down pull-right"></i> - <a class="ticket-action" id="ticket-assign" href="#tickets/<?php echo $ticket->getId(); ?>/assign"><i class="icon-user"></i> <?php + <a class="ticket-action" id="ticket-assign" + data-redirect="tickets.php" + href="#tickets/<?php echo $ticket->getId(); ?>/assign"><i class="icon-user"></i> <?php echo $ticket->isAssigned() ? __('Assign') : __('Reassign'); ?></a> </span> <div id="action-dropdown-assign" class="action-dropdown anchor-right"> <ul> - <li><a class="no-pjax ticket-action" href="#tickets/<?php echo $ticket->getId(); ?>/assign/<?php echo $thisstaff->getId(); ?>"><i + <li><a class="no-pjax ticket-action" + data-redirect="tickets.php" + href="#tickets/<?php echo $ticket->getId(); ?>/assign/<?php echo $thisstaff->getId(); ?>"><i class="icon-chevron-sign-down"></i> <?php echo __('Claim'); ?></a> - <li><a class="no-pjax ticket-action" href="#tickets/<?php echo $ticket->getId(); ?>/assign/agents"><i + <li><a class="no-pjax ticket-action" + data-redirect="tickets.php" + href="#tickets/<?php echo $ticket->getId(); ?>/assign/agents"><i class="icon-user"></i> <?php echo __('Agent'); ?></a> - <li><a class="no-pjax ticket-action" href="#tickets/<?php echo $ticket->getId(); ?>/assign/teams"><i + <li><a class="no-pjax ticket-action" + data-redirect="tickets.php" + href="#tickets/<?php echo $ticket->getId(); ?>/assign/teams"><i class="icon-group"></i> <?php echo __('Team'); ?></a> </ul> </div> @@ -173,7 +182,7 @@ if($ticket->isOverdue()) ?> <li class="danger"><a class="ticket-action" href="#tickets/<?php echo $ticket->getId(); ?>/status/delete" - data-href="tickets.php"><i class="icon-trash"></i> <?php + data-redirect="tickets.php"><i class="icon-trash"></i> <?php echo __('Delete Ticket'); ?></a></li> <?php } diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php index db70a4669..27378bacf 100644 --- a/include/staff/tickets.inc.php +++ b/include/staff/tickets.inc.php @@ -33,10 +33,9 @@ $sort_options = array( ); $use_subquery = true; -$queue_name = strtolower($_GET['a'] ?: $_GET['status']); //Status is overloaded - -// Stash current queue view -$_SESSION['::Q'] = $queue_name; +// Figure out the queue we're viewing +$queue_key = sprintf('::Q:%s', ObjectModel::OBJECT_TYPE_TICKET); +$queue_name = $_SESSION[$queue_key] ?: ''; switch ($queue_name) { case 'closed': @@ -106,6 +105,8 @@ case 'search': } $tickets->filter($basic_search); } + // Clear sticky search queue + unset($_SESSION[$queue_key]); break; } elseif (isset($_SESSION['advsearch'])) { $form = $search->getFormFromSession('advsearch'); diff --git a/scp/js/ticket.js b/scp/js/ticket.js index 21ed2f415..61ba8c7b8 100644 --- a/scp/js/ticket.js +++ b/scp/js/ticket.js @@ -328,10 +328,13 @@ var ticket_onload = function($) { var url = 'ajax.php/' +$(this).attr('href').substr(1) +'?_uid='+new Date().getTime(); - var $redirect = $(this).data('href'); + var $redirect = $(this).data('redirect'); var $options = $(this).data('dialog'); $.dialog(url, [201], function (xhr) { - window.location.href = $redirect ? $redirect : window.location.href; + if (!!$redirect) + window.location.href = $redirect; + else + $.pjax.reload('#pjax-container'); }, $options); return false; diff --git a/scp/tasks.php b/scp/tasks.php index ced34f872..f33018f32 100644 --- a/scp/tasks.php +++ b/scp/tasks.php @@ -118,6 +118,24 @@ $stats= $thisstaff->getTasksStats(); if (isset($_GET['clear_filter'])) unset($_SESSION['advsearch:tasks']); + +if (!$task) { + $queue_key = sprintf('::Q:%s', ObjectModel::OBJECT_TYPE_TASK); + $queue_name = strtolower($_GET['status'] ?: $_GET['a']); + if (!$queue_name && isset($_SESSION[$queue_key])) + $queue_name = $_SESSION[$queue_key]; + + // Stash current queue view + $_SESSION[$queue_key] = $queue_name; + + // Set queue as status + if (@!isset($_REQUEST['advanced']) + && @$_REQUEST['a'] != 'search' + && !isset($_GET['status']) + && $queue_name) + $_GET['status'] = $_REQUEST['status'] = $queue_name; +} + //Navigation $nav->setTabActive('tasks'); $open_name = _P('queue-name', diff --git a/scp/tickets.php b/scp/tickets.php index fadaf9730..e5e03aa2e 100644 --- a/scp/tickets.php +++ b/scp/tickets.php @@ -35,13 +35,25 @@ if($_REQUEST['id']) { } } -//Lookup user if id is available. if ($_REQUEST['uid']) { $user = User::lookup($_REQUEST['uid']); +} elseif (!$ticket) { + $queue_key = sprintf('::Q:%s', ObjectModel::OBJECT_TYPE_TICKET); + $queue_name = strtolower($_GET['status'] ?: $_GET['a']); //Status is overloaded + if (!$queue_name && isset($_SESSION[$queue_key])) + $queue_name = $_SESSION[$queue_key]; + + // Stash current queue view + $_SESSION[$queue_key] = $queue_name; + + // Set queue as status + if (@!isset($_REQUEST['advanced']) + && @$_REQUEST['a'] != 'search' + && !isset($_GET['status']) + && $queue_name) + $_GET['status'] = $_REQUEST['status'] = $queue_name; } -elseif (@!isset($_REQUEST['advanced']) && @$_REQUEST['a'] != 'search' && !isset($_GET['status']) && isset($_SESSION['::Q'])) { - $_GET['status'] = $_REQUEST['status'] = $_SESSION['::Q']; -} + // Configure form for file uploads $response_form = new SimpleForm(array( 'attachments' => new FileUploadField(array('id'=>'attach', -- GitLab