]> git.proxmox.com Git - pve-manager.git/blame_incremental - www/manager6/data/UpdateStore.js
fix updateStore destroy
[pve-manager.git] / www / manager6 / data / UpdateStore.js
... / ...
CommitLineData
1/* Extends the Ext.data.Store type
2 * with startUpdate() and stopUpdate() methods
3 * to refresh the store data in the background
4 * Components using this store directly will flicker
5 * due to the redisplay of the element ater 'config.interval' ms
6 *
7 * Note that you have to call yourself startUpdate() for the background load
8 * to begin
9 */
10Ext.define('PVE.data.UpdateStore', {
11 extend: 'Ext.data.Store',
12
13 isStopped: true,
14
15 destroy: function() {
16 var me = this;
17 me.load_task.cancel();
18 PVE.data.UpdateQueue.unqueue(me);
19 me.callParent();
20 },
21
22 constructor: function(config) {
23 var me = this;
24
25 config = config || {};
26
27 if (!config.interval) {
28 config.interval = 3000;
29 }
30
31 if (!config.storeid) {
32 throw "no storeid specified";
33 }
34
35 var load_task = new Ext.util.DelayedTask();
36
37 var run_load_task = function() {
38 if (me.isStopped) {
39 return;
40 }
41
42 if (PVE.Utils.authOK()) {
43 PVE.data.UpdateQueue.queue(me, function(runtime, success) {
44 var interval = config.interval + runtime*2;
45 load_task.delay(interval, run_load_task);
46 });
47 } else {
48 load_task.delay(200, run_load_task);
49 }
50 };
51
52 Ext.apply(config, {
53 startUpdate: function() {
54 me.isStopped = false;
55 run_load_task();
56 },
57 stopUpdate: function() {
58 me.isStopped = true;
59 load_task.cancel();
60 PVE.data.UpdateQueue.unqueue(me);
61 }
62 });
63
64 me.callParent([config]);
65
66 me.load_task = load_task;
67 }
68});