From 2009dfd3c6bbdfabcb40af27c108fb160a3438e8 Mon Sep 17 00:00:00 2001 From: std-odoo Date: Wed, 21 Feb 2024 15:00:18 +0000 Subject: [PATCH] [FIX] website_slides: fix embedded PDF navigation buttons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug === When we show a PDF in e-learning, we have some navigation buttons (next, previous, last, first) with some conditions for them to be enabled or not (e.g. a documentation can have suggested slides, and so the next button is visible even if we are on the last page). Those conditions are broken (sometimes a button is disabled when it shouldn't and vice versa), this commit aims to fix that issue. Task-3751253 closes odoo/odoo#156363 X-original-commit: f22ef44fc509e4dc1c75fbde54027bf8104c54e6 Signed-off-by: Thibault Delavallee (tde) Signed-off-by: Stéphane Debauche (std) --- .../static/src/js/slides_embed.js | 36 +++++++++++++------ .../static/src/scss/website_slides.scss | 9 +++++ .../website_slides_templates_lesson_embed.xml | 2 +- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/addons/website_slides/static/src/js/slides_embed.js b/addons/website_slides/static/src/js/slides_embed.js index c3e6dedad27..cbe7e400a33 100644 --- a/addons/website_slides/static/src/js/slides_embed.js +++ b/addons/website_slides/static/src/js/slides_embed.js @@ -29,6 +29,7 @@ $(function () { this.canvas = $viewer.find('canvas')[0]; this.pdf_viewer = new PDFSlidesViewer(this.slide_url, this.canvas); + this.hasSuggestions = !!this.$(".oe_slides_suggestion_media").length; this.pdf_viewer.loadDocument().then(function () { self.on_loaded_file(); }); @@ -43,9 +44,6 @@ $(function () { this.$('canvas').show(); this.$('#page_count').text(this.pdf_viewer.pdf_page_total); this.$('#PDFViewerLoader').hide(); - if (this.pdf_viewer.pdf_page_total > 1) { - this.$('.o_slide_navigation_buttons').removeClass('hide'); - } // init first page to display var initpage = this.defaultpage; var pageNum = (initpage > 0 && initpage <= this.pdf_viewer.pdf_page_total) ? initpage : 1; @@ -76,6 +74,13 @@ $(function () { } }, next: function () { + if ( + this.pdf_viewer.pdf_page_current >= + this.pdf_viewer.pdf_page_total + this.hasSuggestions + ) { + return; + } + var self = this; this.pdf_viewer.nextPage().then(function (pageNum) { if (pageNum) { @@ -92,7 +97,10 @@ $(function () { if (!slideSuggestOverlay.hasClass('d-none')) { // Hide suggested slide overlay before changing page nb. slideSuggestOverlay.addClass('d-none'); - this.$('#next, #last').removeClass('disabled'); + this.$("#next").removeClass("disabled"); + if (this.pdf_viewer.pdf_page_total <= 1) { + this.$("#previous, #first").addClass("disabled"); + } return; } var self = this; @@ -130,11 +138,16 @@ $(function () { } }, navUpdate: function (pageNum) { - this.$('#first').toggleClass('disabled', pageNum < 3 ); - this.$('#previous').toggleClass('disabled', pageNum < 2 ); - this.$('#next, #last').removeClass('disabled'); - this.$('#zoomout').toggleClass('disabled', this.pdf_viewer.pdf_zoom <= MIN_ZOOM); - this.$('#zoomin').toggleClass('disabled', this.pdf_viewer.pdf_zoom >= MAX_ZOOM); + const pagesCount = this.pdf_viewer.pdf_page_total + this.hasSuggestions; + this.$("#first").toggleClass("disabled", pagesCount < 2 || pageNum < 2); + this.$("#last").toggleClass( + "disabled", + pagesCount < 2 || pageNum >= this.pdf_viewer.pdf_page_total + ); + this.$("#next").toggleClass("disabled", pageNum >= pagesCount); + this.$("#previous").toggleClass("disabled", pageNum <= 1); + this.$("#zoomout").toggleClass("disabled", this.pdf_viewer.pdf_zoom <= MIN_ZOOM); + this.$("#zoomin").toggleClass("disabled", this.pdf_viewer.pdf_zoom >= MAX_ZOOM); }, // full screen mode fullscreen: function () { @@ -147,8 +160,9 @@ $(function () { }, // display suggestion displayed after last slide display_suggested_slides: function () { - this.$("#slide_suggest").removeClass('d-none'); - this.$('#next, #last').addClass('disabled'); + this.$("#slide_suggest").removeClass("d-none"); + this.$("#next, #last").addClass("disabled"); + this.$("#previous, #first").removeClass("disabled"); }, }; diff --git a/addons/website_slides/static/src/scss/website_slides.scss b/addons/website_slides/static/src/scss/website_slides.scss index cbc2c97cac3..fcddae6f31d 100644 --- a/addons/website_slides/static/src/scss/website_slides.scss +++ b/addons/website_slides/static/src/scss/website_slides.scss @@ -753,6 +753,15 @@ li.o_wslides_fs_sidebar_list_item.active { .oe_slide_embed_option { @include o-position-absolute(0,0,0,0); } + + .disabled { + // remove JS events for disabled elements + pointer-events: none; + } + + .o_slide_navigation_buttons { + user-select: none; + } } .oe_slides_share_bar{ diff --git a/addons/website_slides/views/website_slides_templates_lesson_embed.xml b/addons/website_slides/views/website_slides_templates_lesson_embed.xml index 5e1ae8f6fd2..753c62c9e69 100644 --- a/addons/website_slides/views/website_slides_templates_lesson_embed.xml +++ b/addons/website_slides/views/website_slides_templates_lesson_embed.xml @@ -102,7 +102,7 @@ -
+