summaryrefslogtreecommitdiff
path: root/addons/website/static/src
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2019-02-07 16:41:52 +0000
committerqsm-odoo <qsm@odoo.com>2019-02-26 17:09:22 +0000
commit335a505d1f9b6a978c0fe0f6ea760a45b0d0a67f (patch)
tree208507b876971e1b8a4f25077a16262e3a95dfcd /addons/website/static/src
parent27fca749af30d7dce448f6632132422df8d8a7c1 (diff)
[REF] website, *: move and review the notion of edit mode
* portal, sale, web, website_blog, website_crm_partner_assign, website_forum, website_event_track, website_links, website_mail, website_slides, website_mail_channel, website_mass_mailing, website_sale, website_sale_comparison, website_sale_delivery, website_sale_wishlist The `editableMode` option and its related options in public widget should only be part of website, this commit moves them there. This is also the occasion to implement something that is long overdue: stop creating 'animations' / public widgets in edit mode by default. Indeed, lots of 'animations' were defined by beginning with 'if not edit mode'. Now, if a public widget should be considered in edit mode, it must be defined explicitely through a property at *definition* of the widget. Part of https://github.com/odoo/odoo/pull/29442 task-1932066
Diffstat (limited to 'addons/website/static/src')
-rw-r--r--addons/website/static/src/js/content/menu.js3
-rw-r--r--addons/website/static/src/js/content/snippets.animation.js56
-rw-r--r--addons/website/static/src/js/content/website_root.js12
-rw-r--r--addons/website/static/src/js/editor/snippets.options.js5
4 files changed, 66 insertions, 10 deletions
diff --git a/addons/website/static/src/js/content/menu.js b/addons/website/static/src/js/content/menu.js
index 7e06140f657..b8ea9f61564 100644
--- a/addons/website/static/src/js/content/menu.js
+++ b/addons/website/static/src/js/content/menu.js
@@ -13,9 +13,6 @@ sAnimation.registry.affixMenu = sAnimation.Class.extend({
*/
start: function () {
var def = this._super.apply(this, arguments);
- if (this.editableMode) {
- return def;
- }
var self = this;
this.$headerClone = this.$target.clone().addClass('o_header_affix affix').removeClass('o_affix_enabled');
diff --git a/addons/website/static/src/js/content/snippets.animation.js b/addons/website/static/src/js/content/snippets.animation.js
index d2ef26a1bf6..ae4df825c50 100644
--- a/addons/website/static/src/js/content/snippets.animation.js
+++ b/addons/website/static/src/js/content/snippets.animation.js
@@ -34,6 +34,54 @@ if (!window.performance || !window.performance.now) {
}
/**
+ * Add the notion of edit mode to public widgets.
+ */
+publicWidget.Widget.include({
+ /**
+ * Indicates if the widget should not be instantiated in edit. The default
+ * is true, indeed most (all?) defined widgets only want to initialize
+ * events and states which should not be active in edit mode (this is
+ * especially true for non-website widgets).
+ *
+ * @type {boolean}
+ */
+ disabledInEditableMode: true,
+ /**
+ * Acts as @see Widget.events except that the events are only binded if the
+ * Animation instance is instanciated in edit mode. The property is not
+ * considered if @see disabledInEditableMode is false.
+ */
+ edit_events: null,
+ /**
+ * Acts as @see Widget.events except that the events are only binded if the
+ * Animation instance is instanciated in readonly mode. The property only
+ * makes sense if @see disabledInEditableMode is false, you should simply
+ * use @see Widget.events otherwise.
+ */
+ read_events: null,
+
+ /**
+ * Initializes the events that will need to be binded according to the
+ * given mode.
+ *
+ * @constructor
+ * @param {Object} parent
+ * @param {Object} [options]
+ * @param {boolean} [options.editableMode=false]
+ * true if the page is in edition mode
+ */
+ init: function (parent, options) {
+ this._super.apply(this, arguments);
+
+ this.editableMode = this.options.editableMode || false;
+ var extraEvents = this.editableMode ? this.edit_events : this.read_events;
+ if (extraEvents) {
+ this.events = _.extend(this.events || {}, extraEvents);
+ }
+ },
+});
+
+/**
* In charge of handling one animation loop using the requestAnimationFrame
* feature. This is used by the `Animation` class below and should not be called
* directly by an end developer.
@@ -379,6 +427,7 @@ var registry = publicWidget.registry;
registry.slider = publicWidget.Widget.extend({
selector: '.carousel',
+ disabledInEditableMode: false,
edit_events: {
'slid.bs.carousel': '_onEditionSlide',
},
@@ -669,7 +718,7 @@ registry.ul = publicWidget.Widget.extend({
registry.gallery = publicWidget.Widget.extend({
selector: '.o_gallery:not(.o_slideshow)',
xmlDependencies: ['/website/static/src/xml/website.gallery.xml'],
- read_events: {
+ events: {
'click img': '_onClickImg',
},
@@ -741,6 +790,7 @@ registry.gallery = publicWidget.Widget.extend({
registry.gallerySlider = publicWidget.Widget.extend({
selector: '.o_slideshow',
xmlDependencies: ['/website/static/src/xml/website.gallery.xml'],
+ disabledInEditableMode: false,
/**
* @override
@@ -820,7 +870,7 @@ registry.gallerySlider = publicWidget.Widget.extend({
registry.socialShare = publicWidget.Widget.extend({
selector: '.oe_social_share',
xmlDependencies: ['/website/static/src/xml/website.share.xml'],
- read_events: {
+ events: {
'mouseenter': '_onMouseEnter',
},
@@ -947,7 +997,7 @@ registry.facebookPage = publicWidget.Widget.extend({
registry.anchorSlide = publicWidget.Widget.extend({
selector: 'a[href^="/"][href*="#"], a[href^="#"]',
- read_events: {
+ events: {
'click': '_onAnimateClick',
},
diff --git a/addons/website/static/src/js/content/website_root.js b/addons/website/static/src/js/content/website_root.js
index ce4ebfec435..fee9488583e 100644
--- a/addons/website/static/src/js/content/website_root.js
+++ b/addons/website/static/src/js/content/website_root.js
@@ -70,6 +70,18 @@ var WebsiteRoot = publicRootData.PublicRoot.extend({
'edit_translations': !!html.dataset.edit_translations,
}, this._super.apply(this, arguments));
},
+ /**
+ * @override
+ */
+ _getPublicWidgetsRegistry: function (options) {
+ var registry = this._super.apply(this, arguments);
+ if (options.editableMode) {
+ return _.pick(registry, function (PublicWidget) {
+ return !PublicWidget.prototype.disabledInEditableMode;
+ });
+ }
+ return registry;
+ },
//--------------------------------------------------------------------------
// Handlers
diff --git a/addons/website/static/src/js/editor/snippets.options.js b/addons/website/static/src/js/editor/snippets.options.js
index f51dda964db..c6423fa359d 100644
--- a/addons/website/static/src/js/editor/snippets.options.js
+++ b/addons/website/static/src/js/editor/snippets.options.js
@@ -246,10 +246,7 @@ options.registry.carousel = options.Class.extend({
}
});
_.defer(function () {
- self.trigger_up('animation_start_demand', {
- editableMode: true,
- $target: self.$target,
- });
+ self._refreshAnimations();
self.$target.carousel(index > 0 ? --index : cycle);
});
}