[pve-devel] r6205 - in pve-manager/pve2: . www/manager www/manager/node www/manager/qemu www/manager/window
svn-commits at proxmox.com
svn-commits at proxmox.com
Thu Jun 30 09:31:24 CEST 2011
Author: dietmar
Date: 2011-06-30 09:31:24 +0200 (Thu, 30 Jun 2011)
New Revision: 6205
Added:
pve-manager/pve2/www/manager/window/Edit.js
Modified:
pve-manager/pve2/ChangeLog
pve-manager/pve2/www/manager/Makefile.am
pve-manager/pve2/www/manager/node/DNSEdit.js
pve-manager/pve2/www/manager/node/NetworkEdit.js
pve-manager/pve2/www/manager/node/TimeEdit.js
pve-manager/pve2/www/manager/qemu/HardwareView.js
Log:
new PVE.window.Edit class
Modified: pve-manager/pve2/ChangeLog
===================================================================
--- pve-manager/pve2/ChangeLog 2011-06-29 14:07:10 UTC (rev 6204)
+++ pve-manager/pve2/ChangeLog 2011-06-30 07:31:24 UTC (rev 6205)
@@ -1,3 +1,16 @@
+2011-06-30 Proxmox Support Team <support at proxmox.com>
+
+ * www/manager/window/Edit.js: split out common code into
+ specialized PVE.window.Edit class.
+
+ * www/manager/qemu/HardwareView.js: use new PVE.window.Edit
+
+ * www/manager/node/TimeEdit.js: use new PVE.window.Edit
+
+ * www/manager/node/DNSEdit.js: use new PVE.window.Edit
+
+ * www/manager/node/NetworkEdit.js: use new PVE.window.Edit
+
2011-06-29 Proxmox Support Team <support at proxmox.com>
* www/manager/qemu/HardwareView.js: impl. PVE.qemu.ProcessorEdit
Modified: pve-manager/pve2/www/manager/Makefile.am
===================================================================
--- pve-manager/pve2/www/manager/Makefile.am 2011-06-29 14:07:10 UTC (rev 6204)
+++ pve-manager/pve2/www/manager/Makefile.am 2011-06-30 07:31:24 UTC (rev 6205)
@@ -30,6 +30,7 @@
dc/Log.js \
panel/StatusPanel.js \
panel/RRDView.js \
+ window/Edit.js \
window/LoginWindow.js \
window/TaskViewer.js \
window/Wizard.js \
Modified: pve-manager/pve2/www/manager/node/DNSEdit.js
===================================================================
--- pve-manager/pve2/www/manager/node/DNSEdit.js 2011-06-29 14:07:10 UTC (rev 6204)
+++ pve-manager/pve2/www/manager/node/DNSEdit.js 2011-06-30 07:31:24 UTC (rev 6205)
@@ -1,5 +1,5 @@
Ext.define('PVE.node.DNSEdit', {
- extend: 'Ext.window.Window',
+ extend: 'PVE.window.Edit',
requires: [
'PVE.Utils'
],
@@ -13,85 +13,52 @@
if (!nodename)
throw "no node name specified";
- var formpanel = Ext.create('Ext.form.Panel', {
+ //fieldDefaults: {
+ // labelWidth: 130,
+ // anchor: '100%'
+ // },
+
+ me.items = [
+ {
+ xtype: 'textfield',
+ fieldLabel: 'Search domain',
+ name: 'search',
+ allowBlank: false
+ },
+ {
+ xtype: 'pvetextfield',
+ fieldLabel: 'First DNS server',
+ vtype: 'IPAddress',
+ skipEmptyText: true,
+ name: 'dns1'
+ },
+ {
+ xtype: 'pvetextfield',
+ fieldLabel: 'Second DNS server',
+ vtype: 'IPAddress',
+ skipEmptyText: true,
+ name: 'dns2'
+ },
+ {
+ xtype: 'pvetextfield',
+ fieldLabel: 'Third DNS server',
+ vtype: 'IPAddress',
+ skipEmptyText: true,
+ name: 'dns3'
+ }
+ ];
+
+ Ext.applyIf(me, {
+ title: "Edit DNS settings",
url: "/api2/extjs/nodes/" + nodename + "/dns",
- method: 'PUT',
- trackResetOnLoad: true,
- bodyPadding: 10,
-
fieldDefaults: {
- labelWidth: 130,
- anchor: '100%'
- },
- items: [
- {
- xtype: 'textfield',
- fieldLabel: 'Search domain',
- name: 'search',
- allowBlank: false
- },
- {
- xtype: 'pvetextfield',
- fieldLabel: 'First DNS server',
- vtype: 'IPAddress',
- skipEmptyText: true,
- name: 'dns1'
- },
- {
- xtype: 'pvetextfield',
- fieldLabel: 'Second DNS server',
- vtype: 'IPAddress',
- skipEmptyText: true,
- name: 'dns2'
- },
- {
- xtype: 'pvetextfield',
- fieldLabel: 'Third DNS server',
- vtype: 'IPAddress',
- skipEmptyText: true,
- name: 'dns3'
- }
- ]
- });
-
- var form = formpanel.getForm();
-
- var submitBtn = Ext.create('Ext.Button', {
- text: 'OK',
- disabled: true,
- handler: function() {
- formpanel.submit({
- submitEmptyText: false,
- success: function() {
- me.close();
- },
- failure: function(form, action) {
- Ext.Msg.alert('Error', PVE.Utils.extractFormActionError(action));
- }
- });
+ labelWidth: 120
}
- });
+ });
- var resetBtn = Ext.create('Ext.Button', {
- text: 'Reset',
- disabled: true,
- handler: function(){
- form.reset();
- }
- });
+ me.callParent();
- var set_button_status = function() {
- var valid = form.isValid();
- var dirty = form.isDirty();
- submitBtn.setDisabled(!(valid && dirty));
- resetBtn.setDisabled(!dirty);
-
- };
-
- form.on('dirtychange', set_button_status);
- form.on('validitychange', set_button_status);
-
- formpanel.load({
+ me.down('form').load({
method: 'GET',
failure: function(form, action) {
var msg = PVE.Utils.extractFormActionError(action);
@@ -101,18 +68,5 @@
}
});
-
- Ext.applyIf(me, {
- title: "Edit DNS settings",
- modal: true,
- width: 400,
- height: 200,
- layout: 'fit',
- border: false,
- items: formpanel,
- buttons: [ submitBtn, resetBtn ]
- });
-
- me.callParent();
}
});
Modified: pve-manager/pve2/www/manager/node/NetworkEdit.js
===================================================================
--- pve-manager/pve2/www/manager/node/NetworkEdit.js 2011-06-29 14:07:10 UTC (rev 6204)
+++ pve-manager/pve2/www/manager/node/NetworkEdit.js 2011-06-30 07:31:24 UTC (rev 6205)
@@ -1,5 +1,5 @@
Ext.define('PVE.node.NetworkEdit', {
- extend: 'Ext.window.Window',
+ extend: 'PVE.window.Edit',
alias: ['widget.pveNodeNetworkEdit'],
initComponent : function() {
@@ -30,7 +30,7 @@
title = "Edit network device '" + me.iface + "'";
}
- var col2 = [
+ me.column2 = [
{
xtype: 'pvecheckbox',
fieldLabel: 'Autostart',
@@ -41,18 +41,18 @@
];
if (me.iftype === 'bridge') {
- col2.push({
+ me.column2.push({
xtype: 'textfield',
fieldLabel: 'Bridge ports',
name: 'bridge_ports'
});
} else if (me.iftype === 'bond') {
- col2.push({
+ me.column2.push({
xtype: 'textfield',
fieldLabel: 'Slaves',
name: 'slaves'
});
- col2.push({
+ me.column2.push({
xtype: 'bondModeSelector',
fieldLabel: 'Mode',
name: 'bond_mode',
@@ -72,114 +72,64 @@
method = 'PUT';
}
- var formpanel = Ext.create('Ext.form.Panel', {
- url: url,
- method: method,
- trackResetOnLoad: true,
- bodyPadding: 10,
- border: false,
- fieldDefaults: {
- labelWidth: 100,
- anchor: '100%'
- },
- layout: 'column',
- defaultType: 'container',
- items: [
- {
- columnWidth: .5,
- items: [
- {
- xtype: 'textfield',
- fieldLabel: 'Name',
- name: 'iface',
- value: me.iface,
- disabled: !create,
- vtype: iface_vtype,
- allowBlank: false
- },
- {
- xtype: 'pvetextfield',
- deleteEmpty: !create,
- fieldLabel: 'IP address',
- vtype: 'IPAddress',
- name: 'address'
- },
- {
- xtype: 'pvetextfield',
- deleteEmpty: !create,
- fieldLabel: 'Subnet mask',
- vtype: 'IPAddress',
- name: 'netmask',
- validator: function(value) {
- if (!me.items)
- return true;
- var address = me.down('field[name=address]').getValue();
- if (value !== '') {
- if (address === '')
- return "Subnet mask requires option 'IP address'";
- } else {
- if (address !== '')
- return "Option 'IP address' requires a subnet mask";
- }
-
- return true;
- }
- },
- {
- xtype: 'pvetextfield',
- deleteEmpty: !create,
- fieldLabel: 'Gateway',
- vtype: 'IPAddress',
- name: 'gateway'
- }
- ]
- },
- {
- columnWidth: .5,
- items: col2
- }
- ]
- });
-
- var form = formpanel.getForm();
-
- var submitBtn = Ext.create('Ext.Button', {
- 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.column1 = [
+ {
+ xtype: create ? 'textfield' : 'displayfield',
+ fieldLabel: 'Name',
+ name: 'iface',
+ value: me.iface,
+ vtype: iface_vtype,
+ allowBlank: false
+ },
+ {
+ xtype: 'pvetextfield',
+ deleteEmpty: !create,
+ fieldLabel: 'IP address',
+ vtype: 'IPAddress',
+ name: 'address'
+ },
+ {
+ xtype: 'pvetextfield',
+ deleteEmpty: !create,
+ fieldLabel: 'Subnet mask',
+ vtype: 'IPAddress',
+ name: 'netmask',
+ validator: function(value) {
+ if (!me.items)
+ return true;
+ var address = me.down('field[name=address]').getValue();
+ if (value !== '') {
+ if (address === '')
+ return "Subnet mask requires option 'IP address'";
+ } else {
+ if (address !== '')
+ return "Option 'IP address' requires a subnet mask";
}
- });
+
+ return true;
+ }
+ },
+ {
+ xtype: 'pvetextfield',
+ deleteEmpty: !create,
+ fieldLabel: 'Gateway',
+ vtype: 'IPAddress',
+ name: 'gateway'
}
- });
+ ];
- var resetBtn = Ext.create('Ext.Button', {
- text: 'Reset',
- disabled: true,
- handler: function(){
- form.reset();
- }
+ Ext.applyIf(me, {
+ title: title,
+ url: url,
+ method: method
});
- var set_button_status = function() {
- var valid = form.isValid();
- var dirty = form.isDirty();
- submitBtn.setDisabled(!(valid && dirty));
- resetBtn.setDisabled(!dirty);
+ me.callParent();
- };
-
- form.on('dirtychange', set_button_status);
- form.on('validitychange', set_button_status);
-
- if (!create) {
- formpanel.load({
- url: "/api2/extjs/nodes/" + nodename + "/network/" + me.iface,
+ if (create) {
+ me.down('field[name=iface]').setValue(me.iface_default);
+ } else {
+ me.down('form').load({
method: 'GET',
failure: function(form, action) {
var msg = PVE.Utils.extractFormActionError(action);
@@ -199,20 +149,5 @@
});
}
- Ext.applyIf(me, {
- title: title,
- modal: true,
- width: 600,
- height: 200,
- layout: 'fit',
- border: false,
- items: formpanel,
- buttons: [ submitBtn, resetBtn ]
- });
-
- if (create)
- form.findField('iface').setValue(me.iface_default);
-
- me.callParent();
}
});
Modified: pve-manager/pve2/www/manager/node/TimeEdit.js
===================================================================
--- pve-manager/pve2/www/manager/node/TimeEdit.js 2011-06-29 14:07:10 UTC (rev 6204)
+++ pve-manager/pve2/www/manager/node/TimeEdit.js 2011-06-30 07:31:24 UTC (rev 6205)
@@ -1,5 +1,5 @@
Ext.define('PVE.node.TimeEdit', {
- extend: 'Ext.window.Window',
+ extend: 'PVE.window.Edit',
requires: ['PVE.data.TimezoneStore'],
alias: ['widget.pveNodeTimeEdit'],
@@ -10,21 +10,17 @@
if (!nodename)
throw "no node name specified";
- var formpanel = Ext.create('Ext.form.Panel', {
+ Ext.applyIf(me, {
+ title: "Set time zone",
url: "/api2/extjs/nodes/" + nodename + "/time",
- method: 'PUT',
- trackResetOnLoad: true,
- bodyPadding: 10,
-
fieldDefaults: {
- labelWidth: 80,
- anchor: '100%'
+ labelWidth: 70
},
-
+ width: 400,
items: {
xtype: 'combo',
- fieldLabel: 'Time zone',
- name: 'timezone',
+ fieldLabel: 'Time zone',
+ name: 'timezone',
queryMode: 'local',
store: new PVE.data.TimezoneStore({autoDestory: true}),
valueField: 'zone',
@@ -32,47 +28,13 @@
triggerAction: 'all',
forceSelection: true,
editable: false,
- allowBlank: false
+ allowBlank: false
}
});
- var form = formpanel.getForm();
+ me.callParent();
- var submitBtn = Ext.create('Ext.Button', {
- text: 'OK',
- disabled: true,
- handler: function() {
- formpanel.submit({
- success: function() {
- me.close();
- },
- failure: function(form, action) {
- Ext.Msg.alert('Error', PVE.Utils.extractFormActionError(action));
- }
- });
- }
- });
-
- var resetBtn = Ext.create('Ext.Button', {
- text: 'Reset',
- disabled: true,
- handler: function(){
- form.reset();
- }
- });
-
- var set_button_status = function() {
- var valid = form.isValid();
- var dirty = form.isDirty();
- submitBtn.setDisabled(!(valid && dirty));
- resetBtn.setDisabled(!dirty);
-
- };
-
- form.on('dirtychange', set_button_status);
- form.on('validitychange', set_button_status);
-
- formpanel.load({
+ me.down('form').load({
method: 'GET',
failure: function(form, action) {
var msg = PVE.Utils.extractFormActionError(action);
@@ -82,17 +44,5 @@
}
});
- Ext.applyIf(me, {
- title: "Set time zone",
- modal: true,
- width: 400,
- height: 110,
- layout: 'fit',
- border: false,
- items: formpanel,
- buttons: [ submitBtn, resetBtn ]
- });
-
- me.callParent();
}
});
Modified: pve-manager/pve2/www/manager/qemu/HardwareView.js
===================================================================
--- pve-manager/pve2/www/manager/qemu/HardwareView.js 2011-06-29 14:07:10 UTC (rev 6204)
+++ pve-manager/pve2/www/manager/qemu/HardwareView.js 2011-06-30 07:31:24 UTC (rev 6205)
@@ -1,13 +1,9 @@
Ext.define('PVE.qemu.ProcessorEdit', {
- extend: 'Ext.window.Window',
+ extend: 'PVE.window.Edit',
initComponent : function() {
var me = this;
- var nodename = me.pveSelNode.data.node;
- if (!nodename)
- throw "no node name specified";
-
if (!me.store)
throw "no store specified";
@@ -19,123 +15,63 @@
rec = me.store.getById('cpu');
data.cpu = rec && rec.data.value ? rec.data.value : '';
- var formpanel = Ext.create('Ext.form.Panel', {
- url: me.url,
- method: 'PUT',
- trackResetOnLoad: true,
- bodyPadding: 10,
- border: false,
- fieldDefaults: {
- labelWidth: 100,
- anchor: '100%'
- },
- layout: 'column',
- defaultType: 'container',
- items: [
- {
- columnWidth: .5,
- items: [
- {
- xtype: 'numberfield',
- name: 'sockets',
- minValue: 1,
- maxValue: 4,
- value: 1,
- fieldLabel: 'Sockets',
- allowBlank: false,
- listeners: {
- change: function(f, value) {
- var sockets = me.down('field[name=sockets]').getValue();
- var cores = me.down('field[name=cores]').getValue();
- me.down('field[name=totalcores]').setValue(sockets*cores);
- }
- }
- },
- {
- xtype: 'numberfield',
- name: 'cores',
- minValue: 1,
- maxValue: 32,
- value: 1,
- fieldLabel: 'Cores',
- allowBlank: false,
- listeners: {
- change: function(f, value) {
- var sockets = me.down('field[name=sockets]').getValue();
- var cores = me.down('field[name=cores]').getValue();
- me.down('field[name=totalcores]').setValue(sockets*cores);
- }
- }
- },
- {
- xtype: 'displayfield',
- fieldLabel: 'Total cores',
- name: 'totalcores',
- value: 1
- }
- ]
- },
- {
- columnWidth: .5,
- items: [
- {
- xtype: 'CPUModelSelector',
- name: 'cpu',
- fieldLabel: 'CPU type',
- }
- ]
+ me.column1 = [
+ {
+ xtype: 'numberfield',
+ name: 'sockets',
+ minValue: 1,
+ maxValue: 4,
+ value: 1,
+ fieldLabel: 'Sockets',
+ allowBlank: false,
+ listeners: {
+ change: function(f, value) {
+ var sockets = me.down('field[name=sockets]').getValue();
+ var cores = me.down('field[name=cores]').getValue();
+ me.down('field[name=totalcores]').setValue(sockets*cores);
+ }
}
- ]
- });
-
- var form = formpanel.getForm();
-
- var submitBtn = Ext.create('Ext.Button', {
- text: 'OK',
- disabled: true,
- handler: function() {
- formpanel.submit({
- success: function() {
- me.close();
- },
- failure: function(form, action) {
- Ext.Msg.alert('Error', PVE.Utils.extractFormActionError(action));
+ },
+ {
+ xtype: 'numberfield',
+ name: 'cores',
+ minValue: 1,
+ maxValue: 32,
+ value: 1,
+ fieldLabel: 'Cores',
+ allowBlank: false,
+ listeners: {
+ change: function(f, value) {
+ var sockets = me.down('field[name=sockets]').getValue();
+ var cores = me.down('field[name=cores]').getValue();
+ me.down('field[name=totalcores]').setValue(sockets*cores);
}
- });
+ }
+ },
+ {
+ xtype: 'displayfield',
+ fieldLabel: 'Total cores',
+ name: 'totalcores',
+ value: 1
}
- });
+ ];
- var resetBtn = Ext.create('Ext.Button', {
- text: 'Reset',
- disabled: true,
- handler: function(){
- form.reset();
+
+ me.column2 = [
+ {
+ xtype: 'CPUModelSelector',
+ name: 'cpu',
+ fieldLabel: 'CPU type',
}
- });
+ ];
- var set_button_status = function() {
- var valid = form.isValid();
- var dirty = form.isDirty();
- submitBtn.setDisabled(!(valid && dirty));
- resetBtn.setDisabled(!dirty);
- };
-
- form.on('dirtychange', set_button_status);
- form.on('validitychange', set_button_status);
-
Ext.applyIf(me, {
- title: "Edit processor settings",
- modal: true,
- width: 600,
- height: 200,
- layout: 'fit',
- border: false,
- items: formpanel,
- buttons: [ submitBtn, resetBtn ]
+ title: "Edit processor settings"
});
me.callParent();
+ var form = me.down('form').getForm();
form.setValues(data);
}
});
Added: pve-manager/pve2/www/manager/window/Edit.js
===================================================================
--- pve-manager/pve2/www/manager/window/Edit.js (rev 0)
+++ pve-manager/pve2/www/manager/window/Edit.js 2011-06-30 07:31:24 UTC (rev 6205)
@@ -0,0 +1,109 @@
+Ext.define('PVE.window.Edit', {
+ extend: 'Ext.window.Window',
+
+ resizable: false,
+
+ initComponent : function() {
+ var me = this;
+
+ if (!me.url)
+ throw "no url specified";
+
+ var items;
+
+ if (me.items) {
+ items = [
+ {
+ columnWidth: 1,
+ padding: 5,
+ layout: 'anchor',
+ items: me.items
+ }
+ ];
+ me.items = undefined;
+ } else if (me.column1 && me.column2) {
+ items = [
+ {
+ columnWidth: 0.5,
+ padding: '0 10 0 0',
+ layout: 'anchor',
+ items: me.column1
+ },
+ {
+ columnWidth: 0.5,
+ padding: '0 0 0 10',
+ layout: 'anchor',
+ items: me.column2
+ }
+ ];
+ } else {
+ throw "unsupported config"
+ }
+
+ var formpanel = Ext.create('Ext.form.Panel', {
+ url: me.url,
+ method: me.method || 'PUT',
+ trackResetOnLoad: true,
+ bodyPadding: 10,
+ border: false,
+ fieldDefaults: Ext.apply({}, me.fieldDefaults, {
+ labelWidth: 100,
+ anchor: '100%'
+ }),
+ layout: 'column',
+ defaultType: 'container',
+ items: items
+ });
+
+
+ var form = formpanel.getForm();
+
+ var submitBtn = Ext.create('Ext.Button', {
+ text: 'OK',
+ disabled: true,
+ handler: function() {
+ formpanel.submit({
+ success: function() {
+ me.close();
+ },
+ failure: function(form, action) {
+ Ext.Msg.alert('Error', PVE.Utils.extractFormActionError(action));
+ }
+ });
+ }
+ });
+
+ var resetBtn = Ext.create('Ext.Button', {
+ text: 'Reset',
+ disabled: true,
+ handler: function(){
+ form.reset();
+ }
+ });
+
+ var set_button_status = function() {
+ var valid = form.isValid();
+ var dirty = form.isDirty();
+ submitBtn.setDisabled(!(valid && dirty));
+ resetBtn.setDisabled(!dirty);
+ };
+
+ form.on('dirtychange', set_button_status);
+ form.on('validitychange', set_button_status);
+
+ var colwidth = 300;
+ if (me.fieldDefaults && me.fieldDefaults.labelWidth)
+ colwidth += me.fieldDefaults.labelWidth - 100;
+
+ Ext.applyIf(me, {
+ modal: true,
+ layout: 'auto',
+ width: me.column2 ? colwidth*2 : colwidth,
+ border: false,
+ items: formpanel,
+ buttons: [ submitBtn, resetBtn ]
+ });
+
+ me.callParent();
+ }
+});
More information about the pve-devel
mailing list