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

Merge pull request #32 from protich/feature/ticket-open-typeahead

Feature/ticket open typeahead
parents e525cddd 1775aba9
No related branches found
No related tags found
No related merge requests found
...@@ -24,30 +24,35 @@ class TicketsAjaxAPI extends AjaxController { ...@@ -24,30 +24,35 @@ class TicketsAjaxAPI extends AjaxController {
$limit = isset($_REQUEST['limit']) ? (int) $_REQUEST['limit']:25; $limit = isset($_REQUEST['limit']) ? (int) $_REQUEST['limit']:25;
$items=array(); $items=array();
$ticketid=false;
if(is_numeric($_REQUEST['q'])) { $sql='SELECT DISTINCT ticketID, email'
$WHERE=' WHERE ticketID LIKE \''.db_input($_REQUEST['q'], false).'%\''; .' FROM '.TICKET_TABLE;
$ticketid=true;
} elseif(isset($_REQUEST['q'])) { $emailSearch=false;
$WHERE=' WHERE email LIKE \'%'.db_input(strtolower($_REQUEST['q']), false).'%\''; if(is_numeric($_REQUEST['q']))
} else { $sql.=' WHERE ticketID LIKE \''.db_input($_REQUEST['q'], false).'%\'';
Http::response(400, 'Query argument is required'); else {
$emailSearch=true;
$sql.=' WHERE email LIKE \'%'.db_input(strtolower($_REQUEST['q']), false).'%\' ';
} }
$sql='SELECT DISTINCT ticketID, email, name '
.' FROM '.TICKET_TABLE.' '.$WHERE
.' ORDER BY created '
.' LIMIT '.$limit;
if(($res=db_query($sql)) && db_num_rows($res)){ $sql.=' ORDER BY created LIMIT '.$limit;
if(($res=db_query($sql)) && db_num_rows($res)) {
while(list($id,$email,$name)=db_fetch_row($res)) { while(list($id,$email,$name)=db_fetch_row($res)) {
$info=($ticketid)?$email:$id; if($emailSearch) {
$id=($ticketid)?$id:$email; $info = "$email - $id";
$items[] = array('id'=>$id, 'value'=>$id, 'info'=>$info, $value = $email;
'name'=>$name); } else {
$info = "$id -$email";
$value = $id;
}
$items[] = array('id'=>$id, 'email'=>$email, 'value'=>$value, 'info'=>$info);
} }
} }
return $this->encode($items); return $this->json_encode($items);
} }
function acquireLock($tid) { function acquireLock($tid) {
......
<?php
/*********************************************************************
ajax.users.php
AJAX interface for users (based on submitted tickets)
XXX: osTicket doesn't support user accounts at the moment.
Peter Rotich <peter@osticket.com>
Copyright (c) 2006-2012 osTicket
http://www.osticket.com
Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
if(!defined('INCLUDE_DIR')) die('403');
include_once(INCLUDE_DIR.'class.ticket.php');
class UsersAjaxAPI extends AjaxController {
/* Assumes search by emal for now */
function search() {
if(!isset($_REQUEST['q'])) {
Http::response(400, 'Query argument is required');
}
$limit = isset($_REQUEST['limit']) ? (int) $_REQUEST['limit']:25;
$users=array();
$sql='SELECT DISTINCT email, name '
.' FROM '.TICKET_TABLE
.' WHERE email LIKE \'%'.db_input(strtolower($_REQUEST['q']), false).'%\' '
.' ORDER BY created '
.' LIMIT '.$limit;
if(($res=db_query($sql)) && db_num_rows($res)){
while(list($email,$name)=db_fetch_row($res)) {
$users[] = array('email'=>$email, 'name'=>$name, 'info'=>"$email - $name");
}
}
return $this->json_encode($users);
}
}
?>
...@@ -22,7 +22,8 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); ...@@ -22,7 +22,8 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
Email Address: Email Address:
</td> </td>
<td> <td>
<input type="text" size="30" name="email" value="<?php echo $info['email']; ?>"> <input type="text" size="30" name="email" id="email" class="typeahead" value="<?php echo $info['email']; ?>"
autocomplete="off" autocorrect="off" autocapitalize="off">
&nbsp;<span class="error">*&nbsp;<?php echo $errors['email']; ?></span> &nbsp;<span class="error">*&nbsp;<?php echo $errors['email']; ?></span>
<?php <?php
if($cfg->notifyONNewStaffTicket()) { ?> if($cfg->notifyONNewStaffTicket()) { ?>
...@@ -37,7 +38,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); ...@@ -37,7 +38,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
Full Name: Full Name:
</td> </td>
<td> <td>
<input type="text" size="30" name="name" value="<?php echo $info['name']; ?>"> <input type="text" size="30" name="name" id="name" value="<?php echo $info['name']; ?>">
&nbsp;<span class="error">*&nbsp;<?php echo $errors['name']; ?></span> &nbsp;<span class="error">*&nbsp;<?php echo $errors['name']; ?></span>
</td> </td>
</tr> </tr>
...@@ -46,9 +47,9 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); ...@@ -46,9 +47,9 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
Phone Number: Phone Number:
</td> </td>
<td> <td>
<input type="text" size="18" name="phone" value="<?php echo $info['phone']; ?>"> <input type="text" size="18" name="phone" id="phone" value="<?php echo $info['phone']; ?>">
&nbsp;<span class="error">&nbsp;<?php echo $errors['phone']; ?></span> &nbsp;<span class="error">&nbsp;<?php echo $errors['phone']; ?></span>
Ext <input type="text" size="5" name="phone_ext" value="<?php echo $info['phone_ext']; ?>"> Ext <input type="text" size="5" name="phone_ext" id="phone_ext" value="<?php echo $info['phone_ext']; ?>">
&nbsp;<span class="error">&nbsp;<?php echo $errors['phone_ext']; ?></span> &nbsp;<span class="error">&nbsp;<?php echo $errors['phone_ext']; ?></span>
</td> </td>
</tr> </tr>
......
...@@ -256,99 +256,13 @@ $basic_display=!isset($_REQUEST['advance_search'])?true:false; ...@@ -256,99 +256,13 @@ $basic_display=!isset($_REQUEST['advance_search'])?true:false;
<input type="hidden" name="a" value="search"> <input type="hidden" name="a" value="search">
<table> <table>
<tr> <tr>
<td><input type="text" id="ticket-search" name="query" size=30 value="<?php echo Format::htmlchars($_REQUEST['query']); ?>"></td> <td><input type="text" id="basic-ticket-search" name="query" size=30 value="<?php echo Format::htmlchars($_REQUEST['query']); ?>"
autocomplete="off" autocorrect="off" autocapitalize="off"></td>
<td><input type="submit" name="basic_search" class="button" value="Search"></td> <td><input type="submit" name="basic_search" class="button" value="Search"></td>
</tr> </tr>
</table> </table>
</form> </form>
</div> </div>
<div id='advance' style="display:<?php echo $basic_display?'none':'block'; ?>">
<form action="tickets.php" method="get">
<input type="hidden" name="a" value="search">
<table>
<tr>
<td>Query: </td><td><input type="text" id="query" name="query" value="<?php echo Format::htmlchars($_REQUEST['query']); ?>"></td>
<td>Dept:</td>
<td><select name="dept"><option value=0>All Departments</option>
<?php
//Showing only departments the user has access to...
$sql='SELECT dept_id,dept_name FROM '.DEPT_TABLE;
if(!$thisstaff->isadmin())
$sql.=' WHERE dept_id IN ('.implode(',',$thisstaff->getDepts()).')';
$depts= db_query($sql);
while (list($deptId,$deptName) = db_fetch_row($depts)){
$selected = ($_GET['dept']==$deptId)?'selected':''; ?>
<option value="<?php echo $deptId; ?>"<?php echo $selected; ?>><?php echo $deptName; ?></option>
<?php
} ?>
</select>
</td>
<td>Status is:</td><td>
<select name="status">
<option value='any' selected >Any status</option>
<option value="open" <?php echo !strcasecmp($_REQUEST['status'],'Open')?'selected':''; ?>>Open</option>
<option value="overdue" <?php echo !strcasecmp($_REQUEST['status'],'overdue')?'selected':''; ?>>Overdue</option>
<option value="closed" <?php echo !strcasecmp($_REQUEST['status'],'Closed')?'selected':''; ?>>Closed</option>
</select>
</td>
</tr>
</table>
<div>
Date Span:
&nbsp;From&nbsp;<input id="sd" name="startDate" value="<?php echo Format::htmlchars($_REQUEST['startDate']); ?>"
onclick="event.cancelBubble=true;calendar(this);" autocomplete=OFF>
<a href="#" onclick="event.cancelBubble=true;calendar(getObj('sd')); return false;"><img src='images/cal.png'border=0 alt=""></a>
&nbsp;&nbsp; to &nbsp;&nbsp;
<input id="ed" name="endDate" value="<?php echo Format::htmlchars($_REQUEST['endDate']); ?>"
onclick="event.cancelBubble=true;calendar(this);" autocomplete=OFF >
<a href="#" onclick="event.cancelBubble=true;calendar(getObj('ed')); return false;"><img src='images/cal.png'border=0 alt=""></a>
&nbsp;&nbsp;
</div>
<table>
<tr>
<td>Type:</td>
<td>
<select name="stype">
<option value="LIKE" <?php echo (!$_REQUEST['stype'] || $_REQUEST['stype'] == 'LIKE') ?'selected':''; ?>>Scan (%)</option>
<option value="FT"<?php echo $_REQUEST['stype'] == 'FT'?'selected':''; ?>>Fulltext</option>
</select>
</td>
<td>Sort by:</td><td>
<?php
$sort=$_GET['sort']?$_GET['sort']:'date';
?>
<select name="sort">
<option value="ID" <?php echo $sort== 'ID' ?'selected':''; ?>>Ticket #</option>
<option value="pri" <?php echo $sort == 'pri' ?'selected':''; ?>>Priority</option>
<option value="date" <?php echo $sort == 'date' ?'selected':''; ?>>Date</option>
<option value="dept" <?php echo $sort == 'dept' ?'selected':''; ?>>Dept.</option>
</select>
<select name="order">
<option value="DESC"<?php echo $_REQUEST['order'] == 'DESC' ?'selected':''; ?>>Descending</option>
<option value="ASC"<?php echo $_REQUEST['order'] == 'ASC'?'selected':''; ?>>Ascending</option>
</select>
</td>
<td>Results Per Page:</td><td>
<select name="limit">
<?php
$sel=$_REQUEST['limit']?$_REQUEST['limit']:15;
for ($x = 5; $x <= 25; $x += 5) { ?>
<option value="<?php echo $x; ?>" <?php echo ($sel==$x )?'selected':''; ?>><?php echo $x; ?></option>
<?php } ?>
</select>
</td>
<td>
<input type="submit" name="advance_search" class="button" value="Search">
&nbsp;[ <a href="#" onClick="showHide('advance','basic'); return false;" >Basic</a> ]
</td>
</tr>
</table>
</form>
</div>
<!-- SEARCH FORM END --> <!-- SEARCH FORM END -->
<div class="clear"></div> <div class="clear"></div>
<div style="margin-bottom:20px"> <div style="margin-bottom:20px">
......
...@@ -30,27 +30,28 @@ ini_set('display_startup_errors','0'); ...@@ -30,27 +30,28 @@ ini_set('display_startup_errors','0');
//TODO: disable direct access via the browser? i,e All request must have REFER? //TODO: disable direct access via the browser? i,e All request must have REFER?
if(!defined('INCLUDE_DIR')) Http::response(500,'config error'); if(!defined('INCLUDE_DIR')) Http::response(500,'config error');
require_once INCLUDE_DIR."/class.dispatcher.php"; require_once INCLUDE_DIR.'/class.dispatcher.php';
require_once INCLUDE_DIR."/class.ajax.php"; require_once INCLUDE_DIR.'/class.ajax.php';
$dispatcher = patterns("", $dispatcher = patterns('',
url("^/kb/", patterns("ajax.kbase.php:KbaseAjaxAPI", url('^/kb/', patterns('ajax.kbase.php:KbaseAjaxAPI',
# Send ticket-id as a query arg => canned-response/33?ticket=83 # Send ticket-id as a query arg => canned-response/33?ticket=83
url_get("^canned-response/(?P<id>\d+).(?P<format>json|txt)", "cannedResp"), url_get('^canned-response/(?P<id>\d+).(?P<format>json|txt)', 'cannedResp'),
url_get("^faq/(?P<id>\d+)","faq") url_get('^faq/(?P<id>\d+)', 'faq')
)), )),
url("^/content/", patterns("ajax.content.php:ContentAjaxAPI", url('^/content/', patterns('ajax.content.php:ContentAjaxAPI',
url_get("^log/(?P<id>\d+)", 'log'), url_get('^log/(?P<id>\d+)', 'log'),
url_get("^ticket_variables",'ticket_variables') url_get('^ticket_variables', 'ticket_variables')
)), )),
url("^/config/", patterns("ajax.config.php:ConfigAjaxAPI", url('^/config/', patterns('ajax.config.php:ConfigAjaxAPI',
url_get("^ui",'ui') url_get('^ui', 'ui')
)), )),
url_get("^/tickets$", array("ajax.tickets.php:TicketsAjaxAPI", "search")), url_get('^/users$', array('ajax.users.php:UsersAjaxAPI', 'search')),
url("^/ticket/", patterns("ajax.tickets.php:TicketsAjaxAPI", url_get('^/tickets$', array('ajax.tickets.php:TicketsAjaxAPI', 'search')),
url_get("^(?P<tid>\d+)/preview", "previewTicket"), url('^/ticket/', patterns('ajax.tickets.php:TicketsAjaxAPI',
url_get("^(?P<tid>\d+)/lock", "acquireLock"), url_get('^(?P<tid>\d+)/preview', 'previewTicket'),
url_post("^(?P<tid>\d+)/lock/(?P<id>\d+)/renew", "renewLock"), url_get('^(?P<tid>\d+)/lock', 'acquireLock'),
url_post("^(?P<tid>\d+)/lock/(?P<id>\d+)/release", "releaseLock") url_post('^(?P<tid>\d+)/lock/(?P<id>\d+)/renew', 'renewLock'),
url_post('^(?P<tid>\d+)/lock/(?P<id>\d+)/release', 'releaseLock')
)) ))
); );
......
...@@ -82,7 +82,6 @@ ...@@ -82,7 +82,6 @@
, value , value
this.query = this.$element.val(); this.query = this.$element.val();
/*Check if we have a match on the current source?? */ /*Check if we have a match on the current source?? */
if (typeof this.source == "function") { if (typeof this.source == "function") {
value = this.source(this, this.query) value = this.source(this, this.query)
...@@ -157,8 +156,12 @@ ...@@ -157,8 +156,12 @@
items = $(items).map(function (i, item) { items = $(items).map(function (i, item) {
i = $(that.options.item).attr('data-value', JSON.stringify(item)) i = $(that.options.item).attr('data-value', JSON.stringify(item))
if (!that.strings) if (!that.strings) {
item = item[that.options.property] if(item[that.options.render])
item = item[that.options.render];
else
item = item[that.options.property];
}
i.find('a').html(that.highlighter(item)) i.find('a').html(that.highlighter(item))
return i[0] return i[0]
}) })
...@@ -294,6 +297,7 @@ ...@@ -294,6 +297,7 @@
, item: '<li><a href="#"></a></li>' , item: '<li><a href="#"></a></li>'
, onselect: null , onselect: null
, property: 'value' , property: 'value'
, render: 'info'
} }
$.fn.typeahead.Constructor = Typeahead $.fn.typeahead.Constructor = Typeahead
......
...@@ -199,7 +199,7 @@ $(document).ready(function(){ ...@@ -199,7 +199,7 @@ $(document).ready(function(){
} }
/* Typeahead init */ /* Typeahead init */
$('#ticket-search').typeahead({ $('#basic-ticket-search').typeahead({
source: function (typeahead, query) { source: function (typeahead, query) {
$.ajax({ $.ajax({
url: "ajax.php/tickets?q="+query, url: "ajax.php/tickets?q="+query,
...@@ -210,9 +210,31 @@ $(document).ready(function(){ ...@@ -210,9 +210,31 @@ $(document).ready(function(){
}); });
}, },
onselect: function (obj) { onselect: function (obj) {
$('#ticket-search').closest('form').submit(); $('#basic-ticket-search').val(obj.id); /*overwriting email*/
$('#basic-ticket-search').closest('form').submit();
}, },
property: "value" property: "value"
}); });
$('#email.typeahead').typeahead({
source: function (typeahead, query) {
if(query.length > 2) {
$.ajax({
url: "ajax.php/users?q="+query,
dataType: 'json',
success: function (data) {
typeahead.process(data);
}
});
}
},
onselect: function (obj) {
var fObj=$('#email.typeahead').closest('form');
if(obj.name)
$('#name', fObj).val(obj.name);
},
property: "email"
});
}); });
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