]> git.proxmox.com Git - proxmox-widget-toolkit.git/blob - data/UpdateStore.js
update store: move store parameter into config, use getter/setter
[proxmox-widget-toolkit.git] / data / UpdateStore.js
1 /*
2 * Extends the Ext.data.Store type with startUpdate() and stopUpdate() methods
3 * to refresh the store data in the background.
4 * Components using this store directly will flicker due to the redisplay of
5 * the element ater 'config.interval' ms.
6 *
7 * Note that you have to set 'autoStart' or call startUpdate() once yourself
8 * for the background load to begin.
9 */
10 Ext.define('Proxmox.data.UpdateStore', {
11 extend: 'Ext.data.Store',
12 alias: 'store.update',
13
14 config: {
15 interval: 3000,
16
17 isStopped: true,
18
19 autoStart: false,
20 },
21
22 destroy: function() {
23 let me = this;
24 me.stopUpdate();
25 me.callParent();
26 },
27
28 constructor: function(config) {
29 let me = this;
30
31 config = config || {};
32
33 if (!config.storeid) {
34 throw "no storeid specified";
35 }
36
37 let load_task = new Ext.util.DelayedTask();
38
39 let run_load_task = function() {
40 if (me.getIsStopped()) {
41 return;
42 }
43
44 if (Proxmox.Utils.authOK()) {
45 let start = new Date();
46 me.load(function() {
47 let runtime = (new Date()) - start;
48 let interval = me.getInterval() + runtime*2;
49 load_task.delay(interval, run_load_task);
50 });
51 } else {
52 load_task.delay(200, run_load_task);
53 }
54 };
55
56 Ext.apply(config, {
57 startUpdate: function() {
58 me.setIsStopped(false);
59 // run_load_task(); this makes problems with chrome
60 load_task.delay(1, run_load_task);
61 },
62 stopUpdate: function() {
63 me.setIsStopped(true);
64 load_task.cancel();
65 }
66 });
67
68 me.callParent([config]);
69
70 me.load_task = load_task;
71
72 if (me.getAutoStart()) {
73 me.startUpdate();
74 }
75 }
76 });