snappymail/dev/Component/AbstracRadio.js

45 lines
866 B
JavaScript
Raw Normal View History

2015-11-15 08:23:16 +08:00
2016-07-02 06:49:59 +08:00
import _ from '_';
2015-11-15 08:23:16 +08:00
import ko from 'ko';
2016-06-07 05:57:52 +08:00
import {isUnd} from 'Common/Utils';
2015-11-15 08:23:16 +08:00
import {AbstractComponent} from 'Component/Abstract';
class AbstracRadio extends AbstractComponent
{
/**
2016-06-30 08:02:45 +08:00
* @constructor
2015-11-15 08:23:16 +08:00
* @param {Object} params
*/
constructor(params) {
super();
this.values = ko.observableArray([]);
this.value = params.value;
2016-06-07 05:57:52 +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
if (params.values)
{
2016-07-02 06:49:59 +08:00
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) {
if (!this.readOnly && value)
{
this.value(value.value);
}
2016-04-21 01:12:51 +08:00
}
2015-11-15 08:23:16 +08:00
}
export {AbstracRadio, AbstracRadio as default};