From 34bc02965fc02b6b1ea8e56d765e434f25c67abe Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 22 Jan 2020 22:05:28 +0100 Subject: [PATCH] book and search fixes --- .../javascripts/widgets/search_results.js | 44 ++++++++++--------- .../javascripts/widgets/type_widgets/book.js | 6 +-- .../widgets/type_widgets/type_widget.js | 15 +++++-- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/public/javascripts/widgets/search_results.js b/src/public/javascripts/widgets/search_results.js index 3925b360c..8d0fa4492 100644 --- a/src/public/javascripts/widgets/search_results.js +++ b/src/public/javascripts/widgets/search_results.js @@ -3,24 +3,24 @@ import toastService from "../services/toast.js"; import server from "../services/server.js"; const TPL = ` - -.search-results ul { - padding: 5px 5px 5px 15px; -} - - -
Search results: @@ -29,15 +29,17 @@ const TPL = ` export default class SearchResultsWidget extends BasicWidget { doRender() { - const $widget = $(TPL); + this.$widget = $(TPL); - this.$searchResults = $widget.find(".search-results"); - this.$searchResultsInner = $widget.find(".search-results-inner"); + this.$searchResults = this.$widget; + this.$searchResultsInner = this.$widget.find(".search-results-inner"); - return $widget; + return this.$widget; } async searchForResultsListener({searchText}) { + this.toggle(true); + const response = await server.get('search/' + encodeURIComponent(searchText)); if (!response.success) { diff --git a/src/public/javascripts/widgets/type_widgets/book.js b/src/public/javascripts/widgets/type_widgets/book.js index d08f2936d..515f995e7 100644 --- a/src/public/javascripts/widgets/type_widgets/book.js +++ b/src/public/javascripts/widgets/type_widgets/book.js @@ -193,7 +193,7 @@ export default class BookTypeWidget extends TypeWidget { this.$content.find('.note-book-content').css("max-height", ZOOMS[zoomLevel].height); } - async doRefresh() { + async doRefresh(note) { this.$content.empty(); this.$help.hide(); @@ -208,10 +208,10 @@ export default class BookTypeWidget extends TypeWidget { .append(' if you want to add some text.')) } - const zoomLevel = parseInt(await this.tabContext.note.getLabelValue('bookZoomLevel')) || this.getDefaultZoomLevel(); + const zoomLevel = parseInt(await note.getLabelValue('bookZoomLevel')) || this.getDefaultZoomLevel(); this.setZoom(zoomLevel); - await this.renderIntoElement(this.tabContext.note, this.$content); + await this.renderIntoElement(note, this.$content); } async renderIntoElement(note, $container) { diff --git a/src/public/javascripts/widgets/type_widgets/type_widget.js b/src/public/javascripts/widgets/type_widgets/type_widget.js index 1b42381e9..0529c499b 100644 --- a/src/public/javascripts/widgets/type_widgets/type_widget.js +++ b/src/public/javascripts/widgets/type_widgets/type_widget.js @@ -4,15 +4,24 @@ export default class TypeWidget extends TabAwareWidget { // for overriding static getType() {} - doRefresh() {} + /** + * @param {NoteFull} note + */ + doRefresh(note) {} refresh() { - if (!this.tabContext.note || this.tabContext.note.type !== this.constructor.getType()) { + const note = this.tabContext.note; + const widgetType = this.constructor.getType(); + + if (!note + || (note.type !== widgetType + && (note.type !== 'text' || widgetType !== 'book') // text can be rendered as book if it does not have content + && (widgetType !== 'protected-session' || !note.isProtected))) { this.toggle(false); return; } - this.doRefresh(); + this.doRefresh(note); } } \ No newline at end of file