From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager 11/14] create ImageView and use it for VM and CT images
Date: Wed, 2 Sep 2020 13:03:34 +0200 [thread overview]
Message-ID: <20200902110337.25004-12-f.ebner@proxmox.com> (raw)
In-Reply-To: <20200902110337.25004-1-f.ebner@proxmox.com>
The enableFns that were responsible for switching
between the image remove button and the standard remove button
are not needed anymore.
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
use --color-moved=zebra --color-moved-ws=ignore-all-space for
better readability.
www/manager6/Makefile | 1 +
www/manager6/storage/Browser.js | 4 +-
www/manager6/storage/ContentView.js | 64 ++----------------------
www/manager6/storage/ImageView.js | 76 +++++++++++++++++++++++++++++
4 files changed, 82 insertions(+), 63 deletions(-)
create mode 100644 www/manager6/storage/ImageView.js
diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index 26c91bef..4b9dcf58 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -225,6 +225,7 @@ JSSRC= \
storage/ContentView.js \
storage/DirEdit.js \
storage/GlusterFsEdit.js \
+ storage/ImageView.js \
storage/IScsiEdit.js \
storage/LVMEdit.js \
storage/LvmThinEdit.js \
diff --git a/www/manager6/storage/Browser.js b/www/manager6/storage/Browser.js
index 4536392c..f0d81418 100644
--- a/www/manager6/storage/Browser.js
+++ b/www/manager6/storage/Browser.js
@@ -59,7 +59,7 @@ Ext.define('PVE.storage.Browser', {
}
if (contents.includes('images')) {
items.push({
- xtype: 'pveStorageContentView',
+ xtype: 'pveStorageImageView',
title: PVE.Utils.contentTypes['images'],
iconCls: 'fa fa-th',
itemId: 'contentImages',
@@ -78,7 +78,7 @@ Ext.define('PVE.storage.Browser', {
}
if (contents.includes('rootdir')) {
items.push({
- xtype: 'pveStorageContentView',
+ xtype: 'pveStorageImageView',
title: PVE.Utils.contentTypes['rootdir'],
iconCls: 'fa fa-th',
itemId: 'contentRootdir',
diff --git a/www/manager6/storage/ContentView.js b/www/manager6/storage/ContentView.js
index c78ac398..f9e28b97 100644
--- a/www/manager6/storage/ContentView.js
+++ b/www/manager6/storage/ContentView.js
@@ -252,83 +252,25 @@ Ext.define('PVE.storage.ContentView', {
}
});
- var imageRemoveButton;
var removeButton = Ext.create('Proxmox.button.StdRemoveButton',{
selModel: sm,
delay: 5,
- enableFn: function(rec) {
- if (rec && rec.data.content !== 'images' &&
- rec.data.content !== 'rootdir') {
- imageRemoveButton.setVisible(false);
- removeButton.setVisible(true);
- return true;
- }
- return false;
- },
callback: function() {
reload();
},
baseurl: baseurl + '/'
});
- imageRemoveButton = Ext.create('Proxmox.button.Button',{
- selModel: sm,
- hidden: true,
- text: gettext('Remove'),
- enableFn: function(rec) {
- if (rec && (rec.data.content === 'images' ||
- rec.data.content === 'rootdir')) {
- removeButton.setVisible(false);
- imageRemoveButton.setVisible(true);
- return true;
- }
- return false;
- },
- handler: function(btn, event, rec) {
- var url = baseurl + '/' + rec.data.volid;
- var vmid = rec.data.vmid;
-
- var store = PVE.data.ResourceStore;
-
- if (vmid && store.findVMID(vmid)) {
- var guest_node = store.guestNode(vmid);
- var storage_path = 'storage/' + nodename + '/' + storage;
-
- // allow to delete local backed images if a VMID exists on another node.
- if (store.storageIsShared(storage_path) || guest_node == nodename) {
- var msg = Ext.String.format(
- gettext("Cannot remove image, a guest with VMID '{0}' exists!"), vmid);
- msg += '<br />' + gettext("You can delete the image from the guest's hardware pane");
-
- Ext.Msg.show({
- title: gettext('Cannot remove disk image.'),
- icon: Ext.Msg.ERROR,
- msg: msg
- });
- return;
- }
- }
- var win = Ext.create('PVE.window.SafeDestroy', {
- title: Ext.String.format(gettext("Destroy '{0}'"), rec.data.volid),
- showProgress: true,
- url: url,
- item: { type: 'Image', id: vmid }
- }).show();
- win.on('destroy', function() {
- reload();
- });
- }
- });
-
if (!me.tbar) {
me.tbar = [];
}
if (me.useUploadButton) {
me.tbar.push(uploadButton);
}
+ if (!me.useCustomRemoveButton) {
+ me.tbar.push(removeButton);
+ }
me.tbar.push(
- removeButton,
- imageRemoveButton,
'->',
gettext('Search') + ':', ' ',
{
diff --git a/www/manager6/storage/ImageView.js b/www/manager6/storage/ImageView.js
new file mode 100644
index 00000000..97dae567
--- /dev/null
+++ b/www/manager6/storage/ImageView.js
@@ -0,0 +1,76 @@
+Ext.define('PVE.storage.ImageView', {
+ extend: 'PVE.storage.ContentView',
+
+ alias: 'widget.pveStorageImageView',
+
+ initComponent: function() {
+ var me = this;
+
+ var nodename = me.nodename = me.pveSelNode.data.node;
+ if (!me.nodename) {
+ throw "no node name specified";
+ }
+
+ var storage = me.storage = me.pveSelNode.data.storage;
+ if (!me.storage) {
+ throw "no storage ID specified";
+ }
+
+ if (!me.content || (me.content !== 'images' && me.content !== 'rootdir')) {
+ throw "content needs to be either 'images' or 'rootdir'";
+ }
+
+ var sm = me.sm = Ext.create('Ext.selection.RowModel', {});
+
+ var reload = function() {
+ me.store.load();
+ }
+
+ me.tbar = [
+ {
+ xtype: 'proxmoxButton',
+ selModel: sm,
+ text: gettext('Remove'),
+ disabled: true,
+ handler: function(btn, event, rec) {
+ var url = "/nodes/" + nodename + "/storage/" + storage +
+ "/content" + '/' + rec.data.volid;
+ var vmid = rec.data.vmid;
+
+ var store = PVE.data.ResourceStore;
+
+ if (vmid && store.findVMID(vmid)) {
+ var guest_node = store.guestNode(vmid);
+ var storage_path = 'storage/' + nodename + '/' + storage;
+
+ // allow to delete local backed images if a VMID exists on another node.
+ if (store.storageIsShared(storage_path) || guest_node == nodename) {
+ var msg = Ext.String.format(
+ gettext("Cannot remove image, a guest with VMID '{0}' exists!"), vmid);
+ msg += '<br />' + gettext("You can delete the image from the guest's hardware pane");
+
+ Ext.Msg.show({
+ title: gettext('Cannot remove disk image.'),
+ icon: Ext.Msg.ERROR,
+ msg: msg
+ });
+ return;
+ }
+ }
+ var win = Ext.create('PVE.window.SafeDestroy', {
+ title: Ext.String.format(gettext("Destroy '{0}'"), rec.data.volid),
+ showProgress: true,
+ url: url,
+ item: { type: 'Image', id: vmid }
+ }).show();
+ win.on('destroy', function() {
+ reload();
+ });
+ }
+ },
+ ];
+ me.useCustomRemoveButton = true;
+
+ me.callParent();
+ },
+});
--
2.20.1
next prev parent reply other threads:[~2020-09-02 11:04 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-02 11:03 [pve-devel] [PATCH-SERIES/RFC manager 00/14] split up content view into a view for each type Fabian Ebner
2020-09-02 11:03 ` [pve-devel] [PATCH manager 01/14] config panel: allow new nodes to be added later Fabian Ebner
2020-09-02 11:03 ` [pve-devel] [PATCH manager 02/14] storage panel/browser: use insertNodes function Fabian Ebner
2020-09-02 11:03 ` [pve-devel] [PATCH manager 03/14] use separate view for each content type Fabian Ebner
2020-09-02 11:03 ` [pve-devel] [PATCH manager 04/14] remove the now unneccessary grouping Fabian Ebner
2020-09-02 11:03 ` [pve-devel] [PATCH manager 05/14] content view: allow specifying title bar elements for init Fabian Ebner
2020-09-02 11:03 ` [pve-devel] [PATCH manager 06/14] turn nodename, storage, sm into object variables Fabian Ebner
2020-09-02 11:03 ` [pve-devel] [PATCH manager 07/14] add upload button conditionally Fabian Ebner
2020-09-02 11:03 ` [pve-devel] [PATCH manager 08/14] create and use template view Fabian Ebner
2020-09-02 11:03 ` [pve-devel] [PATCH manager 09/14] create and use backup view Fabian Ebner
2020-09-02 11:03 ` [pve-devel] [PATCH manager 10/14] get rid of unneccessary enableFns Fabian Ebner
2020-09-02 11:03 ` Fabian Ebner [this message]
2020-09-02 11:03 ` [pve-devel] [PATCH manager 12/14] simplify reload call Fabian Ebner
2020-09-02 11:03 ` [pve-devel] [RFC manager 13/14] content view: allow specifying which columns to show on init Fabian Ebner
2020-09-02 11:03 ` [pve-devel] [PATCH manager 14/14] backup view: add prune window Fabian Ebner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200902110337.25004-12-f.ebner@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.