2016-09-26 09:28:47 +00:00
|
|
|
|
|
|
|
var RadioGroup = require ('./radio-group');
|
|
|
|
|
|
|
|
module.exports = new Class
|
2015-01-23 13:09:30 +00:00
|
|
|
({
|
2015-03-27 19:10:49 +00:00
|
|
|
Extends: Htk.Field
|
2015-01-23 13:09:30 +00:00
|
|
|
,Tag: 'htk-radio'
|
2015-03-27 19:10:49 +00:00
|
|
|
,Properties:
|
|
|
|
{
|
|
|
|
tip:
|
|
|
|
{
|
|
|
|
type: String
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
if (x)
|
|
|
|
this.node.title = _(x);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
radioGroup:
|
|
|
|
{
|
2016-09-26 09:28:47 +00:00
|
|
|
type: RadioGroup
|
2015-03-27 19:10:49 +00:00
|
|
|
,set: function (x)
|
|
|
|
{
|
2017-04-19 06:16:37 +00:00
|
|
|
this.link ({_radioGroup: x}, {changed: this._onRadioGroupChange});
|
2017-04-08 11:42:27 +00:00
|
|
|
this.node.name = x.radioName
|
2015-11-17 10:34:33 +00:00
|
|
|
this._onRadioGroupChange ();
|
2015-03-27 19:10:49 +00:00
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._radioGroup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,_radioGroup: null
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2016-10-16 14:16:08 +00:00
|
|
|
,render: function ()
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2017-04-08 11:42:27 +00:00
|
|
|
var radio = this.doc.createElement ('input');
|
|
|
|
radio.type = 'radio';
|
|
|
|
radio.name = '';
|
2015-03-27 19:10:49 +00:00
|
|
|
radio.checked = false;
|
2015-11-17 10:34:33 +00:00
|
|
|
radio.addEventListener ('change', this._onChange.bind (this));
|
2016-10-14 10:58:35 +00:00
|
|
|
this._node = radio;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2015-11-17 10:34:33 +00:00
|
|
|
,_onChange: function ()
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-03-27 19:10:49 +00:00
|
|
|
if (this.node.checked && this._radioGroup)
|
|
|
|
this._radioGroup.value = this.value;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
2015-03-27 19:10:49 +00:00
|
|
|
|
2015-11-17 10:34:33 +00:00
|
|
|
,_onRadioGroupChange: function ()
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-06-30 12:06:19 +00:00
|
|
|
if (this._radioGroup.value && this._radioGroup.value == this.value)
|
2015-03-27 19:10:49 +00:00
|
|
|
this.node.checked = true;
|
|
|
|
else
|
|
|
|
this.node.checked = false;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 19:10:49 +00:00
|
|
|
,putValue: function (value)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-03-27 19:10:49 +00:00
|
|
|
if (!value)
|
|
|
|
this.node.value = '';
|
|
|
|
else
|
|
|
|
this.node.value = value;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,setEditable: function (editable)
|
|
|
|
{
|
2015-03-27 19:10:49 +00:00
|
|
|
this.node.disabled = !editable;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
});
|