load the store later, move non-dynamic properties and methods to class body

this fixes two problems:
 * we were loading the store before the parent ComboGrid class could put
  a listener on the load event
  * displayField must now be set in class body, take opportunity to move out
  what we can of the mega initComponent()

this two fixes allow the HA GroupEdit  Window to properly display the
existing members of a HA Group when editing group membership
This commit is contained in:
Emmanuel Kasper 2016-02-25 13:20:07 +01:00 committed by Dietmar Maurer
parent 55bc792342
commit 9ccd656a61

View File

@ -10,12 +10,10 @@ Ext.define('PVE.form.NodeSelector', {
// only allow those nodes (array) // only allow those nodes (array)
allowedNodes: undefined, allowedNodes: undefined,
initComponent: function() { valueField: 'node',
var me = this; displayField: 'node',
store: {
var store = Ext.create('Ext.data.Store', {
fields: [ 'node', 'cpu', 'maxcpu', 'mem', 'maxmem', 'uptime' ], fields: [ 'node', 'cpu', 'maxcpu', 'mem', 'maxmem', 'uptime' ],
autoLoad: true,
proxy: { proxy: {
type: 'pve', type: 'pve',
url: '/api2/json/nodes' url: '/api2/json/nodes'
@ -30,70 +28,71 @@ Ext.define('PVE.form.NodeSelector', {
direction: 'DESC' direction: 'DESC'
} }
] ]
}); },
Ext.apply(me, { listConfig: {
store: store, columns: [
valueField: 'node', {
displayField: 'node', header: gettext('Node'),
listConfig: { dataIndex: 'node',
columns: [ sortable: true,
{ hideable: false,
header: gettext('Node'), flex: 1
dataIndex: 'node',
sortable: true,
hideable: false,
flex: 1
},
{
header: gettext('Memory usage'),
renderer: PVE.Utils.render_mem_usage,
sortable: true,
width: 100,
dataIndex: 'mem'
},
{
header: gettext('CPU usage'),
renderer: PVE.Utils.render_cpu,
sortable: true,
width: 100,
dataIndex: 'cpu'
}
]
}, },
validator: function(value) { {
/*jslint confusion: true */ header: gettext('Memory usage'),
if (!me.onlineValidator || (me.allowBlank && !value)) { renderer: PVE.Utils.render_mem_usage,
return true; sortable: true,
} width: 100,
dataIndex: 'mem'
var offline = []; },
var notAllowed = []; {
header: gettext('CPU usage'),
renderer: PVE.Utils.render_cpu,
sortable: true,
width: 100,
dataIndex: 'cpu'
}
],
},
Ext.Array.each(value.split(/\s*,\s*/), function(node) { validator: function(value) {
var rec = me.store.findRecord(me.valueField, node); /*jslint confusion: true */
if (!(rec && rec.data) || !Ext.isNumeric(rec.data.mem)) { var me = this;
offline.push(node); if (!me.onlineValidator || (me.allowBlank && !value)) {
} else if (me.allowedNodes && !Ext.Array.contains(me.allowedNodes, node)) { return true;
notAllowed.push(node); }
}
});
if (notAllowed.length !== 0) { var offline = [];
return "Node " + notAllowed.join(', ') + " is not allowed for this action!"; var notAllowed = [];
}
if (offline.length !== 0) { Ext.Array.each(value.split(/\s*,\s*/), function(node) {
return "Node " + offline.join(', ') + " seems to be offline!"; var rec = me.store.findRecord(me.valueField, node);
} if (!(rec && rec.data) || !Ext.isNumeric(rec.data.mem)) {
return true; offline.push(node);
} else if (me.allowedNodes && !Ext.Array.contains(me.allowedNodes, node)) {
notAllowed.push(node);
} }
}); });
if (notAllowed.length !== 0) {
return "Node " + notAllowed.join(', ') + " is not allowed for this action!";
}
if (offline.length !== 0) {
return "Node " + offline.join(', ') + " seems to be offline!";
}
return true;
},
initComponent: function() {
var me = this;
if (me.selectCurNode && PVE.curSelectedNode.data.node) { if (me.selectCurNode && PVE.curSelectedNode.data.node) {
me.preferredValue = PVE.curSelectedNode.data.node; me.preferredValue = PVE.curSelectedNode.data.node;
} }
me.callParent(); me.callParent();
me.getStore().load();
} }
}); });