import TabAwareWidget from "./tab_aware_widget.js";
import protectedSessionService from "../services/protected_session.js";
const TPL = `
`;
export default class NoteActionsWidget extends TabAwareWidget {
doRender() {
this.$widget = $(TPL);
this.$showSourceButton = this.$widget.find('.show-source-button');
this.$exportNoteButton = this.$widget.find('.export-note-button');
this.$exportNoteButton.on("click", () => {
if (this.$exportNoteButton.hasClass("disabled")) {
return;
}
import('../dialogs/export.js').then(d => d.showDialog(this.tabContext.notePath, 'single'));
});
this.$importNoteButton = this.$widget.find('.import-files-button');
this.$importNoteButton.on("click", () => import('../dialogs/import.js').then(d => d.showDialog(this.noteId)));
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));
return this.$widget;
}
refreshWithNote(note) {
if (['text', 'relation-map', 'search', 'code'].includes(note.type)) {
this.$showSourceButton.removeAttr('disabled');
} else {
this.$showSourceButton.attr('disabled', 'disabled');
}
if (note.type === 'text') {
this.$exportNoteButton.removeAttr('disabled');
}
else {
this.$exportNoteButton.attr('disabled', 'disabled');
}
this.$protectButton.toggle(!note.isProtected);
this.$unprotectButton.toggle(!!note.isProtected);
}
entitiesReloadedEvent({loadResults}) {
if (loadResults.isNoteReloaded(this.noteId)) {
this.refresh();
}
}
}