2015-07-03 11:29:11 +02:00
Ext . define ( 'PVE.form.NodeSelector' , {
2018-01-15 15:17:50 +01:00
extend : 'Proxmox.form.ComboGrid' ,
2016-02-25 13:20:05 +01:00
alias : [ 'widget.pveNodeSelector' ] ,
2015-07-03 11:29:11 +02:00
// invalidate nodes which are offline
onlineValidator : false ,
selectCurNode : false ,
2016-11-17 16:49:54 +01:00
// do not allow those nodes (array)
disallowedNodes : undefined ,
2015-07-03 11:29:11 +02:00
// only allow those nodes (array)
allowedNodes : undefined ,
2016-03-08 11:03:55 +01:00
// set default value to empty array, else it inits it with
// null and after the store load it is an empty array,
// triggering dirtychange
value : [ ] ,
2016-02-25 13:20:07 +01:00
valueField : 'node' ,
displayField : 'node' ,
store : {
2015-07-03 11:29:11 +02:00
fields : [ 'node' , 'cpu' , 'maxcpu' , 'mem' , 'maxmem' , 'uptime' ] ,
proxy : {
2017-12-11 14:46:51 +01:00
type : 'proxmox' ,
2015-07-03 11:29:11 +02:00
url : '/api2/json/nodes'
} ,
sorters : [
{
property : 'node' ,
direction : 'ASC'
} ,
{
property : 'mem' ,
direction : 'DESC'
}
]
2016-02-25 13:20:07 +01:00
} ,
2015-07-03 11:29:11 +02:00
2016-02-25 13:20:07 +01:00
listConfig : {
columns : [
{
header : gettext ( 'Node' ) ,
dataIndex : 'node' ,
sortable : true ,
hideable : false ,
flex : 1
2015-07-03 11:29:11 +02:00
} ,
2016-02-25 13:20:07 +01:00
{
2016-04-15 15:26:28 +02:00
header : gettext ( 'Memory usage' ) + " %" ,
renderer : PVE . Utils . render _mem _usage _percent ,
2016-02-25 13:20:07 +01:00
sortable : true ,
width : 100 ,
dataIndex : 'mem'
} ,
{
header : gettext ( 'CPU usage' ) ,
renderer : PVE . Utils . render _cpu ,
sortable : true ,
width : 100 ,
dataIndex : 'cpu'
}
2016-04-29 12:06:28 +02:00
]
2016-02-25 13:20:07 +01:00
} ,
2015-07-03 11:29:11 +02:00
2016-02-25 13:20:07 +01:00
validator : function ( value ) {
/*jslint confusion: true */
var me = this ;
if ( ! me . onlineValidator || ( me . allowBlank && ! value ) ) {
return true ;
}
2015-07-03 11:29:11 +02:00
2016-02-25 13:20:07 +01:00
var offline = [ ] ;
var notAllowed = [ ] ;
2015-07-03 11:29:11 +02:00
2016-02-25 13:20:07 +01:00
Ext . Array . each ( value . split ( /\s*,\s*/ ) , function ( node ) {
var rec = me . store . findRecord ( me . valueField , node ) ;
if ( ! ( rec && rec . data ) || ! Ext . isNumeric ( rec . data . mem ) ) {
offline . push ( node ) ;
} else if ( me . allowedNodes && ! Ext . Array . contains ( me . allowedNodes , node ) ) {
notAllowed . push ( node ) ;
2015-07-03 11:29:11 +02:00
}
} ) ;
2017-02-15 15:00:24 +01:00
if ( value && notAllowed . length !== 0 ) {
2016-02-25 13:20:07 +01:00
return "Node " + notAllowed . join ( ', ' ) + " is not allowed for this action!" ;
}
2017-02-15 15:00:24 +01:00
if ( value && offline . length !== 0 ) {
2016-02-25 13:20:07 +01:00
return "Node " + offline . join ( ', ' ) + " seems to be offline!" ;
}
return true ;
} ,
initComponent : function ( ) {
var me = this ;
2017-08-18 09:04:53 +02:00
if ( me . selectCurNode && PVE . curSelectedNode && PVE . curSelectedNode . data . node ) {
2015-07-03 11:29:11 +02:00
me . preferredValue = PVE . curSelectedNode . data . node ;
}
me . callParent ( ) ;
2016-02-25 13:20:07 +01:00
me . getStore ( ) . load ( ) ;
2016-11-17 16:49:54 +01:00
// filter out disallowed nodes
me . getStore ( ) . addFilter ( new Ext . util . Filter ( {
filterFn : function ( item ) {
2016-11-22 12:32:15 +01:00
if ( Ext . isArray ( me . disallowedNodes ) ) {
return ! Ext . Array . contains ( me . disallowedNodes , item . data . node ) ;
} else {
return true ;
}
2016-11-17 16:49:54 +01:00
}
} ) ) ;
2016-12-07 11:54:35 +01:00
me . mon ( me . getStore ( ) , 'load' , function ( ) {
me . isValid ( ) ;
} ) ;
2015-07-03 11:29:11 +02:00
}
} ) ;