Files
Trilium/src/public/app/widgets/protected_note_switch.js

42 lines
1.5 KiB
JavaScript
Raw Normal View History

import protectedSessionService from "../services/protected_session.js";
2020-02-08 20:53:07 +01:00
import TabAwareWidget from "./tab_aware_widget.js";
2020-01-19 13:19:40 +01:00
const TPL = `
2020-02-27 00:58:10 +01:00
<div class="btn-group btn-group-xs">
2020-01-19 13:19:40 +01:00
<button type="button"
class="btn btn-sm icon-button bx bx-check-shield protect-button"
title="Protected note can be viewed and edited only after entering password">
</button>
<button type="button"
2020-02-15 09:16:23 +01:00
class="btn btn-sm icon-button bx bx-shield-x unprotect-button"
2020-01-19 13:19:40 +01:00
title="Not protected note can be viewed without entering password">
</button>
2020-02-27 00:58:10 +01:00
</div>`;``;
2020-01-19 13:19:40 +01:00
2020-02-08 20:53:07 +01:00
export default class ProtectedNoteSwitchWidget extends TabAwareWidget {
2020-01-19 13:19:40 +01:00
doRender() {
this.$widget = $(TPL);
this.$protectButton = this.$widget.find(".protect-button");
this.$protectButton.on('click', () => protectedSessionService.protectNote(this.noteId, true, false));
this.$unprotectButton = this.$widget.find(".unprotect-button");
this.$unprotectButton.on('click', () => protectedSessionService.protectNote(this.noteId, false, false));
2020-01-19 13:19:40 +01:00
return this.$widget;
}
refreshWithNote(note) {
this.$protectButton.toggleClass("active", note.isProtected);
this.$protectButton.prop("disabled", note.isProtected);
this.$unprotectButton.toggleClass("active", !note.isProtected);
this.$unprotectButton.prop("disabled", !note.isProtected);
}
async entitiesReloadedEvent({loadResults}) {
if (loadResults.isNoteReloaded(this.noteId)) {
this.refresh();
}
}
2020-01-19 13:19:40 +01:00
}