Notes/src/public/app/widgets/buttons/note_actions.js

93 lines
3.7 KiB
JavaScript
Raw Normal View History

2021-05-24 22:29:49 +02:00
import NoteContextAwareWidget from "../note_context_aware_widget.js";
import utils from "../../services/utils.js";
2020-01-19 13:19:40 +01:00
const TPL = `
<div class="dropdown note-actions">
2021-06-13 22:55:31 +02:00
<style>
.note-actions {
width: 35px;
height: 35px;
}
2020-02-27 00:58:10 +01:00
.note-actions .dropdown-menu {
2021-05-26 22:41:55 +02:00
width: 15em;
2020-02-27 00:58:10 +01:00
}
2020-03-25 11:28:44 +01:00
.note-actions .dropdown-item[disabled], .note-actions .dropdown-item[disabled]:hover {
color: var(--muted-text-color) !important;
background-color: transparent !important;
pointer-events: none; /* makes it unclickable */
2020-03-25 11:28:44 +01:00
}
2020-02-27 00:58:10 +01:00
</style>
2021-05-18 22:49:47 +02:00
<button type="button" data-toggle="dropdown" aria-haspopup="true"
2021-05-28 22:47:59 +02:00
aria-expanded="false" class="icon-action bx bx-dots-vertical-rounded"></button>
2021-05-18 22:49:47 +02:00
2020-01-19 13:19:40 +01:00
<div class="dropdown-menu dropdown-menu-right">
2021-03-20 00:00:49 +01:00
<a data-trigger-command="renderActiveNote" class="dropdown-item render-note-button"><kbd data-command="renderActiveNote"></kbd> Re-render note</a>
<a data-trigger-command="findInText" class="dropdown-item find-in-text-button">Search in note <kbd data-command="findInText"></a>
<a data-trigger-command="showNoteSource" class="dropdown-item show-source-button"><kbd data-command="showNoteSource"></kbd> Note source</a>
<a data-trigger-command="openNoteExternally" class="dropdown-item open-note-externally-button"><kbd data-command="openNoteExternally"></kbd> Open note externally</a>
2020-01-19 13:19:40 +01:00
<a class="dropdown-item import-files-button">Import files</a>
2020-01-20 22:35:52 +01:00
<a class="dropdown-item export-note-button">Export note</a>
<a data-trigger-command="printActiveNote" class="dropdown-item print-active-note-button"><kbd data-command="printActiveNote"></kbd> Print note</a>
2020-01-19 13:19:40 +01:00
</div>
</div>`;
2021-05-22 12:35:41 +02:00
export default class NoteActionsWidget extends NoteContextAwareWidget {
2021-09-30 13:02:07 +02:00
isEnabled() {
return true;
}
2020-01-19 13:19:40 +01:00
doRender() {
this.$widget = $(TPL);
this.$findInTextButton = this.$widget.find('.find-in-text-button');
this.$printActiveNoteButton = this.$widget.find('.print-active-note-button');
2020-01-20 22:35:52 +01:00
this.$showSourceButton = this.$widget.find('.show-source-button');
this.$renderNoteButton = this.$widget.find('.render-note-button');
2020-01-21 21:43:23 +01:00
2020-01-20 22:35:52 +01:00
this.$exportNoteButton = this.$widget.find('.export-note-button');
2020-01-21 21:43:23 +01:00
this.$exportNoteButton.on("click", () => {
if (this.$exportNoteButton.hasClass("disabled")) {
return;
}
2021-05-24 22:29:49 +02:00
import('../../dialogs/export.js').then(d => d.showDialog(this.noteContext.notePath, 'single'));
2020-01-21 21:43:23 +01:00
});
this.$importNoteButton = this.$widget.find('.import-files-button');
2021-05-24 22:29:49 +02:00
this.$importNoteButton.on("click", () => import('../../dialogs/import.js').then(d => d.showDialog(this.noteId)));
2020-01-20 22:35:52 +01:00
this.$widget.on('click', '.dropdown-item', () => this.$widget.find("[data-toggle='dropdown']").dropdown('toggle'));
this.$openNoteExternallyButton = this.$widget.find(".open-note-externally-button");
2020-01-19 13:19:40 +01:00
}
2020-01-20 22:35:52 +01:00
refreshWithNote(note) {
this.toggleDisabled(this.$findInTextButton, ['text', 'code', 'book', 'search'].includes(note.type));
this.toggleDisabled(this.$showSourceButton, ['text', 'relation-map', 'search', 'code'].includes(note.type));
this.toggleDisabled(this.$printActiveNoteButton, ['text', 'code'].includes(note.type));
this.$renderNoteButton.toggle(note.type === 'render');
2020-03-25 11:28:44 +01:00
this.$openNoteExternallyButton.toggle(utils.isElectron());
}
toggleDisabled($el, enable) {
if (enable) {
$el.removeAttr('disabled');
} else {
$el.attr('disabled', 'disabled');
}
}
entitiesReloadedEvent({loadResults}) {
if (loadResults.isNoteReloaded(this.noteId)) {
this.refresh();
}
2020-01-20 22:35:52 +01:00
}
2020-07-03 22:27:45 +02:00
}