summaryrefslogtreecommitdiff
path: root/addons/website/static/src/js/editor
diff options
context:
space:
mode:
authorRomain Derie <rde@odoo.com>2019-11-22 13:20:23 +0000
committerqsm-odoo <qsm@odoo.com>2020-01-29 14:53:38 +0000
commit3028e9a8649ae5d9b23a1bdb989b903645ede5fe (patch)
treecf54e7c116cee0cb0cea3f06d65f897e8531596e /addons/website/static/src/js/editor
parent3bce5277e378fd499bf2d0fed8c62929165b7871 (diff)
[IMP] website: introduce cookies bar on website
With this commit, it is now possible to activate a cookies bar on a website through the res.settings. The cookies bar can be edited in the frontend by entering edit mode. The cookies bar will appear until the user clicks on 'I agree'. Part of https://github.com/odoo/odoo/pull/41294 task-2087003 closes odoo/odoo#41294 Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Diffstat (limited to 'addons/website/static/src/js/editor')
-rw-r--r--addons/website/static/src/js/editor/snippets.options.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/addons/website/static/src/js/editor/snippets.options.js b/addons/website/static/src/js/editor/snippets.options.js
index 9765bc57473..0ef07ccc12e 100644
--- a/addons/website/static/src/js/editor/snippets.options.js
+++ b/addons/website/static/src/js/editor/snippets.options.js
@@ -1,6 +1,7 @@
odoo.define('website.editor.snippets.options', function (require) {
'use strict';
+require('website.s_popup_options');
var core = require('web.core');
var Dialog = require('web.Dialog');
const wUtils = require('website.utils');
@@ -913,6 +914,63 @@ options.registry.anchor = options.Class.extend({
},
});
+options.registry.CookiesBar = options.registry.SnippetPopup.extend({
+ xmlDependencies: (options.registry.SnippetPopup.prototype.xmlDependencies || []).concat(
+ ['/website/static/src/xml/website.cookies_bar.xml']
+ ),
+
+ //--------------------------------------------------------------------------
+ // Options
+ //--------------------------------------------------------------------------
+
+ /**
+ * Change the cookies bar layout.
+ *
+ * @see this.selectClass for parameters
+ */
+ selectLayout: function (previewMode, widgetValue, params) {
+ let websiteId;
+ this.trigger_up('context_get', {
+ callback: function (ctx) {
+ websiteId = ctx['website_id'];
+ },
+ });
+
+ const $template = $(qweb.render(`website.cookies_bar.${widgetValue}`, {
+ websiteId: websiteId,
+ }));
+
+ const $content = this.$target.find('.s_popup_content');
+ const selectorsToKeep = [
+ '.o_cookies_bar_text_button',
+ '.o_cookies_bar_text_policy',
+ '.o_cookies_bar_text_title',
+ '.o_cookies_bar_text_primary',
+ '.o_cookies_bar_text_secondary',
+ ];
+
+ if (this.$savedSelectors === undefined) {
+ this.$savedSelectors = [];
+ }
+
+ for (const selector of selectorsToKeep) {
+ const $currentLayoutEls = $content.find(selector).contents();
+ const $newLayoutEl = $template.find(selector);
+ if ($currentLayoutEls.length) {
+ // save value before change, eg 'title' is not inside 'discrete' template
+ // but we want to preserve it in case of select another layout later
+ this.$savedSelectors[selector] = $currentLayoutEls;
+ }
+ const $savedSelector = this.$savedSelectors[selector];
+ if ($newLayoutEl.length && $savedSelector && $savedSelector.length) {
+ $newLayoutEl.empty().append($savedSelector);
+ }
+ }
+
+ $content.empty().append($template);
+ },
+});
+
/**
* Allows edition of 'cover_properties' in website models which have such
* fields (blogs, posts, events, ...).