0
1
Fork 0
hedera-web-mindshore/js/htk/column/spin.js

67 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.
2022-05-26 06:08:31 +00:00
*/
unit:
{
type: String
,value: null
},
/**
* The number of decimal places to display.
2022-05-26 06:08:31 +00:00
*/
digits: {
type: Number
,value: 0
}
}
2022-05-26 06:08:31 +00:00
,initialize: function(props) {
this._cssClass = 'cell-spin';
2022-05-26 06:08:31 +00:00
this.parent(props);
}
2022-05-26 06:08:31 +00:00
,renderHeader: function() {
var th = this.parent();
th.className = 'cell-spin';
return th;
}
2022-05-26 06:08:31 +00:00
,render: function(tr) {
var td = this.parent(tr);
var valueString = null;
if (this.value !== null && this.value !== undefined)
2022-05-26 06:08:31 +00:00
valueString = new Number(this.value).toFixed(this.digits);
2022-05-26 06:08:31 +00:00
if (this.editable) {
var entry = this.createElement('input');
entry.type = 'text';
2022-05-26 06:08:31 +00:00
entry.addEventListener('change', this.inputChanged.bind(this, tr, entry));
td.appendChild(entry);
if (valueString)
entry.value = valueString;
2022-05-26 06:08:31 +00:00
} else if (valueString) {
if (this.unit)
2015-02-01 03:21:54 +00:00
valueString = valueString + this.unit;
2022-05-26 06:08:31 +00:00
var text = this.createTextNode(valueString);
td.appendChild(text);
}
return td;
}
2022-05-26 06:08:31 +00:00
,inputChanged: function(tr, entry) {
this.changed(tr, parseInt(entry.value));
}
});