]> git.proxmox.com Git - pmg-gui.git/commitdiff
attachment grid: default to filtering by content-disposition
authorDominik Csapak <d.csapak@proxmox.com>
Mon, 7 Nov 2022 14:36:20 +0000 (15:36 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 11 Nov 2022 17:40:39 +0000 (18:40 +0100)
Normally, attachments are given the 'content-disposition: attachment'
mime attribute, so we use that to filter the attachments.

But since we're dealing with spam & virus mails here, and that field
is client controlled, give the user a way to toggle the remaining parts
of the mail too.

Added the checkbox in the header part, but that made it necessary to
manually implement the expand/collapse toggle (since the tools are on
the wrong side of the default toggle)

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
js/AttachmentGrid.js

index 3187a58de399adbeaf24b0e780549370b844a4ca..b6d8b4a9e3f4cb0f1921e26540ca7a2771c26fc8 100644 (file)
@@ -11,16 +11,52 @@ Ext.define('PMG.grid.AttachmentGrid', {
     minHeight: 50,
     maxHeight: 250,
     scrollable: true,
+    collapsed: true,
 
-    collapsible: true,
-    titleCollapse: true,
+    tools: [
+       {
+           xtype: 'checkbox',
+           boxLabel: gettext('show all parts'),
+           boxLabelAlgign: 'before',
+           listeners: {
+               change: function(cb, value) {
+                   let grid = this.up('pmgAttachmentGrid');
+                   let store = grid.getStore();
+                   store.clearFilter();
+                   if (!value) {
+                       store.filter({
+                           property: 'content-disposition',
+                           value: 'attachment',
+                       });
+                   }
+               },
+           },
+       },
+       {
+           type: 'down',
+           handler: function() {
+               let me = this;
+               let type = me.type === 'up' ? 'down' : 'up';
+               me.up('pmgAttachmentGrid').toggleCollapse();
+               me.setType(type);
+           },
+       },
+    ],
+
+    header: {
+       padding: '6 10 6 10', // make same height as normal panel
+    },
 
     store: {
        autoDestroy: true,
-       fields: ['name', 'content-type', 'size'],
+       fields: ['name', 'content-type', 'size', 'content-disposition'],
        proxy: {
            type: 'proxmox',
        },
+       filters: {
+           property: 'content-disposition',
+           value: 'attachment',
+       },
     },
 
     controller: {
@@ -35,8 +71,15 @@ Ext.define('PMG.grid.AttachmentGrid', {
                view.updateTitleStats(-1);
                return;
            }
-           let totalSize = records.reduce((sum, { data }) => sum + data.size, 0);
-           view.updateTitleStats(records.length, totalSize);
+           let count = 0;
+           let totalSize = records.reduce((sum, { data }) => {
+               if (data['content-disposition'] === 'attachment') {
+                   count++;
+                   return sum + data.size;
+               }
+               return sum;
+           }, 0);
+           view.updateTitleStats(count, totalSize);
        },
     },
 
@@ -46,14 +89,10 @@ Ext.define('PMG.grid.AttachmentGrid', {
        if (count > 0) {
            title = Ext.String.format(gettext('{0} Attachments'), count);
            title += ` (${Proxmox.Utils.format_size(totalSize)})`;
-           if (me.collapsible) {
-               me.expand();
-           }
+           me.expand();
        } else {
            title = gettext('No Attachments');
-           if (me.collapsible) {
-               me.collapse();
-           }
+           me.collapse();
        }
        me.setTitle(title);
     },