diff --git a/src/public/javascripts/services/note_detail_book.js b/src/public/javascripts/services/note_detail_book.js index c83ba91c6..44f47d302 100644 --- a/src/public/javascripts/services/note_detail_book.js +++ b/src/public/javascripts/services/note_detail_book.js @@ -3,7 +3,8 @@ import linkService from "./link.js"; import utils from "./utils.js"; import treeCache from "./tree_cache.js"; import renderService from "./render.js"; -import zoom from "./zoom.js"; +import protectedSessionHolder from "./protected_session_holder.js"; +import protectedSessionService from "./protected_session.js"; const MIN_ZOOM_LEVEL = 1; const MAX_ZOOM_LEVEL = 6; @@ -128,14 +129,16 @@ class NoteDetailBook { async renderIntoElement(note, $container) { for (const childNote of await note.getChildNotes()) { + const type = this.getRenderingType(childNote); + const $card = $('
").text(fullNote.content); } - else if (note.type === 'image') { + else if (type === 'image') { return $("").attr("src", `api/images/${note.noteId}/${note.title}`); } - else if (note.type === 'file') { + else if (type === 'file') { function getFileUrl() { // electron needs absolute URL so we extract current host, port, protocol return utils.getHost() + "/api/notes/" + note.noteId + "/download"; @@ -207,13 +210,22 @@ class NoteDetailBook { .append(' ') .append($openButton); } - else if (note.type === 'render') { + else if (type === 'render') { const $el = $('
'); await renderService.render(note, $el, this.ctx); return $el; } + else if (type === 'protected-session') { + const $button = $(``) + .click(protectedSessionService.enterProtectedSession); + + return $("") + .append("This note is protected and to access it you need to enter password.") + .append("
") + .append($button); + } else { return "Content of this note cannot be displayed in the book format"; } @@ -228,6 +240,21 @@ class NoteDetailBook { return this.isAutoBook() ? 3 : 1; } + getRenderingType(childNote) { + let type = childNote.type; + + if (childNote.isProtected) { + if (protectedSessionHolder.isProtectedSessionAvailable()) { + protectedSessionHolder.touchProtectedSession(); + } + else { + type = 'protected-session'; + } + } + + return type; + } + getContent() {} show() { diff --git a/src/public/javascripts/services/utils.js b/src/public/javascripts/services/utils.js index 70451c145..d806bcc3a 100644 --- a/src/public/javascripts/services/utils.js +++ b/src/public/javascripts/services/utils.js @@ -202,7 +202,7 @@ function closeActiveDialog() { } function isHtmlEmpty(html) { - return $(html).text().trim().length === 0 && !html.toLowerCase().includes('").html(html).text().trim().length === 0 && !html.toLowerCase().includes('