2017-01-31 09:25:24 +01:00
Ext . define ( 'Proxmox.node.Tasks' , {
extend : 'Ext.grid.GridPanel' ,
alias : [ 'widget.proxmoxNodeTasks' ] ,
stateful : true ,
stateId : 'grid-node-tasks' ,
loadMask : true ,
sortableColumns : false ,
vmidFilter : 0 ,
initComponent : function ( ) {
var me = this ;
if ( ! me . nodename ) {
throw "no node name specified" ;
}
var store = Ext . create ( 'Ext.data.BufferedStore' , {
pageSize : 500 ,
autoLoad : true ,
remoteFilter : true ,
model : 'proxmox-tasks' ,
proxy : {
type : 'proxmox' ,
startParam : 'start' ,
limitParam : 'limit' ,
url : "/api2/json/nodes/" + me . nodename + "/tasks"
}
} ) ;
var userfilter = '' ;
var filter _errors = 0 ;
var updateProxyParams = function ( ) {
var params = {
errors : filter _errors
} ;
if ( userfilter ) {
params . userfilter = userfilter ;
}
if ( me . vmidFilter ) {
params . vmid = me . vmidFilter ;
}
store . proxy . extraParams = params ;
} ;
updateProxyParams ( ) ;
var reload _task = Ext . create ( 'Ext.util.DelayedTask' , function ( ) {
updateProxyParams ( ) ;
store . reload ( ) ;
} ) ;
var run _task _viewer = function ( ) {
var sm = me . getSelectionModel ( ) ;
var rec = sm . getSelection ( ) [ 0 ] ;
if ( ! rec ) {
return ;
}
var win = Ext . create ( 'Proxmox.window.TaskViewer' , {
upid : rec . data . upid
} ) ;
win . show ( ) ;
} ;
var view _btn = new Ext . Button ( {
text : gettext ( 'View' ) ,
disabled : true ,
handler : run _task _viewer
} ) ;
Ext . apply ( me , {
store : store ,
viewConfig : {
trackOver : false ,
stripeRows : false , // does not work with getRowClass()
getRowClass : function ( record , index ) {
var status = record . get ( 'status' ) ;
if ( status && status != 'OK' ) {
return "x-form-invalid-field" ;
}
}
} ,
tbar : [
view _btn , '->' , gettext ( 'User name' ) + ':' , ' ' ,
{
xtype : 'textfield' ,
width : 200 ,
value : userfilter ,
enableKeyEvents : true ,
listeners : {
keyup : function ( field , e ) {
userfilter = field . getValue ( ) ;
reload _task . delay ( 500 ) ;
}
}
} , ' ' , gettext ( 'Only Errors' ) + ':' , ' ' ,
{
xtype : 'checkbox' ,
hideLabel : true ,
checked : filter _errors ,
listeners : {
change : function ( field , checked ) {
filter _errors = checked ? 1 : 0 ;
reload _task . delay ( 10 ) ;
}
}
} , ' '
] ,
columns : [
{
header : gettext ( "Start Time" ) ,
dataIndex : 'starttime' ,
width : 100 ,
renderer : function ( value ) {
return Ext . Date . format ( value , "M d H:i:s" ) ;
}
} ,
{
header : gettext ( "End Time" ) ,
dataIndex : 'endtime' ,
width : 100 ,
renderer : function ( value , metaData , record ) {
return Ext . Date . format ( value , "M d H:i:s" ) ;
}
} ,
{
header : gettext ( "Node" ) ,
dataIndex : 'node' ,
width : 100
} ,
{
header : gettext ( "User name" ) ,
dataIndex : 'user' ,
width : 150
} ,
{
header : gettext ( "Description" ) ,
dataIndex : 'upid' ,
flex : 1 ,
2017-01-31 12:18:29 +01:00
renderer : Proxmox . Utils . render _upid
2017-01-31 09:25:24 +01:00
} ,
{
header : gettext ( "Status" ) ,
dataIndex : 'status' ,
width : 200 ,
renderer : function ( value , metaData , record ) {
if ( value == 'OK' ) {
return 'OK' ;
}
// metaData.attr = 'style="color:red;"';
return "ERROR: " + value ;
}
}
] ,
listeners : {
itemdblclick : run _task _viewer ,
selectionchange : function ( v , selections ) {
view _btn . setDisabled ( ! ( selections && selections [ 0 ] ) ) ;
} ,
show : function ( ) { reload _task . delay ( 10 ) ; } ,
destroy : function ( ) { reload _task . cancel ( ) ; }
}
} ) ;
me . callParent ( ) ;
}
} ) ;