]>
Commit | Line | Data |
---|---|---|
0bb29d35 DM |
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 | */ | |
10 | Ext.define('Proxmox.data.UpdateStore', { | |
11 | extend: 'Ext.data.Store', | |
12 | ||
13 | isStopped: true, | |
14 | ||
15 | constructor: function(config) { | |
16 | var me = this; | |
17 | ||
18 | config = config || {}; | |
19 | ||
20 | if (!config.interval) { | |
21 | config.interval = 3000; | |
22 | } | |
23 | ||
24 | if (!config.storeid) { | |
25 | throw "no storeid specified"; | |
26 | } | |
27 | ||
28 | var load_task = new Ext.util.DelayedTask(); | |
29 | ||
30 | var run_load_task = function() { | |
31 | if (me.isStopped) { | |
32 | return; | |
33 | } | |
34 | ||
35 | if (Proxmox.Utils.authOK()) { | |
36 | Proxmox.data.UpdateQueue.queue(me, function(runtime, success) { | |
37 | var interval = config.interval + runtime*2; | |
38 | load_task.delay(interval, run_load_task); | |
39 | }); | |
40 | } else { | |
41 | load_task.delay(200, run_load_task); | |
42 | } | |
43 | }; | |
44 | ||
45 | Ext.apply(config, { | |
46 | startUpdate: function() { | |
47 | me.isStopped = false; | |
48 | run_load_task(); | |
49 | }, | |
50 | stopUpdate: function() { | |
51 | me.isStopped = true; | |
52 | load_task.cancel(); | |
53 | Proxmox.data.UpdateQueue.unqueue(me); | |
54 | } | |
55 | }); | |
56 | ||
57 | me.callParent([config]); | |
58 | ||
59 | me.on('destroy', function() { | |
60 | load_task.cancel(); | |
61 | Proxmox.data.UpdateQueue.unqueue(me); | |
62 | }); | |
63 | } | |
64 | }); |