hedera-web/web/js/htk/field/spin.js

60 lines
1.0 KiB
JavaScript
Raw Normal View History

Htk.Spin = new Class
({
Extends: Htk.Entry
,Tag: 'htk-spin'
,initialize: function (props)
{
this.parent (props);
this.unit = null;
this.digits = 0;
}
,changed: function ()
{
2015-03-15 12:44:57 +00:00
var newValue = (this.node.value == '') ? null : parseFloat (this.node.value);
this.node.value = newValue;
this.realValue = value;
this.signalEmit ('changed');
}
,setEditable: function (editable)
{
if (editable)
{
2015-03-15 12:44:57 +00:00
var input = document.createElement ('input');
input.style.textAlign = 'right';
input.style.width = '100%';
setInputTypeNumber (input);
2015-03-15 12:44:57 +00:00
input.addEventListener ('change', this.changed.bind (this));
this.node.appendChild (input);
this.entry = input;
}
else
{
removeChilds (this.node);
this.entry = null;
}
}
2015-03-15 12:44:57 +00:00
,putValue: function (value)
{
var text;
if (value != null)
{
text = (new Number (value)).toFixed (this.digits);
if (this.unit != null)
text += ' ' + this.unit;
}
else
text = '';
if (!this.editable)
setText (this.node, text);
else
this.entry.value = text;
}
});