[pve-devel] r6219 - in pve-manager/pve2/www/manager: qemu window

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Jul 1 15:07:22 CEST 2011


Author: dietmar
Date: 2011-07-01 15:07:22 +0200 (Fri, 01 Jul 2011)
New Revision: 6219

Modified:
   pve-manager/pve2/www/manager/qemu/HardwareView.js
   pve-manager/pve2/www/manager/window/Edit.js
Log:
impl. PVE.qemu.HDCreate (first try)


Modified: pve-manager/pve2/www/manager/qemu/HardwareView.js
===================================================================
--- pve-manager/pve2/www/manager/qemu/HardwareView.js	2011-07-01 11:53:29 UTC (rev 6218)
+++ pve-manager/pve2/www/manager/qemu/HardwareView.js	2011-07-01 13:07:22 UTC (rev 6219)
@@ -6,7 +6,7 @@
 
 	var field = me.down('field[name=_cache]');
 	var value = field.getValue();
-	me.drive.cache = value ? field.getValue() : undefined;
+	me.drive.cache = value ? value : undefined;
 	
 	field = me.down('field[name=_nobackup]');
 	value = field.getValue();
@@ -45,20 +45,19 @@
 		xtype: 'displayfield',
                 fieldLabel: 'Image',
                 name: '_file'
- 	    },
+ 	    }
+	];
+
+	me.column2 = [
 	    {
 		xtype: 'CacheTypeSelector',
 		name: '_cache',
 		value: '',
 		fieldLabel: 'Cache',
-	    }
-	];
-
-	me.column2 = [
+	    },
 	    {
 		xtype: 'pvecheckbox',
-                fieldLabel: 'Exclude from backup',
-		labelWidth: 130,
+                fieldLabel: 'No backup',
                 name: '_nobackup'
  	    }
 	];
@@ -100,6 +99,127 @@
     }
 });
 
+Ext.define('PVE.qemu.HDCreate', {
+    extend: 'PVE.window.Edit',
+
+    create: 1,
+
+    submit: function(formpanel) {
+	var me = this;
+
+	var drive = {};
+
+	var confid = me.down('field[name=_confid]').getValue();
+	
+	var field = me.down('field[name=_disksize]');
+	var hdsize = field.getValue();
+
+	var field = me.down('field[name=_storage]');
+	var value = field.getValue();
+	drive.file = value + ":" + hdsize;
+
+	var field = me.down('field[name=_diskformat]');
+	drive.format = field.getValue();
+	
+	var field = me.down('field[name=_cache]');
+	if (value = field.getValue())
+	    drive.cache = value;
+	
+	field = me.down('field[name=_nobackup]');
+	if (value = field.getValue())
+	    drive.backup = 'no';
+
+	var params = {};
+
+	params[confid] = PVE.Parser.printQemuDrive(drive);
+
+	console.dir(params);
+
+	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";	    
+
+	var hdstoragesel = Ext.create('PVE.form.StorageSelector', {
+	    name: '_storage',
+	    nodename: nodename,
+	    fieldLabel: 'Storage',
+	    storageContent: 'images',
+	    allowBlank: false
+	});
+
+	me.column1 = [
+	    hdstoragesel,
+	    {
+		xtype: 'numberfield',
+		name: '_disksize',
+		minValue: 1,
+		maxValue: 128*1024,
+		value: 32,
+		fieldLabel: 'Disk size (GB)',
+		allowBlank: false
+	    },
+	    {
+		// fixme: we need a selector for all unused disk ids
+		xtype: 'displayfield',
+		name: '_confid',
+		value: 'virtio5',
+		fieldLabel: 'Bus/Device',
+		allowBlank: false
+	    },
+	    {
+		xtype: 'PVE.form.DiskFormatSelector',
+		name: '_diskformat',
+		fieldLabel: 'Image format',
+		value: 'raw',
+		allowBlank: false
+	    }
+	];
+
+	me.column2 = [
+	    {
+		xtype: 'CacheTypeSelector',
+		name: '_cache',
+		value: '',
+		fieldLabel: 'Cache',
+	    },
+	    {
+		xtype: 'pvecheckbox',
+                fieldLabel: 'No backup',
+                name: '_nobackup'
+ 	    }
+	];
+
+	Ext.applyIf(me, {
+	    title: 'Add Harddisk',
+	});
+
+	me.callParent();
+
+	me.load({
+	    success: function(form, action) {
+		me.vmconfig = action.result.data;
+	    }
+	});
+    }
+});
+
 Ext.define('PVE.qemu.MemoryEdit', {
     extend: 'PVE.window.Edit',
 
@@ -361,6 +481,10 @@
 	    };
 	}
 
+	var reload = function() {
+	    me.rstore.load();
+	};
+
 	var baseurl = 'nodes/' + nodename + '/qemu/' + vmid + '/config';
 
 	var run_editor = function() {
@@ -380,9 +504,7 @@
 	    });
 
 	    win.show();
-	    win.on('destroy', function() {
-		me.rstore.load();
-	    });
+	    win.on('destroy', reload);
 	};
 
 	var edit_btn = new Ext.Button({
@@ -428,10 +550,11 @@
 				text: 'Hard Disk',
 				iconCls: 'pve-itype-icon-storage',
 				handler: function() {
-				    var win = Ext.create('PVE.qemu.HDEdit', {
-					pveSelNode: me.pveSelNode,
+				    var win = Ext.create('PVE.qemu.HDCreate', {
+					url: '/api2/extjs/' + baseurl,
+					pveSelNode: me.pveSelNode
 				    });
-				    win.on('destroy', reload)
+				    win.on('destroy', reload);
 				    win.show();
 				}
 			    },

Modified: pve-manager/pve2/www/manager/window/Edit.js
===================================================================
--- pve-manager/pve2/www/manager/window/Edit.js	2011-07-01 11:53:29 UTC (rev 6218)
+++ pve-manager/pve2/www/manager/window/Edit.js	2011-07-01 13:07:22 UTC (rev 6219)
@@ -3,6 +3,10 @@
 
     resizable: false,
 
+    // set create to true if you want a CREAT button (instead 
+    // OK and RESET) 
+    create: false, 
+
     submit: function(formpanel) {
 	var me = this;
 
@@ -87,7 +91,7 @@
 	var form = formpanel.getForm();
 
 	var submitBtn = Ext.create('Ext.Button', {
-	    text: 'OK',
+	    text: me.create ? 'Create' : 'OK',
 	    disabled: true,
 	    handler: function() {
 		me.submit(formpanel);
@@ -122,7 +126,7 @@
 	    width: me.column2 ? colwidth*2 : colwidth,
 	    border: false,
 	    items: formpanel,
-	    buttons: [ submitBtn, resetBtn ]
+	    buttons: me.create ? [ submitBtn ] : [ submitBtn, resetBtn ]
 	});
 
 	me.callParent();




More information about the pve-devel mailing list