]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/data/UpdateStore.js
rename manager5 to manager6
[pve-manager.git] / www / manager6 / data / UpdateStore.js
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 Ext.define('PVE.data.UpdateStore', {
8 extend: 'Ext.data.Store',
9
10 constructor: function(config) {
11 var me = this;
12
13 config = config || {};
14
15 if (!config.interval) {
16 config.interval = 3000;
17 }
18
19 if (!config.storeid) {
20 throw "no storeid specified";
21 }
22
23 var load_task = new Ext.util.DelayedTask();
24
25 var run_load_task = function() {
26 if (PVE.Utils.authOK()) {
27 PVE.data.UpdateQueue.queue(me, function(runtime, success) {
28 var interval = config.interval + runtime*2;
29 load_task.delay(interval, run_load_task);
30 });
31 } else {
32 load_task.delay(200, run_load_task);
33 }
34 };
35
36 Ext.apply(config, {
37 startUpdate: function() {
38 run_load_task();
39 },
40 stopUpdate: function() {
41 load_task.cancel();
42 }
43 });
44
45 me.callParent([config]);
46
47 me.on('destroy', function() {
48 load_task.cancel();
49 });
50 }
51 });