]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/form/BandwidthSelector.js
1 Ext
.define('PVE.form.BandwidthField', {
2 extend
: 'Ext.form.FieldContainer',
3 alias
: 'widget.pveBandwidthField',
5 mixins
: ['Proxmox.Mixin.CBind'],
12 unitlabel
: (get) => get('unit') + '/s',
26 'GiB': 1024*1024*1024,
32 // display unit (TODO: make (optionally) selectable)
35 // use this if the backend saves values in another unit tha bytes, e.g.,
36 // for KiB set it to 'KiB'
37 backendUnit
: undefined,
44 emptyText
: '{emptyText}',
48 submitLocaleSeparator
: false,
49 fieldStyle
: 'text-align: right',
51 enableKeyEvents
: true,
52 setValue: function(v
) {
53 if (!this._transformed
) {
54 let fieldct
= this.up('pveBandwidthField');
55 let vm
= fieldct
.getViewModel();
56 let unit
= vm
.get('unit');
58 v
/= fieldct
.units
[unit
];
59 v
*= fieldct
.backendFactor
;
61 this._transformed
= true;
64 if (v
== 0) v
= undefined;
66 return Ext
.form
.field
.Text
.prototype.setValue
.call(this, v
);
68 getSubmitValue: function() {
69 let v
= this.processRawValue(this.getRawValue());
70 v
= v
.replace(this.decimalSeparator
, '.');
72 if (v
=== undefined) return null;
73 // FIXME: make it configurable, as this only works if 0 === default
74 if (v
== 0 || v
== 0.0) return null;
76 let fieldct
= this.up('pveBandwidthField');
77 let vm
= fieldct
.getViewModel();
78 let unit
= vm
.get('unit');
80 v
= parseFloat(v
) * fieldct
.units
[unit
];
81 v
/= fieldct
.backendFactor
;
83 return ''+ Math
.floor(v
);
86 // our setValue gets only called if we have a value, avoid
87 // transformation of the first user-entered value
88 keydown: function() { this._transformed
= true; },
92 xtype
: 'displayfield',
100 change
: (f
, v
) => f
.originalValue
= v
,
106 initComponent: function() {
109 me
.unit
= me
.unit
|| 'MiB';
110 if (!(me
.unit
in me
.units
)) {
111 throw "unknown unit: " + me
.unit
;
114 me
.backendFactor
= 1;
115 if (me
.backendUnit
!== undefined) {
116 if (!(me
.unit
in me
.units
)) {
117 throw "unknown backend unit: " + me
.backendUnit
;
119 me
.backendFactor
= me
.units
[me
.backendUnit
];
123 me
.callParent(arguments
);
125 me
.getViewModel().set('unit', me
.unit
);