[pve-devel] r5912 - in pve-manager/pve2/www/new: . qemu window

svn-commits at proxmox.com svn-commits at proxmox.com
Thu May 5 15:21:46 CEST 2011


Author: dietmar
Date: 2011-05-05 15:21:46 +0200 (Thu, 05 May 2011)
New Revision: 5912

Modified:
   pve-manager/pve2/www/new/PVEUtils.js
   pve-manager/pve2/www/new/qemu/CreateWizard.js
   pve-manager/pve2/www/new/window/Wizard.js
Log:
improve wizard


Modified: pve-manager/pve2/www/new/PVEUtils.js
===================================================================
--- pve-manager/pve2/www/new/PVEUtils.js	2011-05-05 09:57:07 UTC (rev 5911)
+++ pve-manager/pve2/www/new/PVEUtils.js	2011-05-05 13:21:46 UTC (rev 5912)
@@ -53,6 +53,27 @@
 	return 21;
     },
 
+    assemble_field_data: function(values, data) {
+        if (Ext.isObject(data)) {
+            Ext.iterate(data, function(name, val) {
+                if (name in values) {
+                    var bucket = values[name],
+                    isArray = Ext.isArray;
+                    if (!isArray(bucket)) {
+                        bucket = values[name] = [bucket];
+                    }
+                    if (isArray(val)) {
+                        values[name] = bucket.concat(val);
+                    } else {
+                        bucket.push(val);
+                    }
+                } else {
+                    values[name] = val;
+                }
+            });
+	}
+    },
+
     format_size: function(size) {
 
 	var kb = size / 1024;

Modified: pve-manager/pve2/www/new/qemu/CreateWizard.js
===================================================================
--- pve-manager/pve2/www/new/qemu/CreateWizard.js	2011-05-05 09:57:07 UTC (rev 5911)
+++ pve-manager/pve2/www/new/qemu/CreateWizard.js	2011-05-05 13:21:46 UTC (rev 5912)
@@ -19,11 +19,11 @@
         });
 
 	diskTypeStore = Ext.create('Ext.data.ArrayStore', {
-            fields: ['key'],
+            fields: ['key', 'value'],
             data : [ 
-		['IDE'], 
-		['VIRTIO'],
-		['SCSI']
+		['ide', 'IDE'], 
+		['virtio', 'VIRTIO'],
+		['scsi', 'SCSI']
 	    ]
         });
 
@@ -67,6 +67,7 @@
 	    title: 'Create new virtual machine',
 	    items: [
 		{
+		    xtype: 'inputpanel',
 		    title: 'General',
 		    items: [
 			{
@@ -97,7 +98,13 @@
 			    fieldLabel: 'VM name',
 			    allowBlank: true
 			}
-		    ]
+		    ],
+		    getValues: function() {
+			var values = this.getFieldValues();
+			if (!values.name)
+			    delete values.name;
+			return values;
+		    }
 		},
 		{
 		    title: 'OS Type',
@@ -174,6 +181,7 @@
 		    }
 		},
 		{
+		    xtype: 'inputpanel',
 		    title: 'Installation Media',
 		    items: [
 			{
@@ -203,9 +211,18 @@
 			    inputValue: 'none',
 			    boxLabel: 'Do not use any installation media'
 			}
-		    ]
+		    ],
+		    getValues: function() {
+			var values = this.getFieldValues();
+			if (values.mediaType === 'iso')
+			    return { cdrom: values.cdimage };
+			if (values.mediaType === 'cdrom')
+			    return { cdrom: 'cdrom' };
+			return { cdrom: 'none' };
+		    }
 		},
 		{
+		    xtype: 'inputpanel',
 		    title: 'Harddisk',
 		    items: [
 			hdstoragesel,
@@ -220,13 +237,13 @@
 			},
 			{
 			    xtype: 'combobox',
-			    name: 'disktype',
+			    name: 'controller',
 			    fieldLabel: 'Controller',
 			    store: diskTypeStore,
 			    queryMode: 'local',
 			    editable: false,
-			    value: 'IDE',
-			    displayField: 'key',
+			    value: 'ide',
+			    displayField: 'value',
 			    valueField: 'key',
 			    allowBlank: false
 			},
@@ -242,7 +259,17 @@
 			    valueField: 'key',
 			    allowBlank: false
 			}
-		    ]
+		    ],
+		    getValues: function() {
+			var values = this.getFieldValues();
+			var str = values.hdstorage + ':' + values.disksize +
+			    ',format=' + values.diskformat;
+			var busid = 0;
+			var key = values.controller + "" + busid;
+			var res = {};
+			res[key] = str;
+			return res;
+		    }
 		},	
 		{
 		    title: 'CPU',
@@ -283,6 +310,7 @@
 		    ]
 		},
 		{
+		    xtype: 'inputpanel',
 		    title: 'Network',
 		    items: [
 			{
@@ -311,21 +339,35 @@
 			    allowBlank: true,
 			    emptyText: 'auto'
 			}
-		    ]
+		    ],
+		    getValues: function() {
+			var values = this.getFieldValues();
+			var str = values.netcard;
+			if (values.mac)
+			    str += '=' + values.mac;
+			str += ',bridge=' + values.bridge;
+
+			return { net0: str };
+		    }
 		},
 		{
 		    title: 'Confirm',
+		    layout: 'fit',
 		    listeners: {
 			show: function() {
 			    var form = me.down('form').getForm();
-			    var kv = form.getFieldValues();
-			    this.update(Ext.JSON.encode(kv));
-
+			    var kv = me.getFieldValues();
+			    var html = '';
+			    Ext.Object.each(kv, function(key, value) {
+				html += Ext.htmlEncode(key) + ": " +
+				    Ext.htmlEncode(Ext.JSON.encode(value)) + '<br>';
+			    });
+			    this.update(html);
 			}
 		    },
 		    onSubmit: function() {
-			var form = me.down('form').getForm();
-			var kv = form.getFieldValues();
+			//var form = me.down('form').getForm();
+			var kv = me.getFieldValues();
 			console.dir(kv);
 		    },
 		    html: 'no content'

Modified: pve-manager/pve2/www/new/window/Wizard.js
===================================================================
--- pve-manager/pve2/www/new/window/Wizard.js	2011-05-05 09:57:07 UTC (rev 5911)
+++ pve-manager/pve2/www/new/window/Wizard.js	2011-05-05 13:21:46 UTC (rev 5912)
@@ -1,3 +1,35 @@
+Ext.define('PVE.panel.InputPanel', {
+    extend: 'Ext.panel.Panel',
+    requires: [
+	'PVE.Utils'
+    ],
+    alias: ['widget.inputpanel'],
+
+    getFieldValues: function(dirtyOnly) {
+	var me = this;
+
+	var values = {};
+
+	Ext.Array.each(me.query('[isFormField]'), function(field) {
+            if (!dirtyOnly || field.isDirty()) {
+                PVE.Utils.assemble_field_data(values, field.getModelData());
+	    }
+	});
+
+	return values;
+		       
+    },
+
+    initComponent: function() {
+	var me = this;
+
+	Ext.applyIf(me, {
+	});
+
+	me.callParent();
+    }
+});
+
 Ext.define('PVE.window.Wizard', {
     extend: 'Ext.window.Window',
     requires: [
@@ -3,6 +35,28 @@
 	'PVE.Utils'
     ],
+    
+    getFieldValues: function(dirtyOnly) {
+	var me = this;
 
-    
+        var values = {};
+
+	var form = me.down('form').getForm();
+
+        form.getFields().each(function(field) {
+            if (!field.up('inputpanel') && (!dirtyOnly || field.isDirty())) {
+                PVE.Utils.assemble_field_data(values, field.getModelData());
+            }
+        });
+
+	Ext.Array.each(me.query('inputpanel'), function(panel) {
+	    if (Ext.isFunction(panel.getValues))
+		PVE.Utils.assemble_field_data(values, panel.getValues(dirtyOnly));
+	    else 
+		PVE.Utils.assemble_field_data(values, panel.getFieldValues(dirtyOnly));
+	});
+
+        return values;
+    },
+
     initComponent: function() {
 	var me = this;




More information about the pve-devel mailing list