summaryrefslogtreecommitdiff
path: root/addons/website_slides_survey/static
diff options
context:
space:
mode:
authorAurélien Warnon <awa@odoo.com>2019-02-11 14:03:02 +0000
committerAurélien Warnon <awa@odoo.com>2019-02-15 15:32:46 +0000
commitf322816ae826f14eafd6f1d4855b0e2a741530d5 (patch)
tree77176562e6128b65275b9096a0e278789b122f75 /addons/website_slides_survey/static
parentdcce7716b3202eabd77666bcaaee9040e6a5e5b8 (diff)
[ADD] website_slides_survey: add a new bridge between slide and survey
Task #1940360 Subtask of #1902304 Purpose ======= Adds certification capabilities to the website_slides module. Channel/courses can now include certifications as a new type of slide. This new type of slide is available as a "Certification" button on the slide creation frontend view (next to "Video", "Presentation", ...). Users have to link the slide to an actual survey that has the 'certificate' field set to true (that will populate the slide's survey_id field). Slides of type certification are handled in frontend in a very simple way for now: - A button "Begin certification" that redirects the user to the related survey frontend. - A button "Download certification" when the user has succeeded the certification. - When the survey is done, if it's linked to a slide, a button "Go back to course" allows the user to go back to the slide frontend. (There is a special use case for when the website_publisher designing the survey lands on a certification slide: he is allowed to test the survey with a survey_input created as test_entry) Survey creation as well as limited time, limited number of attempts, ... are still completely handled in the survey module. That means that the user will have to first create a suitable survey that is a certification and only then create a slide of type "certification" and link the created survey to it. Ideally, the taking of the survey should be transparently included in the slide frontend but it requires a full refactoring of the way surveys are submitted. This will most likely come in a later commit. This commit is an advanced merge of full eLearning module (see task #1902304).
Diffstat (limited to 'addons/website_slides_survey/static')
-rw-r--r--addons/website_slides_survey/static/src/js/slides_certification_download.js23
-rw-r--r--addons/website_slides_survey/static/src/js/slides_upload.js96
-rw-r--r--addons/website_slides_survey/static/src/xml/website_slide_upload.xml36
3 files changed, 155 insertions, 0 deletions
diff --git a/addons/website_slides_survey/static/src/js/slides_certification_download.js b/addons/website_slides_survey/static/src/js/slides_certification_download.js
new file mode 100644
index 00000000000..d1469ab63a8
--- /dev/null
+++ b/addons/website_slides_survey/static/src/js/slides_certification_download.js
@@ -0,0 +1,23 @@
+odoo.define('website_slides_survey.certification_download', function (require) {
+'use strict';
+
+var WebsiteSlides = require('website_slides.slides');
+var session = require('web.session');
+
+WebsiteSlides.include({
+ events: _.extend({}, WebsiteSlides.prototype.events, {
+ 'click .o_wslides_survey_download_certification': '_onDownloadCertificationClick'
+ }),
+
+ /**
+ * @private
+ */
+ _onDownloadCertificationClick: function () {
+ var surveyId = this.$('.o_wslides_survey_download_certification').data('survey_id');
+ session.get_file({
+ url: '/survey/' + surveyId + '/get_certification'
+ });
+ }
+});
+
+});
diff --git a/addons/website_slides_survey/static/src/js/slides_upload.js b/addons/website_slides_survey/static/src/js/slides_upload.js
new file mode 100644
index 00000000000..817f80004c0
--- /dev/null
+++ b/addons/website_slides_survey/static/src/js/slides_upload.js
@@ -0,0 +1,96 @@
+odoo.define('website_slides_survey.upload_modal', function (require) {
+"use strict";
+
+var core = require('web.core');
+var _t = core._t;
+var SlidesUpload = require('website_slides.upload_modal');
+
+/**
+ * Management of the new 'certification' slide_type
+ */
+SlidesUpload.SlideUploadDialog.include({
+ /**
+ * Overridden to add the "certification" slide type
+ *
+ * @override
+ * @private
+ */
+ _setup: function () {
+ this._super.apply(this, arguments);
+ this.slide_type_data['certification'] = {
+ icon: 'fa-trophy',
+ label: _t('Certification'),
+ template: 'website.slide.upload.modal.certification',
+ };
+ },
+ /**
+ * Overridden to add certifications management in select2
+ *
+ * @override
+ * @private
+ */
+ _bindSelect2Dropdown: function () {
+ this._super.apply(this, arguments);
+
+ var self = this;
+ this.$('#certification_id').select2(this._select2Wrapper(_t('Certification'), false,
+ function () {
+ return self._rpc({
+ route: '/slides_survey/certification/search_read',
+ params: {
+ fields: ['title'],
+ }
+ });
+ }, 'title')
+ );
+ },
+ /**
+ * The select2 field makes the "required" input hidden on the interface.
+ * We need to make the "certification" field required so we override this method
+ * to handle validation in a fully custom way.
+ *
+ * @override
+ * @private
+ */
+ _formValidate: function () {
+ var result = this._super.apply(this, arguments);
+
+ var $certificationInput = this.$('#certification_id');
+ if ($certificationInput.length !== 0){
+ var $select2Container = $certificationInput
+ .closest('.form-group')
+ .find('.select2-container');
+ $select2Container.removeClass('is-invalid is-valid');
+ if ($certificationInput.is(':invalid')) {
+ $select2Container.addClass('is-invalid');
+ } else if ($certificationInput.is(':valid')) {
+ $select2Container.addClass('is-valid');
+ }
+ }
+
+ return result;
+ },
+ /**
+ * Overridden to add the 'certification' field into the submitted values
+ *
+ * @override
+ * @private
+ */
+ _getSelect2DropdownValues: function (){
+ var result = this._super.apply(this, arguments);
+
+ var certificateValue = this.$('#certification_id').select2('data');
+ if (certificateValue) {
+ result['survey_id'] = certificateValue.id;
+ }
+ return result;
+ }
+});
+
+SlidesUpload.websiteSlidesUpload.include({
+ xmlDependencies: (SlidesUpload.websiteSlidesUpload.prototype.xmlDependencies || []).concat(
+ ["/website_slides_survey/static/src/xml/website_slide_upload.xml"]
+ ),
+});
+
+});
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
new file mode 100644
index 00000000000..0b273a15b21
--- /dev/null
+++ b/addons/website_slides_survey/static/src/xml/website_slide_upload.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template>
+ <t t-name="website.slide.upload.modal.certification">
+ <div>
+ <form class="clearfix">
+ <div class="form-group row">
+ <label for="certification_id" class="col-form-label col-md-3">Certification</label>
+ <div class="controls col-md-9">
+ <input class="form-control" id="certification_id" required="required"/>
+ </div>
+ </div>
+ <t t-call="website.slide.upload.modal.common"/>
+ <div class="form-group row">
+ <div class="col-md-4">
+ <div class="img-thumbnail">
+ <div class="o_slide_preview">
+ <img src="/website_slides/static/src/img/document.png" id="slide-image" title="Content Preview" alt="Content Preview" class="img-fluid"/>
+ </div>
+ </div>
+ </div>
+ <div class="col-md-8">
+ <ul class="list-group">
+ <li class="list-group-item">
+ <h5 class="list-group-item-heading">
+ <label for="upload" class="col-form-label">Cover Image File</label>
+ </h5>
+ <input id="upload" name="file" class="form-control" accept="image/*" type="file" required="required" data-prevent-onchange="1"/>
+ </li>
+ </ul>
+ </div>
+ </div>
+ <canvas id="data_canvas" class="d-none"></canvas>
+ </form>
+ </div>
+ </t>
+</template>