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 8901B6A345
 for <pbs-devel@lists.proxmox.com>; Tue, 16 Feb 2021 12:48:16 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 875B215691
 for <pbs-devel@lists.proxmox.com>; Tue, 16 Feb 2021 12:48:16 +0100 (CET)
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 14F4015638
 for <pbs-devel@lists.proxmox.com>; Tue, 16 Feb 2021 12:48:13 +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 D324A46176
 for <pbs-devel@lists.proxmox.com>; Tue, 16 Feb 2021 12:48:12 +0100 (CET)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Tue, 16 Feb 2021 12:48:10 +0100
Message-Id: <20210216114812.8406-1-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.20.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.221 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. [rec.data, record.data]
Subject: [pbs-devel] [PATCH proxmox-backup 1/3] ui: tape: improve tape-erase
 and add it to library view
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: Tue, 16 Feb 2021 11:48:16 -0000

refactor erase window, limit drives to changer if given

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 www/Makefile              |  1 +
 www/tape/ChangerStatus.js | 23 ++++++++++++++++++
 www/tape/TapeInventory.js | 42 ++++++--------------------------
 www/tape/window/Erase.js  | 51 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 83 insertions(+), 34 deletions(-)
 create mode 100644 www/tape/window/Erase.js

diff --git a/www/Makefile b/www/Makefile
index 8391e68f..b82a91ed 100644
--- a/www/Makefile
+++ b/www/Makefile
@@ -18,6 +18,7 @@ TAPE_UI_FILES=						\
 	tape/form/KeySelector.js			\
 	tape/window/ChangerEdit.js			\
 	tape/window/DriveEdit.js			\
+	tape/window/Erase.js			\
 	tape/window/EncryptionEdit.js			\
 	tape/window/LabelMedia.js			\
 	tape/window/PoolEdit.js				\
diff --git a/www/tape/ChangerStatus.js b/www/tape/ChangerStatus.js
index 017759c7..c51dea4b 100644
--- a/www/tape/ChangerStatus.js
+++ b/www/tape/ChangerStatus.js
@@ -91,6 +91,23 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
 	    }).show();
 	},
 
+	erase: function(view, rI, cI, button, el, record) {
+	    let me = this;
+	    let vm = me.getViewModel();
+	    let label = record.data['label-text'];
+
+	    let changer = vm.get('changer');
+	    Ext.create('PBS.TapeManagement.EraseWindow', {
+		label,
+		changer,
+		listeners: {
+		    destroy: function() {
+			me.reload();
+		    },
+		},
+	    }).show();
+	},
+
 	load: function(view, rI, cI, button, el, record) {
 	    let me = this;
 	    let vm = me.getViewModel();
@@ -566,6 +583,12 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
 				    tooltip: gettext('Transfer'),
 				    isDisabled: (v, r, c, i, rec) => !rec.data['label-text'],
 				},
+				{
+				    iconCls: 'fa fa-trash-o',
+				    handler: 'erase',
+				    tooltip: gettext('Erase'),
+				    isDisabled: (v, r, c, i, rec) => !rec.data['label-text'],
+				},
 				{
 				    iconCls: 'fa fa-rotate-90 fa-upload',
 				    handler: 'load',
diff --git a/www/tape/TapeInventory.js b/www/tape/TapeInventory.js
index ec10f5c9..c369a393 100644
--- a/www/tape/TapeInventory.js
+++ b/www/tape/TapeInventory.js
@@ -41,40 +41,14 @@ Ext.define('PBS.TapeManagement.TapeInventory', {
 		return;
 	    }
 	    let label = selection[0].data['label-text'];
-	    Ext.create('Proxmox.window.Edit', {
-		title: gettext('Erase'),
-		url: `/api2/extjs/tape/drive`,
-		showProgress: true,
-		submitUrl: function(url, values) {
-		    let drive = values.drive;
-		    delete values.drive;
-		    return `${url}/${drive}/erase-media`;
-		},
-		method: 'POST',
-		items: [
-		    {
-			xtype: 'displayfield',
-			cls: 'pmx-hint',
-			value: gettext('Make sure to insert the tape into the selected drive.'),
-		    },
-		    {
-			xtype: 'pbsDriveSelector',
-			fieldLabel: gettext('Drive'),
-			name: 'drive',
-		    },
-		    {
-			xtype: 'displayfield',
-			name: 'label-text',
-			value: label,
-			submitValue: true,
-			fieldLabel: gettext('Media'),
-		    },
-		    {
-			xtype: 'proxmoxcheckbox',
-			fieldLabel: gettext('Fast Erase'),
-			name: 'fast',
-		    },
-		],
+	    let inChanger = selection[0].data.location.startsWith('online-');
+	    let changer;
+	    if (inChanger) {
+		changer = selection[0].data.location.slice("online-".length);
+	    }
+	    Ext.create('PBS.TapeManagement.EraseWindow', {
+		label,
+		changer,
 		listeners: {
 		    destroy: function() {
 			me.reload();
diff --git a/www/tape/window/Erase.js b/www/tape/window/Erase.js
new file mode 100644
index 00000000..61bd2130
--- /dev/null
+++ b/www/tape/window/Erase.js
@@ -0,0 +1,51 @@
+Ext.define('PBS.TapeManagement.EraseWindow', {
+    extend: 'Proxmox.window.Edit',
+    mixins: ['Proxmox.Mixin.CBind'],
+
+
+    changer: undefined,
+    label: undefined,
+
+    cbindData: function(config) {
+	let me = this;
+	return {};
+    },
+
+    title: gettext('Erase'),
+    url: `/api2/extjs/tape/drive`,
+    showProgress: true,
+    submitUrl: function(url, values) {
+	let drive = values.drive;
+	delete values.drive;
+	return `${url}/${drive}/erase-media`;
+    },
+
+    method: 'POST',
+    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}',
+	    },
+	},
+    ],
+});
-- 
2.20.1