From d981d7efc152c129e4212bb1752dc45ce5d74841 Mon Sep 17 00:00:00 2001 From: Adrien Schoffeniels Date: Thu, 19 May 2022 06:18:52 +0000 Subject: [PATCH] [IMP] survey: improve survey samples accessibility PURPOSE: This commit improves the accessibility of the survey samples when no records are shown. SPECS Remove the modal used to show the samples and show them on the empty screen instead. When no survey exists, the user gets the proposition of trying survey samples. Previously, the user had to click on a button to open a modal showing the different samples. Now, the samples are shown in the empty screen directly. If the user does not have the rights to create surveys, the "Try It" buttons are removed from the NoContentHelper. Task-2794884 Part-of: odoo/odoo#87326 --- .../survey/static/src/js/survey_renderers.js | 73 ++++++++++--------- .../static/src/xml/survey_sample_modal.xml | 37 ---------- addons/survey/views/survey_survey_views.xml | 57 ++++++++++++--- 3 files changed, 86 insertions(+), 81 deletions(-) delete mode 100644 addons/survey/static/src/xml/survey_sample_modal.xml diff --git a/addons/survey/static/src/js/survey_renderers.js b/addons/survey/static/src/js/survey_renderers.js index 7db75e22549..b156df21921 100644 --- a/addons/survey/static/src/js/survey_renderers.js +++ b/addons/survey/static/src/js/survey_renderers.js @@ -1,55 +1,58 @@ /** @odoo-module */ -import Dialog from 'web.Dialog'; import KanbanRenderer from 'web.KanbanRenderer'; import ListRenderer from 'web.ListRenderer'; -import { qweb as QWeb, _t } from 'web.core'; +import { Markup } from 'web.utils'; + +const SurveySampleMixin = { -const SurveySampleModalMixin = { /** - * Opens a dialog allowing the user to load a sample survey - * We currently have 3 different samples to load (and one "tile" to click on - * for each in the modal). + * @override + */ + _render: function () { + // Remove "Try It" buttons of the no content helper if user can not create surveys + if (!this.activeActions.create) { + this.noContentHelp = Markup(this.noContentHelp.replaceAll( + 'Try It', + '' + )); + } + this.isLoadingSample = false; + this._super.apply(this, arguments); + }, + + /** + * Load and show the sample survey related to the clicked element, + * when there is no survey to display. + * We currently have 3 different samples to load: * - Sample Feedback Form * - Sample Certification * - Sample Live Presentation + * + * @private + * @param {Event} ev */ - _onOpenSurveySampleModalClick: function () { - const $content = $(QWeb.render('survey.survey_sample_modal_body')); - $content.find('.o_survey_sample_tile').each((_index, tile) => { - const $tile = $(tile); - $tile.on('click', async () => { - const surveySampleAction = await this._rpc({ - model: 'survey.survey', - method: $tile.data('action'), - }); - this.do_action(surveySampleAction); - }); - }); - const dialog = new Dialog(this, { - title: _t('Load a Survey'), - $content: $content, - renderFooter: false, - }); - dialog.open(); + _loadSample: function (ev) { + // Prevent loading multiple samples if double clicked + if (!this.isLoadingSample && this.activeActions.create) { + this.isLoadingSample = true; + this.do_action(this._rpc({ + model: 'survey.survey', + method: $(ev.target).closest('.o_survey_sample_container').attr('action'), + })); + } }, -} +}; -const SurveyKanbanRenderer = KanbanRenderer.extend(SurveySampleModalMixin, { - xmlDependencies: (KanbanRenderer.prototype.xmlDependencies || []).concat([ - 'survey/static/src/xml/survey_sample_modal.xml', - ]), +const SurveyKanbanRenderer = KanbanRenderer.extend(SurveySampleMixin, { events: _.extend({}, KanbanRenderer.prototype.events, { - 'click .o_survey_open_sample_modal': '_onOpenSurveySampleModalClick', + 'click .o_survey_load_sample': '_loadSample', }), }); -const SurveyListRenderer = ListRenderer.extend(SurveySampleModalMixin, { - xmlDependencies: (ListRenderer.prototype.xmlDependencies || []).concat([ - 'survey/static/src/xml/survey_sample_modal.xml', - ]), +const SurveyListRenderer = ListRenderer.extend(SurveySampleMixin, { events: _.extend({}, ListRenderer.prototype.events, { - 'click .o_survey_open_sample_modal': '_onOpenSurveySampleModalClick', + 'click .o_survey_load_sample': '_loadSample', }), }); diff --git a/addons/survey/static/src/xml/survey_sample_modal.xml b/addons/survey/static/src/xml/survey_sample_modal.xml deleted file mode 100644 index 9416d0b7a2e..00000000000 --- a/addons/survey/static/src/xml/survey_sample_modal.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - -
-
-
- -
- Gather feedbacks from your employees and customers. -
-
-
Feedback Form
-
-
-
- -
- Handle quiz & certifications online. -
-
-
Certification
-
-
-
- -
- Add some fun to your presentations by sharing questions live. -
-
-
Live Presentation
-
-
-
-
diff --git a/addons/survey/views/survey_survey_views.xml b/addons/survey/views/survey_survey_views.xml index b3178cfaadd..530951427ee 100644 --- a/addons/survey/views/survey_survey_views.xml +++ b/addons/survey/views/survey_survey_views.xml @@ -180,7 +180,7 @@ survey.survey.view.tree survey.survey - + @@ -202,7 +202,7 @@ survey.survey.view.kanban survey.survey - + @@ -399,13 +399,52 @@ survey.survey kanban,tree,form,activity -

- Create a Survey -

- Surveys can serve many purposes: collect customer feedback, gather market insights, structure employee evaluations, test and certify resellers, support a live presentation, ... -

- Let's create one and share it! Not sure where to start? Load a survey -

+
+
+
+ +
+ Gather feedbacks from your employees and customers. +
+
+ + Try It +
+
+
+ +
+ Handle quiz & certifications online. +
+
+ + Try It +
+
+
+ +
+ Add some fun to your presentations by sharing questions live. +
+
+ + Try It +
+
+

+ Create a Survey +

+

+ Surveys can serve many purposes: collect customer feedback, gather market insights, structure employee evaluations, test and certify resellers, support a live presentation, ... +

+ Not sure where to start? Try a sample Survey! +