proxmox-widget-toolkit/data/UpdateStore.js
Dominik Csapak 5f0f6b13b5 fix updateStore destroy
the store never fires/gets a destroy event, thus it
never stops the load_task and never unqueues itself in case
the store gets destroyed but not explicitely stopped

with overriding the destroy method, this works now as intended

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2017-10-11 11:46:29 +02:00

76 lines
1.5 KiB
JavaScript

/* Extends the Ext.data.Store type
* 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
*
* Note that you have to call yourself startUpdate() for the background load
* to begin
*/
Ext.define('Proxmox.data.UpdateStore', {
extend: 'Ext.data.Store',
alias: 'store.update',
isStopped: true,
autoStart: false,
destroy: function() {
var me = this;
me.load_task.cancel();
Proxmox.data.UpdateQueue.unqueue(me);
me.callParent();
},
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() {
if (me.isStopped) {
return;
}
if (Proxmox.Utils.authOK()) {
Proxmox.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() {
me.isStopped = false;
run_load_task();
},
stopUpdate: function() {
me.isStopped = true;
load_task.cancel();
Proxmox.data.UpdateQueue.unqueue(me);
}
});
me.callParent([config]);
me.load_task = load_task;
if (me.autoStart) {
me.startUpdate();
}
}
});