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

74 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-09-26 09:28:47 +00:00
module.exports = new Class
({
Extends: Htk.Column
,Tag: 'htk-column-spin'
,Properties:
{
/**
* The text to append to the number.
2016-12-20 09:32:17 +00:00
*/
unit:
{
type: String
,value: null
},
/**
* The number of decimal places to display.
2016-12-20 09:32:17 +00:00
*/
digits: {
type: Number
,value: 0
}
}
,initialize: function (props)
{
this._cssClass = 'cell-spin';
this.parent (props);
}
,renderHeader: function ()
{
var th = this.parent ();
th.className = 'cell-spin';
return th;
}
,render: function (tr)
{
var td = this.parent (tr);
var valueString = null;
if (this.value !== null && this.value !== undefined)
valueString = new Number (this.value).toFixed (this.digits);
if (this.editable)
{
2016-10-16 14:16:08 +00:00
var entry = this.createElement ('input');
entry.type = 'text';
entry.addEventListener ('change', this.inputChanged.bind (this, tr, entry));
td.appendChild (entry);
if (valueString)
entry.value = valueString;
}
else if (valueString)
{
if (this.unit)
2015-02-01 03:21:54 +00:00
valueString = valueString + this.unit;
2016-10-16 14:16:08 +00:00
var text = this.createTextNode (valueString);
td.appendChild (text);
}
return td;
}
,inputChanged: function (tr, entry)
{
this.changed (tr, parseInt (entry.value));
}
});