[pve-devel] r6218 - in pve-manager/pve2/www/manager: . form qemu window

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Jul 1 13:53:29 CEST 2011


Author: dietmar
Date: 2011-07-01 13:53:29 +0200 (Fri, 01 Jul 2011)
New Revision: 6218

Added:
   pve-manager/pve2/www/manager/Parser.js
   pve-manager/pve2/www/manager/form/CacheTypeSelector.js
Modified:
   pve-manager/pve2/www/manager/Makefile.am
   pve-manager/pve2/www/manager/PVEUtils.js
   pve-manager/pve2/www/manager/form/ComboGrid.js
   pve-manager/pve2/www/manager/form/StorageSelector.js
   pve-manager/pve2/www/manager/qemu/HardwareView.js
   pve-manager/pve2/www/manager/window/Edit.js
Log:
impl. PVE.qemu.HDEdit (first try)


Modified: pve-manager/pve2/www/manager/Makefile.am
===================================================================
--- pve-manager/pve2/www/manager/Makefile.am	2011-07-01 07:31:42 UTC (rev 6217)
+++ pve-manager/pve2/www/manager/Makefile.am	2011-07-01 11:53:29 UTC (rev 6218)
@@ -2,6 +2,7 @@
 
 JSSRC= 				                 	\
 	PVEUtils.js					\
+	Parser.js					\
 	StateProvider.js				\
 	VNCConsole.js					\
 	data/TimezoneStore.js				\
@@ -29,6 +30,7 @@
 	form/CPUModelSelector.js			\
 	form/VNCKeyboardSelector.js			\
 	form/DisplaySelector.js				\
+	form/CacheTypeSelector.js			\
 	dc/Tasks.js					\
 	dc/Log.js					\
 	panel/StatusPanel.js				\

Modified: pve-manager/pve2/www/manager/PVEUtils.js
===================================================================
--- pve-manager/pve2/www/manager/PVEUtils.js	2011-07-01 07:31:42 UTC (rev 6217)
+++ pve-manager/pve2/www/manager/PVEUtils.js	2011-07-01 11:53:29 UTC (rev 6218)
@@ -207,7 +207,8 @@
 	var successFn = options.success;
 	var failureFn = options.failure;
 
-	options.url = '/api2/extjs' + options.url;
+	if (!options.url.match(/^\/api2/))
+	    options.url = '/api2/extjs' + options.url;
 
 	delete options.callback;
 

Added: pve-manager/pve2/www/manager/Parser.js
===================================================================
--- pve-manager/pve2/www/manager/Parser.js	                        (rev 0)
+++ pve-manager/pve2/www/manager/Parser.js	2011-07-01 11:53:29 UTC (rev 6218)
@@ -0,0 +1,72 @@
+// Some configuration values are complex strings - 
+// so we need parsers/generators for them. 
+
+Ext.define('PVE.Parser', { statics: {
+
+    // this class only contains static functions
+
+    parseQemuDrive: function(key, value) {
+	if (!(key && value))
+	    return;
+
+	var res = {};
+
+	var match_res = key.match(/^([^\d]+)(\d+)$/);
+	if (!match_res)
+	    return;
+
+	res['interface'] = match_res[1];
+	res['index'] = match_res[2];
+
+	var errors = false;
+	Ext.Array.each(value.split(','), function(p) {
+	    if (!p || p.match(/^\s*$/))
+		return; // continue
+	    var match_res = p.match(/^([a-z]+)=(.+)$/);
+	    if (!match_res) {
+		if (!p.match(/=/)) {
+		    res.file = p;
+		    return; // continue
+		}
+		errors = true;
+		return false; // break
+	    }
+	    var k = match_res[1];
+	    if (k === 'volume')
+		k = 'file';
+	    
+	    if (Ext.isDefined(res[k])) {
+		errors = true;
+		return false; // break
+	    }
+
+	    var v = match_res[2];
+	    
+	    if (k === 'cache' && v === 'off')
+		v = 'none';
+	    
+	    res[k] = v;
+	});
+
+	if (errors)
+	    return;
+	
+	return res;
+    },
+
+    printQemuDrive: function(drive) {
+
+	var drivestr = drive.file;
+
+	Ext.Object.each(drive, function(key, value) {
+	    if (!Ext.isDefined(value) || key === 'file' || 
+		key === 'index' || key === 'interface')
+		return; // continue
+
+	    drivestr += ',' + key + '=' + value;
+	});
+
+	return drivestr;
+    }
+
+}});

Added: pve-manager/pve2/www/manager/form/CacheTypeSelector.js
===================================================================
--- pve-manager/pve2/www/manager/form/CacheTypeSelector.js	                        (rev 0)
+++ pve-manager/pve2/www/manager/form/CacheTypeSelector.js	2011-07-01 11:53:29 UTC (rev 6218)
@@ -0,0 +1,17 @@
+Ext.define('PVE.form.CacheTypeSelector', {
+    extend: 'PVE.form.KVComboBox',
+    alias: ['widget.CacheTypeSelector'],
+  
+    initComponent: function() {
+	var me = this;
+
+	me.data = [
+	    ['', 'Default (no cache)'],
+	    ['writethrough', 'Write through'],
+	    ['writeback', 'Write back'],
+	    ['none', 'No cache']
+	];
+
+	me.callParent();
+    }
+});

Modified: pve-manager/pve2/www/manager/form/ComboGrid.js
===================================================================
--- pve-manager/pve2/www/manager/form/ComboGrid.js	2011-07-01 07:31:42 UTC (rev 6217)
+++ pve-manager/pve2/www/manager/form/ComboGrid.js	2011-07-01 11:53:29 UTC (rev 6218)
@@ -74,11 +74,14 @@
         me.callParent();
 
 	me.store.on('beforeload', function() {
-	    me.up('form').setLoading(true, true);
+	    var form = me.up('form');
+	    if (form)
+		form.setLoading(true, true);
 	});
 
 	// hack: autoSelect does not work
 	me.store.on('load', function(store, r, success, o) {
+	    var form = me.up('form');
 	    if (success) {
 		var def = me.getValue();
 		if (!def || !store.findRecord(me.valueField, def)) {
@@ -91,7 +94,8 @@
 		    }
 		}
 	    }
-	    me.up('form').setLoading(false);
+	    if (form)
+		form.setLoading(false);
 	});
     }
 });
\ No newline at end of file

Modified: pve-manager/pve2/www/manager/form/StorageSelector.js
===================================================================
--- pve-manager/pve2/www/manager/form/StorageSelector.js	2011-07-01 07:31:42 UTC (rev 6217)
+++ pve-manager/pve2/www/manager/form/StorageSelector.js	2011-07-01 11:53:29 UTC (rev 6218)
@@ -29,6 +29,9 @@
     initComponent: function() {
 	var me = this;
 
+	var nodename = me.nodename;
+	me.nodename = undefined; 
+
 	var store = Ext.create('Ext.data.Store', {
 	    fields: [ 'storage', 'active', 'type', 'used', 'total' ],
 	    autoDestory: true
@@ -70,6 +73,7 @@
 
         me.callParent();
 
-	me.setNodename(me.nodename);
+	if (nodename)
+	    me.setNodename(nodename);
     }
 });
\ No newline at end of file

Modified: pve-manager/pve2/www/manager/qemu/HardwareView.js
===================================================================
--- pve-manager/pve2/www/manager/qemu/HardwareView.js	2011-07-01 07:31:42 UTC (rev 6217)
+++ pve-manager/pve2/www/manager/qemu/HardwareView.js	2011-07-01 11:53:29 UTC (rev 6218)
@@ -1,3 +1,105 @@
+Ext.define('PVE.qemu.HDEdit', {
+    extend: 'PVE.window.Edit',
+
+    submit: function(formpanel) {
+	var me = this;
+
+	var field = me.down('field[name=_cache]');
+	var value = field.getValue();
+	me.drive.cache = value ? field.getValue() : undefined;
+	
+	field = me.down('field[name=_nobackup]');
+	value = field.getValue();
+	me.drive.backup = value ? 'no' : undefined;
+
+	var params = {};
+
+	params[me.confid] = PVE.Parser.printQemuDrive(me.drive);
+
+	PVE.Utils.API2Request({
+	    url: me.url,
+	    method: 'PUT',
+	    params: params,
+	    failure: function(response, opts) {
+		Ext.Msg.alert('Error', response.htmlStatus);
+	    },
+	    success: function(response, opts) {
+		me.close();
+	    }
+	});
+	
+    },
+
+    initComponent : function() {
+	var me = this;
+
+	var nodename = me.pveSelNode.data.node;
+	if (!nodename) 
+	    throw "no node name specified";
+
+	if (!me.confid)
+	    throw "create not implemented";
+	    
+	me.column1 = [
+	    {
+		xtype: 'displayfield',
+                fieldLabel: 'Image',
+                name: '_file'
+ 	    },
+	    {
+		xtype: 'CacheTypeSelector',
+		name: '_cache',
+		value: '',
+		fieldLabel: 'Cache',
+	    }
+	];
+
+	me.column2 = [
+	    {
+		xtype: 'pvecheckbox',
+                fieldLabel: 'Exclude from backup',
+		labelWidth: 130,
+                name: '_nobackup'
+ 	    }
+	];
+
+	Ext.applyIf(me, {
+	    title: "Edit Harddisk settings (" + me.confid + ")",
+	    fieldDefaults: {
+		labelWidth: 70
+	    }
+ 	});
+
+	me.callParent();
+
+	me.load({
+	    success: function(form, action) {
+		var value = action.result.data[me.confid];
+		me.drive = PVE.Parser.parseQemuDrive(me.confid, value);
+		if (!me.drive) {
+		    Ext.Msg.alert('Error', 'Unable to parse drive options');
+		    me.close();
+		    return;
+		}
+
+		var field = me.down('field[name=_file]');
+		field.setValue(me.drive.file);
+		field.resetOriginalValue();
+
+		field = me.down('field[name=_cache]');
+		field.setValue(me.drive.cache || '');
+		field.resetOriginalValue();
+
+		if (me.drive.backup === 'no') {
+		    field = me.down('field[name=_nobackup]');
+		    field.setValue(true);
+		    field.resetOriginalValue();
+		}
+	    }
+	});
+    }
+});
+
 Ext.define('PVE.qemu.MemoryEdit', {
     extend: 'PVE.window.Edit',
 
@@ -225,6 +327,7 @@
 	    confid = "ide" + i;
 	    rows[confid] = {
 		tdCls: 'pve-itype-icon-storage',
+		editor: 'PVE.qemu.HDEdit',
 		header: 'Hard Disk ' + '(' + confid +')'
 	    };
 	}
@@ -232,6 +335,7 @@
 	    confid = "scsi" + i;
 	    rows[confid] = {
 		tdCls: 'pve-itype-icon-storage',
+		editor: 'PVE.qemu.HDEdit',
 		header: 'Hard Disk ' + '(' + confid +')'
 	    };
 	}
@@ -239,6 +343,7 @@
 	    confid = "virtio" + i;
 	    rows[confid] = {
 		tdCls: 'pve-itype-icon-storage',
+		editor: 'PVE.qemu.HDEdit',
 		header: 'Hard Disk ' + '(' + confid +')'
 	    };
 	}
@@ -270,6 +375,7 @@
 
 	    var win = Ext.create(rowdef.editor, {
 		pveSelNode: me.pveSelNode,
+		confid: rec.data.key,
 		url: '/api2/extjs/' + baseurl
 	    });
 

Modified: pve-manager/pve2/www/manager/window/Edit.js
===================================================================
--- pve-manager/pve2/www/manager/window/Edit.js	2011-07-01 07:31:42 UTC (rev 6217)
+++ pve-manager/pve2/www/manager/window/Edit.js	2011-07-01 11:53:29 UTC (rev 6218)
@@ -3,6 +3,19 @@
 
     resizable: false,
 
+    submit: function(formpanel) {
+	var me = this;
+
+	formpanel.submit({
+	    success: function() { 
+		me.close();
+	    },
+	    failure: function(form, action) {
+		Ext.Msg.alert('Error', PVE.Utils.extractFormActionError(action));
+	    }
+	});
+    },
+
     load: function(options) {
 	var me = this;
 
@@ -77,14 +90,7 @@
 	    text: 'OK',
 	    disabled: true,
 	    handler: function() {
-		formpanel.submit({
-		    success: function() { 
-			me.close();
-		    },
-		    failure: function(form, action) {
-			Ext.Msg.alert('Error', PVE.Utils.extractFormActionError(action));
-		    }
-		});
+		me.submit(formpanel);
 	    }
 	});
 




More information about the pve-devel mailing list