]> git.proxmox.com Git - pve-manager.git/blame - www/manager/data/DiffStore.js
disable animation of charts on load
[pve-manager.git] / www / manager / data / DiffStore.js
CommitLineData
aff192e6
DM
1/* Config properties:
2 * rstore: A storage to track changes
3 * Only works if rstore has a model and use 'idProperty'
4 */
5Ext.define('PVE.data.DiffStore', {
6 extend: 'Ext.data.Store',
7
71e43f5b
DM
8 sortAfterUpdate: false,
9
aff192e6
DM
10 constructor: function(config) {
11 var me = this;
12
13 config = config || {};
14
15 if (!config.rstore) {
16 throw "no rstore specified";
17 }
18
19 if (!config.rstore.model) {
20 throw "no rstore model specified";
21 }
22
23 var rstore = config.rstore;
24
25 Ext.apply(config, {
26 model: rstore.model,
27 proxy: { type: 'memory' }
28 });
29
30 me.callParent([config]);
31
32 var first_load = true;
33
34 var cond_add_item = function(data, id) {
35 var olditem = me.getById(id);
36 if (olditem) {
37 olditem.beginEdit();
38 me.model.prototype.fields.eachKey(function(field) {
39 if (olditem.data[field] !== data[field]) {
40 olditem.set(field, data[field]);
41 }
42 });
43 olditem.endEdit(true);
44 olditem.commit();
45 } else {
46 var newrec = Ext.ModelMgr.create(data, me.model, id);
47 var pos = (me.appendAtStart && !first_load) ? 0 : me.data.length;
48 me.insert(pos, newrec);
49 }
50 };
51
52 me.mon(rstore, 'load', function(s, records, success) {
53
54 if (!success) {
55 return;
56 }
57
58 me.suspendEvents();
59
60 // remove vanished items
61 (me.snapshot || me.data).each(function(olditem) {
62 var item = rstore.getById(olditem.getId());
63 if (!item) {
64 me.remove(olditem);
65 }
66 });
67
68 rstore.each(function(item) {
69 cond_add_item(item.data, item.getId());
70 });
71
72 me.filter();
73
71e43f5b
DM
74 if (me.sortAfterUpdate) {
75 me.sort();
76 }
77
aff192e6
DM
78 first_load = false;
79
80 me.resumeEvents();
81 me.fireEvent('datachanged', me);
82 });
83 }
84});