[pve-devel] [PATCH manager v2 2/3] accept type 'node' for NotesView and refactor it

Dominik Csapak d.csapak at proxmox.com
Fri May 25 10:31:55 CEST 2018


so that we can use it for the notes of a node,
also changes the configuration to a static declaration,
this adds an 'edit' button for the node panel

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes from v1:
* move the configuration to the static declaration of the class
* introduce a run_editor function and reuse this
* add a toolbar with an 'edit' button which is only shown for nodes
 www/manager6/panel/NotesView.js | 88 +++++++++++++++++++++++++----------------
 1 file changed, 53 insertions(+), 35 deletions(-)

diff --git a/www/manager6/panel/NotesView.js b/www/manager6/panel/NotesView.js
index b420d8c8..94408837 100644
--- a/www/manager6/panel/NotesView.js
+++ b/www/manager6/panel/NotesView.js
@@ -7,9 +7,33 @@ Ext.define('PVE.panel.NotesView', {
     bodyPadding: 10,
     scrollable: true,
 
+    tbar: {
+	itemId: 'tbar',
+	hidden: true,
+	items: [
+	    {
+		text: gettext('Edit'),
+		handler: function() {
+		    var me = this.up('panel');
+		    me.run_editor();
+		}
+	    }
+	]
+    },
+
+    run_editor: function() {
+	var me = this;
+	var win = Ext.create('PVE.window.NotesEdit', {
+	    pveSelNode: me.pveSelNode,
+	    url: me.url
+	});
+	win.show();
+	win.on('destroy', me.load, me);
+    },
+
     load: function() {
 	var me = this;
-	
+
 	Proxmox.Utils.API2Request({
 	    url: me.url,
 	    waitMsgTarget: me,
@@ -23,6 +47,20 @@ Ext.define('PVE.panel.NotesView', {
 	});
     },
 
+    listeners: {
+	render: function(c) {
+	    var me = this;
+	    me.getEl().on('dblclick', me.run_editor, me);
+	}
+    },
+
+    tools: [{
+	type: 'gear',
+	handler: function() {
+	    me.run_editor();
+	}
+    }],
+
     initComponent : function() {
 	var me = this;
 
@@ -31,49 +69,29 @@ Ext.define('PVE.panel.NotesView', {
 	    throw "no node name specified";
 	}
 
+	var type = me.pveSelNode.data.type;
+	if (!Ext.Array.contains(['node', 'qemu', 'lxc'], type)) {
+	    throw 'invalid type specified';
+	}
+
 	var vmid = me.pveSelNode.data.vmid;
-	if (!vmid) {
+	if (!vmid && type !== 'node') {
 	    throw "no VM ID specified";
 	}
 
-	var vmtype = me.pveSelNode.data.type;
-	var url;
+	me.url = '/api2/extjs/nodes/' + nodename + '/';
 
-	if (vmtype === 'qemu') {
-	    me.url = '/api2/extjs/nodes/' + nodename + '/qemu/' + vmid + '/config';
-	} else if (vmtype === 'lxc') {
-	    me.url = '/api2/extjs/nodes/' + nodename + '/lxc/' + vmid + '/config';
-	} else {
-	    throw "unknown vm type '" + vmtype + "'";
+	// add the type specific path if qemu/lxc
+	if (type === 'qemu' || type === 'lxc') {
+	    me.url += type + '/' + vmid + '/';
 	}
 
-	Ext.apply(me, {
-	    listeners: {
-		render: function(c) {
-		    c.el.on('dblclick', function() { 
-			var win = Ext.create('PVE.window.NotesEdit', {
-			    pveSelNode: me.pveSelNode,
-			    url: me.url
-			});
-			win.show();
-			win.on('destroy', me.load, me);
-		    });
-		}
-	    },
-	    tools: [{
-		type: 'gear',
-		handler: function() {
-		    var win = Ext.create('PVE.window.NotesEdit', {
-			pveSelNode: me.pveSelNode,
-			url: me.url
-		    });
-		    win.show();
-		    win.on('destroy', me.load, me);
-		}
-	    }]
-	});
+	me.url += 'config';
 
 	me.callParent();
+	if (type === 'node') {
+	    me.down('#tbar').setVisible(true);
+	}
 	me.load();
     }
 });
-- 
2.11.0





More information about the pve-devel mailing list