[pve-devel] [PATCH manager v2 08/29] dc/OptionView: cleanup & use new features from ObjectGrid

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Dec 19 08:55:00 CET 2017


Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 www/manager6/Toolkit.js       |   6 +
 www/manager6/Utils.js         |   6 +
 www/manager6/dc/OptionView.js | 255 ++++++++----------------------------------
 3 files changed, 56 insertions(+), 211 deletions(-)

diff --git a/www/manager6/Toolkit.js b/www/manager6/Toolkit.js
index 56b06686..5ab03e29 100644
--- a/www/manager6/Toolkit.js
+++ b/www/manager6/Toolkit.js
@@ -55,6 +55,12 @@ Ext.apply(Ext.form.field.VTypes, {
     MacAddressMask: /[a-fA-F0-9:]/,
     MacAddressText: gettext('Example') + ': 01:23:45:67:89:ab',
 
+    MacPrefix:  function(v) {
+	return (/^[a-f0-9]{2}(?::[a-f0-9]{2}){0,2}:?$/i).test(v);
+    },
+    MacPrefixMask: /[a-fA-F0-9:]/,
+    MacPrefixText: gettext('Example') + ': 02:8f',
+
     BridgeName: function(v) {
         return (/^vmbr\d{1,4}$/).test(v);
     },
diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index 67f26e4f..9a483893 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -315,6 +315,12 @@ Ext.define('PVE.Utils', { utilities: {
 	}
     },
 
+    console_viewer_array: function() {
+	return Ext.Array.map(['__default__','vv', 'html5'], function(v) {
+	    return [v, PVE.Utils.render_console_viewer(v)];
+	});
+    },
+
     render_kvm_vga_driver: function (value) {
 	if (!value) {
 	    return PVE.Utils.defaultText;
diff --git a/www/manager6/dc/OptionView.js b/www/manager6/dc/OptionView.js
index 988ff530..1b13572a 100644
--- a/www/manager6/dc/OptionView.js
+++ b/www/manager6/dc/OptionView.js
@@ -1,231 +1,64 @@
-Ext.define('PVE.dc.HttpProxyEdit', {
-    extend: 'PVE.window.Edit',
-
-    initComponent : function() {
-	var me = this;
-
-	Ext.applyIf(me, {
-	    subject: gettext('HTTP proxy'),
-	    items: {
-		xtype: 'pvetextfield',
-		name: 'http_proxy',
-		vtype: 'HttpProxy',
-		emptyText: PVE.Utils.noneText,
-		deleteEmpty: true,
-		value: '',
-		fieldLabel: gettext('HTTP proxy')
-	    }
-	});
-
-	me.callParent();
-
-	me.load();
-    }
-});
-
-Ext.define('PVE.dc.KeyboardEdit', {
-    extend: 'PVE.window.Edit',
-
-    initComponent : function() {
-	var me = this;
-
-	Ext.applyIf(me, {
-	    subject: gettext('Keyboard Layout'),
-	    items: {
-		xtype: 'VNCKeyboardSelector',
-		name: 'keyboard',
-		value: '__default__',
-		fieldLabel: gettext('Keyboard Layout')
-	    }
-	});
-
-	me.callParent();
-
-	me.load();
-    }
-});
-
-Ext.define('PVE.dc.ConsoleViewerEdit', {
-    extend: 'PVE.window.Edit',
-
-    initComponent : function() {
-	var me = this;
-
-	var data = [];
-
-	Ext.Array.each(['__default__','vv', 'html5'], function(value) {
-	    data.push([value, PVE.Utils.render_console_viewer(value)]);
-	});
-
-	Ext.applyIf(me, {
-	    subject: gettext('Console Viewer'),
-	    items: {
-		xtype: 'proxmoxKVComboBox',
-		name: 'console',
-		value: '__default__',
-		fieldLabel: gettext('Console Viewer'),
-		comboItems: data
-	    }
-	});
-
-	me.callParent();
-
-	me.load();
-    }
-});
-
-Ext.define('PVE.dc.EmailFromEdit', {
-    extend: 'PVE.window.Edit',
-
-    initComponent : function() {
-	var me = this;
-
-	Ext.applyIf(me, {
-	    subject: gettext('Email from address'),
-	    items: {
-		xtype: 'pvetextfield',
-		name: 'email_from',
-		vtype: 'pveMail',
-		emptyText: 'root@$hostname',
-		deleteEmpty: true,
-		value: '',
-		fieldLabel: gettext('Email from address')
-	    }
-	});
-
-	me.callParent();
-
-	me.load();
-    }
-});
-
-Ext.define('PVE.dc.MacPrefixEdit', {
-    extend: 'PVE.window.Edit',
-
-    initComponent : function() {
-	var me = this;
-
-	Ext.applyIf(me, {
-	    subject: gettext('MAC address prefix'),
-	    items: {
-		xtype: 'pvetextfield',
-		name: 'mac_prefix',
-		regex: /^[a-f0-9]{2}(?::[a-f0-9]{2}){0,2}:?$/i,
-		regexText: gettext('Example') + ': 02:8f',
-		emptyText: PVE.Utils.noneText,
-		deleteEmpty: true,
-		value: '',
-		fieldLabel: gettext('MAC address prefix')
-	    }
-	});
-
-	me.callParent();
-
-	me.load();
-    }
-});
-
 Ext.define('PVE.dc.OptionView', {
     extend: 'Proxmox.grid.ObjectGrid',
     alias: ['widget.pveDcOptionView'],
 
     onlineHelp: 'datacenter_configuration_file',
 
+    monStoreErrors: true,
+
     initComponent : function() {
 	var me = this;
 
-	var reload = function() {
-	    me.rstore.load();
-	};
-
-	var rows = {
-	    keyboard: { 
-		header: gettext('Keyboard Layout'), 
-		editor: 'PVE.dc.KeyboardEdit',
-		renderer: PVE.Utils.render_kvm_language,
-		required: true 
-	    },
-	    http_proxy: { 
-		header: gettext('HTTP proxy'),
-		editor: 'PVE.dc.HttpProxyEdit', 
-		required: true,
-		renderer: function(value) {
-		    if (!value) {
-			return PVE.Utils.noneText;
-		    }
-		    return value;
-		}
-	    },
-	    console: {
-		header: gettext('Console Viewer'),
-		editor: 'PVE.dc.ConsoleViewerEdit',
-		required: true,
-		renderer: PVE.Utils.render_console_viewer
-	    },
-	    email_from: { 
-		header: gettext('Email from address'),
-		editor: 'PVE.dc.EmailFromEdit', 
-		required: true,
-		renderer: function(value) {
-		    if (!value) {
-			return 'root@$hostname';
-		    }
-		    return value;
-		}
-	    },
-	    mac_prefix: {
-		header: gettext('MAC address prefix'),
-		editor: 'PVE.dc.MacPrefixEdit',
-		required: true,
-		renderer: function(value) {
-		    if (!value) {
-			return PVE.Utils.noneText;
-		    }
-		    return value;
-		}
-	    }
-	};
-
-	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 win = Ext.create(rowdef.editor, {
-		url: "/api2/extjs/cluster/options",
-		confid: rec.data.key
-	    });
-	    win.show();
-	    win.on('destroy', reload);
-	};
-
-	var edit_btn = new PVE.button.Button({
-	    text: gettext('Edit'),
-	    disabled: true,
-	    selModel: sm,
-	    handler: run_editor
+	me.add_combobox_row('keyboard', gettext('Keyboard Layout'), {
+	    renderer: PVE.Utils.render_kvm_language,
+	    comboItems: PVE.Utils.kvm_keymap_array()
 	});
+	me.add_text_row('http_proxy', gettext('HTTP proxy'), {
+	    defaultValue: PVE.Utils.noneText,
+	    vtype: 'HttpProxy',
+	    deleteEmpty: true
+	});
+	me.add_combobox_row('console', gettext('Console Viewer'), {
+	    renderer: PVE.Utils.render_console_viewer,
+	    comboItems: PVE.Utils.console_viewer_array(),
+	    defaultValue: '__default__',
+	    deleteEmpty: true
+	});
+	me.add_text_row('email_from', gettext('Email from address'), {
+	    deleteEmpty: true,
+	    vtype: 'pveMail',
+	    defaultValue: 'root@$hostname'
+	});
+	me.add_text_row('mac_prefix', gettext('MAC address prefix'), {
+	    vtype: 'MacPrefix',
+	    defaultValue: PVE.Utils.noneText
+	});
+
+	me.selModel = Ext.create('Ext.selection.RowModel', {});
 
 	Ext.apply(me, {
+	    tbar: [{
+		text: gettext('Edit'),
+		xtype: 'proxmoxButton',
+		disabled: true,
+		handler: function() { me.run_editor(); },
+		selModel: me.selModel
+	    }],
 	    url: "/api2/json/cluster/options",
-	    interval: 1000,
-	    selModel: sm,
-	    tbar: [ edit_btn ],
-	    rows: rows,
+	    editorConfig: {
+		url: "/api2/extjs/cluster/options"
+	    },
+	    interval: 5000,
+	    cwidth1: 200,
 	    listeners: {
-		itemdblclick: run_editor,
-		activate: reload
+		itemdblclick: me.run_editor
 	    }
 	});
 
 	me.callParent();
+
+	me.on('activate', me.rstore.startUpdate);
+	me.on('destroy', me.rstore.stopUpdate);
+	me.on('deactivate', me.rstore.stopUpdate);
     }
 });
-- 
2.11.0





More information about the pve-devel mailing list