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.
|
|
|
|
**/
|
|
|
|
unit:
|
|
|
|
{
|
|
|
|
type: String
|
|
|
|
,value: null
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The number of decimal places to display.
|
|
|
|
**/
|
|
|
|
digits: {
|
|
|
|
type: Number
|
|
|
|
,value: 0
|
|
|
|
}
|
|
|
|
}
|
2015-11-26 12:30:04 +00:00
|
|
|
|
|
|
|
,initialize: function (props)
|
|
|
|
{
|
|
|
|
this._cssClass = 'cell-spin';
|
|
|
|
this.parent (props);
|
|
|
|
}
|
|
|
|
|
|
|
|
,renderHeader: function ()
|
|
|
|
{
|
|
|
|
var th = this.parent ();
|
|
|
|
th.className = 'cell-spin';
|
|
|
|
return th;
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
,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');
|
2015-01-23 13:09:30 +00:00
|
|
|
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;
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2016-10-16 14:16:08 +00:00
|
|
|
var text = this.createTextNode (valueString);
|
2015-01-23 13:09:30 +00:00
|
|
|
td.appendChild (text);
|
|
|
|
}
|
|
|
|
|
|
|
|
return td;
|
|
|
|
}
|
|
|
|
|
|
|
|
,inputChanged: function (tr, entry)
|
|
|
|
{
|
|
|
|
this.changed (tr, parseInt (entry.value));
|
|
|
|
}
|
|
|
|
});
|