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 50949B86D4
 for <pbs-devel@lists.proxmox.com>; Tue,  5 Dec 2023 11:54:18 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 2917D192E0
 for <pbs-devel@lists.proxmox.com>; Tue,  5 Dec 2023 11:53:48 +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
 for <pbs-devel@lists.proxmox.com>; Tue,  5 Dec 2023 11:53:47 +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 CBB7244C3D
 for <pbs-devel@lists.proxmox.com>; Tue,  5 Dec 2023 11:53:46 +0100 (CET)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Tue,  5 Dec 2023 11:53:45 +0100
Message-Id: <20231205105345.1656325-5-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20231205105345.1656325-1-d.csapak@proxmox.com>
References: <20231205105345.1656325-1-d.csapak@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.018 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 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
 T_SCC_BODY_TEXT_LINE    -0.01 -
Subject: [pbs-devel] [PATCH proxmox-backup v2 4/4] ui: datastore content:
 add 'more actions' menu to actions
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, 05 Dec 2023 10:54:18 -0000

and move change owner and change protection there, since these are not
that often used. Also add the 'Show Information' action there for
snapshots, as this was not available via actions.

Refactor the menu creation for this.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 www/datastore/Content.js | 110 ++++++++++++++++++++++-----------------
 1 file changed, 61 insertions(+), 49 deletions(-)

diff --git a/www/datastore/Content.js b/www/datastore/Content.js
index f715f814..8f063287 100644
--- a/www/datastore/Content.js
+++ b/www/datastore/Content.js
@@ -806,6 +806,48 @@ Ext.define('PBS.DataStoreContent', {
 	    }).show();
 	},
 
+	onMoreActions: function(panel, rI, cI, item, event, record) {
+	    this.showContextMenu(panel, record, event, false);
+	},
+
+	showContextMenu: function(panel, record, event, rightClick) {
+	    let me = this;
+	    event.stopEvent();
+	    let menu;
+	    let view = me.getView();
+	    let createControllerCallback = function(name) {
+		return function() {
+		    me[name](view, undefined, undefined, undefined, undefined, record);
+		};
+	    };
+	    if (record.data.ty === 'group') {
+		let params = {
+		    title: gettext('Group'),
+		    onChangeOwner: createControllerCallback('onChangeOwner'),
+		};
+		if (rightClick) {
+		    params.onVerify = createControllerCallback('onVerify');
+		    params.onPrune = createControllerCallback('onPrune');
+		    params.onForget = createControllerCallback('onForget');
+		}
+		menu = Ext.create('PBS.datastore.GroupCmdMenu', params);
+	    } else if (record.data.ty === 'dir') {
+		let params = {
+		    title: gettext('Snapshot'),
+		    onProtectionChange: createControllerCallback('onProtectionChange'),
+		    onShowInformation: createControllerCallback('onShowInformation'),
+		};
+		if (rightClick) {
+		    params.onVerify = createControllerCallback('onVerify');
+		    params.onForget = createControllerCallback('onForget');
+		}
+		menu = Ext.create('PBS.datastore.SnapshotCmdMenu', params);
+	    }
+	    if (menu) {
+		menu.showAt(event.getXY());
+	    }
+	},
+
 	filter: function(item, value) {
 	    if (item.data.text.indexOf(value) !== -1) {
 		return true;
@@ -882,35 +924,7 @@ Ext.define('PBS.DataStoreContent', {
 	    }
 	},
 	itemcontextmenu: function(panel, record, item, index, event) {
-	    event.stopEvent();
-	    let menu;
-	    let view = panel.up('pbsDataStoreContent');
-	    let controller = view.getController();
-	    let createControllerCallback = function(name) {
-		return function() {
-		    controller[name](view, undefined, undefined, undefined, undefined, record);
-		};
-	    };
-	    if (record.data.ty === 'group') {
-		menu = Ext.create('PBS.datastore.GroupCmdMenu', {
-		    title: gettext('Group'),
-		    onVerify: createControllerCallback('onVerify'),
-		    onChangeOwner: createControllerCallback('onChangeOwner'),
-		    onPrune: createControllerCallback('onPrune'),
-		    onForget: createControllerCallback('onForget'),
-		});
-	    } else if (record.data.ty === 'dir') {
-		menu = Ext.create('PBS.datastore.SnapshotCmdMenu', {
-		    title: gettext('Snapshot'),
-		    onVerify: createControllerCallback('onVerify'),
-		    onProtectionChange: createControllerCallback('onProtectionChange'),
-		    onShowInformation: createControllerCallback('onShowInformation'),
-		    onForget: createControllerCallback('onForget'),
-		});
-	    }
-	    if (menu) {
-		menu.showAt(event.getXY());
-	    }
+	    this.getController().showContextMenu(panel, record, event, true);
 	},
     },
 
@@ -1000,30 +1014,12 @@ Ext.define('PBS.DataStoreContent', {
 		        ? 'pve-icon-verify-lettering' : 'pmx-hidden',
 		    isActionDisabled: (v, r, c, i, rec) => !!rec.data.leaf,
                 },
-                {
-		    handler: 'onChangeOwner',
-		    getClass: (v, m, { data }) => data.ty === 'group' ? 'fa fa-user' : 'pmx-hidden',
-		    getTip: (v, m, rec) => Ext.String.format(gettext("Change owner of '{0}'"), v),
-		    isActionDisabled: (v, r, c, i, { data }) => data.ty !== 'group',
-                },
 		{
 		    handler: 'onPrune',
 		    getTip: (v, m, rec) => Ext.String.format(gettext("Prune '{0}'"), v),
 		    getClass: (v, m, { data }) => data.ty === 'group' ? 'fa fa-scissors' : 'pmx-hidden',
 		    isActionDisabled: (v, r, c, i, { data }) => data.ty !== 'group',
 		},
-		{
-		    handler: 'onProtectionChange',
-		    getTip: (v, m, rec) => Ext.String.format(gettext("Change protection of '{0}'"), v),
-		    getClass: (v, m, rec) => {
-			if (rec.data.ty === 'dir') {
-			    let extraCls = rec.data.protected ? 'good' : 'faded';
-			    return `fa fa-shield ${extraCls}`;
-			}
-			return 'pmx-hidden';
-		    },
-		    isActionDisabled: (v, r, c, i, rec) => rec.data.ty !== 'dir',
-		},
 		{
 		    handler: 'onForget',
 		    getTip: (v, m, { data }) => {
@@ -1044,6 +1040,12 @@ Ext.define('PBS.DataStoreContent', {
 		        : 'pmx-hidden',
 		    isActionDisabled: (v, r, c, i, { data }) => false,
 		},
+		{
+		    handler: 'onMoreActions',
+		    getTip: (v, m, { data }) => gettext('Show more actions'),
+		    getClass: (v, m, { data }) => data.ty === 'group' || data.ty === 'dir' ? 'fa fa-bars' : 'pmx-hidden',
+		    isActionDisabled: (v, r, c, i, { data }) => data.ty !== 'group' && data.ty !== 'dir',
+		},
 		{
 		    handler: 'downloadFile',
 		    getTip: (v, m, rec) => Ext.String.format(gettext("Download '{0}'"), v),
@@ -1325,7 +1327,12 @@ Ext.define('PBS.datastore.GroupCmdMenu', {
 		hidden: '{!onPrune}',
 	    },
 	},
-	{ xtype: 'menuseparator' },
+	{
+	    xtype: 'menuseparator',
+	    cbind: {
+		hidden: '{!onForget}',
+	    },
+	},
 	{
 	    text: gettext('Remove'),
 	    iconCls: 'fa critical fa-trash-o',
@@ -1374,7 +1381,12 @@ Ext.define('PBS.datastore.SnapshotCmdMenu', {
 		disabled: '{!onShowInformation}',
 	    },
 	},
-	{ xtype: 'menuseparator' },
+	{
+	    xtype: 'menuseparator',
+	    cbind: {
+		hidden: '{!onForget}',
+	    },
+	},
 	{
 	    text: gettext('Remove'),
 	    iconCls: 'fa critical fa-trash-o',
-- 
2.30.2