[pve-devel] [PATCH manager] move cmdmenu function and use it in poolmemberlist

Dominik Csapak d.csapak at proxmox.com
Thu May 19 14:27:05 CEST 2016


we had the function for the cmdmenu at two
different places (resourcetree and resourcegrid)

move it to PVE.Utils to reuse code, and
also use it in pool members list

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/manager6/Utils.js             | 32 +++++++++++++++++++++++++++++++-
 www/manager6/grid/PoolMembers.js  |  1 +
 www/manager6/grid/ResourceGrid.js | 31 +------------------------------
 www/manager6/tree/ResourceTree.js | 31 +------------------------------
 4 files changed, 34 insertions(+), 61 deletions(-)

diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index 7fd0298..992ae85 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -1184,7 +1184,37 @@ Ext.define('PVE.Utils', { statics: {
 	    }
 	    PVE.Utils.setErrorMask(me, msg);
 	});
-    }
+    },
 
+    createCmdMenu: function(v, record, item, index, event) {
+	event.stopEvent();
+	v.select(record);
+	var menu;
+
+	if (record.data.type === 'qemu' && !record.data.template) {
+	    menu = Ext.create('PVE.qemu.CmdMenu', {
+		pveSelNode: record
+	    });
+	} else if (record.data.type === 'qemu' && record.data.template) {
+	    menu = Ext.create('PVE.qemu.TemplateMenu', {
+		pveSelNode: record
+	    });
+	} else if (record.data.type === 'lxc' && !record.data.template) {
+	    menu = Ext.create('PVE.lxc.CmdMenu', {
+		pveSelNode: record
+	    });
+	} else if (record.data.type === 'lxc' && record.data.template) {
+	    /* since clone does not work reliably, disable for now
+	    menu = Ext.create('PVE.lxc.TemplateMenu', {
+		pveSelNode: record
+	    });
+	    */
+	    return;
+	} else {
+	    return;
+	}
+
+	menu.showAt(event.getXY());
+    }
 }});
 
diff --git a/www/manager6/grid/PoolMembers.js b/www/manager6/grid/PoolMembers.js
index aec15be..6c7164d 100644
--- a/www/manager6/grid/PoolMembers.js
+++ b/www/manager6/grid/PoolMembers.js
@@ -237,6 +237,7 @@ Ext.define('PVE.grid.PoolMembers', {
             },
             columns: coldef,
 	    listeners: {
+		itemcontextmenu: PVE.Utils.createCmdMenu,
 		activate: reload
 	    }
 	});
diff --git a/www/manager6/grid/ResourceGrid.js b/www/manager6/grid/ResourceGrid.js
index 935bdd0..ad6f05d 100644
--- a/www/manager6/grid/ResourceGrid.js
+++ b/www/manager6/grid/ResourceGrid.js
@@ -186,36 +186,7 @@ Ext.define('PVE.grid.ResourceGrid', {
 		stripeRows: true
             },
 	    listeners: {
-		itemcontextmenu: function(v, record, item, index, event) {
-		    event.stopEvent();
-		    v.select(record);
-		    var menu;
-		    
-		    if (record.data.type === 'qemu' && !record.data.template) {
-			menu = Ext.create('PVE.qemu.CmdMenu', {
-			    pveSelNode: record
-			});
-		    } else if (record.data.type === 'qemu' && record.data.template) {
-			menu = Ext.create('PVE.qemu.TemplateMenu', {
-			    pveSelNode: record
-			});
-		    } else if (record.data.type === 'lxc' && !record.data.template) {
-			menu = Ext.create('PVE.lxc.CmdMenu', {
-			    pveSelNode: record
-			});
-		    } else if (record.data.type === 'lxc' && record.data.template) {
-			/* since clone does not work reliably, disable for now
-			menu = Ext.create('PVE.lxc.TemplateMenu', {
-			    pveSelNode: record
-			});
-			*/
-			return;
-		    } else {
-			return;
-		    }
-
-		    menu.showAt(event.getXY());
-		},
+		itemcontextmenu: PVE.Utils.createCmdMenu,
 		itemdblclick: function(v, record) {
 		    var ws = me.up('pveStdWorkspace');
 		    ws.selectById(record.data.id);
diff --git a/www/manager6/tree/ResourceTree.js b/www/manager6/tree/ResourceTree.js
index d94a63c..b15ed4f 100644
--- a/www/manager6/tree/ResourceTree.js
+++ b/www/manager6/tree/ResourceTree.js
@@ -375,36 +375,7 @@ Ext.define('PVE.tree.ResourceTree', {
             //rootVisible: false,
             //title: 'Resource Tree',
 	    listeners: {
-		itemcontextmenu: function(v, record, item, index, event) {
-		    event.stopEvent();
-		    //v.select(record);
-		    var menu;
-		    
-		    if (record.data.type === 'qemu' && !record.data.template) {
-			menu = Ext.create('PVE.qemu.CmdMenu', {
-			    pveSelNode: record
-			});
-		    } else if (record.data.type === 'qemu' && record.data.template) {
-			menu = Ext.create('PVE.qemu.TemplateMenu', {
-			    pveSelNode: record
-			});
-		    } else if (record.data.type === 'lxc' && !record.data.template) {
-			menu = Ext.create('PVE.lxc.CmdMenu', {
-			    pveSelNode: record
-			});
-		    } else if (record.data.type === 'lxc' && record.data.template) {
-			/* since clone does not work reliably, disable for now
-			menu = Ext.create('PVE.lxc.TemplateMenu', {
-			    pveSelNode: record
-			});
-			*/
-			return;
-		    } else {
-			return;
-		    }
-
-		    menu.showAt(event.getXY());
-		},
+		itemcontextmenu: PVE.Utils.createCmdMenu,
 		destroy: function() {
 		    rstore.un("load", updateTree);
 		},
-- 
2.1.4





More information about the pve-devel mailing list