Skip to content
Snippets Groups Projects
Commit cdddd81d authored by Peter Rotich's avatar Peter Rotich
Browse files

Refactor ticket open on staff interface

- Remove Client form
- Provide name and email fields for cases where use is not selected (JS
issues)
parent 10ee1757
No related branches found
No related tags found
No related merge requests found
......@@ -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'])
......
......@@ -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">&lt;<?php echo $user->getEmail(); ?>&gt;</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 &amp; 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>
......@@ -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'),
......
......@@ -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']);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment