From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@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 9F8F4715EF
 for <pbs-devel@lists.proxmox.com>; Thu,  8 Apr 2021 13:39:23 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 99D551A99F
 for <pbs-devel@lists.proxmox.com>; Thu,  8 Apr 2021 13:39:23 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (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 BC6AD1A973
 for <pbs-devel@lists.proxmox.com>; Thu,  8 Apr 2021 13:39:21 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 7B6F645A0C
 for <pbs-devel@lists.proxmox.com>; Thu,  8 Apr 2021 13:39:21 +0200 (CEST)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Thu,  8 Apr 2021 13:39:16 +0200
Message-Id: <20210408113920.24416-3-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20210408113920.24416-1-d.csapak@proxmox.com>
References: <20210408113920.24416-1-d.csapak@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.167 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_DNSWL_MED        -2.3 Sender listed at https://www.dnswl.org/,
 medium trust
 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. [record.data]
Subject: [pbs-devel] [PATCH proxmox-backup 3/7] ui: tape/ChangerStatus:
 rework EraseWindow
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Thu, 08 Apr 2021 11:39:23 -0000

to make it more like a 'dangerous' remove window
also works in the singleDrive logic to hide/show the driveselector

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
i am not completely happy with the code, but i did not want
to completely rewrite neither the editwindow nor the safedestroy window,
and i did not want to reimplement the editwindow functions...

if someone has a better idea/suggestions how to implement this
(especially the layout...), please do so

 www/tape/ChangerStatus.js |  2 +
 www/tape/window/Erase.js  | 90 +++++++++++++++++++++++++++++----------
 2 files changed, 69 insertions(+), 23 deletions(-)

diff --git a/www/tape/ChangerStatus.js b/www/tape/ChangerStatus.js
index fb4ad1e3..dadb2a6e 100644
--- a/www/tape/ChangerStatus.js
+++ b/www/tape/ChangerStatus.js
@@ -144,9 +144,11 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
 	    let label = record.data['label-text'];
 
 	    let changer = encodeURIComponent(view.changer);
+	    let singleDrive = me.drives.length === 1 ? me.drives[0] : undefined;
 	    Ext.create('PBS.TapeManagement.EraseWindow', {
 		label,
 		changer,
+		singleDrive,
 		listeners: {
 		    destroy: function() {
 			me.reload();
diff --git a/www/tape/window/Erase.js b/www/tape/window/Erase.js
index 1177dfeb..8b166d30 100644
--- a/www/tape/window/Erase.js
+++ b/www/tape/window/Erase.js
@@ -8,7 +8,11 @@ Ext.define('PBS.TapeManagement.EraseWindow', {
 
     cbindData: function(config) {
 	let me = this;
-	return {};
+	return {
+	    singleDrive: me.singleDrive,
+	    hasSingleDrive: !!me.singleDrive,
+	    warning: Ext.String.format(gettext("Are you sure you want to erase tape '{0}' ?"), me.label),
+	};
     },
 
     title: gettext('Format/Erase'),
@@ -20,32 +24,72 @@ Ext.define('PBS.TapeManagement.EraseWindow', {
 	return `${url}/${drive}/format-media`;
     },
 
+    layout: 'hbox',
+    width: 400,
     method: 'POST',
+    isCreate: true,
+    submitText: gettext('Ok'),
     items: [
 	{
-	    xtype: 'displayfield',
-	    cls: 'pmx-hint',
-	    value: gettext('Make sure to insert the tape into the selected drive.'),
-	    cbind: {
-		hidden: '{changer}',
-	    },
-	},
-	{
-	    xtype: 'displayfield',
-	    name: 'label-text',
-	    submitValue: true,
-	    fieldLabel: gettext('Media'),
-	    cbind: {
-		value: '{label}',
-	    },
-	},
-	{
-	    xtype: 'pbsDriveSelector',
-	    fieldLabel: gettext('Drive'),
-	    name: 'drive',
-	    cbind: {
-		changer: '{changer}',
+	    xtype: 'container',
+	    padding: 0,
+	    layout: {
+		type: 'hbox',
+		align: 'stretch',
 	    },
+	    items: [
+		{
+		    xtype: 'component',
+		    cls: [Ext.baseCSSPrefix + 'message-box-icon',
+			Ext.baseCSSPrefix + 'message-box-warning',
+			Ext.baseCSSPrefix + 'dlg-icon'],
+		},
+		{
+		    xtype: 'container',
+		    flex: 1,
+		    items: [
+			{
+			    xtype: 'displayfield',
+			    cbind: {
+				value: '{warning}',
+			    },
+			},
+			{
+			    xtype: 'displayfield',
+			    cls: 'pmx-hint',
+			    value: gettext('Make sure to insert the tape into the selected drive.'),
+			    cbind: {
+				hidden: '{changer}',
+			    },
+			},
+			{
+			    xtype: 'hidden',
+			    name: 'label-text',
+			    cbind: {
+				value: '{label}',
+			    },
+			},
+			{
+			    xtype: 'hidden',
+			    name: 'drive',
+			    cbind: {
+				disabled: '{!hasSingleDrive}',
+				value: '{singleDrive}',
+			    },
+			},
+			{
+			    xtype: 'pbsDriveSelector',
+			    fieldLabel: gettext('Drive'),
+			    name: 'drive',
+			    cbind: {
+				changer: '{changer}',
+				disabled: '{hasSingleDrive}',
+				hidden: '{hasSingleDrive}',
+			    },
+			},
+		    ],
+		},
+	    ],
 	},
     ],
 });
-- 
2.20.1