]>
Commit | Line | Data |
---|---|---|
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 | */ |
10 | Ext.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 || {}; | |
32 | ||
0bb29d35 DM |
33 | if (!config.storeid) { |
34 | throw "no storeid specified"; | |
35 | } | |
36 | ||
94f17704 | 37 | let load_task = new Ext.util.DelayedTask(); |
0bb29d35 | 38 | |
94f17704 | 39 | let run_load_task = function() { |
4a2f360d | 40 | if (me.getIsStopped()) { |
0bb29d35 DM |
41 | return; |
42 | } | |
43 | ||
44 | if (Proxmox.Utils.authOK()) { | |
94f17704 | 45 | let start = new Date(); |
ff5351f7 | 46 | me.load(function() { |
94f17704 | 47 | let runtime = (new Date()) - start; |
4a2f360d | 48 | let interval = me.getInterval() + runtime*2; |
0bb29d35 DM |
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() { | |
4a2f360d | 58 | me.setIsStopped(false); |
929d5ff7 DM |
59 | // run_load_task(); this makes problems with chrome |
60 | load_task.delay(1, run_load_task); | |
0bb29d35 DM |
61 | }, |
62 | stopUpdate: function() { | |
4a2f360d | 63 | me.setIsStopped(true); |
0bb29d35 | 64 | load_task.cancel(); |
0bb29d35 DM |
65 | } |
66 | }); | |
67 | ||
68 | me.callParent([config]); | |
69 | ||
5f0f6b13 | 70 | me.load_task = load_task; |
b07f3756 | 71 | |
4a2f360d | 72 | if (me.getAutoStart()) { |
b07f3756 DC |
73 | me.startUpdate(); |
74 | } | |
0bb29d35 DM |
75 | } |
76 | }); |