protected session in a dialog now works, proper reloading

This commit is contained in:
zadam
2019-05-05 20:45:07 +02:00
parent 61696f0287
commit d36bff2a97
6 changed files with 130 additions and 127 deletions

View File

@@ -15,6 +15,7 @@ import noteDetailSearch from "./note_detail_search.js";
import noteDetailRender from "./note_detail_render.js";
import noteDetailRelationMap from "./note_detail_relation_map.js";
import noteDetailProtectedSession from "./note_detail_protected_session.js";
import protectedSessionService from "./protected_session.js";
const $noteTabContentsContainer = $("#note-tab-container");
@@ -32,26 +33,24 @@ const componentClasses = {
let tabIdCounter = 1;
class NoteContext {
constructor(chromeTabs, note, openOnBackground) {
constructor(chromeTabs, openOnBackground) {
this.tabId = tabIdCounter++;
this.chromeTabs = chromeTabs;
/** @type {NoteFull} */
this.note = note;
this.noteId = note.noteId;
this.tab = this.chromeTabs.addTab({
title: '', // will be set later
id: this.tabId
}, {
background: openOnBackground
});
this.$noteTabContent = $(".note-tab-content-template").clone();
this.$noteTabContent.removeClass('note-tab-content-template');
this.$noteTabContent.attr('data-note-id', this.noteId);
this.$noteTabContent.attr('data-tab-id', this.tabId);
$noteTabContentsContainer.append(this.$noteTabContent);
console.log(`Creating note tab ${this.tabId} for ${this.noteId}`);
this.$noteTitle = this.$noteTabContent.find(".note-title");
this.$noteDetailComponents = this.$noteTabContent.find(".note-detail-component");
this.$protectButton = this.$noteTabContent.find(".protect-button");
this.$unprotectButton = this.$noteTabContent.find(".unprotect-button");
this.$childrenOverview = this.$noteTabContent.find(".children-overview");
this.$scriptArea = this.$noteTabContent.find(".note-detail-script-area");
this.$savedIndicator = this.$noteTabContent.find(".saved-indicator");
@@ -69,25 +68,40 @@ class NoteContext {
treeService.setNoteTitle(this.noteId, title);
});
this.tab = this.chromeTabs.addTab({
title: note.title,
id: this.tabId
}, {
background: openOnBackground
});
this.$protectButton = this.$noteTabContent.find(".protect-button");
this.$protectButton.click(protectedSessionService.protectNoteAndSendToServer);
this.tab.setAttribute('data-note-id', this.noteId);
this.$unprotectButton = this.$noteTabContent.find(".unprotect-button");
this.$unprotectButton.click(protectedSessionService.unprotectNoteAndSendToServer);
console.log(`Created note tab ${this.tabId} for ${this.noteId}`);
}
setNote(note) {
this.noteId = note.noteId;
this.note = note;
this.tab.setAttribute('data-note-id', this.noteId);
this.$noteTabContent.attr('data-note-id', note.noteId);
this.chromeTabs.updateTab(this.tab, {title: note.title});
this.attributes.invalidateAttributes();
this.$noteTabContent.toggleClass("protected", this.note.isProtected);
this.$protectButton.toggleClass("active", this.note.isProtected);
this.$protectButton.prop("disabled", this.note.isProtected);
this.$unprotectButton.toggleClass("active", !this.note.isProtected);
this.$unprotectButton.prop("disabled", !this.note.isProtected || !protectedSessionHolder.isProtectedSessionAvailable());
for (const clazz of Array.from(this.$noteTabContent[0].classList)) { // create copy to safely iterate over while removing classes
if (clazz.startsWith("type-") || clazz.startsWith("mime-")) {
this.$noteTabContent.removeClass(clazz);
}
}
this.$noteTabContent.addClass(utils.getNoteTypeClass(this.note.type));
this.$noteTabContent.addClass(utils.getMimeTypeClass(this.note.mime));
console.log(`Switched tab ${this.tabId} to ${this.noteId}`);
}
@@ -183,23 +197,6 @@ class NoteContext {
this.$childrenOverview.show();
}
updateNoteView() {
this.$noteTabContent.toggleClass("protected", this.note.isProtected);
this.$protectButton.toggleClass("active", this.note.isProtected);
this.$protectButton.prop("disabled", this.note.isProtected);
this.$unprotectButton.toggleClass("active", !this.note.isProtected);
this.$unprotectButton.prop("disabled", !this.note.isProtected || !protectedSessionHolder.isProtectedSessionAvailable());
for (const clazz of Array.from(this.$noteTabContent[0].classList)) { // create copy to safely iterate over while removing classes
if (clazz.startsWith("type-") || clazz.startsWith("mime-")) {
this.$noteTabContent.removeClass(clazz);
}
}
this.$noteTabContent.addClass(utils.getNoteTypeClass(this.note.type));
this.$noteTabContent.addClass(utils.getMimeTypeClass(this.note.mime));
}
}
export default NoteContext;