snappymail/dev/Component/AbstractCheckbox.js

24 lines
533 B
JavaScript
Raw Normal View History

2015-11-15 08:23:16 +08:00
import ko from 'ko';
2022-02-17 06:12:12 +08:00
export class AbstractCheckbox {
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 = {}) {
2021-09-08 05:09:56 +08:00
this.value = ko.isObservable(params.value) ? params.value
: ko.observable(!!params.value);
2015-11-15 08:23:16 +08:00
2021-09-08 05:09:56 +08:00
this.enable = ko.isObservable(params.enable) ? params.enable
: ko.observable(undefined === params.enable || !!params.enable);
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
this.labeled = undefined !== params.label;
2015-11-15 08:23:16 +08:00
}
click() {
this.enable() && this.value(!this.value());
2015-11-15 08:23:16 +08:00
}
}