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

56 lines
2.5 KiB
JavaScript
Raw Normal View History

2020-01-21 05:35:52 +08:00
import TabAwareWidget from "./tab_aware_widget.js";
2020-01-19 20:19:40 +08:00
const TPL = `
<div class="dropdown note-actions">
<button type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="btn btn-sm dropdown-toggle">
Note actions
<span class="caret"></span>
</button>
<div class="dropdown-menu dropdown-menu-right">
<a data-trigger-event="showNoteRevisions" class="dropdown-item show-note-revisions-button">Revisions</a>
<a data-trigger-event="showAttributes" class="dropdown-item show-attributes-button"><kbd data-kb-action="ShowAttributes"></kbd> Attributes</a>
<a data-trigger-event="showLinkMap" class="dropdown-item show-link-map-button"><kbd data-kb-action="ShowLinkMap"></kbd> Link map</a>
<a data-trigger-event="showNoteSource" class="dropdown-item show-source-button"><kbd data-kb-action="ShowNoteSource"></kbd> Note source</a>
2020-01-19 20:19:40 +08:00
<a class="dropdown-item import-files-button">Import files</a>
2020-01-21 05:35:52 +08:00
<a class="dropdown-item export-note-button">Export note</a>
<a data-trigger-event="printActiveNote" class="dropdown-item print-note-button"><kbd data-kb-action="PrintActiveNote"></kbd> Print note</a>
<a data-trigger-event="showNoteInfo" class="dropdown-item show-note-info-button"><kbd data-kb-action="ShowNoteInfo"></kbd> Note info</a>
2020-01-19 20:19:40 +08:00
</div>
</div>`;
2020-01-21 05:35:52 +08:00
export default class NoteActionsWidget extends TabAwareWidget {
2020-01-19 20:19:40 +08:00
doRender() {
this.$widget = $(TPL);
2020-01-21 05:35:52 +08:00
this.$showSourceButton = this.$widget.find('.show-source-button');
2020-01-22 04:43:23 +08:00
2020-01-21 05:35:52 +08:00
this.$exportNoteButton = this.$widget.find('.export-note-button');
2020-01-22 04:43:23 +08:00
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');
2020-02-04 04:56:45 +08:00
this.$importNoteButton.on("click", () => import('../dialogs/import.js').then(d => d.showDialog(this.noteId)));
2020-01-21 05:35:52 +08:00
2020-01-19 20:19:40 +08:00
return this.$widget;
}
2020-01-21 05:35:52 +08:00
refreshWithNote(note) {
this.$showSourceButton.prop('disabled', !['text', 'relation-map', 'search', 'code'].includes(note.type));
this.$exportNoteButton.prop('disabled', note.type !== 'text');
}
triggerEvent(e, eventName) {
const $item = $(e.target).closest('dropdown-item');
if ($item.is('[disabled]')) {
return;
}
this.trigger(eventName);
}
2020-01-19 20:19:40 +08:00
}