Notes/src/public/app/widgets/standard_top_widget.js

113 lines
3.7 KiB
JavaScript
Raw Normal View History

2020-01-15 20:10:54 +01:00
import BasicWidget from "./basic_widget.js";
import HistoryNavigationWidget from "./history_navigation.js";
import protectedSessionHolder from "../services/protected_session_holder.js";
2020-01-15 20:10:54 +01:00
import protectedSessionService from "../services/protected_session.js";
2021-01-31 22:45:45 +01:00
import QuickSearchWidget from "./quick_search.js";
2020-01-15 20:10:54 +01:00
const TPL = `
<div class="standard-top-widget">
<style>
.standard-top-widget {
background-color: var(--header-background-color);
display: flex;
align-items: center;
padding-top: 4px;
height: 35px;
2020-01-15 20:10:54 +01:00
}
.standard-top-widget > div {
flex-shrink: 0; /* fixes https://github.com/zadam/trilium/issues/1745 */
}
2021-02-01 23:51:04 +01:00
.standard-top-widget button.noborder {
2020-01-15 20:10:54 +01:00
padding: 1px 5px 1px 5px;
2020-11-27 21:57:41 +01:00
font-size: 90%;
2020-01-15 20:10:54 +01:00
margin-bottom: 2px;
margin-top: 2px;
margin-right: 8px;
border-color: transparent !important;
}
.standard-top-widget button.btn-sm .bx {
position: relative;
2020-11-27 21:57:41 +01:00
top: 2px;
font-size: 120%;
2020-01-15 20:10:54 +01:00
}
.standard-top-widget button:hover {
border-color: var(--button-border-color) !important;
}
</style>
<div style="flex-grow: 100; display: flex;">
2021-02-01 23:51:04 +01:00
<button class="btn btn-sm noborder" data-trigger-command="createNoteIntoInbox">
2020-11-27 22:21:13 +01:00
<span class="bx bx-file-blank"></span>
New note
</button>
2021-02-01 23:51:04 +01:00
<button class="btn btn-sm noborder" data-trigger-command="searchNotes">
2020-11-27 20:40:32 +01:00
<span class="bx bx-search"></span>
Search
</button>
2021-02-01 23:51:04 +01:00
<button class="btn btn-sm noborder" data-trigger-command="jumpToNote">
2020-11-27 21:57:41 +01:00
<span class="bx bx-send"></span>
2020-01-15 20:10:54 +01:00
Jump to note
</button>
2021-02-01 23:51:04 +01:00
<button class="btn btn-sm noborder" data-trigger-command="showRecentChanges">
2020-01-15 20:10:54 +01:00
<span class="bx bx-history"></span>
Recent changes
</button>
2021-02-01 23:51:04 +01:00
<button class="btn btn-sm enter-protected-session-button noborder"
2020-01-15 20:10:54 +01:00
title="Enter protected session to be able to find and view protected notes">
<span class="bx bx-log-in"></span>
Enter protected session
</button>
2021-02-01 23:51:04 +01:00
<button class="btn btn-sm leave-protected-session-button noborder"
title="Leave protected session so that protected notes are not accessible any more.">
2020-01-15 20:10:54 +01:00
<span class="bx bx-log-out"></span>
Leave protected session
</button>
</div>
<div id="plugin-buttons"></div>
</div>`;
export default class StandardTopWidget extends BasicWidget {
2020-01-22 20:48:56 +01:00
doRender() {
2020-01-15 20:10:54 +01:00
this.$widget = $(TPL);
this.overflowing();
2020-01-15 20:10:54 +01:00
2020-02-27 10:08:21 +01:00
const historyNavigationWidget = new HistoryNavigationWidget();
this.child(historyNavigationWidget);
2020-01-15 20:10:54 +01:00
this.$widget.prepend(historyNavigationWidget.render());
2021-01-31 22:45:45 +01:00
const quickSearchWidget = new QuickSearchWidget();
this.child(quickSearchWidget);
this.$widget.append(quickSearchWidget.render());
2020-03-29 20:37:40 +02:00
this.$enterProtectedSessionButton = this.$widget.find(".enter-protected-session-button");
this.$enterProtectedSessionButton.on('click', protectedSessionService.enterProtectedSession);
this.$enterProtectedSessionButton.toggle(!protectedSessionHolder.isProtectedSessionAvailable());
2020-03-29 20:37:40 +02:00
this.$leaveProtectedSessionButton = this.$widget.find(".leave-protected-session-button");
this.$leaveProtectedSessionButton.on('click', protectedSessionService.leaveProtectedSession);
this.$leaveProtectedSessionButton.toggle(protectedSessionHolder.isProtectedSessionAvailable());
2020-01-15 20:10:54 +01:00
return this.$widget;
2020-01-15 20:10:54 +01:00
}
2020-03-29 20:37:40 +02:00
protectedSessionStartedEvent() {
this.$enterProtectedSessionButton.hide();
this.$leaveProtectedSessionButton.show();
}
}