From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <s.ivanov@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 03E1B7DE31
 for <pve-devel@lists.proxmox.com>; Tue,  9 Nov 2021 17:36:47 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id D9FE710ABF
 for <pve-devel@lists.proxmox.com>; Tue,  9 Nov 2021 17:36:46 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 5C83110A27
 for <pve-devel@lists.proxmox.com>; Tue,  9 Nov 2021 17:36:44 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id C116845CDB
 for <pve-devel@lists.proxmox.com>; Tue,  9 Nov 2021 17:36:43 +0100 (CET)
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Tue,  9 Nov 2021 17:36:33 +0100
Message-Id: <20211109163633.1721670-7-s.ivanov@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20211109163633.1721670-1-s.ivanov@proxmox.com>
References: <20211109163633.1721670-1-s.ivanov@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.347 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [values.data, values.id, definition.name]
Subject: [pve-devel] [PATCH manager 3/3] gui: use acme plugin editor from
 proxmox-widget-toolkit
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 09 Nov 2021 16:36:47 -0000

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
 www/manager6/Makefile              |   1 -
 www/manager6/dc/ACMEClusterView.js |  13 +-
 www/manager6/dc/ACMEPluginEdit.js  | 223 -----------------------------
 3 files changed, 10 insertions(+), 227 deletions(-)
 delete mode 100644 www/manager6/dc/ACMEPluginEdit.js

diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index 4011d4e5..302a106d 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -120,7 +120,6 @@ JSSRC= 							\
 	ha/StatusView.js				\
 	dc/ACLView.js					\
 	dc/ACMEClusterView.js				\
-	dc/ACMEPluginEdit.js				\
 	dc/AuthEditBase.js				\
 	dc/AuthEditAD.js				\
 	dc/AuthEditLDAP.js				\
diff --git a/www/manager6/dc/ACMEClusterView.js b/www/manager6/dc/ACMEClusterView.js
index d02aeef0..2237314b 100644
--- a/www/manager6/dc/ACMEClusterView.js
+++ b/www/manager6/dc/ACMEClusterView.js
@@ -130,7 +130,11 @@ Ext.define('PVE.dc.ACMEPluginView', {
 
 	addPlugin: function() {
 	    let me = this;
-	    Ext.create('PVE.dc.ACMEPluginEditor', {
+	    let acmeUrl = '/cluster/acme/';
+	    Ext.create('Proxmox.window.ACMEPluginEdit', {
+		onlineHelp: 'sysadmin_certs_acme_plugins',
+		acmeUrl: acmeUrl,
+		url: `${acmeUrl}/plugins/`,
 		isCreate: true,
 		apiCallDone: function() {
 		    me.reload();
@@ -144,8 +148,11 @@ Ext.define('PVE.dc.ACMEPluginView', {
 	    let selection = view.getSelection();
 	    if (selection.length < 1) return;
 	    let plugin = selection[0].data.plugin;
-	    Ext.create('PVE.dc.ACMEPluginEditor', {
-		url: `/cluster/acme/plugins/${plugin}`,
+	    let acmeUrl = '/cluster/acme/';
+	    Ext.create('Proxmox.window.ACMEPluginEdit', {
+		onlineHelp: 'sysadmin_certs_acme_plugins',
+		acmeUrl: acmeUrl,
+		url: `${acmeUrl}/plugins/${plugin}`,
 		apiCallDone: function() {
 		    me.reload();
 		},
diff --git a/www/manager6/dc/ACMEPluginEdit.js b/www/manager6/dc/ACMEPluginEdit.js
deleted file mode 100644
index 570b4dd2..00000000
--- a/www/manager6/dc/ACMEPluginEdit.js
+++ /dev/null
@@ -1,223 +0,0 @@
-Ext.define('PVE.dc.ACMEPluginEditor', {
-    extend: 'Proxmox.window.Edit',
-    xtype: 'pveACMEPluginEditor',
-    mixins: ['Proxmox.Mixin.CBind'],
-
-    onlineHelp: 'sysadmin_certs_acme_plugins',
-
-    isAdd: true,
-    isCreate: false,
-
-    width: 550,
-    url: '/cluster/acme/plugins/',
-
-    subject: 'ACME DNS Plugin',
-
-    items: [
-	{
-	    xtype: 'inputpanel',
-	    // we dynamically create fields from the given schema
-	    // things we have to do here:
-	    // * save which fields we created to remove them again
-	    // * split the data from the generic 'data' field into the boxes
-	    // * on deletion collect those values again
-	    // * save the original values of the data field
-	    createdFields: {},
-	    createdInitially: false,
-	    originalValues: {},
-	    createSchemaFields: function(schema) {
-		let me = this;
-		// we know where to add because we define it right below
-		let container = me.down('container');
-		let datafield = me.down('field[name=data]');
-		let hintfield = me.down('field[name=hint]');
-		if (!me.createdInitially) {
-		    [me.originalValues] = PVE.Parser.parseACMEPluginData(datafield.getValue());
-		}
-
-		// collect values from custom fields and add it to 'data'',
-		// then remove the custom fields
-		let data = [];
-		for (const [name, field] of Object.entries(me.createdFields)) {
-		    let value = field.getValue();
-		    if (value !== undefined && value !== null && value !== '') {
-			data.push(`${name}=${value}`);
-		    }
-		    container.remove(field);
-		}
-		let datavalue = datafield.getValue();
-		if (datavalue !== undefined && datavalue !== null && datavalue !== '') {
-		    data.push(datavalue);
-		}
-		datafield.setValue(data.join('\n'));
-
-		me.createdFields = {};
-
-		if (typeof schema.fields !== 'object') {
-		    schema.fields = {};
-		}
-		// create custom fields according to schema
-		let gotSchemaField = false;
-		let cmp = (a, b) => a[0].localeCompare(b[0]);
-		for (const [name, definition] of Object.entries(schema.fields).sort(cmp)) {
-		    let xtype;
-		    switch (definition.type) {
-			case 'string':
-			    xtype = 'proxmoxtextfield';
-			    break;
-			case 'integer':
-			    xtype = 'proxmoxintegerfield';
-			    break;
-			case 'number':
-			    xtype = 'numberfield';
-			    break;
-			default:
-			    console.warn(`unknown type '${definition.type}'`);
-			    xtype = 'proxmoxtextfield';
-			    break;
-		    }
-
-		    let label = name;
-		    if (typeof definition.name === "string") {
-			label = definition.name;
-		    }
-
-		    let field = Ext.create({
-			xtype,
-			name: `custom_${name}`,
-			fieldLabel: label,
-			width: '100%',
-			labelWidth: 150,
-			labelSeparator: '=',
-			emptyText: definition.default || '',
-			autoEl: definition.description ? {
-			    tag: 'div',
-			    'data-qtip': definition.description,
-			} : undefined,
-		    });
-
-		    me.createdFields[name] = field;
-		    container.add(field);
-		    gotSchemaField = true;
-		}
-		datafield.setHidden(gotSchemaField); // prefer schema-fields
-
-		if (schema.description) {
-		    hintfield.setValue(schema.description);
-		    hintfield.setHidden(false);
-		} else {
-		    hintfield.setValue('');
-		    hintfield.setHidden(true);
-		}
-
-		// parse data from field and set it to the custom ones
-		let extradata = [];
-		[data, extradata] = PVE.Parser.parseACMEPluginData(datafield.getValue());
-		for (const [key, value] of Object.entries(data)) {
-		    if (me.createdFields[key]) {
-			me.createdFields[key].setValue(value);
-			me.createdFields[key].originalValue = me.originalValues[key];
-		    } else {
-			extradata.push(`${key}=${value}`);
-		    }
-		}
-		datafield.setValue(extradata.join('\n'));
-		if (!me.createdInitially) {
-		    datafield.resetOriginalValue();
-		    me.createdInitially = true; // save that we initally set that
-		}
-	    },
-	    onGetValues: function(values) {
-		let me = this;
-		let win = me.up('pveACMEPluginEditor');
-		if (win.isCreate) {
-		    values.id = values.plugin;
-		    values.type = 'dns'; // the only one for now
-		}
-		delete values.plugin;
-
-		PVE.Utils.delete_if_default(values, 'validation-delay', '30', win.isCreate);
-
-		let data = '';
-		for (const [name, field] of Object.entries(me.createdFields)) {
-		    let value = field.getValue();
-		    if (value !== null && value !== undefined && value !== '') {
-			data += `${name}=${value}\n`;
-		    }
-		    delete values[`custom_${name}`];
-		}
-		values.data = Ext.util.Base64.encode(data + values.data);
-		return values;
-	    },
-	    items: [
-		{
-		    xtype: 'pmxDisplayEditField',
-		    cbind: {
-			editable: (get) => get('isCreate'),
-			submitValue: (get) => get('isCreate'),
-		    },
-		    editConfig: {
-			flex: 1,
-			xtype: 'proxmoxtextfield',
-			allowBlank: false,
-		    },
-		    name: 'plugin',
-		    labelWidth: 150,
-		    fieldLabel: gettext('Plugin ID'),
-		},
-		{
-		    xtype: 'proxmoxintegerfield',
-		    name: 'validation-delay',
-		    labelWidth: 150,
-		    fieldLabel: gettext('Validation Delay'),
-		    emptyText: 30,
-		    cbind: {
-			deleteEmpty: '{!isCreate}',
-		    },
-		    minValue: 0,
-		    maxValue: 48*60*60,
-		},
-		{
-		    xtype: 'pveACMEApiSelector',
-		    name: 'api',
-		    labelWidth: 150,
-		    listeners: {
-			change: function(selector) {
-			    let schema = selector.getSchema();
-			    selector.up('inputpanel').createSchemaFields(schema);
-			},
-		    },
-		},
-		{
-		    xtype: 'textarea',
-		    fieldLabel: gettext('API Data'),
-		    labelWidth: 150,
-		    name: 'data',
-		},
-		{
-		    xtype: 'displayfield',
-		    fieldLabel: gettext('Hint'),
-		    labelWidth: 150,
-		    name: 'hint',
-		    hidden: true,
-		},
-	    ],
-	},
-    ],
-
-    initComponent: function() {
-	var me = this;
-
-	me.callParent();
-
-	if (!me.isCreate) {
-	    me.load({
-		success: function(response, opts) {
-		    me.setValues(response.result.data);
-		},
-	    });
-	} else {
-	    me.method = 'POST';
-	}
-    },
-});
-- 
2.30.2