2024-09-08 22:18:54 +03:00
|
|
|
import { t } from "../services/i18n.js";
|
2021-12-20 17:30:47 +01:00
|
|
|
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
|
|
|
|
|
2025-04-01 23:24:21 +03:00
|
|
|
const TPL = /*html*/`
|
2021-12-20 17:30:47 +01:00
|
|
|
<div class="switch-widget">
|
2025-01-21 04:21:01 +02:00
|
|
|
<style>
|
2025-01-21 21:59:08 +02:00
|
|
|
|
2021-12-20 17:30:47 +01:00
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
</div>`;
|
|
|
|
|
|
|
|
|
|
export default class SwitchWidget extends NoteContextAwareWidget {
|
|
|
|
|
|
2025-01-21 04:21:01 +02:00
|
|
|
doRender() {
|
|
|
|
|
this.$widget = $(TPL);
|
|
|
|
|
this.$switchButton = this.$widget.find(".switch-button");
|
2025-01-21 04:49:07 +02:00
|
|
|
|
|
|
|
|
this.$switchToggle = this.$widget.find(".switch-toggle");
|
2025-01-21 04:21:01 +02:00
|
|
|
this.$switchName = this.$widget.find(".switch-name");
|
2021-12-20 17:30:47 +01:00
|
|
|
this.$helpButton = this.$widget.find(".switch-help-button");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switchOff() {}
|
|
|
|
|
switchOn() {}
|
2025-01-21 04:21:01 +02:00
|
|
|
|
|
|
|
|
/** Gets or sets whether the switch is toggled. */
|
|
|
|
|
get isToggled() {
|
|
|
|
|
return this.currentState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set isToggled(state) {
|
|
|
|
|
this.currentState = !!state;
|
|
|
|
|
|
2025-01-21 04:49:07 +02:00
|
|
|
this.$switchButton.toggleClass("on", this.currentState);
|
2025-01-21 04:21:01 +02:00
|
|
|
}
|
2025-01-22 01:24:09 +02:00
|
|
|
|
2025-01-22 01:30:10 +02:00
|
|
|
/** Gets or sets whether the switch is enabled. */
|
2025-01-22 01:24:09 +02:00
|
|
|
get canToggle() {
|
2025-03-02 20:47:57 +01:00
|
|
|
return !this.$switchButton.hasClass("disabled");
|
2025-01-22 01:24:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set canToggle(isEnabled) {
|
|
|
|
|
if (isEnabled) {
|
|
|
|
|
this.isToggled = this.currentState; // Reapply the correct tooltip
|
|
|
|
|
} else {
|
|
|
|
|
this.$switchButton.attr("title", this.disabledTooltip);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-20 17:30:47 +01:00
|
|
|
}
|