snappymail/dev/Component/AbstractRadio.js

38 lines
852 B
JavaScript
Raw Normal View History

2016-07-02 06:49:59 +08:00
import _ from '_';
2015-11-15 08:23:16 +08:00
import ko from 'ko';
2019-07-05 03:09:27 +08:00
import { isUnd } from 'Common/Utils';
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;
2019-07-05 03:09:27 +08:00
if (isUnd(this.value) || !this.value.subscribe) {
2015-11-15 08:23:16 +08:00
this.value = ko.observable('');
}
2016-06-07 05:57:52 +08:00
this.inline = isUnd(params.inline) ? false : params.inline;
this.readOnly = isUnd(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(_.map(params.values, (label, value) => ({ label: label, value: value })));
2015-11-15 08:23:16 +08:00
}
this.click = _.bind(this.click, this);
}
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 };