diff options
| author | Florent Lejoly <fle@odoo.com> | 2019-11-27 12:51:28 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2020-04-16 10:26:32 +0000 |
| commit | 24033e4aaf65a52fedaa13fc0846eb745238f09d (patch) | |
| tree | c15a062d15ba6d1776ad2a4fee237735d6951d51 /addons/website_slides_survey/static/src/js/slides_upload.js | |
| parent | dd53c515c8c4d63ec714c765db911f2407bae175 (diff) | |
[IMP] website_slides,_survey: allow certification creation at frontend
Purpose
=======
Before this commit, in the front end, you had to create a certification before
adding it to a course. This commit allows creation of certification in
front-end with pre-filled settings.
Functional Spec
===============
1. On a course, add content, type certification, you can choose an existing one
(normal flow) or create a new one in the dropdown by typing a new survey
name (new flow).
3. When submitting (Publish or save as draft), a certification survey, with
pre-filled settings is created and linked to the slide.
Pre-filled settings:
* One page per question
* Attempts limit : 1
* Time limit : no limit
* Scoring without answers
* Passing score : 70%
* Is Certification : True
* Email Template : Certification: Send by email
* Give Badge : False
4. After submit, the user stays on the Course Content.
5. A toaster is displayed in the top right saying:
Toaster's Title: Certification created
Content: Follow this link to add questions to your certification.
<a>Edit certification</a>
A website editor can select a certification (if available) for the creation of
a slide.
Task id: 1981399
PR #43577
Co-Authored-By: Florent Lejoly <fle@odoo.com>
Co-Authored-By: David Beguin <dbe@odoo.com>
Diffstat (limited to 'addons/website_slides_survey/static/src/js/slides_upload.js')
| -rw-r--r-- | addons/website_slides_survey/static/src/js/slides_upload.js | 53 |
1 files changed, 49 insertions, 4 deletions
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 817f80004c0..54dc18da723 100644 --- a/addons/website_slides_survey/static/src/js/slides_upload.js +++ b/addons/website_slides_survey/static/src/js/slides_upload.js @@ -3,12 +3,34 @@ 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.upload_modal'); /** * Management of the new 'certification' slide_type */ SlidesUpload.SlideUploadDialog.include({ + events: _.extend({}, SlidesUpload.SlideUploadDialog.prototype.events || {}, { + 'change input#certification_id': '_onChangeCertification' + }), + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * Will automatically set the title of the slide to the title of the chosen certification + */ + _onChangeCertification: function (ev) { + if (ev.added && ev.added.text) { + this.$("input#name").val(ev.added.text); + } + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + /** * Overridden to add the "certification" slide type * @@ -56,7 +78,7 @@ SlidesUpload.SlideUploadDialog.include({ var result = this._super.apply(this, arguments); var $certificationInput = this.$('#certification_id'); - if ($certificationInput.length !== 0){ + if ($certificationInput.length !== 0) { var $select2Container = $certificationInput .closest('.form-group') .find('.select2-container'); @@ -76,15 +98,38 @@ SlidesUpload.SlideUploadDialog.include({ * @override * @private */ - _getSelect2DropdownValues: function (){ + _getSelect2DropdownValues: function () { var result = this._super.apply(this, arguments); var certificateValue = this.$('#certification_id').select2('data'); + var survey = {}; if (certificateValue) { - result['survey_id'] = certificateValue.id; + if (certificateValue.create) { + survey.id = false; + survey.title = certificateValue.text; + } else { + survey.id = certificateValue.id; + } } + 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({ |
