]>
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', | |
b07f3756 | 12 | alias: 'store.update', |
0bb29d35 DM |
13 | |
14 | isStopped: true, | |
15 | ||
b07f3756 DC |
16 | autoStart: false, |
17 | ||
5f0f6b13 DC |
18 | destroy: function() { |
19 | var me = this; | |
ff5351f7 | 20 | me.stopUpdate(); |
5f0f6b13 DC |
21 | me.callParent(); |
22 | }, | |
23 | ||
0bb29d35 DM |
24 | constructor: function(config) { |
25 | var me = this; | |
26 | ||
27 | config = config || {}; | |
28 | ||
29 | if (!config.interval) { | |
30 | config.interval = 3000; | |
31 | } | |
32 | ||
33 | if (!config.storeid) { | |
34 | throw "no storeid specified"; | |
35 | } | |
36 | ||
37 | var load_task = new Ext.util.DelayedTask(); | |
38 | ||
39 | var run_load_task = function() { | |
40 | if (me.isStopped) { | |
41 | return; | |
42 | } | |
43 | ||
44 | if (Proxmox.Utils.authOK()) { | |
ff5351f7 DC |
45 | var start = new Date(); |
46 | me.load(function() { | |
47 | var runtime = (new Date()) - start; | |
0bb29d35 DM |
48 | var interval = config.interval + 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.isStopped = 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() { | |
63 | me.isStopped = true; | |
64 | load_task.cancel(); | |
0bb29d35 DM |
65 | } |
66 | }); | |
67 | ||
68 | me.callParent([config]); | |
69 | ||
5f0f6b13 | 70 | me.load_task = load_task; |
b07f3756 DC |
71 | |
72 | if (me.autoStart) { | |
73 | me.startUpdate(); | |
74 | } | |
0bb29d35 DM |
75 | } |
76 | }); |