From 4010b27a5fd90ac08c9603636e6d65113c5ded51 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Tue, 29 Apr 2014 13:02:50 +0000
Subject: [PATCH] Add user preview tool tip

---
 include/ajax.users.php                 | 23 +++++++++++++++++++++++
 include/staff/templates/user.tmpl.php  | 12 ++++++++----
 include/staff/templates/users.tmpl.php |  2 +-
 include/staff/users.inc.php            |  2 +-
 scp/ajax.php                           |  1 +
 scp/css/scp.css                        | 22 ++++++++++++++++++++--
 scp/js/scp.js                          |  4 ++--
 scp/js/tips.js                         | 26 ++++++++++++++++++++++++++
 8 files changed, 82 insertions(+), 10 deletions(-)

diff --git a/include/ajax.users.php b/include/ajax.users.php
index 43a7864b0..a523695e5 100644
--- a/include/ajax.users.php
+++ b/include/ajax.users.php
@@ -79,6 +79,29 @@ class UsersAjaxAPI extends AjaxController {
 
     }
 
+    function preview($id) {
+        global $thisstaff;
+
+        if(!$thisstaff)
+            Http::response(403, 'Login Required');
+        elseif(!($user = User::lookup($id)))
+            Http::response(404, 'Unknown user');
+
+        $info = array('title' => '');
+
+        ob_start();
+        echo sprintf('<div style="width:650px; padding: 2px 2px 0 5px;"
+                id="u%d">', $user->getId());
+        include(STAFFINC_DIR . 'templates/user.tmpl.php');
+        echo '</div>';
+        $resp = ob_get_contents();
+        ob_end_clean();
+
+        return $resp;
+
+    }
+
+
     function editUser($id) {
         global $thisstaff;
 
diff --git a/include/staff/templates/user.tmpl.php b/include/staff/templates/user.tmpl.php
index 2aabe3ba5..5848055a0 100644
--- a/include/staff/templates/user.tmpl.php
+++ b/include/staff/templates/user.tmpl.php
@@ -1,11 +1,15 @@
 <?php
-if (!$info['title'])
+if (!isset($info['title']))
     $info['title'] = Format::htmlchars($user->getName());
-?>
+
+if ($info['title']) { ?>
 <h3><?php echo $info['title']; ?></h3>
 <b><a class="close" href="#"><i class="icon-remove-circle"></i></a></b>
-<hr/>
+<hr>
 <?php
+} else {
+    echo '<div class="clear"></div>';
+}
 if ($info['error']) {
     echo sprintf('<p id="msg_error">%s</p>', $info['error']);
 } elseif ($info['msg']) {
@@ -49,7 +53,7 @@ if ($info['error']) {
     <a href="users.php?id=<?php echo $user->getId(); ?>" title="Manage User"
         class="action"><i class="icon-share"></i></a>
 </div>
-    <table class="custom-info">
+    <table class="custom-info" width="100%">
 <?php foreach ($user->getDynamicData() as $entry) {
 ?>
     <tr><th colspan="2"><strong><?php
diff --git a/include/staff/templates/users.tmpl.php b/include/staff/templates/users.tmpl.php
index 11e094d28..d5beaf2c7 100644
--- a/include/staff/templates/users.tmpl.php
+++ b/include/staff/templates/users.tmpl.php
@@ -91,7 +91,7 @@ if ($num) { ?>
                 ?>
                <tr id="<?php echo $row['id']; ?>">
                 <td>&nbsp;
-                    <a href="users.php?id=<?php echo $row['id']; ?>"><?php echo $name; ?></a>
+                    <a class="userPreview" href="users.php?id=<?php echo $row['id']; ?>"><?php echo $name; ?></a>
                     &nbsp;
                     <?php
                     if ($row['tickets'])
diff --git a/include/staff/users.inc.php b/include/staff/users.inc.php
index b4d64f846..91362ae32 100644
--- a/include/staff/users.inc.php
+++ b/include/staff/users.inc.php
@@ -139,7 +139,7 @@ else
                 ?>
                <tr id="<?php echo $row['id']; ?>">
                 <td>&nbsp;
-                    <a href="users.php?id=<?php echo $row['id']; ?>"><?php echo $name; ?></a>
+                    <a class="userPreview" href="users.php?id=<?php echo $row['id']; ?>"><?php echo $name; ?></a>
                     &nbsp;
                     <?php
                     if ($row['tickets'])
diff --git a/scp/ajax.php b/scp/ajax.php
index 75a3c4ac6..ff6703a5a 100644
--- a/scp/ajax.php
+++ b/scp/ajax.php
@@ -73,6 +73,7 @@ $dispatcher = patterns('',
         url_get('^/remote$', 'search', array('remote')),
         url_get('^/(?P<id>\d+)$', 'getUser'),
         url_post('^/(?P<id>\d+)$', 'updateUser'),
+        url_get('^/(?P<id>\d+)/preview$', 'preview'),
         url_get('^/(?P<id>\d+)/edit$', 'editUser'),
         url('^/lookup$', 'getUser'),
         url_get('^/lookup/form$', 'getLookupForm'),
diff --git a/scp/css/scp.css b/scp/css/scp.css
index 416ee3850..e51a3b970 100644
--- a/scp/css/scp.css
+++ b/scp/css/scp.css
@@ -8,10 +8,25 @@ body {
 }
 
 a {
-    color:#E65524;
+    color:#184E81;
     text-decoration:none;
 }
 
+a:hover {
+    text-decoration: underline;
+}
+
+#nav a:hover,
+#sub_nav a:hover,
+a:hover i[class^="icon-"],
+.tabs a {
+    text-decoration: none;
+}
+
+div#header a {
+    color:#E65524;
+}
+
 .form_table a:hover {
     text-decoration: underline;
 }
@@ -1444,11 +1459,14 @@ time {
 }
 
 /* Dynamic forms in dialogs */
+.dialog th, .tip_box th {
+    text-align: left;
+}
+
 .dialog th {
     background-color: #eee;
     border: 1px dotted #bbb;
     padding: 0.3em;
-    text-align: left;
     padding-left: 0.3em;
 }
 
diff --git a/scp/js/scp.js b/scp/js/scp.js
index 40e77866d..219c1eb08 100644
--- a/scp/js/scp.js
+++ b/scp/js/scp.js
@@ -672,7 +672,7 @@ $('.quicknote .action.edit-note').live('click.note', function() {
     var note = $(this).closest('.quicknote'),
         body = note.find('.body'),
         T = $('<textarea>').text(body.html());
-    if (note.closest('.dialog').length)
+    if (note.closest('.dialog, .tip_box').length)
         T.addClass('no-bar small');
     body.replaceWith(T);
     $.redact(T);
@@ -742,7 +742,7 @@ $('#new-note').live('click', function() {
         'html'
       );
     });
-    if (note.closest('.dialog').length)
+    if (note.closest('.dialog, .tip_box').length)
         T.addClass('no-bar small');
     note.replaceWith(T);
     $('<p>').addClass('submit').css('text-align', 'center')
diff --git a/scp/js/tips.js b/scp/js/tips.js
index db5a1aaf5..a1b7f88d5 100644
--- a/scp/js/tips.js
+++ b/scp/js/tips.js
@@ -214,6 +214,32 @@ jQuery(function() {
         clearTimeout($(this).data('timer'));
     });
 
+    //User preview
+    $('.userPreview').live('mouseover', function(e) {
+        e.preventDefault();
+        var elem = $(this);
+
+        var vars = elem.attr('href').split('=');
+        var url = 'ajax.php/users/'+vars[1]+'/preview';
+        var id='u'+vars[1];
+        var xoffset = 80;
+
+        elem.data('timer', 0);
+        if(!elem.data('id')) {
+            elem.data('id', id);
+            if(e.type=='mouseover') {
+                 /* wait about 1 sec - before showing the tip - mouseout kills the timeout*/
+                 elem.data('timer',setTimeout(function() { showtip(url,elem,xoffset);},750))
+            }else{
+                clearTimeout(elem.data('timer'));
+                showtip(url, elem, xoffset);
+            }
+        }
+    }).live('mouseout', function(e) {
+        $(this).data('id', 0);
+        clearTimeout($(this).data('timer'));
+    });
+
     $('body')
     .delegate('.tip_close', 'click', function(e) {
         e.preventDefault();
-- 
GitLab