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 AbstracCheckbox extends AbstractComponent
|
|
|
|
{
|
|
|
|
/**
|
2015-11-19 01:32:29 +08:00
|
|
|
* @param {Object} params = {}
|
2015-11-15 08:23:16 +08:00
|
|
|
*/
|
2015-11-19 01:32:29 +08:00
|
|
|
constructor(params = {}) {
|
2015-11-15 08:23:16 +08:00
|
|
|
|
|
|
|
super();
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2016-06-07 05:57:52 +08:00
|
|
|
this.value = ko.observable(isUnd(this.value) ? false : !!this.value);
|
2015-11-15 08:23:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
this.enable = params.enable;
|
2016-06-07 05:57:52 +08:00
|
|
|
if (isUnd(this.enable) || !this.enable.subscribe)
|
2015-11-15 08:23:16 +08:00
|
|
|
{
|
2016-06-07 05:57:52 +08:00
|
|
|
this.enable = ko.observable(isUnd(this.enable) ? true : !!this.enable);
|
2015-11-15 08:23:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
this.disable = params.disable;
|
2016-06-07 05:57:52 +08:00
|
|
|
if (isUnd(this.disable) || !this.disable.subscribe)
|
2015-11-15 08:23:16 +08:00
|
|
|
{
|
2016-06-07 05:57:52 +08:00
|
|
|
this.disable = ko.observable(isUnd(this.disable) ? false : !!this.disable);
|
2015-11-15 08:23:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
this.label = params.label || '';
|
2016-06-07 05:57:52 +08:00
|
|
|
this.inline = isUnd(params.inline) ? false : params.inline;
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-06-07 05:57:52 +08:00
|
|
|
this.readOnly = isUnd(params.readOnly) ? false : !!params.readOnly;
|
|
|
|
this.inverted = isUnd(params.inverted) ? false : !!params.inverted;
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-06-07 05:57:52 +08:00
|
|
|
this.labeled = !isUnd(params.label);
|
2015-11-15 08:23:16 +08:00
|
|
|
this.labelAnimated = !!params.labelAnimated;
|
|
|
|
}
|
|
|
|
|
|
|
|
click() {
|
|
|
|
if (!this.readOnly && this.enable() && !this.disable())
|
|
|
|
{
|
|
|
|
this.value(!this.value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export {AbstracCheckbox, AbstracCheckbox as default};
|