From 68917edf2b941b1de57d3512ed0becc9d2a3d29c Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Mon, 3 Feb 2014 23:13:31 +0000
Subject: [PATCH] Move collaborator specific javascript to collaborator popup
 window

---
 .../staff/templates/collaborators.tmpl.php    | 54 ++++++++++++++++
 include/staff/ticket-view.inc.php             |  2 +-
 scp/js/scp.js                                 | 13 ++++
 scp/js/ticket.js                              | 63 -------------------
 scp/js/tips.js                                |  2 +-
 5 files changed, 69 insertions(+), 65 deletions(-)

diff --git a/include/staff/templates/collaborators.tmpl.php b/include/staff/templates/collaborators.tmpl.php
index 20e5192ca..2c0de2a2e 100644
--- a/include/staff/templates/collaborators.tmpl.php
+++ b/include/staff/templates/collaborators.tmpl.php
@@ -69,3 +69,57 @@ if ($_POST && $ticket && $ticket->getNumCollaborators()) {
 <?php
 }
 ?>
+
+<script type="text/javascript">
+$(function() {
+
+    $(document).on('click', 'form.collaborators a#addcollaborator', function (e) {
+        e.preventDefault();
+        $('div#manage_collaborators').hide();
+        $('div#add_collaborator').fadeIn();
+        return false;
+     });
+
+    $(document).on('click', 'form.collaborators a.remove', function (e) {
+        e.preventDefault();
+        var fObj = $(this).closest('form');
+        $('input'+$(this).attr('href'))
+            .val($(this).attr('href').substr(2))
+            .trigger('change');
+        $(this).closest('tr').addClass('strike');
+
+        return false;
+     });
+
+    $(document).on('change', 'form.collaborators input:checkbox, input[name="del[]"]', function (e) {
+       var fObj = $(this).closest('form');
+       $('div#savewarning', fObj).fadeIn();
+       $('input:submit', fObj).css('color', 'red');
+     });
+
+    $(document).on('click', 'form.collaborators input:reset', function(e) {
+        var fObj = $(this).closest('form');
+        fObj.find('input[name="del[]"]').val('');
+        fObj.find('tr').removeClass('strike');
+        $('div#savewarning', fObj).hide();
+        $('input:submit', fObj).removeAttr('style');
+    });
+
+    $(document).on('click', 'form.collaborators input.cancel', function (e) {
+        e.preventDefault();
+        var $elem = $(this);
+
+        if($elem.attr('data-href')) {
+            var href = $elem.data('href').substr(1);
+            $('.dialog.collaborators .body').load('ajax.php/'+href, function () {
+                });
+        } else {
+
+            $('div#manage_collaborators').show();
+            $('div#add_collaborator').hide();
+        }
+        return false;
+    });
+
+});
+</script>
diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php
index 4829fd667..7449197a1 100644
--- a/include/staff/ticket-view.inc.php
+++ b/include/staff/ticket-view.inc.php
@@ -459,7 +459,7 @@ $tcount+= $ticket->getNumNotes();
                                 $ticket->getNumActiveCollaborators(),
                                 $ticket->getNumCollaborators());
 
-                    echo sprintf('<span><a class="collaborators" id="manageCollab"
+                    echo sprintf('<span><a class="collaborators preview"
                             href="#tickets/%d/collaborators"><span id="recipients">%s</span></a></span>',
                             $ticket->getId(),
                             $recipients);
diff --git a/scp/js/scp.js b/scp/js/scp.js
index 944ca6a2e..6e2ae6ea8 100644
--- a/scp/js/scp.js
+++ b/scp/js/scp.js
@@ -560,6 +560,19 @@ $(document).ready(function(){
         }
     });
 
+    //Collaborators
+    $(document).on('click', 'a.collaborator, a.collaborators', function(e) {
+        e.preventDefault();
+        var url = 'ajax.php/'+$(this).attr('href').substr(1);
+        $.dialog(url, 201, function (resp) {
+           $('input#emailcollab').show();
+           $('#recipients').text(resp);
+           $('.tip_box').remove();
+        }, {
+            onshow: function() { $('#user-search').focus(); }
+        });
+        return false;
+     });
 });
 
 // NOTE: getConfig should be global
diff --git a/scp/js/ticket.js b/scp/js/ticket.js
index 66d5881dc..aa808746c 100644
--- a/scp/js/ticket.js
+++ b/scp/js/ticket.js
@@ -363,69 +363,6 @@ jQuery(function($) {
         return false;
     });
 
-    //Collaborators
-    $(document).on('click', 'a.collaborator, a.collaborators', function(e) {
-        e.preventDefault();
-        var url = 'ajax.php/'+$(this).attr('href').substr(1);
-        $.dialog(url, 201, function (resp) {
-           $('input#emailcollab').show();
-           $('#recipients').text(resp);
-        }, {
-            onshow: function() { $('#user-search').focus(); }
-        });
-;
-        return false;
-     });
-
-    $(document).on('click', 'form.collaborators a#addcollaborator', function (e) {
-        e.preventDefault();
-        $('div#manage_collaborators').hide();
-        $('div#add_collaborator').fadeIn();
-        return false;
-     });
-
-    $(document).on('click', 'form.collaborators a.remove', function (e) {
-        e.preventDefault();
-        var fObj = $(this).closest('form');
-        $('input'+$(this).attr('href'))
-            .val($(this).attr('href').substr(2))
-            .trigger('change');
-        $(this).closest('tr').addClass('strike');
-
-        return false;
-     });
-
-    $(document).on('change', 'form.collaborators input:checkbox, input[name="del[]"]', function (e) {
-       var fObj = $(this).closest('form');
-       $('div#savewarning', fObj).fadeIn();
-       $('input:submit', fObj).css('color', 'red');
-     });
-
-    $(document).on('click', 'form.collaborators input:reset', function(e) {
-        var fObj = $(this).closest('form');
-        fObj.find('input[name="del[]"]').val('');
-        fObj.find('tr').removeClass('strike');
-        $('div#savewarning', fObj).hide();
-        $('input:submit', fObj).removeAttr('style');
-    });
-
-
-    $(document).on('click', 'form.collaborators input.cancel', function (e) {
-        e.preventDefault();
-        var $elem = $(this);
-
-        if($elem.attr('data-href')) {
-            var href = $elem.data('href').substr(1);
-            $('.dialog.collaborators .body').load('ajax.php/'+href, function () {
-                });
-        } else {
-
-            $('div#manage_collaborators').show();
-            $('div#add_collaborator').hide();
-        }
-        return false;
-    });
-
     $(document).on('change', 'form#reply select#emailreply', function(e) {
          var $cc = $('form#reply tbody#cc_sec');
         if($(this).val() == 0)
diff --git a/scp/js/tips.js b/scp/js/tips.js
index 6a801a18b..fb7ccbf93 100644
--- a/scp/js/tips.js
+++ b/scp/js/tips.js
@@ -161,7 +161,7 @@ jQuery(function() {
     });
 
 
-    $('a#manageCollab').live('mouseover', function(e) {
+    $('a.collaborators.preview').live('mouseover', function(e) {
         e.preventDefault();
         var elem = $(this);
 
-- 
GitLab