]> git.proxmox.com Git - proxmox-widget-toolkit.git/blob - src/panel/InfoWidget.js
8005fa80e085f8c54fb73468f16e9cb087d6202c
[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 updateValue: function(text, usage) {
58 var me = this;
59 var label = me.getComponent('label');
60 label.update(Ext.apply(label.data, { title: me.title, usage: text }));
61
62 if (usage !== undefined &&
63 me.printBar &&
64 Ext.isNumeric(usage) &&
65 usage >= 0) {
66 var progressBar = me.getComponent('progress');
67 progressBar.updateProgress(usage, '');
68 if (usage > me.criticalThreshold) {
69 progressBar.removeCls('warning');
70 progressBar.addCls('critical');
71 } else if (usage > me.warningThreshold) {
72 progressBar.removeCls('critical');
73 progressBar.addCls('warning');
74 } else {
75 progressBar.removeCls('warning');
76 progressBar.removeCls('critical');
77 }
78 }
79 },
80
81 initComponent: function() {
82 var me = this;
83
84 if (!me.title) {
85 throw "no title defined";
86 }
87
88 me.callParent();
89
90 me.getComponent('progress').setVisible(me.printBar);
91
92 me.updateValue(me.text, me.value);
93 me.setIconCls(me.iconCls);
94 },
95
96 });