trilium/src/public/javascripts/widgets/protected_note_switch.js

38 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-01-19 20:19:40 +08:00
import BasicWidget from "./basic_widget.js";
import protectedSessionService from "../services/protected_session.js";
import protectedSessionHolder from "../services/protected_session_holder.js";
2020-02-09 03:53:07 +08:00
import TabAwareWidget from "./tab_aware_widget.js";
2020-01-19 20:19:40 +08:00
const TPL = `
<div class="btn-group btn-group-xs" style="margin-left: 10px; margin-right: 10px;">
2020-01-19 20:19:40 +08: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"
class="btn btn-sm icon-button bx bx-shield unprotect-button"
title="Not protected note can be viewed without entering password">
</button>
</div>`;
2020-02-09 03:53:07 +08:00
export default class ProtectedNoteSwitchWidget extends TabAwareWidget {
2020-01-19 20:19:40 +08:00
doRender() {
this.$widget = $(TPL);
this.$protectButton = this.$widget.find(".protect-button");
this.$protectButton.on('click', protectedSessionService.protectNoteAndSendToServer);
this.$unprotectButton = this.$widget.find(".unprotect-button");
this.$unprotectButton.on('click', protectedSessionService.unprotectNoteAndSendToServer);
2020-01-19 20:19:40 +08: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 || !protectedSessionHolder.isProtectedSessionAvailable());
}
2020-01-19 20:19:40 +08:00
}