]>
Commit | Line | Data |
---|---|---|
054ac1b8 DC |
1 | Ext.define('PVE.panel.StatusView', { |
2 | extend: 'Ext.panel.Panel', | |
3 | alias: 'widget.pveStatusView', | |
4 | ||
5 | layout: { | |
6 | type: 'column' | |
7 | }, | |
8 | ||
9 | title: gettext('Status'), | |
10 | ||
11 | getRecordValue: function(key, store) { | |
12 | if (!key) { | |
13 | throw "no key given"; | |
14 | } | |
15 | var me = this; | |
16 | ||
17 | if (store === undefined) { | |
18 | store = me.getStore(); | |
19 | } | |
20 | ||
21 | var rec = store.getById(key); | |
22 | if (rec) { | |
23 | return rec.data.value; | |
24 | } | |
25 | ||
26 | return ''; | |
27 | }, | |
28 | ||
29 | fieldRenderer: function(val,max) { | |
30 | if (max === undefined) { | |
31 | return val; | |
32 | } | |
33 | ||
34 | if (!Ext.isNumeric(max) || max === 1) { | |
35 | return PVE.Utils.render_usage(val); | |
36 | } | |
37 | return PVE.Utils.render_size_usage(val,max); | |
38 | }, | |
39 | ||
40 | fieldCalculator: function(used, max) { | |
41 | if (!Ext.isNumeric(max) && Ext.isNumeric(used)) { | |
42 | return used; | |
43 | } else if(!Ext.isNumeric(used)) { | |
44 | /* we come here if the field is from a node | |
45 | * where the records are not mem and maxmem | |
46 | * but mem.used and mem.total | |
47 | */ | |
48 | if (used.used !== undefined && | |
49 | used.total !== undefined) { | |
50 | return used.used/used.total; | |
51 | } | |
52 | } | |
53 | ||
54 | return used/max; | |
55 | }, | |
56 | ||
57 | updateField: function(field) { | |
58 | var me = this; | |
59 | var text = ''; | |
60 | var renderer = me.fieldRenderer; | |
61 | if (Ext.isFunction(field.renderer)) { | |
62 | renderer = field.renderer; | |
63 | } | |
aec9d2ec DC |
64 | if (field.multiField === true) { |
65 | field.updateValue(renderer.call(field, me.getStore().getRecord())); | |
66 | } else if (field.textField !== undefined) { | |
67 | field.updateValue(renderer.call(field, me.getRecordValue(field.textField))); | |
054ac1b8 DC |
68 | } else if(field.valueField !== undefined) { |
69 | var used = me.getRecordValue(field.valueField); | |
70 | /*jslint confusion: true*/ | |
71 | /* string and int */ | |
72 | var max = field.maxField !== undefined ? me.getRecordValue(field.maxField) : 1; | |
73 | ||
74 | var calculate = me.fieldCalculator; | |
75 | ||
76 | if (Ext.isFunction(field.calculate)) { | |
77 | calculate = field.calculate; | |
78 | } | |
d3ecda12 | 79 | field.updateValue(renderer.call(field, used,max), calculate(used,max)); |
054ac1b8 DC |
80 | } |
81 | }, | |
82 | ||
83 | getStore: function() { | |
84 | var me = this; | |
85 | if (!me.rstore) { | |
86 | throw "there is no rstore"; | |
87 | } | |
88 | ||
89 | return me.rstore; | |
90 | }, | |
91 | ||
92 | updateTitle: function() { | |
93 | var me = this; | |
94 | me.setTitle(me.getRecordValue('name')); | |
95 | }, | |
96 | ||
97 | updateValues: function(store, records, success) { | |
98 | if (!success) { | |
99 | return; // do not update if store load was not successful | |
100 | } | |
101 | var me = this; | |
102 | var itemsToUpdate = me.query('pveInfoWidget'); | |
103 | ||
104 | itemsToUpdate.forEach(me.updateField, me); | |
105 | ||
106 | me.updateTitle(store); | |
107 | }, | |
108 | ||
109 | initComponent: function() { | |
110 | var me = this; | |
111 | ||
112 | if (!me.rstore) { | |
113 | throw "no rstore given"; | |
114 | } | |
115 | ||
116 | if (!me.title) { | |
117 | throw "no title given"; | |
118 | } | |
119 | ||
e7ade592 | 120 | Proxmox.Utils.monStoreErrors(me, me.rstore); |
054ac1b8 DC |
121 | |
122 | me.callParent(); | |
123 | ||
124 | me.mon(me.rstore, 'load', 'updateValues'); | |
125 | } | |
126 | ||
127 | }); |