diff --git a/src/public/javascripts/services/note_detail_book.js b/src/public/javascripts/services/note_detail_book.js index 98f07846a..309f40422 100644 --- a/src/public/javascripts/services/note_detail_book.js +++ b/src/public/javascripts/services/note_detail_book.js @@ -1,6 +1,7 @@ import server from "./server.js"; import linkService from "./link.js"; import utils from "./utils.js"; +import treeCache from "./tree_cache.js"; const MIN_ZOOM_LEVEL = 1; const MAX_ZOOM_LEVEL = 6; @@ -28,6 +29,26 @@ class NoteDetailBook { this.$zoomInButton.click(() => this.setZoom(this.zoomLevel - 1)); this.$zoomOutButton.click(() => this.setZoom(this.zoomLevel + 1)); + + this.$content.on('click', '.note-book-open-children-button', async ev => { + const $card = $(ev.target).closest('.note-book-card'); + const noteId = $card.attr('data-note-id'); + const note = await treeCache.getNote(noteId); + + $card.find('.note-book-open-children-button').hide(); + $card.find('.note-book-hide-children-button').show(); + + await this.renderIntoElement(note, $card.find('.note-book-children-content')); + }); + + this.$content.on('click', '.note-book-hide-children-button', async ev => { + const $card = $(ev.target).closest('.note-book-card'); + + $card.find('.note-book-open-children-button').show(); + $card.find('.note-book-hide-children-button').hide(); + + $card.find('.note-book-children-content').empty(); + }); } setZoom(zoomLevel) { @@ -36,20 +57,37 @@ class NoteDetailBook { this.$zoomInButton.prop("disabled", zoomLevel === MIN_ZOOM_LEVEL); this.$zoomOutButton.prop("disabled", zoomLevel === MAX_ZOOM_LEVEL); - this.$content.find('.note-book').css("flex-basis", ZOOMS[zoomLevel] + "%"); + this.$content.find('.note-book-card').css("flex-basis", ZOOMS[zoomLevel] + "%"); } async render() { this.$content.empty(); - for (const childNote of await this.ctx.note.getChildNotes()) { - this.$content.append( - $('