2020-01-19 13:19:40 +01:00
|
|
|
import BasicWidget from "./basic_widget.js";
|
2020-01-19 15:36:42 +01:00
|
|
|
import protectedSessionService from "../services/protected_session.js";
|
|
|
|
|
import protectedSessionHolder from "../services/protected_session_holder.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-01-19 18:05:06 +01:00
|
|
|
<div class="btn-group btn-group-xs" style="margin-left: 10px; margin-right: 10px;">
|
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>
|
|
|
|
|
</div>`;
|
|
|
|
|
|
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);
|
|
|
|
|
|
2020-01-19 15:36:42 +01:00
|
|
|
this.$protectButton = this.$widget.find(".protect-button");
|
2020-02-26 16:37:17 +01:00
|
|
|
this.$protectButton.on('click', () => protectedSessionService.protectNote(this.noteId, true, false));
|
2020-01-19 15:36:42 +01:00
|
|
|
|
|
|
|
|
this.$unprotectButton = this.$widget.find(".unprotect-button");
|
2020-02-26 16:37:17 +01:00
|
|
|
this.$unprotectButton.on('click', () => protectedSessionService.protectNote(this.noteId, false, false));
|
2020-01-19 15:36:42 +01:00
|
|
|
|
2020-01-19 13:19:40 +01:00
|
|
|
return this.$widget;
|
|
|
|
|
}
|
2020-01-19 15:36:42 +01:00
|
|
|
|
|
|
|
|
refreshWithNote(note) {
|
|
|
|
|
this.$protectButton.toggleClass("active", note.isProtected);
|
|
|
|
|
this.$protectButton.prop("disabled", note.isProtected);
|
|
|
|
|
this.$unprotectButton.toggleClass("active", !note.isProtected);
|
2020-02-26 16:37:17 +01:00
|
|
|
this.$unprotectButton.prop("disabled", !note.isProtected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async entitiesReloadedEvent({loadResults}) {
|
|
|
|
|
if (loadResults.isNoteReloaded(this.noteId)) {
|
|
|
|
|
this.refresh();
|
|
|
|
|
}
|
2020-01-19 15:36:42 +01:00
|
|
|
}
|
2020-01-19 13:19:40 +01:00
|
|
|
}
|