This commit is contained in:
zadam
2020-02-08 20:53:07 +01:00
parent 08687b76ea
commit 18ee239362
8 changed files with 23 additions and 36 deletions
+1 -23
View File
@@ -1,7 +1,6 @@
import TabAwareWidget from "./tab_aware_widget.js";
import utils from "../services/utils.js";
import protectedSessionHolder from "../services/protected_session_holder.js";
import treeCache from "../services/tree_cache.js";
import server from "../services/server.js";
import SpacedUpdate from "../services/spaced_update.js";
@@ -40,7 +39,7 @@ export default class NoteTitleWidget extends TabAwareWidget {
this.$widget = $(TPL);
this.$noteTitle = this.$widget.find(".note-title");
this.$noteTitle.on('input', () => this.titleChanged());
this.$noteTitle.on('input', () => this.spacedUpdate.scheduleUpdate());
utils.bindElShortcut(this.$noteTitle, 'return', () => {
this.trigger('focusOnDetail', {tabId: this.tabContext.tabId});
@@ -49,27 +48,6 @@ export default class NoteTitleWidget extends TabAwareWidget {
return this.$widget;
}
async titleChanged() {
const {note} = this.tabContext;
if (!note) {
return;
}
note.title = this.$noteTitle.val();
this.spacedUpdate.scheduleUpdate();
const noteFromCache = await treeCache.getNote(note.noteId);
noteFromCache.title = note.title;
this.trigger(`noteTitleChanged`, {
tabId: this.tabContext.tabId, // used to identify that the event comes from this tab so we should not update this tab's input
title: note.title,
noteId: note.noteId
});
}
async refreshWithNote(note) {
this.$noteTitle.val(note.title);
@@ -1,6 +1,7 @@
import BasicWidget from "./basic_widget.js";
import protectedSessionService from "../services/protected_session.js";
import protectedSessionHolder from "../services/protected_session_holder.js";
import TabAwareWidget from "./tab_aware_widget.js";
const TPL = `
<div class="btn-group btn-group-xs" style="margin-left: 10px; margin-right: 10px;">
@@ -15,7 +16,7 @@ const TPL = `
</button>
</div>`;
export default class ProtectedNoteSwitchWidget extends BasicWidget {
export default class ProtectedNoteSwitchWidget extends TabAwareWidget {
doRender() {
this.$widget = $(TPL);
@@ -8,6 +8,10 @@ export default class TabCachingWidget extends TabAwareWidget {
this.widgets = {};
}
async isEnabled() {
return this.tabContext.isActive();
}
doRender() {
this.$widget = $(`<div class="marker" style="display: none;">`);
return this.$widget;
@@ -53,9 +57,12 @@ export default class TabCachingWidget extends TabAwareWidget {
}
}
toggle(show) {
async toggle(show) {
for (const tabId in this.widgets) {
this.widgets[tabId].toggle(show && this.tabContext && tabId === this.tabContext.tabId);
this.widgets[tabId].toggle(
show
&& this.tabContext && tabId === this.tabContext.tabId
&& await this.widgets[tabId].isEnabled());
}
}
}
+2 -2
View File
@@ -421,7 +421,7 @@ export default class TabRowWidget extends BasicWidget {
tabEl.setAttribute('active', '');
}
tabOpenedListener({tabId}) {
newTabOpenedListener({tabId}) {
this.addTab(tabId);
}
@@ -553,7 +553,7 @@ export default class TabRowWidget extends BasicWidget {
this.$tabContainer.append(this.$newTab);
this.$newTab.on('click', _ => this.trigger('newTab'));
this.$newTab.on('click', _ => this.trigger('openNewTab'));
}
setupFiller() {