2016-09-26 09:28:47 +00:00
|
|
|
|
|
|
|
module.exports = new Class
|
2015-01-23 13:09:30 +00:00
|
|
|
({
|
|
|
|
Extends: Htk.Column
|
|
|
|
,Tag: 'htk-column-spin'
|
|
|
|
,Properties:
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The text to append to the number.
|
2022-05-26 06:08:31 +00:00
|
|
|
*/
|
2015-01-23 13:09:30 +00:00
|
|
|
unit:
|
|
|
|
{
|
|
|
|
type: String
|
|
|
|
,value: null
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The number of decimal places to display.
|
2022-05-26 06:08:31 +00:00
|
|
|
*/
|
2015-01-23 13:09:30 +00:00
|
|
|
digits: {
|
|
|
|
type: Number
|
|
|
|
,value: 0
|
|
|
|
}
|
|
|
|
}
|
2015-11-26 12:30:04 +00:00
|
|
|
|
2022-05-26 06:08:31 +00:00
|
|
|
,initialize: function(props) {
|
2015-11-26 12:30:04 +00:00
|
|
|
this._cssClass = 'cell-spin';
|
2022-05-26 06:08:31 +00:00
|
|
|
this.parent(props);
|
2015-11-26 12:30:04 +00:00
|
|
|
}
|
|
|
|
|
2022-05-26 06:08:31 +00:00
|
|
|
,renderHeader: function() {
|
|
|
|
var th = this.parent();
|
2015-11-26 12:30:04 +00:00
|
|
|
th.className = 'cell-spin';
|
|
|
|
return th;
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2022-05-26 06:08:31 +00:00
|
|
|
,render: function(tr) {
|
|
|
|
var td = this.parent(tr);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
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);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2022-05-26 06:08:31 +00:00
|
|
|
if (this.editable) {
|
|
|
|
var entry = this.createElement('input');
|
2015-01-23 13:09:30 +00:00
|
|
|
entry.type = 'text';
|
2022-05-26 06:08:31 +00:00
|
|
|
entry.addEventListener('change', this.inputChanged.bind(this, tr, entry));
|
|
|
|
td.appendChild(entry);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
if (valueString)
|
|
|
|
entry.value = valueString;
|
2022-05-26 06:08:31 +00:00
|
|
|
} else if (valueString) {
|
2015-01-23 13:09:30 +00:00
|
|
|
if (this.unit)
|
2015-02-01 03:21:54 +00:00
|
|
|
valueString = valueString + this.unit;
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2022-05-26 06:08:31 +00:00
|
|
|
var text = this.createTextNode(valueString);
|
|
|
|
td.appendChild(text);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return td;
|
|
|
|
}
|
|
|
|
|
2022-05-26 06:08:31 +00:00
|
|
|
,inputChanged: function(tr, entry) {
|
|
|
|
this.changed(tr, parseInt(entry.value));
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
});
|