Contain delete result data in a single object
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 18 Dec 2009 23:44:05 +0000 (16:44 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 18 Dec 2009 23:44:05 +0000 (16:44 -0700)
imp/ajax.php
imp/js/DimpBase.js

index 5ace1e6..0c219da 100644 (file)
@@ -15,12 +15,15 @@ function _generateDeleteResult($mbox, $indices, $change, $nothread = false)
 {
     $imp_mailbox = IMP_Mailbox::singleton($mbox);
 
-    $result = new stdClass;
-    $result->folder = $mbox;
-    $result->uids = $GLOBALS['imp_imap']->ob()->utils->toSequenceString($indices, array('mailbox' => true));
-    $result->remove = intval($GLOBALS['prefs']->getValue('hide_deleted') ||
+    $del = new stdClass;
+    $del->folder = $mbox;
+    $del->uids = $GLOBALS['imp_imap']->ob()->utils->toSequenceString($indices, array('mailbox' => true));
+    $del->remove = intval($GLOBALS['prefs']->getValue('hide_deleted') ||
                              $GLOBALS['prefs']->getValue('use_trash'));
-    $result->cacheid = $imp_mailbox->getCacheID($mbox);
+    $del->cacheid = $imp_mailbox->getCacheID($mbox);
+
+    $result = new stdClass;
+    $result->delete = $del;
 
     /* Check if we need to update thread information. */
     if (!$change && !$nothread) {
@@ -446,7 +449,7 @@ case 'CopyMessage':
                 $result = _generateDeleteResult($mbox, $indices, $change);
                 // Need to manually set remove to true since we want to remove
                 // message from the list no matter the current pref settings.
-                $result->remove = 1;
+                $result->delete->remove = 1;
             }
 
             // Update poll information for destination folder if necessary.
@@ -536,7 +539,7 @@ case 'ReportSpam':
         $result = _generateDeleteResult($mbox, $indices, $change);
         // If result is non-zero, then we know the message has been removed
         // from the current mailbox.
-        $result->remove = 1;
+        $result->delete->remove = 1;
     } elseif (!is_null($change)) {
         $check_uidvalidity = true;
     }
@@ -770,7 +773,7 @@ case 'PurgeDeleted':
             $result = _generateDeleteResult($mbox, $expunged, $change);
             // Need to manually set remove to true since we want to remove
             // message from the list no matter the current pref settings.
-            $result->remove = 1;
+            $result->delete->remove = 1;
         }
     }
     break;
index 796317b..f1e9ed6 100644 (file)
@@ -1541,7 +1541,7 @@ var DimpBase = {
                 } else if (this.folder != foldername) {
                     // Don't allow drag/drop to the current folder.
                     this.updateFlag(uids, '\\deleted', true);
-                    DimpCore.doAction('MoveMessage', this.viewport.addRequestParams({ tofld: foldername }), { uids: uids, callback: this._deleteCallback.bind(this) });
+                    DimpCore.doAction('MoveMessage', this.viewport.addRequestParams({ tofld: foldername }), { uids: uids });
                 }
             }
         }
@@ -2089,13 +2089,17 @@ var DimpBase = {
         }
     },
 
-    _deleteCallback: function(r)
+    deleteCallback: function(r)
     {
         var search = null, uids = [], vs;
 
+        if (!r.delete) {
+            return;
+        }
+
         this.loadingImg('viewport', false);
 
-        r = r.response;
+        r = r.delete;
         if (!r.uids || r.folder != this.folder) {
             return;
         }
@@ -2563,7 +2567,7 @@ var DimpBase = {
             // This needs to be synchronous Ajax if we are calling from a
             // popup window because Mozilla will not correctly call the
             // callback function if the calling window has been closed.
-            DimpCore.doAction(type, this.viewport.addRequestParams(args), { uids: vs, callback: this._deleteCallback.bind(this), ajaxopts: { asynchronous: !(opts.uid && opts.mailbox) } });
+            DimpCore.doAction(type, this.viewport.addRequestParams(args), { uids: vs, ajaxopts: { asynchronous: !(opts.uid && opts.mailbox) } });
             return vs;
         }
 
@@ -2704,7 +2708,7 @@ var DimpBase = {
     /* Miscellaneous folder actions. */
     purgeDeleted: function()
     {
-        DimpCore.doAction('PurgeDeleted', this.viewport.addRequestParams({}), { callback: this._deleteCallback.bind(this) });
+        DimpCore.doAction('PurgeDeleted', this.viewport.addRequestParams({}));
     },
 
     modifyPoll: function(folder, add)
@@ -3021,6 +3025,7 @@ DimpBase._folderDropConfig = {
 };
 
 DimpCore.onDoActionComplete = function(r) {
+    DimpBase.deleteCallback(r);
     if (DimpBase.viewport) {
         DimpBase.viewport.parseJSONResponse(r);
     }