[pve-devel] [PATCH v2 proxmox-widget-toolkit 44/52] notification ui: add enable checkbox for targets/matchers

Lukas Wagner l.wagner at proxmox.com
Tue Nov 14 13:59:52 CET 2023


Add a 'enable' checkbox for targets and matchers in their edit
windows. Also show a new 'enable' column in the overview panel.
The parameter in the config is actually called 'disable', so
the UI needs to invert the setting in the appropriate
on{Get,Set}Values hooks.

Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
---
 src/data/model/NotificationConfig.js  |  4 ++--
 src/panel/GotifyEditPanel.js          | 30 +++++++++++++++++++++++++++
 src/panel/NotificationConfigView.js   | 12 +++++++++++
 src/panel/SendmailEditPanel.js        | 28 ++++++++++++++++++++++++-
 src/panel/SmtpEditPanel.js            | 23 +++++++++++++++++++-
 src/window/NotificationMatcherEdit.js | 30 +++++++++++++++++++++++++++
 6 files changed, 123 insertions(+), 4 deletions(-)

diff --git a/src/data/model/NotificationConfig.js b/src/data/model/NotificationConfig.js
index f447db4..9171515 100644
--- a/src/data/model/NotificationConfig.js
+++ b/src/data/model/NotificationConfig.js
@@ -1,6 +1,6 @@
 Ext.define('proxmox-notification-endpoints', {
     extend: 'Ext.data.Model',
-    fields: ['name', 'type', 'comment'],
+    fields: ['name', 'type', 'comment', 'disable'],
     proxy: {
         type: 'proxmox',
     },
@@ -9,7 +9,7 @@ Ext.define('proxmox-notification-endpoints', {
 
 Ext.define('proxmox-notification-matchers', {
     extend: 'Ext.data.Model',
-    fields: ['name', 'comment'],
+    fields: ['name', 'comment', 'disable'],
     proxy: {
         type: 'proxmox',
     },
diff --git a/src/panel/GotifyEditPanel.js b/src/panel/GotifyEditPanel.js
index 5d814e5..7e6ecd8 100644
--- a/src/panel/GotifyEditPanel.js
+++ b/src/panel/GotifyEditPanel.js
@@ -16,6 +16,13 @@ Ext.define('Proxmox.panel.GotifyEditPanel', {
 	    fieldLabel: gettext('Endpoint Name'),
 	    allowBlank: false,
 	},
+	{
+	    xtype: 'proxmoxcheckbox',
+	    name: 'enable',
+	    fieldLabel: gettext('Enable'),
+	    allowBlank: false,
+	    checked: true,
+	},
 	{
 	    xtype: 'proxmoxtextfield',
 	    fieldLabel: gettext('Server URL'),
@@ -41,4 +48,27 @@ Ext.define('Proxmox.panel.GotifyEditPanel', {
 	    },
 	},
     ],
+
+    onSetValues: (values) => {
+	values.enable = !values.disable;
+
+	delete values.disable;
+	return values;
+    },
+
+    onGetValues: function(values) {
+	let me = this;
+
+	if (values.enable) {
+	    if (!me.isCreate) {
+		Proxmox.Utils.assemble_field_data(values, { 'delete': 'disable' });
+	    }
+	} else {
+	    values.disable = 1;
+	}
+
+	delete values.enable;
+
+	return values;
+    },
 });
diff --git a/src/panel/NotificationConfigView.js b/src/panel/NotificationConfigView.js
index 6a9bc20..ba69298 100644
--- a/src/panel/NotificationConfigView.js
+++ b/src/panel/NotificationConfigView.js
@@ -119,6 +119,12 @@ Ext.define('Proxmox.panel.NotificationEndpointView', {
     emptyText: gettext('No notification targets configured'),
 
     columns: [
+	{
+	    dataIndex: 'disable',
+	    text: gettext('Enable'),
+	    renderer: (disable) => Proxmox.Utils.renderEnabledIcon(!disable),
+	    align: 'center',
+	},
 	{
 	    dataIndex: 'name',
 	    text: gettext('Target Name'),
@@ -250,6 +256,12 @@ Ext.define('Proxmox.panel.NotificationMatcherView', {
     emptyText: gettext('No notification matchers configured'),
 
     columns: [
+	{
+	    dataIndex: 'disable',
+	    text: gettext('Enable'),
+	    renderer: (disable) => Proxmox.Utils.renderEnabledIcon(!disable),
+	    align: 'center',
+	},
 	{
 	    dataIndex: 'name',
 	    text: gettext('Matcher Name'),
diff --git a/src/panel/SendmailEditPanel.js b/src/panel/SendmailEditPanel.js
index 17f2d4f..930c4db 100644
--- a/src/panel/SendmailEditPanel.js
+++ b/src/panel/SendmailEditPanel.js
@@ -27,6 +27,13 @@ Ext.define('Proxmox.panel.SendmailEditPanel', {
 	    fieldLabel: gettext('Endpoint Name'),
 	    allowBlank: false,
 	},
+	{
+	    xtype: 'proxmoxcheckbox',
+	    name: 'enable',
+	    fieldLabel: gettext('Enable'),
+	    allowBlank: false,
+	    checked: true,
+	},
 	{
 	    // provides 'mailto' and 'mailto-user' fields
 	    xtype: 'pmxEmailRecipientPanel',
@@ -67,7 +74,26 @@ Ext.define('Proxmox.panel.SendmailEditPanel', {
 	},
     ],
 
-    onGetValues: (values) => {
+    onSetValues: (values) => {
+	values.enable = !values.disable;
+
+	delete values.disable;
+	return values;
+    },
+
+    onGetValues: function(values) {
+	let me = this;
+
+	if (values.enable) {
+	    if (!me.isCreate) {
+		Proxmox.Utils.assemble_field_data(values, { 'delete': 'disable' });
+	    }
+	} else {
+	    values.disable = 1;
+	}
+
+	delete values.enable;
+
 	if (values.mailto) {
 	    values.mailto = values.mailto.split(/[\s,;]+/);
 	}
diff --git a/src/panel/SmtpEditPanel.js b/src/panel/SmtpEditPanel.js
index ab21217..218485d 100644
--- a/src/panel/SmtpEditPanel.js
+++ b/src/panel/SmtpEditPanel.js
@@ -49,6 +49,13 @@ Ext.define('Proxmox.panel.SmtpEditPanel', {
 	    fieldLabel: gettext('Endpoint Name'),
 	    allowBlank: false,
 	},
+	{
+	    xtype: 'proxmoxcheckbox',
+	    name: 'enable',
+	    fieldLabel: gettext('Enable'),
+	    allowBlank: false,
+	    checked: true,
+	},
     ],
 
     column1: [
@@ -161,15 +168,27 @@ Ext.define('Proxmox.panel.SmtpEditPanel', {
     ],
 
     onGetValues: function(values) {
+	let me = this;
+
 	if (values.mailto) {
 	    values.mailto = values.mailto.split(/[\s,;]+/);
 	}
 
-	if (!values.authentication && !this.isCreate) {
+	if (!values.authentication && !me.isCreate) {
 	    Proxmox.Utils.assemble_field_data(values, { 'delete': 'username' });
 	    Proxmox.Utils.assemble_field_data(values, { 'delete': 'password' });
 	}
 
+	if (values.enable) {
+	    if (!me.isCreate) {
+		Proxmox.Utils.assemble_field_data(values, { 'delete': 'disable' });
+	    }
+	} else {
+	    values.disable = 1;
+	}
+
+	delete values.enable;
+
 	delete values.authentication;
 
 	return values;
@@ -177,6 +196,8 @@ Ext.define('Proxmox.panel.SmtpEditPanel', {
 
     onSetValues: function(values) {
 	values.authentication = !!values.username;
+	values.enable = !values.disable;
+	delete values.disable;
 
 	return values;
     },
diff --git a/src/window/NotificationMatcherEdit.js b/src/window/NotificationMatcherEdit.js
index fb55e17..c0dfa34 100644
--- a/src/window/NotificationMatcherEdit.js
+++ b/src/window/NotificationMatcherEdit.js
@@ -14,6 +14,13 @@ Ext.define('Proxmox.panel.NotificationMatcherGeneralPanel', {
 	    fieldLabel: gettext('Matcher Name'),
 	    allowBlank: false,
 	},
+	{
+	    xtype: 'proxmoxcheckbox',
+	    name: 'enable',
+	    fieldLabel: gettext('Enable'),
+	    allowBlank: false,
+	    checked: true,
+	},
 	{
 	    xtype: 'proxmoxtextfield',
 	    name: 'comment',
@@ -23,6 +30,29 @@ Ext.define('Proxmox.panel.NotificationMatcherGeneralPanel', {
 	    },
 	},
     ],
+
+
+    onSetValues: function(values) {
+	values.enable = !values.disable;
+
+	delete values.disable;
+	return values;
+    },
+
+    onGetValues: function(values) {
+	let me = this;
+
+	if (values.enable) {
+	    if (!me.isCreate) {
+		Proxmox.Utils.assemble_field_data(values, { 'delete': 'disable' });
+	    }
+	} else {
+	    values.disable = 1;
+	}
+	delete values.enable;
+
+	return values;
+    },
 });
 
 Ext.define('Proxmox.panel.NotificationMatcherTargetPanel', {
-- 
2.39.2






More information about the pve-devel mailing list