0
1
Fork 0
hedera-web-mindshore/package/usr/share/hedera-web/js/htk/field/spin.js

64 lines
1.1 KiB
JavaScript
Executable File

Htk.Spin = new Class
({
Extends: Htk.Entry
,Tag: 'htk-spin'
,initialize: function (props)
{
this.parent (props);
this.unit = null;
this.digits = 0;
}
,changed: function ()
{
var value = (this.entry.value == '') ? null : parseFloat (this.entry.value);
this.entry.value = value;
this.realValue = value;
this.signalEmit ('changed');
}
,setEditable: function (editable)
{
if (editable)
{
var input;
var obj = this;
input = document.createElement ('input');
input.style.textAlign = 'right';
input.style.width = '100%';
setInputTypeNumber (input);
input.addEventListener ('change',
function () { obj.changed (); }, false);
this.node.appendChild (input);
this.entry = input;
}
else
{
removeChilds (this.node);
this.entry = null;
}
}
,setRealValue: 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;
}
});