From 997e484cd0aa050ff0ab5ff92abed56175b3e4fb Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@enhancesoft.com>
Date: Tue, 17 Dec 2013 04:05:02 +0000
Subject: [PATCH] Update collaborators count on update

---
 include/ajax.tickets.php                      | 10 +++----
 .../staff/templates/collaborators.tmpl.php    |  2 +-
 include/staff/ticket-view.inc.php             | 26 +++++++++----------
 scp/js/ticket.js                              |  1 +
 4 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php
index bee2c7d6c..cbb954be4 100644
--- a/include/ajax.tickets.php
+++ b/include/ajax.tickets.php
@@ -554,12 +554,12 @@ class TicketsAjaxAPI extends AjaxController {
                 || !$ticket->checkStaffAccess($thisstaff))
             Http::response(404, 'No such ticket');
 
-       $errors = $info = array();
-        if ($ticket->updateCollaborators($_POST, $errors)) {
-            $info +=array('msg' => 'Collaborators updated successfully');
-        } elseif($errors && $errors['err']) {
+        $errors = $info = array();
+        if ($ticket->updateCollaborators($_POST, $errors))
+            Http::response(201, sprintf('Recipients (%d)', $ticket->getNumCollaborators()));
+
+        if($errors && $errors['err'])
             $info +=array('error' => $errors['err']);
-        }
 
         return self::_collaborators($ticket, $info);
     }
diff --git a/include/staff/templates/collaborators.tmpl.php b/include/staff/templates/collaborators.tmpl.php
index a10bf0c10..3136cc96d 100644
--- a/include/staff/templates/collaborators.tmpl.php
+++ b/include/staff/templates/collaborators.tmpl.php
@@ -40,8 +40,8 @@ if(($users=$ticket->getCollaborators())) {?>
     <div id="savewarning" style="display:none; padding-top:2px;"><p id="msg_warning">You have made changes that you need to save.</p></div>
     <p class="full-width">
         <span class="buttons" style="float:left">
+            <input type="button" value="Cancel" class="close">
             <input type="reset" value="Reset">
-            <input type="button" value="Done" class="close">
         </span>
         <span class="buttons" style="float:right">
             <input type="submit" value="Save Changes">
diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php
index 213c2f4fb..d541caa35 100644
--- a/include/staff/ticket-view.inc.php
+++ b/include/staff/ticket-view.inc.php
@@ -439,11 +439,11 @@ $tcount+= $ticket->getNumNotes();
             <?php
             if(1) { //Make CC optional feature? NO, for now.
                 ?>
-            <tbody id="cc_sec" style="display:<?php echo $emailReply?
-            'table-row-group':'none'; ?>;">
-            <tr>
+            <tbody id="cc_sec"
+                style="display:<?php echo $emailReply?  'table-row-group':'none'; ?>;">
+             <tr>
                 <td width="120">
-                    <label><strong>Recipients:</strong></label>
+                    <label><strong>Collaborators:</strong></label>
                 </td>
                 <td>
                     <?php
@@ -451,18 +451,18 @@ $tcount+= $ticket->getNumNotes();
                         <input type='checkbox' value='1' name="emailcollab" id="emailcollab"
                             <?php echo ((!$info['emailcollab'] && !$errors) || isset($info['emailcollab']))?'checked="checked"':''; ?>>
                        <?php
-                        echo sprintf('<a class="collaborators"
-                                href="#tickets/%d/collaborators/manage">Collaborators (%d)</a>',
-                                $ticket->getId(),
-                                $ticket->getNumCollaborators());
-                    } else {
-                        echo sprintf('<div><a class="collaborators"
-                                href="#tickets/%d/collaborators/manage" >Add Collaborators</a></div>',
-                                $ticket->getId());
                     }
+                    $recipients = 'Add Recipients';
+                    if ($ticket->getNumCollaborators())
+                        $recipients = sprintf('Recipients (%d)', $ticket->getNumCollaborators());
+
+                    echo sprintf('<span><a class="collaborators"
+                            href="#tickets/%d/collaborators/manage"><span id="recipients">%s</span></a></span>',
+                            $ticket->getId(),
+                            $recipients);
                    ?>
                 </td>
-            </tr>
+             </tr>
             </tbody>
             <?php
             } ?>
diff --git a/scp/js/ticket.js b/scp/js/ticket.js
index c91cacaa9..cbe25c1e3 100644
--- a/scp/js/ticket.js
+++ b/scp/js/ticket.js
@@ -368,6 +368,7 @@ jQuery(function($) {
         e.preventDefault();
         var url = 'ajax.php/'+$(this).attr('href').substr(1);
         $.dialog(url, 201, function (resp) {
+           $('#recipients').text(resp);
             });
         return false;
      });
-- 
GitLab