From 8a83f563dda747a114adea234efee992c55cb528 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@enhancesoft.com> Date: Sat, 23 Nov 2013 20:20:35 +0000 Subject: [PATCH] Use the unified user lookup dialog modal to change ticket user (owner) --- include/ajax.tickets.php | 25 +++++++++++++++++++++++++ include/staff/ticket-edit.inc.php | 31 ++++++++++++++++++------------- scp/ajax.php | 2 ++ 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php index a142fc105..ef207f84d 100644 --- a/include/ajax.tickets.php +++ b/include/ajax.tickets.php @@ -448,5 +448,30 @@ class TicketsAjaxAPI extends AjaxController { return $resp; } + + function changeUserForm($tid) { + global $thisstaff; + + if(!$thisstaff + || !($ticket=Ticket::lookup($tid)) + || !$ticket->checkStaffAccess($thisstaff)) + Http::response(404, 'No such ticket'); + + + $user = $ticket->getOwner(); + + $info = array( + 'title' => sprintf('Change user for ticket #%s', $ticket->getNumber()) + ); + + ob_start(); + include(STAFFINC_DIR . 'templates/user-lookup.tmpl.php'); + $resp = ob_get_contents(); + ob_end_clean(); + return $resp; + + } + + } ?> diff --git a/include/staff/ticket-edit.inc.php b/include/staff/ticket-edit.inc.php index 668cd5234..fa4b40690 100644 --- a/include/staff/ticket-edit.inc.php +++ b/include/staff/ticket-edit.inc.php @@ -20,21 +20,26 @@ if ($_POST) </th> </tr> <?php - $client = User::lookup($info['user_id']); + if(!$info['user_id'] || !($user = User::lookup($info['user_id']))) + $user = $ticket->getUser(); ?> <tr><td>Client:</td><td> - <span id="client-info"><?php echo $client->getName(); ?> - <<?php echo $client->getEmail(); ?>></span> - <a class="action-button" style="float:none;overflow:inherit" - href="ajax.php/users/lookup?id=<?php echo $client->getId(); ?>" - onclick="javascript: - $('#overlay').show(); - $('#user-lookup .body').load(this.href); - $('#user-lookup').show(); - return false; - "><i class="icon-edit"></i> Change</a> - <input type="hidden" name="user_id" id="user_id" - value="<?php echo $info['user_id']; ?>" /> + <div id="client-info"> + <span id="client-name"><?php echo $user->getName(); ?></span> + <span id="client-email"><<?php echo $user->getEmail(); ?>></span> + <a class="action-button" style="float:none;overflow:inherit" href="#" + onclick="javascript: + $.userLookup('ajax.php/tickets/<?php echo $ticket->getId(); ?>/change-user', + function(user) { + $('input#user_id').val(user.id); + $('#user_name').html(user.name); + $('#user_email').html('<'+user.email+'>'); + }); + return false; + "><i class="icon-edit"></i> Change</a> + <input type="hidden" name="user_id" id="user_id" + value="<?php echo $info['user_id']; ?>" /> + </div> </td></tr> <tbody> <tr> diff --git a/scp/ajax.php b/scp/ajax.php index 460248be2..82a2ce3ef 100644 --- a/scp/ajax.php +++ b/scp/ajax.php @@ -67,6 +67,8 @@ $dispatcher = patterns('', url_post('^/lookup/form$', 'addUser') )), url('^/tickets/', patterns('ajax.tickets.php:TicketsAjaxAPI', + url_get('^(?P<tid>\d+)/change-user$', 'changeUserForm'), + url_post('^(?P<tid>\d+)/change-user$', 'changeUser'), url_get('^(?P<tid>\d+)/preview', 'previewTicket'), url_post('^(?P<tid>\d+)/lock', 'acquireLock'), url_post('^(?P<tid>\d+)/lock/(?P<id>\d+)/renew', 'renewLock'), -- GitLab