Notes/src/public/app/widgets/protected_note_switch.js

34 lines
1015 B
JavaScript
Raw Normal View History

2021-05-26 22:41:55 +02:00
import protectedSessionService from "../services/protected_session.js";
2021-12-20 17:30:47 +01:00
import SwitchWidget from "./switch.js";
2021-05-26 22:41:55 +02:00
2021-12-20 17:30:47 +01:00
export default class ProtectedNoteSwitchWidget extends SwitchWidget {
doRender() {
super.doRender();
2021-05-26 22:41:55 +02:00
2021-12-20 17:30:47 +01:00
this.$switchOnName.text("Protect the note");
this.$switchOnButton.attr("title", "Note is not protected, click to make it protected");
2021-05-26 22:41:55 +02:00
2021-12-20 17:30:47 +01:00
this.$switchOffName.text("Unprotect the note");
this.$switchOffButton.attr("title", "Note is protected, click to make it unprotected");
}
2021-05-26 22:41:55 +02:00
2021-12-20 17:30:47 +01:00
switchOn() {
protectedSessionService.protectNote(this.noteId, true, false);
}
2021-05-26 22:41:55 +02:00
2021-12-20 17:30:47 +01:00
switchOff() {
protectedSessionService.protectNote(this.noteId, false, false)
2021-05-26 22:41:55 +02:00
}
async refreshWithNote(note) {
2021-12-20 17:30:47 +01:00
this.$switchOn.toggle(!note.isProtected);
this.$switchOff.toggle(!!note.isProtected);
2021-05-26 22:41:55 +02:00
}
entitiesReloadedEvent({loadResults}) {
if (loadResults.isNoteReloaded(this.noteId)) {
this.refresh();
}
}
}