]>
Commit | Line | Data |
---|---|---|
11514ea3 EK |
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 | |
636247e2 EK |
6 | * |
7 | * Note that you have to call yourself startUpdate() for the background load | |
8 | * to begin | |
11514ea3 | 9 | */ |
3445bd32 DM |
10 | Ext.define('PVE.data.UpdateStore', { |
11 | extend: 'Ext.data.Store', | |
12 | ||
6897aeb3 DC |
13 | isStopped: true, |
14 | ||
e2c2bf5e DC |
15 | destroy: function() { |
16 | var me = this; | |
17 | me.load_task.cancel(); | |
18 | PVE.data.UpdateQueue.unqueue(me); | |
19 | me.callParent(); | |
20 | }, | |
21 | ||
3445bd32 DM |
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() { | |
6897aeb3 DC |
38 | if (me.isStopped) { |
39 | return; | |
40 | } | |
41 | ||
3445bd32 DM |
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() { | |
6897aeb3 | 54 | me.isStopped = false; |
3445bd32 DM |
55 | run_load_task(); |
56 | }, | |
57 | stopUpdate: function() { | |
6897aeb3 | 58 | me.isStopped = true; |
3445bd32 | 59 | load_task.cancel(); |
fd02b3c5 | 60 | PVE.data.UpdateQueue.unqueue(me); |
3445bd32 DM |
61 | } |
62 | }); | |
63 | ||
64 | me.callParent([config]); | |
65 | ||
e2c2bf5e | 66 | me.load_task = load_task; |
3445bd32 DM |
67 | } |
68 | }); |