]> git.proxmox.com Git - pmg-gui.git/blobdiff - js/SpamQuarantine.js
object editors: rework so that default label width fits everywhere
[pmg-gui.git] / js / SpamQuarantine.js
index f5875bc3158df028a683d5094f7d391b7312d64f..efb7fdc91dcb743bc92ab8e0d48a904c549f02f5 100644 (file)
@@ -67,7 +67,10 @@ Ext.define('PMG.SpamQuarantine', {
                return;
            }
 
-           var url = '/api2/htmlmail/quarantine/content?id=' + rec.data.id + (raw?'&raw=1':'');
+           let url = `/api2/htmlmail/quarantine/content?id=${rec.data.id}`;
+           if (raw) {
+               url += '&raw=1';
+           }
            preview.setDisabled(false);
            this.lookupReference('raw').setDisabled(false);
            this.lookupReference('spam').setDisabled(false);
@@ -118,31 +121,55 @@ Ext.define('PMG.SpamQuarantine', {
            var list = this.lookupReference('list');
 
            if (selected.length > 1) {
-               var idlist = [];
-               selected.forEach(function(item) {
-                   idlist.push(item.data.id);
-               });
+               let idlist = selected.map(item => item.data.id);
                Ext.Msg.confirm(
                    gettext('Confirm'),
                    Ext.String.format(
                        gettext("Action '{0}' for '{1}' items"),
                        action, selected.length,
                    ),
-                   function(button) {
+                   async function(button) {
                        if (button !== 'yes') {
                            return;
                        }
 
-                       PMG.Utils.doQuarantineAction(action, idlist.join(';'), function() {
-                           list.getController().load();
-                       });
+                       list.mask(gettext('Processing...'), 'x-mask-loading');
+
+                       const sliceSize = 2500, maxInFlight = 2;
+                       let batches = [], batchCount = Math.ceil(selected.length / sliceSize);
+                       for (let i = 0; i * sliceSize < selected.length; i++) {
+                           let sliceStart = i * sliceSize;
+                           let sliceEnd = Math.min(sliceStart + sliceSize, selected.length);
+                           batches.push(
+                               PMG.Async.doQAction(
+                                   action,
+                                   idlist.slice(sliceStart, sliceEnd),
+                                   i + 1,
+                                   batchCount,
+                               ),
+                           );
+                           if (batches.length >= maxInFlight) {
+                               await Promise.allSettled(batches); // eslint-disable-line no-await-in-loop
+                               batches = [];
+                           }
+                       }
+                       await Promise.allSettled(batches); // await possible remaining ones
+                       list.unmask();
+                       // below can be slow, we could remove directly from the in-memory store, but
+                       // with lots of elements and some failures we could be quite out of sync?
+                       list.getController().load();
                    },
                );
                return;
            }
 
            PMG.Utils.doQuarantineAction(action, selected[0].data.id, function() {
-               list.getController().load();
+               let listController = list.getController();
+               listController.allowPositionSave = false;
+               // success -> remove directly to avoid slow store reload for a single-element action
+               list.getStore().remove(selected[0]);
+               listController.restoreSavedSelection();
+               listController.allowPositionSave = true;
            });
        },
 
@@ -171,15 +198,11 @@ Ext.define('PMG.SpamQuarantine', {
 
        openContextMenu: function(table, record, tr, index, event) {
            event.stopEvent();
-           var me = this;
-           var list = me.lookup('list');
-           var menu = Ext.create('PMG.menu.SpamContextMenu', {
-               callback: function(action) {
-                   me.doAction(action, list.getSelection());
-               },
-           });
-
-           menu.showAt(event.getXY());
+           let me = this;
+           let list = me.lookup('list');
+           Ext.create('PMG.menu.SpamContextMenu', {
+               callback: action => me.doAction(action, list.getSelection()),
+           }).showAt(event.getXY());
        },
 
        keyPress: function(table, record, item, index, event) {
@@ -288,6 +311,7 @@ Ext.define('PMG.SpamQuarantine', {
            title: gettext('Selected Mail'),
            border: false,
            region: 'center',
+           layout: 'fit',
            split: true,
            reference: 'preview',
            disabled: true,