2015-11-15 08:23:16 +08:00
|
|
|
import ko from 'ko';
|
2019-07-05 03:09:27 +08:00
|
|
|
import { AbstractComponent } from 'Component/Abstract';
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2019-07-05 03:09:27 +08:00
|
|
|
class AbstractRadio extends AbstractComponent {
|
2015-11-15 08:23:16 +08:00
|
|
|
/**
|
|
|
|
* @param {Object} params
|
|
|
|
*/
|
|
|
|
constructor(params) {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.values = ko.observableArray([]);
|
|
|
|
|
|
|
|
this.value = params.value;
|
2020-07-30 03:49:41 +08:00
|
|
|
if (undefined === this.value || !this.value.subscribe) {
|
2015-11-15 08:23:16 +08:00
|
|
|
this.value = ko.observable('');
|
|
|
|
}
|
|
|
|
|
2020-07-30 03:49:41 +08:00
|
|
|
this.inline = undefined === params.inline ? false : params.inline;
|
|
|
|
this.readOnly = undefined === params.readOnly ? false : !!params.readOnly;
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2019-07-05 03:09:27 +08:00
|
|
|
if (params.values) {
|
2020-07-23 02:09:31 +08:00
|
|
|
this.values(Object.entries(params.values).map((label, value) => ({ label: label, value: value })));
|
2015-11-15 08:23:16 +08:00
|
|
|
}
|
|
|
|
|
2020-07-20 21:47:33 +08:00
|
|
|
this.click = this.click.bind(this);
|
2015-11-15 08:23:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
click(value) {
|
2019-07-05 03:09:27 +08:00
|
|
|
if (!this.readOnly && value) {
|
2015-11-15 08:23:16 +08:00
|
|
|
this.value(value.value);
|
|
|
|
}
|
2016-04-21 01:12:51 +08:00
|
|
|
}
|
2015-11-15 08:23:16 +08:00
|
|
|
}
|
|
|
|
|
2019-07-05 03:09:27 +08:00
|
|
|
export { AbstractRadio, AbstractRadio as default };
|