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 AbstractCheckbox extends AbstractComponent {
|
2015-11-15 08:23:16 +08:00
|
|
|
/**
|
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;
|
2020-07-30 03:49:41 +08:00
|
|
|
if (undefined === this.value || !this.value.subscribe) {
|
2020-11-03 23:11:04 +08:00
|
|
|
this.value = ko.observable(!!this.value);
|
2015-11-15 08:23:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
this.enable = params.enable;
|
2020-07-30 03:49:41 +08:00
|
|
|
if (undefined === this.enable || !this.enable.subscribe) {
|
2020-11-03 23:11:04 +08:00
|
|
|
this.enable = ko.observable(undefined === this.enable || !!this.enable);
|
2015-11-15 08:23:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
this.disable = params.disable;
|
2020-07-30 03:49:41 +08:00
|
|
|
if (undefined === this.disable || !this.disable.subscribe) {
|
2020-11-03 23:11:04 +08:00
|
|
|
this.disable = ko.observable(!!this.disable);
|
2015-11-15 08:23:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
this.label = params.label || '';
|
2020-11-03 23:11:04 +08:00
|
|
|
this.inline = !!params.inline;
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2020-07-30 03:49:41 +08:00
|
|
|
this.labeled = undefined !== params.label;
|
2015-11-15 08:23:16 +08:00
|
|
|
this.labelAnimated = !!params.labelAnimated;
|
|
|
|
}
|
|
|
|
|
|
|
|
click() {
|
2020-11-10 16:29:00 +08:00
|
|
|
if (this.enable() && !this.disable()) {
|
2015-11-15 08:23:16 +08:00
|
|
|
this.value(!this.value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-22 23:32:08 +08:00
|
|
|
export { AbstractCheckbox };
|