]> git.proxmox.com Git - proxmox-widget-toolkit.git/blame - data/UpdateStore.js
use eslint and execute as check target
[proxmox-widget-toolkit.git] / data / UpdateStore.js
CommitLineData
94f17704
TL
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.
0bb29d35 6 *
94f17704
TL
7 * Note that you have to set 'autoStart' or call startUpdate() once yourself
8 * for the background load to begin.
0bb29d35
DM
9 */
10Ext.define('Proxmox.data.UpdateStore', {
11 extend: 'Ext.data.Store',
b07f3756 12 alias: 'store.update',
0bb29d35 13
4a2f360d
TL
14 config: {
15 interval: 3000,
0bb29d35 16
4a2f360d
TL
17 isStopped: true,
18
19 autoStart: false,
20 },
b07f3756 21
5f0f6b13 22 destroy: function() {
94f17704 23 let me = this;
ff5351f7 24 me.stopUpdate();
5f0f6b13
DC
25 me.callParent();
26 },
27
0bb29d35 28 constructor: function(config) {
94f17704 29 let me = this;
0bb29d35
DM
30
31 config = config || {};
d4c342fb
DC
32 if (config.interval === undefined) {
33 delete config.interval;
34 }
0bb29d35 35
0bb29d35
DM
36 if (!config.storeid) {
37 throw "no storeid specified";
38 }
39
94f17704 40 let load_task = new Ext.util.DelayedTask();
0bb29d35 41
94f17704 42 let run_load_task = function() {
4a2f360d 43 if (me.getIsStopped()) {
0bb29d35
DM
44 return;
45 }
46
47 if (Proxmox.Utils.authOK()) {
94f17704 48 let start = new Date();
ff5351f7 49 me.load(function() {
01031528 50 let runtime = new Date() - start;
4a2f360d 51 let interval = me.getInterval() + runtime*2;
0bb29d35
DM
52 load_task.delay(interval, run_load_task);
53 });
54 } else {
55 load_task.delay(200, run_load_task);
56 }
57 };
58
59 Ext.apply(config, {
60 startUpdate: function() {
4a2f360d 61 me.setIsStopped(false);
929d5ff7
DM
62 // run_load_task(); this makes problems with chrome
63 load_task.delay(1, run_load_task);
0bb29d35
DM
64 },
65 stopUpdate: function() {
4a2f360d 66 me.setIsStopped(true);
0bb29d35 67 load_task.cancel();
01031528 68 },
0bb29d35
DM
69 });
70
71 me.callParent([config]);
72
5f0f6b13 73 me.load_task = load_task;
b07f3756 74
4a2f360d 75 if (me.getAutoStart()) {
b07f3756
DC
76 me.startUpdate();
77 }
01031528 78 },
0bb29d35 79});