From 70c7de2cca3798010d5672238abec2fd4971bcdc Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Wed, 26 Mar 2014 21:43:18 +0000
Subject: [PATCH] Make dialog support multiple exit codes

---
 scp/js/scp.js | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/scp/js/scp.js b/scp/js/scp.js
index 33839e80c..003c41913 100644
--- a/scp/js/scp.js
+++ b/scp/js/scp.js
@@ -431,9 +431,12 @@ $(document).ready(function(){
         $('#advanced-search').show();
     });
 
-    $.dialog = function (url, code, cb, options) {
+    $.dialog = function (url, codes, cb, options) {
         options = options||{};
 
+        if (codes && !$.isArray(codes))
+            codes = [codes];
+
         $('.dialog#popup .body').load(url, function () {
             $('#overlay').show();
             $('.dialog#popup').show({
@@ -451,11 +454,12 @@ $(document).ready(function(){
                     data: $form.serialize(),
                     cache: false,
                     success: function(resp, status, xhr) {
-                        if (xhr && xhr.status == code) {
+                        if (xhr && xhr.status && codes
+                            && $.inArray(xhr.status, codes) != -1) {
                             $('div.body', $dialog).empty();
                             $dialog.hide();
                             $('#overlay').hide();
-                            if(cb) cb(xhr.responseText);
+                            if(cb) cb(xhr);
                         } else {
                             $('div.body', $dialog).html(resp);
                             $('#msg_notice, #msg_error', $dialog).delay(5000).slideUp();
@@ -471,9 +475,9 @@ $(document).ready(function(){
      };
 
     $.userLookup = function (url, cb) {
-        $.dialog(url, 201, function (resp) {
-            var user = $.parseJSON(resp);
-            if(cb) cb(user);
+        $.dialog(url, 201, function (xhr) {
+            var user = $.parseJSON(xhr.responseText);
+            if (cb) cb(user);
         }, {
             onshow: function() { $('#user-search').focus(); }
         });
@@ -569,9 +573,9 @@ $(document).ready(function(){
     $(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) {
+        $.dialog(url, 201, function (xhr) {
            $('input#emailcollab').show();
-           $('#recipients').text(resp);
+           $('#recipients').text(xhr.responseText);
            $('.tip_box').remove();
         }, {
             onshow: function() { $('#user-search').focus(); }
-- 
GitLab