more refactoring ...

This commit is contained in:
zadam 2020-01-12 23:03:55 +01:00
parent bf7541bfb9
commit 17e2627a34
6 changed files with 27 additions and 16 deletions

View File

@ -8,6 +8,7 @@ import TabContext from "./tab_context.js";
import server from "./server.js";
import keyboardActionService from "./keyboard_actions.js";
import TabRowWidget from "./tab_row.js";
import NoteTitleWidget from "../widgets/note_title.js";
class AppContext {
constructor() {
@ -27,6 +28,9 @@ class AppContext {
$("#global-menu-wrapper").after(contents);
this.noteTitleWidget = new NoteTitleWidget(this);
$("#center-pane").prepend(this.noteTitleWidget.render());
this.noteTreeWidget = new NoteTreeWidget(this);
this.widgets = [
@ -41,14 +45,26 @@ class AppContext {
$leftPane.append($widget);
}
this.widgets.push(this.noteTitleWidget);
}
trigger(name, data) {
this.eventReceived(name, data);
for (const widget of this.widgets) {
widget.eventReceived(name, data);
}
}
eventReceived(name, data) {
const fun = this[name + 'Listener'];
if (typeof fun === 'function') {
fun.call(this, data);
}
}
/** @return {TabContext[]} */
getTabContexts() {
return this.tabContexts;

View File

@ -118,7 +118,7 @@ async function loadNoteDetail(origNotePath, options = {}) {
const loadPromise = loadNoteDetailToContext(ctx, loadedNote, notePath).then(() => {
if (activate) {
appContext.activateTab(ctx);
return appContext.activateTab(ctx);
}
else {
return Promise.resolve();

View File

@ -138,6 +138,8 @@ class TabContext {
// after loading new note make sure editor is scrolled to the top
this.getComponent().scrollToTop();
appContext.trigger('activeNoteChanged');
}
async show() {
@ -175,9 +177,6 @@ class TabContext {
this.$noteDetailComponents.hide();
this.$noteTitle.show(); // this can be hidden by empty detail
this.$noteTitle.removeAttr("readonly"); // this can be set by protected session service
this.getComponent().show();
await this.getComponent().render();
}

View File

@ -380,8 +380,6 @@ export default class TabRowWidget extends BasicWidget {
}
addTab(tabId) {
console.log("Adding tab", tabId);
const div = document.createElement('div');
div.innerHTML = TAB_TPL;
const tabEl = div.firstElementChild;

View File

@ -271,8 +271,6 @@ async function treeInitialized() {
filteredTabs[0].active = true;
}
console.log("filteredTabs", filteredTabs);
for (const tab of filteredTabs) {
await noteDetailService.loadNoteDetail(tab.notePath, {
state: tab,

View File

@ -101,18 +101,18 @@ export default class NoteTitleWidget extends TabAwareWidget {
doRender() {
const $widget = $(TPL);
this.$noteTitle = this.$tabContent.find(".note-title");
this.$noteTitleRow = this.$tabContent.find(".note-title-row");
this.$notePathList = this.$tabContent.find(".note-path-list");
this.$notePathCount = this.$tabContent.find(".note-path-count");
this.$noteTitle = $widget.find(".note-title");
this.$noteTitleRow = $widget.find(".note-title-row");
this.$notePathList = $widget.find(".note-path-list");
this.$notePathCount = $widget.find(".note-path-count");
this.$protectButton = this.$tabContent.find(".protect-button");
this.$protectButton = $widget.find(".protect-button");
this.$protectButton.on('click', protectedSessionService.protectNoteAndSendToServer);
this.$unprotectButton = this.$tabContent.find(".unprotect-button");
this.$unprotectButton = $widget.find(".unprotect-button");
this.$unprotectButton.on('click', protectedSessionService.unprotectNoteAndSendToServer);
this.$savedIndicator = this.$tabContent.find(".saved-indicator");
this.$savedIndicator = $widget.find(".saved-indicator");
this.noteType = new NoteTypeWidget(this);
@ -147,7 +147,7 @@ export default class NoteTitleWidget extends TabAwareWidget {
async activeTabChanged() {
const note = this.tabContext.note;
this.$noteTitle.val(this.note.title);
this.$noteTitle.val(note.title);
this.$protectButton.toggleClass("active", note.isProtected);
this.$protectButton.prop("disabled", note.isProtected);