From 6a7bcfa975140627b1a4cd6e459fc05fcc0590c1 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Wed, 14 Oct 2015 10:23:10 +0000
Subject: [PATCH] Make ticket related action buttons icon-based

Implement auto focus and scroll when post reply or note action button is
clicked as well as tab highlight on error
Unpack tickets' mass action buttons - more options retired for now
Translate missed phases
---
 .../staff/templates/status-options.tmpl.php   |   2 +-
 .../staff/templates/tickets-actions.tmpl.php  | 103 ++++++++----------
 include/staff/ticket-view.inc.php             | 102 ++++++++++++-----
 scp/css/scp.css                               |   9 +-
 scp/js/thread.js                              |   8 --
 5 files changed, 122 insertions(+), 102 deletions(-)

diff --git a/include/staff/templates/status-options.tmpl.php b/include/staff/templates/status-options.tmpl.php
index 30adcd8ec..3b493f379 100644
--- a/include/staff/templates/status-options.tmpl.php
+++ b/include/staff/templates/status-options.tmpl.php
@@ -33,7 +33,7 @@ if (!$nextStatuses)
 ?>
 
 <span
-    class="action-button pull-right"
+    class="action-button"
     data-dropdown="#action-dropdown-statuses" data-placement="bottom" data-toggle="tooltip" title="<?php echo __('Change Status'); ?>">
     <i class="icon-caret-down pull-right"></i>
     <a class="tickets-action"
diff --git a/include/staff/templates/tickets-actions.tmpl.php b/include/staff/templates/tickets-actions.tmpl.php
index cdc741db9..d52eca94e 100644
--- a/include/staff/templates/tickets-actions.tmpl.php
+++ b/include/staff/templates/tickets-actions.tmpl.php
@@ -1,72 +1,59 @@
 <?php
 // Tickets mass actions based on logged in agent
 
+// Status change
 if ($agent->canManageTickets())
     echo TicketStatus::status_options();
 
-$actions = array();
-if ($agent->hasPerm(Ticket::PERM_ASSIGN, false)) {
-    $actions += array(
-            'assign' => array(
-                'icon' => 'icon-user',
-                'action' => __('Assign')
-            ));
+
+// Mass Claim/Assignment
+if ($agent->hasPerm(Ticket::PERM_ASSIGN, false)) {?>
+<span
+    class="action-button" data-placement="bottom"
+    data-dropdown="#action-dropdown-assign" data-toggle="tooltip" title=" <?php
+    echo __('Assign'); ?>">
+    <i class="icon-caret-down pull-right"></i>
+    <a class="tickets-action" id="tickets-assign"
+        href="#tickets/mass/assign"><i class="icon-user"></i></a>
+</span>
+<div id="action-dropdown-assign" class="action-dropdown anchor-right">
+  <ul>
+     <li><a class="no-pjax tickets-action"
+        href="#tickets/mass/assign/<?php echo $agent->getId(); ?>"><i
+        class="icon-chevron-sign-down"></i> <?php echo __('Claim'); ?></a>
+     <li><a class="no-pjax tickets-action"
+        href="#tickets/mass/assign/agents"><i
+        class="icon-user"></i> <?php echo __('Agent'); ?></a>
+     <li><a class="no-pjax tickets-action"
+        href="#tickets/mass/assign/teams"><i
+        class="icon-group"></i> <?php echo __('Team'); ?></a>
+  </ul>
+</div>
+<?php
 }
 
-if ($agent->hasPerm(Ticket::PERM_TRANSFER, false)) {
-    $actions += array(
-            'transfer' => array(
-                'icon' => 'icon-share',
-                'action' => __('Transfer')
-            ));
+// Mass Transfer
+if ($agent->hasPerm(Ticket::PERM_TRANSFER, false)) {?>
+<span class="action-button">
+ <a class="tickets-action" id="tickets-transfer" data-placement="bottom"
+    data-toggle="tooltip" title="<?php echo __('Transfer'); ?>"
+    href="#tickets/mass/transfer"><i class="icon-share"></i></a>
+</span>
+<?php
 }
 
-if ($agent->hasPerm(Ticket::PERM_DELETE, false)) {
-    $actions += array(
-            'delete' => array(
-                'class' => 'danger',
-                'icon' => 'icon-trash',
-                'action' => __('Delete')
-            ));
+
+// Mass Delete
+if ($agent->hasPerm(Ticket::PERM_DELETE, false)) {?>
+<span class="red button action-button">
+ <a class="tickets-action" id="tickets-delete" data-placement="bottom"
+    data-toggle="tooltip" title="<?php echo __('Delete'); ?>"
+    href="#tickets/mass/delete"><i class="icon-trash"></i></a>
+</span>
+<?php
 }
-if ($actions) {
-    $more = $options['morelabel'] ?: __('More');
-    ?>
-    <span
-        class="action-button"
-        data-dropdown="#action-dropdown-moreoptions">
-        <i class="icon-caret-down pull-right"></i>
-        <a class="tickets-action"
-            href="#moreoptions"><i
-            class="icon-reorder"></i> <?php
-            echo $more; ?></a>
-    </span>
-    <div id="action-dropdown-moreoptions"
-        class="action-dropdown anchor-right">
-        <ul>
-    <?php foreach ($actions as $a => $action) { ?>
-            <li <?php
-                if ($action['class'])
-                    echo sprintf("class='%s'", $action['class']); ?> >
-                <a class="no-pjax tickets-action"
-                    <?php
-                    if ($action['dialog'])
-                        echo sprintf("data-dialog-config='%s'", $action['dialog']);
-                    if ($action['redirect'])
-                        echo sprintf("data-redirect='%s'", $action['redirect']);
-                    ?>
-                    href="<?php
-                    echo sprintf('#tickets/mass/%s', $a); ?>"
-                    ><i class="icon-fixed-width <?php
-                    echo $action['icon'] ?: 'icon-tag'; ?>"></i> <?php
-                    echo $action['action']; ?></a>
-            </li>
-        <?php
-        } ?>
-        </ul>
-    </div>
- <?php
- } ?>
+
+?>
 <script type="text/javascript">
 $(function() {
     $(document).off('.tickets-actions');
diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php
index 481017f5a..1247affae 100644
--- a/include/staff/ticket-view.inc.php
+++ b/include/staff/ticket-view.inc.php
@@ -71,6 +71,18 @@ if($ticket->isOverdue())
                 <span class="action-button pull-right"><a data-placement="bottom" data-toggle="tooltip" title="<?php echo __('Edit'); ?>" href="tickets.php?id=<?php echo $ticket->getId(); ?>&a=edit"><i class="icon-edit"></i></a></span>
             <?php
             } ?>
+            <span class="action-button pull-right" data-placement="bottom" data-dropdown="#action-dropdown-print" data-toggle="tooltip" title="<?php echo __('Print'); ?>">
+                <i class="icon-caret-down pull-right"></i>
+                <a id="ticket-print" href="tickets.php?id=<?php echo $ticket->getId(); ?>&a=print"><i class="icon-print"></i></a>
+            </span>
+            <div id="action-dropdown-print" class="action-dropdown anchor-right">
+              <ul>
+                 <li><a class="no-pjax" target="_blank" href="tickets.php?id=<?php echo $ticket->getId(); ?>&a=print&notes=0"><i
+                 class="icon-file-alt"></i> <?php echo __('Ticket Thread'); ?></a>
+                 <li><a class="no-pjax" target="_blank" href="tickets.php?id=<?php echo $ticket->getId(); ?>&a=print&notes=1"><i
+                 class="icon-file-text-alt"></i> <?php echo __('Thread + Internal Notes'); ?></a>
+              </ul>
+            </div>
             <?php
             // Transfer
             if ($role->hasPerm(TicketModel::PERM_TRANSFER)) {?>
@@ -89,7 +101,7 @@ if($ticket->isOverdue())
                 data-dropdown="#action-dropdown-assign"
                 data-placement="bottom"
                 data-toggle="tooltip"
-                title=" <?php echo $ticket->isAssigned() ? _↪_('Assign') : __('Reassign'); ?>"
+                title=" <?php echo $ticket->isAssigned() ? __('Assign') : __('Reassign'); ?>"
                 >
                 <i class="icon-caret-down pull-right"></i>
                 <a class="ticket-action" id="ticket-assign"
@@ -119,18 +131,6 @@ if($ticket->isOverdue())
             </div>
             <?php
             } ?>
-            <span class="action-button pull-right" data-placement="bottom" data-dropdown="#action-dropdown-print" data-toggle="tooltip" title="<?php echo __('Print'); ?>">
-                <i class="icon-caret-down pull-right"></i>
-                <a id="ticket-print" href="tickets.php?id=<?php echo $ticket->getId(); ?>&a=print"><i class="icon-print"></i></a>
-            </span>
-            <div id="action-dropdown-print" class="action-dropdown anchor-right">
-              <ul>
-                 <li><a class="no-pjax" target="_blank" href="tickets.php?id=<?php echo $ticket->getId(); ?>&a=print&notes=0"><i
-                 class="icon-file-alt"></i> <?php echo __('Ticket Thread'); ?></a>
-                 <li><a class="no-pjax" target="_blank" href="tickets.php?id=<?php echo $ticket->getId(); ?>&a=print&notes=1"><i
-                 class="icon-file-text-alt"></i> <?php echo __('Thread + Internal Notes'); ?></a>
-              </ul>
-            </div>
             <div id="action-dropdown-more" class="action-dropdown anchor-right">
               <ul>
                 <?php
@@ -197,11 +197,19 @@ if($ticket->isOverdue())
                 ?>
               </ul>
             </div>
-            <?php
-            // Status change options
-            echo TicketStatus::status_options(); ?>
-                <a href="#" class="post-note ticket-response action-button pull-right" data-placement="bottom" data-toggle="tooltip" title="Internal Note"><i class="icon-file-text"></i></a>
-                <a href="#" class="post-reply ticket-response action-button pull-right" data-placement="bottom" data-toggle="tooltip" title="Post Reply"><i class="icon-mail-reply"></i></a>
+                <?php
+                if ($role->hasPerm(TicketModel::PERM_REPLY)) { ?>
+                <a href="#post-reply" class="post-response action-button"
+                data-placement="bottom" data-toggle="tooltip"
+                title="<?php echo __('Post Reply'); ?>"><i class="icon-mail-reply"></i></a>
+                <?php
+                } ?>
+                <a href="#post-note" id="post-note" class="post-response action-button"
+                data-placement="bottom" data-toggle="tooltip"
+                title="<?php echo __('Post Internal Note'); ?>"><i class="icon-file-text"></i></a>
+                <?php // Status change options
+                echo TicketStatus::status_options();
+                ?>
            </div>
         <div class="flush-left">
              <h2><a href="tickets.php?id=<?php echo $ticket->getId(); ?>"
@@ -467,7 +475,8 @@ echo $v;
 $tcount = $ticket->getThreadEntries($types)->count();
 ?>
 <ul  class="tabs clean threads" id="ticket_tabs" >
-    <li class="active"><a href="#ticket_thread"><?php echo sprintf(__('Ticket Thread (%d)'), $tcount); ?></a></li>
+    <li class="active"><a id="ticket-thread-tab" href="#ticket_thread"><?php
+        echo sprintf(__('Ticket Thread (%d)'), $tcount); ?></a></li>
     <li><a id="ticket-tasks-tab" href="#tasks"
             data-url="<?php
         echo sprintf('#tickets/%d/tasks', $ticket->getId()); ?>"><?php
@@ -490,23 +499,31 @@ $tcount = $ticket->getThreadEntries($types)->count();
             );
 ?>
 <div class="clear"></div>
-<?php if($errors['err']) { ?>
-    <div id="msg_error"><?php echo $errors['err']; ?></div>
-<?php }elseif($msg) { ?>
+<?php
+if ($errors['err'] && isset($_POST['a'])) {
+    // Reflect errors back to the tab.
+    $errors[$_POST['a']] = $errors['err'];
+} elseif($msg) { ?>
     <div id="msg_notice"><?php echo $msg; ?></div>
-<?php }elseif($warn) { ?>
+<?php
+} elseif($warn) { ?>
     <div id="msg_warning"><?php echo $warn; ?></div>
-<?php } ?>
+<?php
+} ?>
 
 <div class="sticky bar stop actions" id="response_options"
 >
-    <ul class="tabs">
+    <ul class="tabs" id="response-tabs">
         <?php
         if ($role->hasPerm(TicketModel::PERM_REPLY)) { ?>
-        <li class="active"><a href="#reply"><?php echo __('Post Reply');?></a></li>
+        <li class="active <?php
+            echo isset($errors['reply']) ? 'error' : ''; ?>"><a
+            href="#reply" id="post-reply-tab"><?php echo __('Post Reply');?></a></li>
         <?php
         } ?>
-        <li><a href="#note"><?php echo __('Post Internal Note');?></a></li>
+        <li><a href="#note" <?php
+            echo isset($errors['postnote']) ?  'class="error"' : ''; ?>
+            id="post-note-tab"><?php echo __('Post Internal Note');?></a></li>
     </ul>
     <?php
     if ($role->hasPerm(TicketModel::PERM_REPLY)) { ?>
@@ -520,8 +537,12 @@ $tcount = $ticket->getThreadEntries($types)->count();
         <input type="hidden" name="msgId" value="<?php echo $msgId; ?>">
         <input type="hidden" name="a" value="reply">
         <input type="hidden" name="lockCode" value="<?php echo $mylock ? $mylock->getCode() : ''; ?>">
-        <span class="error"></span>
         <table style="width:100%" border="0" cellspacing="0" cellpadding="3">
+            <?php
+            if ($errors['reply']) {?>
+            <tr><td width="120">&nbsp;</td><td class="error"><?php echo $errors['reply']; ?>&nbsp;</td></tr>
+            <?php
+            }?>
            <tbody id="to_sec">
             <tr>
                 <td width="120">
@@ -908,5 +929,30 @@ $(function() {
             }
         });
     });
+
+    // Post Reply or Note action buttons.
+    $('a.post-response').click(function (e) {
+        var $r = $('ul.tabs > li > a'+$(this).attr('href')+'-tab');
+        if ($r.length) {
+            // Make sure ticket thread tab is visiable.
+            var $t = $('ul#ticket_tabs > li > a#ticket-thread-tab');
+            if ($t.length && !$t.hasClass('active'))
+                $t.trigger('click');
+            // Make the target response tab active.
+            if (!$r.hasClass('active'))
+                $r.trigger('click');
+
+            // Scroll to the response section.
+            var $stop = $(document).height();
+            var $s = $('div#response_options');
+            if ($s.length)
+                $stop = $s.offset().top-125
+
+            $('html, body').animate({scrollTop: $stop}, 'fast');
+        }
+
+        return false;
+    });
+
 });
 </script>
diff --git a/scp/css/scp.css b/scp/css/scp.css
index 71b494360..73c0e0029 100644
--- a/scp/css/scp.css
+++ b/scp/css/scp.css
@@ -905,16 +905,11 @@ h2 .reload {
     margin:0;
 }
 /***** top page ticket response buttons *****/
-a.post-reply {
-    color:#555!IMPORTANT;
-}
-a.post-note {
+a#post-note:hover {
     background-color:#fff9e2;
     color:#555!IMPORTANT;
 }
-a.post-note:hover {
-    color:#555!IMPORTANT;
-}
+
 .thread-entry {
     margin-bottom: 15px;
     z-index: 0;
diff --git a/scp/js/thread.js b/scp/js/thread.js
index 0a9fe075f..0b4ebe502 100644
--- a/scp/js/thread.js
+++ b/scp/js/thread.js
@@ -166,14 +166,6 @@ var thread = {
         // Open first response option tab if not already active
         if (!document.location.hash)
             $('.actions .tabs li:visible:first:not(.active) a', $container.parent()).trigger('click');
-        
-        //Reply and Internal Note buttons scroll to bottom and changes tabs.
-        $('.ticket-response').click(function () {
-            $('html, body').animate({
-                scrollTop: $(document).height()
-            }, 'slow');
-            return false;
-        });
     }
 };
 
-- 
GitLab