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 6073670EAF
 for <pbs-devel@lists.proxmox.com>; Mon, 17 May 2021 09:03:50 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 5D1B127E3A
 for <pbs-devel@lists.proxmox.com>; Mon, 17 May 2021 09:03:20 +0200 (CEST)
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 35F3027E2F
 for <pbs-devel@lists.proxmox.com>; Mon, 17 May 2021 09:03:16 +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 1082443CBA
 for <pbs-devel@lists.proxmox.com>; Mon, 17 May 2021 09:03:16 +0200 (CEST)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Mon, 17 May 2021 09:03:15 +0200
Message-Id: <20210517070315.4510-2-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20210517070315.4510-1-d.csapak@proxmox.com>
References: <20210517070315.4510-1-d.csapak@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.015 Adjusted score from AWL reputation of From: address
 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
Subject: [pbs-devel] [PATCH proxmox-backup 2/2] ui: datastore/Content:
 change group remove to SafeDestroy Window
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: Mon, 17 May 2021 07:03:50 -0000

so that a user does not accidentally remove a whole group instead
of a snapshot

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 www/Utils.js             |  1 +
 www/datastore/Content.js | 68 +++++++++++++++++++++++++---------------
 2 files changed, 43 insertions(+), 26 deletions(-)

diff --git a/www/Utils.js b/www/Utils.js
index 14561ad4..f614d77e 100644
--- a/www/Utils.js
+++ b/www/Utils.js
@@ -384,6 +384,7 @@ Ext.define('PBS.Utils', {
 	    dirremove: [gettext('Directory'), gettext('Remove')],
 	    'eject-media': [gettext('Drive'), gettext('Eject Media')],
 	    "format-media": [gettext('Drive'), gettext('Format media')],
+	    "forget-group": [gettext('Group'), gettext('Remove Group')],
 	    garbage_collection: ['Datastore', gettext('Garbage Collect')],
 	    'inventory-update': [gettext('Drive'), gettext('Inventory Update')],
 	    'label-media': [gettext('Drive'), gettext('Label Media')],
diff --git a/www/datastore/Content.js b/www/datastore/Content.js
index ca90f82a..5be5bb93 100644
--- a/www/datastore/Content.js
+++ b/www/datastore/Content.js
@@ -374,38 +374,35 @@ Ext.define('PBS.DataStoreContent', {
 	    });
 	},
 
-	onForget: function(view, rI, cI, item, e, rec) {
+	forgetGroup: function(data) {
 	    let me = this;
-	    view = this.getView();
-
-	    if (!(rec && rec.data)) return;
-	    let data = rec.data;
-	    if (!view.datastore) return;
+	    let view = me.getView();
 
-	    let params;
-	    let message;
-	    let url;
-	    if (rec.parentNode.id !== 'root') {
-		message = Ext.String.format(gettext('Are you sure you want to remove snapshot {0}'), `'${data.text}'`);
-		url = `/admin/datastore/${view.datastore}/snapshots`;
-		params = {
-		    "backup-type": data["backup-type"],
-		    "backup-id": data["backup-id"],
-		    "backup-time": (data['backup-time'].getTime()/1000).toFixed(0),
-		};
-	    } else {
-		message = Ext.String.format(gettext('Are you sure you want to remove group {0}'), `'${data.text}'`);
-		url = `/admin/datastore/${view.datastore}/groups`;
-		params = {
+	    Ext.create('Proxmox.window.SafeDestroy', {
+		url: `/admin/datastore/${view.datastore}/groups`,
+		params: {
 		    "backup-type": data.backup_type,
 		    "backup-id": data.backup_id,
-		};
-	    }
+		},
+		item: {
+		    id: data.text,
+		},
+		autoShow: true,
+		taskName: 'forget-group',
+		listeners: {
+		    destroy: () => me.reload(),
+		},
+	    });
+	},
+
+	forgetSnapshot: function(data) {
+	    let me = this;
+	    let view = me.getView();
 
 	    Ext.Msg.show({
 		title: gettext('Confirm'),
 		icon: Ext.Msg.WARNING,
-		message,
+		message: Ext.String.format(gettext('Are you sure you want to remove snapshot {0}'), `'${data.text}'`),
 		buttons: Ext.Msg.YESNO,
 		defaultFocus: 'no',
 		callback: function(btn) {
@@ -414,8 +411,12 @@ Ext.define('PBS.DataStoreContent', {
 		    }
 
 		    Proxmox.Utils.API2Request({
-			url,
-			params,
+			url: `/admin/datastore/${view.datastore}/snapshots`,
+			params: {
+			    "backup-type": data["backup-type"],
+			    "backup-id": data["backup-id"],
+			    "backup-time": (data['backup-time'].getTime()/1000).toFixed(0),
+			},
 			method: 'DELETE',
 			waitMsgTarget: view,
 			failure: function(response, opts) {
@@ -427,6 +428,21 @@ Ext.define('PBS.DataStoreContent', {
 	    });
 	},
 
+	onForget: function(view, rI, cI, item, e, rec) {
+	    let me = this;
+	    view = this.getView();
+
+	    if (!(rec && rec.data)) return;
+	    let data = rec.data;
+	    if (!view.datastore) return;
+
+	    if (rec.parentNode.id !== 'root') {
+		me.forgetSnapshot(data);
+	    } else {
+		me.forgetGroup(data);
+	    }
+	},
+
 	downloadFile: function(tV, rI, cI, item, e, rec) {
 	    let me = this;
 	    let view = me.getView();
-- 
2.20.1