2016-09-26 09:28:47 +00:00
|
|
|
|
2022-05-24 21:11:12 +00:00
|
|
|
var RadioGroup = require('./radio-group');
|
2016-09-26 09:28:47 +00:00
|
|
|
|
2022-05-24 21:11:12 +00:00
|
|
|
module.exports = new Class({
|
2015-03-27 19:10:49 +00:00
|
|
|
Extends: Htk.Field
|
2015-01-23 13:09:30 +00:00
|
|
|
,Tag: 'htk-radio'
|
2022-05-24 21:11:12 +00:00
|
|
|
,Properties: {
|
|
|
|
tip: {
|
2015-03-27 19:10:49 +00:00
|
|
|
type: String
|
2022-05-24 21:11:12 +00:00
|
|
|
,set: function(x) {
|
2015-03-27 19:10:49 +00:00
|
|
|
if (x)
|
|
|
|
this.node.title = _(x);
|
|
|
|
}
|
|
|
|
},
|
2022-05-24 21:11:12 +00:00
|
|
|
val: {
|
|
|
|
type: String
|
|
|
|
,get: function() {
|
|
|
|
return this._val;
|
|
|
|
}
|
|
|
|
,set: function(x) {
|
|
|
|
this._val = x;
|
|
|
|
this.node.value = !x ? '' : x;
|
|
|
|
this._onRadioGroupChange();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: String
|
|
|
|
,get: function() {
|
|
|
|
return this.node.name;
|
|
|
|
}
|
|
|
|
,set: function(x) {
|
|
|
|
this.node.name = x;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
radioGroup: {
|
2016-09-26 09:28:47 +00:00
|
|
|
type: RadioGroup
|
2022-05-24 21:11:12 +00:00
|
|
|
,get: function() {
|
|
|
|
return this._radioGroup;
|
|
|
|
}
|
|
|
|
,set: function(x) {
|
2018-05-16 09:36:42 +00:00
|
|
|
if (this._radioGroup)
|
2022-05-24 21:11:12 +00:00
|
|
|
this._radioGroup.removeButton(this);
|
2018-05-16 09:36:42 +00:00
|
|
|
|
2022-05-24 21:11:12 +00:00
|
|
|
this.link({_radioGroup: x}, {'changed': this._onRadioGroupChange});
|
2018-05-16 09:36:42 +00:00
|
|
|
this.node.name = x.name;
|
|
|
|
x.buttons.push(this);
|
2022-05-24 21:11:12 +00:00
|
|
|
this._onRadioGroupChange();
|
2015-03-27 19:10:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,_radioGroup: null
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2022-05-24 21:11:12 +00:00
|
|
|
,render: function() {
|
|
|
|
var radio = Vn.Browser.createRadio('', this.doc);
|
2015-03-27 19:10:49 +00:00
|
|
|
radio.checked = false;
|
2022-05-24 21:11:12 +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
|
|
|
}
|
|
|
|
|
2022-05-24 21:11:12 +00:00
|
|
|
,_onChange: function() {
|
|
|
|
console.log(this._val);
|
2015-03-27 19:10:49 +00:00
|
|
|
if (this.node.checked && this._radioGroup)
|
2022-05-24 21:11:12 +00:00
|
|
|
this._radioGroup.value = this._val || this.value;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
2015-03-27 19:10:49 +00:00
|
|
|
|
2022-05-24 21:11:12 +00:00
|
|
|
,_onRadioGroupChange: function() {
|
|
|
|
const value = this._radioGroup.value;
|
|
|
|
this.node.checked =
|
|
|
|
value && (value == this._val || value == this.value);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 21:11:12 +00:00
|
|
|
,putValue: function(value) {
|
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
|
|
|
}
|
|
|
|
|
2022-05-24 21:11:12 +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
|
|
|
}
|
|
|
|
});
|