From 2e0490beb5bdf84c835eab5a3db4fb9db5da58bb Mon Sep 17 00:00:00 2001 From: Adrien Schoffeniels Date: Wed, 4 May 2022 14:54:32 +0000 Subject: [PATCH] [IMP] website_slides: improve website_slides_survey integration SPECS 1. Change the default content of the modal opened after the installation of a module When the installation of a suggested module from the upload dialog is completed, the page is reloaded and the upload dialog is opened on load. Since the user installed the module to add content of the category related to this module, it is more convenient to open the modal directly on this category. 2. Replace the notification displayed when the user creates a new certification by a permanent button allowing to add questions When a user creates a certification, he must then add questions to this certification. Instead of showing a notification after the creation proposing to add questions that was shown only once, a permanent button has been added to the view of the certification so that anyone with the sufficient access rights can add questions, at any time, from the certification view. Task-2727654 closes odoo/odoo#86721 Signed-off-by: Thibault Delavallee (tde) --- addons/website_slides/controllers/main.py | 11 ++++-- .../static/src/js/slides_upload.js | 34 ++++++++++++---- .../static/src/xml/website_slides_upload.xml | 4 +- addons/website_slides_survey/__manifest__.py | 1 - .../controllers/slides.py | 11 ++---- .../js/slides_certification_upload_toast.js | 39 ------------------- .../static/src/js/slides_upload.js | 28 +++++-------- .../static/src/xml/website_slide_upload.xml | 3 +- .../src/xml/website_slides_fullscreen.xml | 13 +++++-- .../views/website_slides_templates_lesson.xml | 16 +++++--- ...ite_slides_templates_lesson_fullscreen.xml | 1 + 11 files changed, 71 insertions(+), 90 deletions(-) delete mode 100644 addons/website_slides_survey/static/src/js/slides_certification_upload_toast.js diff --git a/addons/website_slides/controllers/main.py b/addons/website_slides/controllers/main.py index 7cac5ce0bb7..a52ba886922 100644 --- a/addons/website_slides/controllers/main.py +++ b/addons/website_slides/controllers/main.py @@ -544,7 +544,7 @@ class WebsiteSlides(WebsiteProfile): # display data 'pager': pager, # display upload modal - 'enable_slide_upload': 'enable_slide_upload' in kw, + 'enable_slide_upload': kw.get('enable_slide_upload', False), ** errors, ** self._slide_channel_prepare_review_values(channel), }) @@ -580,7 +580,8 @@ class WebsiteSlides(WebsiteProfile): render_values['modules_to_install'] = [{ 'id': module.id, 'name': module.shortdesc, - 'motivational': _('Evaluate and certify your students.'), + 'motivational': _('Want to test and certify your students?'), + 'default_slide_category': 'certification', }] render_values = self._prepare_additional_channel_values(render_values, **kw) @@ -1246,10 +1247,12 @@ class WebsiteSlides(WebsiteProfile): channel._resequence_slides(slide, force_category=category) redirect_url = "/slides/slide/%s" % (slide.id) - if channel.channel_type == "training" and slide.slide_category not in ["article", "quiz"]: - redirect_url = "/slides/%s" % (slug(channel)) if slide.slide_category == 'article': redirect_url += "?enable_editor=1" + elif slide.slide_category == 'quiz': + redirect_url += "?quiz_quick_create" + elif channel.channel_type == "training": + redirect_url = "/slides/%s" % (slug(channel)) return { 'url': redirect_url, 'channel_type': channel.channel_type, diff --git a/addons/website_slides/static/src/js/slides_upload.js b/addons/website_slides/static/src/js/slides_upload.js index f7f901c82cc..3321da9b4f5 100644 --- a/addons/website_slides/static/src/js/slides_upload.js +++ b/addons/website_slides/static/src/js/slides_upload.js @@ -34,13 +34,20 @@ var SlideUploadDialog = Dialog.extend({ this._setup(); this.channelID = parseInt(options.channelId, 10); - this.defaultCategoryID = parseInt(options.categoryId,10); + this.defaultCategoryID = parseInt(options.categoryId, 10); this.canUpload = options.canUpload === 'True'; this.canPublish = options.canPublish === 'True'; this.modulesToInstall = options.modulesToInstall ? JSON.parse(options.modulesToInstall.replace(/'/g, '"')) : null; this.modulesToInstallStatus = null; - this.set('state', '_select'); + if (options.openModal && options.openModal in this.slide_category_data) { + // Sets the appropriate category's upload template if one has to be opened on load. + this.set('state', options.openModal); + this.set('defaultTemplate', this.slide_category_data[options.openModal]['template']); + } else { + this.set('state', '_select'); + this.set('defaultTemplate', 'website.slide.upload.modal.select'); + } this.on('change:state', this, this._onChangeType); this.set('can_submit_form', false); this.on('change:can_submit_form', this, this._onChangeCanSubmitForm); @@ -51,6 +58,10 @@ var SlideUploadDialog = Dialog.extend({ start: function () { var self = this; return this._super.apply(this, arguments).then(function () { + if (self.get('state') !== '_select') { + self.$modal.find('.modal-dialog').addClass('modal-lg'); + } + self._bindSelect2Dropdown(); self._resetModalButton(); }); }, @@ -668,7 +679,12 @@ var SlideUploadDialog = Dialog.extend({ method: 'button_immediate_install', args: [[this.modulesToInstallStatus.id]], }).then(function () { - window.location.href = window.location.origin + window.location.pathname + '?enable_slide_upload'; + let redirectUrl = window.location.origin + window.location.pathname + '?enable_slide_upload'; + if (self.modulesToInstallStatus.default_slide_category) { + redirectUrl += '='; + redirectUrl += self.modulesToInstallStatus.default_slide_category; + } + window.location.href = redirectUrl; }, function () { $el.text(_.str.sprintf(_t('Failed to install "%s".'), self.modulesToInstallStatus.name)); self.modulesToInstallStatus.installing = false; @@ -733,13 +749,16 @@ publicWidget.registry.websiteSlidesUpload = publicWidget.Widget.extend({ }, /** + * Automatically opens the upload dialog if requested from query string. + * If openModal is defined ( === '' ), opens the category selection dialog. + * If openModal is a category name, opens the category's upload dialog. + * * @override */ start: function () { - // Automatically open the upload dialog if requested from query string - if (this.$el.attr('data-open-modal')) { - this.$el.removeAttr('data-open-modal'); + if ('openModal' in this.$el.data()) { this._openDialog(this.$el); + this.$el.data('openModal', false); } return this._super.apply(this, arguments); }, @@ -749,8 +768,7 @@ publicWidget.registry.websiteSlidesUpload = publicWidget.Widget.extend({ //-------------------------------------------------------------------------- _openDialog: function ($element) { - var data = $element.data(); - return new SlideUploadDialog(this, data).open(); + return new SlideUploadDialog(this, $element.data()).open(); }, //-------------------------------------------------------------------------- diff --git a/addons/website_slides/static/src/xml/website_slides_upload.xml b/addons/website_slides/static/src/xml/website_slides_upload.xml index f5874a0fa5b..def77ee04da 100644 --- a/addons/website_slides/static/src/xml/website_slides_upload.xml +++ b/addons/website_slides/static/src/xml/website_slides_upload.xml @@ -4,7 +4,7 @@
- +
@@ -29,7 +29,7 @@ - + Install the app. diff --git a/addons/website_slides_survey/__manifest__.py b/addons/website_slides_survey/__manifest__.py index 7ea5efdd570..94f19c2ba0b 100644 --- a/addons/website_slides_survey/__manifest__.py +++ b/addons/website_slides_survey/__manifest__.py @@ -37,7 +37,6 @@ 'website_slides_survey/static/src/scss/website_slides_survey.scss', 'website_slides_survey/static/src/js/slides_upload.js', 'website_slides_survey/static/src/js/slides_course_fullscreen_player.js', - 'website_slides_survey/static/src/js/slides_certification_upload_toast.js', ], 'survey.survey_assets': [ 'website_slides_survey/static/src/scss/website_slides_survey_result.scss', diff --git a/addons/website_slides_survey/controllers/slides.py b/addons/website_slides_survey/controllers/slides.py index 7141c2e7163..577afcb795d 100644 --- a/addons/website_slides_survey/controllers/slides.py +++ b/addons/website_slides_survey/controllers/slides.py @@ -7,6 +7,7 @@ import werkzeug.exceptions from odoo import _ from odoo import http +from odoo.addons.http_routing.models.ir_http import slug from odoo.exceptions import AccessError from odoo.http import request from odoo.osv import expression @@ -74,13 +75,9 @@ class WebsiteSlidesSurvey(WebsiteSlides): # Then create the slide result = super(WebsiteSlidesSurvey, self).create_slide(*args, **post) - if create_new_survey: - # Set the redirect_url used in toaster - action_id = request.env.ref('survey.action_survey_form').id - result.update({ - 'redirect_url': '/web#id=%s&action=%s&model=survey.survey&view_type=form' % (post['survey_id'], action_id), - 'redirect_to_certification': True - }) + if post['slide_category'] == "certification": + # Set the url to redirect the user to the survey + result['url'] = '/slides/slide/%s?fullscreen=1' % (slug(request.env['slide.slide'].browse(result['slide_id']))), return result diff --git a/addons/website_slides_survey/static/src/js/slides_certification_upload_toast.js b/addons/website_slides_survey/static/src/js/slides_certification_upload_toast.js deleted file mode 100644 index 519af24a4b0..00000000000 --- a/addons/website_slides_survey/static/src/js/slides_certification_upload_toast.js +++ /dev/null @@ -1,39 +0,0 @@ -odoo.define('website_slides_survey.certification_upload_toast', function (require) { -'use strict'; - -var publicWidget = require('web.public.widget'); -var {Markup, sprintf} = require('web.utils'); - -var sessionStorage = window.sessionStorage; -var core = require('web.core'); -var _t = core._t; - - -publicWidget.registry.CertificationUploadToast = publicWidget.Widget.extend({ - selector: '.o_wslides_survey_certification_upload_toast', - - /** - * @override - */ - start: function () { - var self = this; - this._super.apply(this, arguments).then(function () { - var url = sessionStorage.getItem("survey_certification_url"); - if (url) { - var message = sprintf(Markup( - _t('Follow this link to add questions to your certification. Edit certification')), url); - self.displayNotification({ - type: 'info', - title: _t('Certification created'), - message: message, - sticky: true, - }); - sessionStorage.removeItem("survey_certification_url"); - } - }); - }, -}); - -return publicWidget.registry.CertificationUploadToast; - -}); diff --git a/addons/website_slides_survey/static/src/js/slides_upload.js b/addons/website_slides_survey/static/src/js/slides_upload.js index d14fec1c254..21e7dfcae42 100644 --- a/addons/website_slides_survey/static/src/js/slides_upload.js +++ b/addons/website_slides_survey/static/src/js/slides_upload.js @@ -3,7 +3,6 @@ odoo.define('website_slides_survey.upload_modal', function (require) { var core = require('web.core'); var _t = core._t; -var sessionStorage = window.sessionStorage; var SlidesUpload = require('@website_slides/js/slides_upload')[Symbol.for("default")]; /** @@ -23,8 +22,12 @@ SlidesUpload.SlideUploadDialog.include({ */ _onChangeCertification: function (ev) { const $inputElement = this.$("input#name"); - if (ev.added && ev.added.text && !$inputElement.val().trim()) { - $inputElement.val(ev.added.text); + if (ev.added) { + this.$('.o_error_no_certification').addClass('d-none'); + this.$('#certification_id').closest('.form-group').find('.select2-container').removeClass('is-invalid'); + if (ev.added.text && !$inputElement.val().trim()) { + $inputElement.val(ev.added.text); + } } }, @@ -83,11 +86,14 @@ SlidesUpload.SlideUploadDialog.include({ var $select2Container = $certificationInput .closest('.form-group') .find('.select2-container'); + var $errorContainer = $('.o_error_no_certification'); $select2Container.removeClass('is-invalid is-valid'); if ($certificationInput.is(':invalid')) { $select2Container.addClass('is-invalid'); + $errorContainer.removeClass('d-none'); } else if ($certificationInput.is(':valid')) { $select2Container.addClass('is-valid'); + $errorContainer.addClass('d-none'); } } @@ -115,22 +121,6 @@ SlidesUpload.SlideUploadDialog.include({ result['survey'] = survey; return result; }, - - /** - * Overridde to handle certification created on-the-fly: toaster will hold - * survey edit url, need to put it in session to use it in CertificationUploadToast - * - * @override - * @private - */ - _onFormSubmitDone: function (data) { - if (!data.error && data.redirect_to_certification) { - sessionStorage.setItem("survey_certification_url", data.redirect_url); - window.location.reload(); - } else { - this._super.apply(this, arguments); - } - }, }); SlidesUpload.websiteSlidesUpload.include({ diff --git a/addons/website_slides_survey/static/src/xml/website_slide_upload.xml b/addons/website_slides_survey/static/src/xml/website_slide_upload.xml index c34a0811132..d936c2f68a8 100644 --- a/addons/website_slides_survey/static/src/xml/website_slide_upload.xml +++ b/addons/website_slides_survey/static/src/xml/website_slide_upload.xml @@ -8,6 +8,7 @@
+ Please select a certification.
@@ -17,7 +18,7 @@
How to upload a certification on your course?
-
You can create your certification from here or use an existing one. Once your certification is created, you can still edit it in backend.
+
You can create your certification from here or use an existing one. Once your certification is created, you can still edit it in backend.
diff --git a/addons/website_slides_survey/static/src/xml/website_slides_fullscreen.xml b/addons/website_slides_survey/static/src/xml/website_slides_fullscreen.xml index 9fb80767b8c..7cac7d460c2 100644 --- a/addons/website_slides_survey/static/src/xml/website_slides_fullscreen.xml +++ b/addons/website_slides_survey/static/src/xml/website_slides_fullscreen.xml @@ -2,20 +2,25 @@ -
+
-
+

Congratulations, you passed the Certification!

Download certification
+
diff --git a/addons/website_slides_survey/views/website_slides_templates_lesson.xml b/addons/website_slides_survey/views/website_slides_templates_lesson.xml index 24b9604d375..f760936715c 100644 --- a/addons/website_slides_survey/views/website_slides_templates_lesson.xml +++ b/addons/website_slides_survey/views/website_slides_templates_lesson.xml @@ -3,22 +3,28 @@