snappymail/dev/Component/AbstractRadio.js

36 lines
826 B
JavaScript
Raw Normal View History

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;
if (undefined === this.value || !this.value.subscribe) {
2015-11-15 08:23:16 +08:00
this.value = ko.observable('');
}
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) {
this.values(Object.entries(params.values).map((label, value) => ({ label: label, value: value })));
2015-11-15 08:23:16 +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 };