]> git.proxmox.com Git - proxmox-widget-toolkit.git/blob - src/panel/InfoWidget.js
InfoWidget: add setData, so that we can bind it
[proxmox-widget-toolkit.git] / src / panel / InfoWidget.js
1 Ext.define('Proxmox.widget.Info', {
2 extend: 'Ext.container.Container',
3 alias: 'widget.pmxInfoWidget',
4
5 layout: {
6 type: 'vbox',
7 align: 'stretch',
8 },
9
10 value: 0,
11 maximum: 1,
12 printBar: true,
13 items: [
14 {
15 xtype: 'component',
16 itemId: 'label',
17 data: {
18 title: '',
19 usage: '',
20 iconCls: undefined,
21 },
22 tpl: [
23 '<div class="left-aligned">',
24 '<tpl if="iconCls">',
25 '<i class="{iconCls}"></i> ',
26 '</tpl>',
27 '{title}</div>&nbsp;<div class="right-aligned">{usage}</div>',
28 ],
29 },
30 {
31 height: 2,
32 border: 0,
33 },
34 {
35 xtype: 'progressbar',
36 itemId: 'progress',
37 height: 5,
38 value: 0,
39 animate: true,
40 },
41 ],
42
43 warningThreshold: 0.6,
44 criticalThreshold: 0.9,
45
46 setPrintBar: function(enable) {
47 var me = this;
48 me.printBar = enable;
49 me.getComponent('progress').setVisible(enable);
50 },
51
52 setIconCls: function(iconCls) {
53 var me = this;
54 me.getComponent('label').data.iconCls = iconCls;
55 },
56
57 setData: function(data) {
58 this.updateValue(data.text, data.usage);
59 },
60
61 updateValue: function(text, usage) {
62 var me = this;
63 var label = me.getComponent('label');
64 label.update(Ext.apply(label.data, { title: me.title, usage: text }));
65
66 if (usage !== undefined &&
67 me.printBar &&
68 Ext.isNumeric(usage) &&
69 usage >= 0) {
70 var progressBar = me.getComponent('progress');
71 progressBar.updateProgress(usage, '');
72 if (usage > me.criticalThreshold) {
73 progressBar.removeCls('warning');
74 progressBar.addCls('critical');
75 } else if (usage > me.warningThreshold) {
76 progressBar.removeCls('critical');
77 progressBar.addCls('warning');
78 } else {
79 progressBar.removeCls('warning');
80 progressBar.removeCls('critical');
81 }
82 }
83 },
84
85 initComponent: function() {
86 var me = this;
87
88 if (!me.title) {
89 throw "no title defined";
90 }
91
92 me.callParent();
93
94 me.getComponent('progress').setVisible(me.printBar);
95
96 me.updateValue(me.text, me.value);
97 me.setIconCls(me.iconCls);
98 },
99
100 });