From cdddd81d151213e96583ff07ee0de0407bbc3d5d Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@enhancesoft.com> Date: Tue, 26 Nov 2013 16:37:31 +0000 Subject: [PATCH] Refactor ticket open on staff interface - Remove Client form - Provide name and email fields for cases where use is not selected (JS issues) --- include/ajax.users.php | 15 ++++++ include/staff/ticket-open.inc.php | 78 +++++++++++++++++++++++++++++-- scp/ajax.php | 4 +- scp/tickets.php | 12 ++++- 4 files changed, 103 insertions(+), 6 deletions(-) diff --git a/include/ajax.users.php b/include/ajax.users.php index a0e3b234e..91af6fee9 100644 --- a/include/ajax.users.php +++ b/include/ajax.users.php @@ -88,6 +88,21 @@ class UsersAjaxAPI extends AjaxController { return self::_lookupform(); } + function selectUser($id) { + + if ($id) + $user = User::lookup($id); + + $info = array('title' => 'Select User'); + + ob_start(); + include(STAFFINC_DIR . 'templates/user-lookup.tmpl.php'); + $resp = ob_get_contents(); + ob_end_clean(); + return $resp; + + } + static function _lookupform($form=null, $info=array()) { if (!$info or !$info['title']) diff --git a/include/staff/ticket-open.inc.php b/include/staff/ticket-open.inc.php index 0bbaa7691..6e7a76a96 100644 --- a/include/staff/ticket-open.inc.php +++ b/include/staff/ticket-open.inc.php @@ -17,17 +17,64 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); </tr> </thead> <tbody> + <tr> + <th colspan="2"> + <em><strong>Client Information</strong>: </em> + </th> + </tr> + <?php + if ($user) { ?> + <tr><td>Client:</td><td> + <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/users/select/<?php echo $user->getId(); ?>', + function(user) { + $('input#uid').val(user.id); + $('#client-name').html(user.name); + $('#client-email').text('<'+user.email+'>'); + }); + return false; + "><i class="icon-edit"></i> Change</a> + <input type="hidden" name="uid" id="uid" value="<?php echo $user->getId(); ?>" /> + </div> + </td></tr> + <?php + } else { //Fallback: Just ask for email and name + ?> + <tr> + <td width="160" class="required"> Email Address: </td> + <td> + <span style="display:inline-block;"> + <input type="text" size=45 name="email" id="user-email" value="<?php echo $info['email']; ?>" /> </span> + <font class="error">* <?php echo $errors['email']; ?></font> + </td> + </td> + <tr> + <td width="160" class="required"> Full Name: </td> + <td> + <span style="display:inline-block;"> + <input type="text" size=45 name="name" id="user-name" value="<?php echo $info['name']; ?>" /> </span> + <font class="error">* <?php echo $errors['name']; ?></font> + </td> + </td> + <?php + } ?> + <?php - $uf = UserForm::getUserForm(); - $uf->render(); if($cfg->notifyONNewStaffTicket()) { ?> <tr> - <td width="160">Alert:</td> + <td width="160">Ticket Notice:</td> <td> <input type="checkbox" name="alertuser" <?php echo (!$errors || $info['alertuser'])? 'checked="checked"': ''; ?>>Send alert to user. </td> </tr> - <?php } ?> + <?php + } ?> + </tbody> + <tbody> <tr> <th colspan="2"> <em><strong>Ticket Information & Options</strong>:</em> @@ -289,3 +336,26 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <input type="button" name="cancel" value="Cancel" onclick='window.location.href="tickets.php"'> </p> </form> +<script type="text/javascript"> +$(function() { + $('input#user-email').typeahead({ + source: function (typeahead, query) { + $.ajax({ + url: "ajax.php/users?q="+query, + dataType: 'json', + success: function (data) { + typeahead.process(data); + } + }); + }, + onselect: function (obj) { + $('#uid').val(obj.id); + $('#user-name').val(obj.name); + $('#user-email').val(obj.email); + }, + property: "/bin/true" + }); + +}); +</script> + diff --git a/scp/ajax.php b/scp/ajax.php index 02895d6e3..106f3366a 100644 --- a/scp/ajax.php +++ b/scp/ajax.php @@ -62,7 +62,9 @@ $dispatcher = patterns('', url_get('^/(?P<id>\d+)$', 'getUser'), url_get('^/lookup$', 'getUser'), url_get('^/lookup/form$', 'getLookupForm'), - url_post('^/lookup/form$', 'addUser') + url_post('^/lookup/form$', 'addUser'), + url_get('^/select$', 'selectUser'), + url_get('^/select/(?P<id>\d+)$', 'selectUser') )), url('^/tickets/', patterns('ajax.tickets.php:TicketsAjaxAPI', url_get('^(?P<tid>\d+)/change-user$', 'changeUserForm'), diff --git a/scp/tickets.php b/scp/tickets.php index b7ac97fe1..36b1ef9be 100644 --- a/scp/tickets.php +++ b/scp/tickets.php @@ -24,7 +24,7 @@ require_once(INCLUDE_DIR.'class.dynamic_forms.php'); $page=''; -$ticket=null; //clean start. +$ticket = $user = null; //clean start. //LOCKDOWN...See if the id provided is actually valid and if the user has access. if($_REQUEST['id']) { if(!($ticket=Ticket::lookup($_REQUEST['id']))) @@ -34,6 +34,11 @@ if($_REQUEST['id']) { $ticket=null; //Clear ticket obj. } } + +//Lookup user if id is available. +if ($_REQUEST['uid']) + $user = User::lookup($_REQUEST['uid']); + //At this stage we know the access status. we can process the post. if($_POST && !$errors): @@ -486,6 +491,11 @@ if($_POST && !$errors): $errors['err']='You do not have permission to create tickets. Contact admin for such access'; } else { $vars = $_POST; + if ($user) { + $vars['name'] = $user->getName(); + $vars['email'] = $user->getEmail(); + } + if($_FILES['attachments']) $vars['files'] = AttachmentFile::format($_FILES['attachments']); -- GitLab