From 2385efa61a67f5ad7189751f31a5f35d8b0e69c6 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Thu, 29 Mar 2012 22:25:03 -0400
Subject: [PATCH] Add user search - typeahead

---
 include/ajax.users.php            |  2 +-
 include/staff/ticket-open.inc.php |  9 +++++----
 scp/js/scp.js                     | 26 ++++++++++++++++++++++++--
 3 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/include/ajax.users.php b/include/ajax.users.php
index 11b765923..01a0cdbf4 100644
--- a/include/ajax.users.php
+++ b/include/ajax.users.php
@@ -43,7 +43,7 @@ class UsersAjaxAPI extends AjaxController {
             }                    
         }  
         
-        return $this->encode($users);
+        return $this->json_encode($users);
 
     }
 }
diff --git a/include/staff/ticket-open.inc.php b/include/staff/ticket-open.inc.php
index a858c5708..d15eb6170 100644
--- a/include/staff/ticket-open.inc.php
+++ b/include/staff/ticket-open.inc.php
@@ -22,7 +22,8 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
                 Email Address:
             </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>
             <?php 
             if($cfg->notifyONNewStaffTicket()) { ?>
@@ -37,7 +38,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
                 Full Name:
             </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>
             </td>
         </tr>
@@ -46,9 +47,9 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
                 Phone Number:
             </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>
-                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>
             </td>
         </tr>
diff --git a/scp/js/scp.js b/scp/js/scp.js
index f993a5a46..08da6525e 100644
--- a/scp/js/scp.js
+++ b/scp/js/scp.js
@@ -199,7 +199,7 @@ $(document).ready(function(){
     }
 
     /* Typeahead init */
-    $('#ticket-search').typeahead({
+    $('#basic-ticket-search').typeahead({
         source: function (typeahead, query) {
             $.ajax({
                 url: "ajax.php/tickets?q="+query,
@@ -210,9 +210,31 @@ $(document).ready(function(){
             });
         },
         onselect: function (obj) {
-            $('#ticket-search').closest('form').submit();
+            $('#basic-ticket-search').val(obj.id); /*overwriting email*/
+            $('#basic-ticket-search').closest('form').submit();
         },
         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"
+    });
+
+
 });
-- 
GitLab