[pve-devel] [PATCH manager 31/49] lxc/Resources: cleanup & use new features from ObjectGrid

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Jan 23 11:05:48 CET 2018


Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
Reviewed-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/manager6/lxc/Resources.js | 87 ++++++++++---------------------------------
 1 file changed, 20 insertions(+), 67 deletions(-)

diff --git a/www/manager6/lxc/Resources.js b/www/manager6/lxc/Resources.js
index 0ed9c2ff..0d867892 100644
--- a/www/manager6/lxc/Resources.js
+++ b/www/manager6/lxc/Resources.js
@@ -5,22 +5,6 @@ Ext.define('PVE.lxc.RessourceView', {
 
     onlineHelp: 'pct_configuration',
 
-    renderKey: function(key, metaData, rec, rowIndex, colIndex, store) {
-	var me = this;
-	var rows = me.rows;
-	var rowdef = rows[key] || {};
-
-	metaData.tdAttr = "valign=middle";
-
-	if (rowdef.tdCls) {
-	    metaData.tdCls = rowdef.tdCls;
-	    if (rowdef.tdCls == 'pve-itype-icon-storage') {
-		var value = me.getObjectValue(key, '', true);
-	    }
-	}
-	return rowdef.header || key;
-    },
-
     initComponent : function() {
 	var me = this;
 	var i, confid;
@@ -43,7 +27,6 @@ Ext.define('PVE.lxc.RessourceView', {
 	    memory: {
 		header: gettext('Memory'),
 		editor: caps.vms['VM.Config.Memory'] ? 'PVE.lxc.MemoryEdit' : undefined,
-		never_delete: true,
 		defaultValue: 512,
 		tdCls: 'pve-itype-icon-memory',
 		renderer: function(value) {
@@ -53,7 +36,6 @@ Ext.define('PVE.lxc.RessourceView', {
 	    swap: {
 		header: gettext('Swap'),
 		editor: caps.vms['VM.Config.Memory'] ? 'PVE.lxc.MemoryEdit' : undefined,
-		never_delete: true,
 		defaultValue: 512,
 		tdCls: 'pve-itype-icon-swap',
 		renderer: function(value) {
@@ -62,7 +44,6 @@ Ext.define('PVE.lxc.RessourceView', {
 	    },
 	    cores: {
 		header: gettext('Cores'),
-		never_delete: true,
 		editor: caps.vms['VM.Config.CPU'] ? 'PVE.lxc.CPUEdit' : undefined,
 		defaultValue: '',
 		tdCls: 'pve-itype-icon-processor',
@@ -73,7 +54,6 @@ Ext.define('PVE.lxc.RessourceView', {
 	    },
 	    cpulimit: {
 		header: gettext('CPU limit'),
-		never_delete: true,
 		editor: caps.vms['VM.Config.CPU'] ? 'PVE.lxc.CPUEdit' : undefined,
 		defaultValue: 0,
 		tdCls: 'pve-itype-icon-processor',
@@ -84,7 +64,6 @@ Ext.define('PVE.lxc.RessourceView', {
 	    },
 	    cpuunits: {
 		header: gettext('CPU units'),
-		never_delete: true,
 		editor: caps.vms['VM.Config.CPU'] ? 'PVE.lxc.CPUEdit' : undefined,
 		defaultValue: 1024,
 		tdCls: 'pve-itype-icon-processor'
@@ -120,40 +99,12 @@ Ext.define('PVE.lxc.RessourceView', {
 	    };
 	}
 
-	var reload = function() {
-	    me.rstore.load();
-	};
-
 	var baseurl = 'nodes/' + nodename + '/lxc/' + vmid + '/config';
 
-	var sm = Ext.create('Ext.selection.RowModel', {});
-
-	var run_editor = function() {
-	    var rec = sm.getSelection()[0];
-	    if (!rec) {
-		return;
-	    }
-
-	    var rowdef = rows[rec.data.key];
-	    if (!rowdef.editor) {
-		return;
-	    }
-
-	    var editor = rowdef.editor;
-
-	    var win = Ext.create(editor, {
-		pveSelNode: me.pveSelNode,
-		confid: rec.data.key,
-		unprivileged: me.getObjectValue('unprivileged'),
-		url: '/api2/extjs/' + baseurl
-	    });
-
-	    win.show();
-	    win.on('destroy', reload);
-	};
+	me.selModel = Ext.create('Ext.selection.RowModel', {});
 
 	var run_resize = function() {
-	    var rec = sm.getSelection()[0];
+	    var rec = me.selModel.getSelection()[0];
 	    if (!rec) {
 		return;
 	    }
@@ -165,8 +116,6 @@ Ext.define('PVE.lxc.RessourceView', {
 	    });
 
 	    win.show();
-
-	    win.on('destroy', reload);
 	};
 
 	var run_remove = function(b, e, rec) {
@@ -177,9 +126,6 @@ Ext.define('PVE.lxc.RessourceView', {
 		params: {
 		    'delete': rec.data.key
 		},
-		callback: function() {
-		    reload();
-		},
 		failure: function (response, opts) {
 		    Ext.Msg.alert('Error', response.htmlStatus);
 		}
@@ -188,7 +134,7 @@ Ext.define('PVE.lxc.RessourceView', {
 
 	var edit_btn = new Proxmox.button.Button({
 	    text: gettext('Edit'),
-	    selModel: sm,
+	    selModel: me.selModel,
 	    disabled: true,
 	    enableFn: function(rec) {
 		if (!rec) {
@@ -197,19 +143,19 @@ Ext.define('PVE.lxc.RessourceView', {
 		var rowdef = rows[rec.data.key];
 		return !!rowdef.editor;
 	    },
-	    handler: run_editor
+	    handler: me.run_editor
 	});
 
 	var resize_btn = new Proxmox.button.Button({
 	    text: gettext('Resize disk'),
-	    selModel: sm,
+	    selModel: me.selModel,
 	    disabled: true,
 	    handler: run_resize
 	});
 
 	var remove_btn = new Proxmox.button.Button({
 	    text: gettext('Remove'),
-	    selModel: sm,
+	    selModel: me.selModel,
 	    disabled: true,
 	    dangerous: true,
 	    confirmMsg: function(rec) {
@@ -225,8 +171,7 @@ Ext.define('PVE.lxc.RessourceView', {
 	});
 
 	var set_button_status = function() {
-	    var sm = me.getSelectionModel();
-	    var rec = sm.getSelection()[0];
+	    var rec = me.selModel.getSelection()[0];
 
 	    if (!rec) {
 		edit_btn.disable();
@@ -256,7 +201,8 @@ Ext.define('PVE.lxc.RessourceView', {
 	
 	Ext.apply(me, {
 	    url: '/api2/json/' + baseurl,
-	    selModel: sm,
+	    selModel: me.selModel,
+	    interval: 2000,
 	    cwidth1: 170,
 	    tbar: [
 		{
@@ -273,7 +219,6 @@ Ext.define('PVE.lxc.RessourceView', {
 					unprivileged: me.getObjectValue('unprivileged'),
 					pveSelNode: me.pveSelNode
 				    });
-				    win.on('destroy', reload);
 				    win.show();
 				}
 			    }
@@ -285,14 +230,22 @@ Ext.define('PVE.lxc.RessourceView', {
 		resize_btn
 	    ],
 	    rows: rows,
+	    editorConfig: {
+		pveSelNode: me.pveSelNode,
+		url: '/api2/extjs/' + baseurl
+	    },
 	    listeners: {
-		afterrender: reload,
-		activate: reload,
-		itemdblclick: run_editor,
+		itemdblclick: me.run_editor,
 		selectionchange: set_button_status
 	    }
 	});
 
 	me.callParent();
+
+	me.on('activate', me.rstore.startUpdate);
+	me.on('destroy', me.rstore.stopUpdate);
+	me.on('deactivate', me.rstore.stopUpdate);
+
+	Ext.apply(me.editorConfig, { unprivileged: me.getObjectValue('unprivileged') });
     }
 });
-- 
2.14.2





More information about the pve-devel mailing list