summaryrefslogtreecommitdiff
path: root/addons/website_slides_survey/static/src/js
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/website_slides_survey/static/src/js
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/website_slides_survey/static/src/js')
-rw-r--r--addons/website_slides_survey/static/src/js/slides_certification_upload_toast.js39
-rw-r--r--addons/website_slides_survey/static/src/js/slides_course_fullscreen_player.js31
-rw-r--r--addons/website_slides_survey/static/src/js/slides_upload.js141
3 files changed, 211 insertions, 0 deletions
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
new file mode 100644
index 00000000..e258201b
--- /dev/null
+++ b/addons/website_slides_survey/static/src/js/slides_certification_upload_toast.js
@@ -0,0 +1,39 @@
+odoo.define('website_slides_survey.certification_upload_toast', function (require) {
+'use strict';
+
+var publicWidget = require('web.public.widget');
+
+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) {
+ self.displayNotification({
+ type: 'info',
+ title: _t('Certification created'),
+ message: _.str.sprintf(
+ _t('Follow this link to add questions to your certification. <a href="%s">Edit certification</a>'),
+ url
+ ),
+ sticky: true,
+ });
+ sessionStorage.removeItem("survey_certification_url");
+ }
+ });
+ },
+});
+
+return publicWidget.registry.CertificationUploadToast;
+
+});
diff --git a/addons/website_slides_survey/static/src/js/slides_course_fullscreen_player.js b/addons/website_slides_survey/static/src/js/slides_course_fullscreen_player.js
new file mode 100644
index 00000000..07277be6
--- /dev/null
+++ b/addons/website_slides_survey/static/src/js/slides_course_fullscreen_player.js
@@ -0,0 +1,31 @@
+odoo.define('website_slides_survey.fullscreen', function (require) {
+"use strict";
+
+var core = require('web.core');
+var QWeb = core.qweb;
+var Fullscreen = require('website_slides.fullscreen');
+
+Fullscreen.include({
+ xmlDependencies: (Fullscreen.prototype.xmlDependencies || []).concat(
+ ["/website_slides_survey/static/src/xml/website_slides_fullscreen.xml"]
+ ),
+
+ /**
+ * Extend the _renderSlide method so that slides of type "certification"
+ * are also taken into account and rendered correctly
+ *
+ * @private
+ * @override
+ */
+ _renderSlide: function (){
+ var def = this._super.apply(this, arguments);
+ var $content = this.$('.o_wslides_fs_content');
+ if (this.get('slide').type === "certification"){
+ $content.html(QWeb.render('website.slides.fullscreen.certification',{widget: this}));
+ }
+ return Promise.all([def]);
+ },
+});
+});
+
+
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 00000000..54dc18da
--- /dev/null
+++ b/addons/website_slides_survey/static/src/js/slides_upload.js
@@ -0,0 +1,141 @@
+odoo.define('website_slides_survey.upload_modal', function (require) {
+"use strict";
+
+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
+ *
+ * @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');
+ var survey = {};
+ if (certificateValue) {
+ 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({
+ xmlDependencies: (SlidesUpload.websiteSlidesUpload.prototype.xmlDependencies || []).concat(
+ ["/website_slides_survey/static/src/xml/website_slide_upload.xml"]
+ ),
+});
+
+});