2015-06-15 15:31:09 +02:00
/ * E x t e n d s t h e E x t . d a t a . S t o r e t y p e
* with startUpdate ( ) and stopUpdate ( ) methods
* to refresh the store data in the background
* Components using this store directly will flicker
* due to the redisplay of the element ater 'config.interval' ms
2016-02-24 10:53:51 +01:00
*
* Note that you have to call yourself startUpdate ( ) for the background load
* to begin
2015-06-15 15:31:09 +02:00
* /
2015-04-20 06:08:47 +02:00
Ext . define ( 'PVE.data.UpdateStore' , {
extend : 'Ext.data.Store' ,
2016-07-04 13:16:10 +02:00
isStopped : true ,
2015-04-20 06:08:47 +02:00
constructor : function ( config ) {
var me = this ;
config = config || { } ;
if ( ! config . interval ) {
config . interval = 3000 ;
}
if ( ! config . storeid ) {
throw "no storeid specified" ;
}
var load _task = new Ext . util . DelayedTask ( ) ;
var run _load _task = function ( ) {
2016-07-04 13:16:10 +02:00
if ( me . isStopped ) {
return ;
}
2015-04-20 06:08:47 +02:00
if ( PVE . Utils . authOK ( ) ) {
PVE . data . UpdateQueue . queue ( me , function ( runtime , success ) {
var interval = config . interval + runtime * 2 ;
load _task . delay ( interval , run _load _task ) ;
} ) ;
} else {
load _task . delay ( 200 , run _load _task ) ;
}
} ;
Ext . apply ( config , {
startUpdate : function ( ) {
2016-07-04 13:16:10 +02:00
me . isStopped = false ;
2015-04-20 06:08:47 +02:00
run _load _task ( ) ;
} ,
stopUpdate : function ( ) {
2016-07-04 13:16:10 +02:00
me . isStopped = true ;
2015-04-20 06:08:47 +02:00
load _task . cancel ( ) ;
2016-03-11 15:57:28 +01:00
PVE . data . UpdateQueue . unqueue ( me ) ;
2015-04-20 06:08:47 +02:00
}
} ) ;
me . callParent ( [ config ] ) ;
me . on ( 'destroy' , function ( ) {
load _task . cancel ( ) ;
2016-03-11 15:57:28 +01:00
PVE . data . UpdateQueue . unqueue ( me ) ;
2015-04-20 06:08:47 +02:00
} ) ;
}
} ) ;