[pmg-devel] [PATCH pmg-gui 1/1] fix #3287: add recipient filter for virus/attach. quarantine view

Dominik Csapak d.csapak at proxmox.com
Wed Nov 23 15:52:22 CET 2022


so that users can filter these quarantine views if they have
many mails there.

replaced the emailSelection config with a quarantineType configs
since we want to have different behaviour for different quaratine types
e.g. we want to show 'all' mails by default for the virus/attachment
quarantine, but not for the spam one.

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 js/AttachmentQuarantine.js |  2 +-
 js/QuarantineList.js       | 48 ++++++++++++++++++++++++--------------
 js/SpamQuarantine.js       |  1 -
 js/VirusQuarantine.js      |  2 +-
 4 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/js/AttachmentQuarantine.js b/js/AttachmentQuarantine.js
index 09406e7..4e9bb80 100644
--- a/js/AttachmentQuarantine.js
+++ b/js/AttachmentQuarantine.js
@@ -43,7 +43,7 @@ Ext.define('PMG.AttachmentQuarantine', {
 	    xtype: 'pmgQuarantineList',
 	    emptyText: gettext('No data in database'),
 	    selModel: 'checkboxmodel',
-	    emailSelection: false,
+	    quarantineType: 'attachment',
 	    reference: 'list',
 	    region: 'west',
 	    width: 500,
diff --git a/js/QuarantineList.js b/js/QuarantineList.js
index 74163cf..2da02dc 100644
--- a/js/QuarantineList.js
+++ b/js/QuarantineList.js
@@ -8,7 +8,7 @@ Ext.define('PMG.QuarantineList', {
     },
 
     config: {
-	emailSelection: false,
+	quarantineType: 'spam',
 	notFoundText: gettext('No data in database'),
     },
 
@@ -24,13 +24,22 @@ Ext.define('PMG.QuarantineList', {
 
         init: function(view) {
 	    let me = this;
+	    let emailCombobox = me.lookupReference('email');
 	    if (PMG.view === 'quarantineview') {
-		view.emailSelection = false;
+		view.autoLoadAll = false;
 		me.setEmptyText();
+	    } else {
+		emailCombobox.setVisible(true);
+		emailCombobox.setDisabled(false);
+		emailCombobox.getStore().on('load', me.injectAllOption, me);
+	    }
+
+
+	    if (view.quarantineType) {
+		emailCombobox.getStore().getProxy().setExtraParams({
+		    'quarantine-type': view.quarantineType,
+		});
 	    }
-	    let emailCombobox = me.lookupReference('email');
-	    emailCombobox.setVisible(view.emailSelection);
-	    emailCombobox.setDisabled(!view.emailSelection);
 
 	    let from;
 	    if (PMG.QuarantineList.from !== 0) {
@@ -70,7 +79,7 @@ Ext.define('PMG.QuarantineList', {
 	    me.allowPositionSave = false;
 	    let view = me.getView();
 	    let store = view.getStore();
-	    if (view.emailSelection) {
+	    if (view.quarantineType === 'spam' && PMG.view !== 'quarantineview') {
 		if (!me.lookupReference('email').getSelection()) {
 		    return; // if the combobox has no selection we do not reload
 		}
@@ -123,7 +132,7 @@ Ext.define('PMG.QuarantineList', {
 	setUser: function(user) {
 	    let view = this.getView();
 	    let params = view.getStore().getProxy().getExtraParams();
-	    if (user === null) {
+	    if (!user) {
 		delete params.pmail;
 	    } else {
 		params.pmail = user;
@@ -169,10 +178,7 @@ Ext.define('PMG.QuarantineList', {
 
 	resetEmail: function() {
 	    let me = this;
-	    let view = me.getView();
-	    if (view.emailSelection) {
-		me.setUser(undefined);
-	    }
+	    me.setUser(undefined);
 	},
 
 	changeEmail: function(tb, value) {
@@ -264,6 +270,18 @@ Ext.define('PMG.QuarantineList', {
 	    }
 	},
 
+	injectAllOption: function(store, records, successfull) {
+	    let me = this;
+	    let view = me.getView();
+	    if (successfull && records.length > 1) {
+		store.insert(0, { mail: 'all' });
+	    }
+	    let emailCombobox = me.lookup('email');
+	    if (!emailCombobox.getSelection() && view.quarantineType !== 'spam') {
+		emailCombobox.setSelection(store.getAt(0));
+	    }
+	},
+
 	control: {
 	    '#': {
 		beforedestroy: 'resetEmail',
@@ -314,6 +332,7 @@ Ext.define('PMG.QuarantineList', {
 	    {
 		xtype: 'combobox',
 		hidden: true,
+		disabled: true,
 		displayField: 'mail',
 		valueField: 'mail',
 		listConfig: {
@@ -333,13 +352,6 @@ Ext.define('PMG.QuarantineList', {
 			    renderer: Ext.htmlEncode,
 			},
 		    ],
-		    listeners: {
-			load: function(store, records, successfull) {
-			    if (successfull && records.length > 1) {
-				store.insert(0, { mail: 'all' });
-			    }
-			},
-		    },
 		},
 		queryMode: 'local',
 		editable: true,
diff --git a/js/SpamQuarantine.js b/js/SpamQuarantine.js
index 7487c8f..1608f18 100644
--- a/js/SpamQuarantine.js
+++ b/js/SpamQuarantine.js
@@ -143,7 +143,6 @@ Ext.define('PMG.SpamQuarantine', {
 	    title: gettext('Spam Quarantine'),
 	    xtype: 'pmgQuarantineList',
 	    selModel: 'checkboxmodel',
-	    emailSelection: true,
 	    reference: 'list',
 	    region: 'west',
 	    width: 500,
diff --git a/js/VirusQuarantine.js b/js/VirusQuarantine.js
index ff349ba..65c4fda 100644
--- a/js/VirusQuarantine.js
+++ b/js/VirusQuarantine.js
@@ -45,7 +45,7 @@ Ext.define('PMG.VirusQuarantine', {
 	    xtype: 'pmgQuarantineList',
 	    emptyText: gettext('No data in database'),
 	    selModel: 'checkboxmodel',
-	    emailSelection: false,
+	    quarantineType: 'virus',
 	    reference: 'list',
 	    region: 'west',
 	    width: 500,
-- 
2.30.2





More information about the pmg-devel mailing list