diff --git a/addons/portal/static/src/js/portal.js b/addons/portal/static/src/js/portal.js index 6a96ac5c967..08e37bb2681 100644 --- a/addons/portal/static/src/js/portal.js +++ b/addons/portal/static/src/js/portal.js @@ -5,7 +5,7 @@ var publicWidget = require('web.public.widget'); publicWidget.registry.portalDetails = publicWidget.Widget.extend({ selector: '.o_portal_details', - read_events: { + events: { 'change select[name="country_id"]': '_onCountryChange', }, @@ -14,9 +14,6 @@ publicWidget.registry.portalDetails = publicWidget.Widget.extend({ */ start: function () { var def = this._super.apply(this, arguments); - if (this.editableMode) { - return; - } this.$state = this.$('select[name="state_id"]'); this.$stateOptions = this.$state.filter(':enabled').find('option:not(:first)'); @@ -55,7 +52,7 @@ publicWidget.registry.portalDetails = publicWidget.Widget.extend({ publicWidget.registry.portalSearchPanel = publicWidget.Widget.extend({ selector: '.o_portal_search_panel', - read_events: { + events: { 'click .search-submit': '_onSearchSubmitClick', 'click .dropdown-item': '_onDropdownItemClick', 'keyup input[name="search"]': '_onSearchInputKeyup', @@ -66,12 +63,7 @@ publicWidget.registry.portalSearchPanel = publicWidget.Widget.extend({ */ start: function () { var def = this._super.apply(this, arguments); - if (this.editableMode) { - return; - } - this._adaptSearchLabel(this.$('.dropdown-item.active')); - return def; }, diff --git a/addons/sale/static/src/js/product_configurator_renderer.js b/addons/sale/static/src/js/product_configurator_renderer.js index 899656c8065..8d16f2a329a 100644 --- a/addons/sale/static/src/js/product_configurator_renderer.js +++ b/addons/sale/static/src/js/product_configurator_renderer.js @@ -4,7 +4,7 @@ odoo.define('sale.ProductConfiguratorFormRenderer', function (require) { var FormRenderer = require('web.FormRenderer'); var ProductConfiguratorMixin = require('sale.ProductConfiguratorMixin'); -var ProductConfiguratorFormRenderer = FormRenderer.extend(ProductConfiguratorMixin ,{ +var ProductConfiguratorFormRenderer = FormRenderer.extend(ProductConfiguratorMixin, { /** * @override */ diff --git a/addons/web/static/src/js/public/public_root.js b/addons/web/static/src/js/public/public_root.js index eedc6cf5377..ebf9bb0937d 100644 --- a/addons/web/static/src/js/public/public_root.js +++ b/addons/web/static/src/js/public/public_root.js @@ -135,6 +135,14 @@ var PublicRoot = publicWidget.RootWidget.extend(ServiceProviderMixin, { _getExtraContext: function (context) { return this._getContext(context); }, + /** + * @private + * @param {Object} [options] + * @returns {Object} + */ + _getPublicWidgetsRegistry: function (options) { + return publicWidget.registry; + }, /** * As the root instance is designed to be unique, the associated * registry has been instantiated outside of the class and is simply @@ -176,7 +184,7 @@ var PublicRoot = publicWidget.RootWidget.extend(ServiceProviderMixin, { this._stopAnimations($from); - var defs = _.map(publicWidget.registry, function (WebsiteWidget) { + var defs = _.map(this._getPublicWidgetsRegistry(options), function (WebsiteWidget) { var selector = WebsiteWidget.prototype.selector || ''; var $target = $from.find(selector).addBack(selector); diff --git a/addons/web/static/src/js/public/public_widget.js b/addons/web/static/src/js/public/public_widget.js index 2f720c019f1..ed99c5da457 100644 --- a/addons/web/static/src/js/public/public_widget.js +++ b/addons/web/static/src/js/public/public_widget.js @@ -207,41 +207,15 @@ var PublicWidget = Widget.extend({ * @type {Object} */ events: {}, - /** - * Acts as @see Widget.events except that the events are only binded if the - * Animation instance is instanciated in edit mode. - */ - edit_events: {}, - /** - * Acts as @see Widget.events except that the events are only binded if the - * Animation instance is instanciated in readonly mode. - */ - read_events: {}, /** - * 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 - true if the page is in edition mode + * @param {Object} [options] */ init: function (parent, options) { this._super.apply(this, arguments); - - // Note that the notion of editable mode is kept here for now even - // though nothing can be edited here. This allows to have a readable - // code for frontend widgets and mainly to prevent having loading - // problems an "include" could have caused. this.options = options || {}; - this.editableMode = this.options.editableMode || false; - - if (this.editableMode) { - this.events = _.extend({}, this.events || {}, this.edit_events || {}); - } else { - this.events = _.extend({}, this.events || {}, this.read_events || {}); - } }, /** * Destroys the animation and basically restores the target to the state it 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 @@ -33,6 +33,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 @@ -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); }); } diff --git a/addons/website_blog/static/src/js/s_latest_posts_frontend.js b/addons/website_blog/static/src/js/s_latest_posts_frontend.js index f1b8ea4f23d..fcc0ea087cf 100644 --- a/addons/website_blog/static/src/js/s_latest_posts_frontend.js +++ b/addons/website_blog/static/src/js/s_latest_posts_frontend.js @@ -8,6 +8,7 @@ var _t = core._t; sAnimation.registry.js_get_posts = sAnimation.Class.extend({ selector : '.js_get_posts', + disabledInEditableMode: false, /** * @override diff --git a/addons/website_blog/static/src/js/website_blog.js b/addons/website_blog/static/src/js/website_blog.js index 9d2af1a3bbc..ee0d9313600 100644 --- a/addons/website_blog/static/src/js/website_blog.js +++ b/addons/website_blog/static/src/js/website_blog.js @@ -5,7 +5,7 @@ var sAnimations = require('website.content.snippets.animation'); sAnimations.registry.websiteBlog = sAnimations.Class.extend({ selector: '.website_blog', - read_events: { + events: { 'click .cover_footer': '_onNextBlogClick', 'click a[href^="#blog_content"]': '_onContentAnchorClick', 'click .o_twitter, .o_facebook, .o_linkedin, .o_google, .o_twitter_complete, .o_facebook_complete, .o_linkedin_complete, .o_google_complete': '_onShareArticle', diff --git a/addons/website_crm_partner_assign/static/src/js/crm_partner_assign.js b/addons/website_crm_partner_assign/static/src/js/crm_partner_assign.js index 78b427eb296..8c185aa72c6 100644 --- a/addons/website_crm_partner_assign/static/src/js/crm_partner_assign.js +++ b/addons/website_crm_partner_assign/static/src/js/crm_partner_assign.js @@ -5,7 +5,7 @@ var sAnimations = require('website.content.snippets.animation'); sAnimations.registry.crmPartnerAssign = sAnimations.Class.extend({ selector: '#wrapwrap:has(.interested_partner_assign_form, .desinterested_partner_assign_form, .opp-stage-button, .new_opp_form)', - read_events: { + events: { 'click .interested_partner_assign_confirm': '_onInterestedPartnerAssignConfirm', 'click .desinterested_partner_assign_confirm': '_onDesinterestedPartnerAssignConfirm', 'click .opp-stage-button': '_onOppStageButtonClick', diff --git a/addons/website_event_track/static/src/js/website_event_track.js b/addons/website_event_track/static/src/js/website_event_track.js index 77c54c10501..152792bb9e5 100644 --- a/addons/website_event_track/static/src/js/website_event_track.js +++ b/addons/website_event_track/static/src/js/website_event_track.js @@ -5,7 +5,7 @@ var sAnimations = require('website.content.snippets.animation'); sAnimations.registry.websiteEventTrack = sAnimations.Class.extend({ selector: '.o_website_event', - read_events: { + events: { 'input #event_track_search': '_onEventTrackSearchInput', }, diff --git a/addons/website_forum/static/src/js/website_forum.js b/addons/website_forum/static/src/js/website_forum.js index 613163a045a..d1ce5b18f5c 100644 --- a/addons/website_forum/static/src/js/website_forum.js +++ b/addons/website_forum/static/src/js/website_forum.js @@ -12,7 +12,7 @@ var _t = core._t; sAnimations.registry.websiteForum = sAnimations.Class.extend({ selector: '.website_forum', xmlDependencies: ['/website_forum/static/src/xml/website_forum_share_templates.xml'], - read_events: { + events: { 'click .karma_required': '_onKarmaRequiredClick', 'mouseenter .o_js_forum_tag_follow': '_onTagFollowBoxMouseEnter', 'mouseleave .o_js_forum_tag_follow': '_onTagFollowBoxMouseLeave', @@ -506,7 +506,7 @@ sAnimations.registry.websiteForum = sAnimations.Class.extend({ sAnimations.registry.websiteForumSpam = sAnimations.Class.extend({ selector: '.o_wforum_moderation_queue', xmlDependencies: ['/website_forum/static/src/xml/website_forum_share_templates.xml'], - read_events: { + events: { 'click .o_wforum_select_all_spam': '_onSelectallSpamClick', 'click .o_wforum_mark_spam': 'async _onMarkSpamClick', 'input #spamSearch': '_onSpamSearchInput', diff --git a/addons/website_forum/static/src/js/website_forum.share.js b/addons/website_forum/static/src/js/website_forum.share.js index c1d0d8a1b4a..0fea6e4ef9c 100644 --- a/addons/website_forum/static/src/js/website_forum.share.js +++ b/addons/website_forum/static/src/js/website_forum.share.js @@ -11,15 +11,15 @@ var ForumShare = sAnimations.registry.socialShare.extend({ selector: '', xmlDependencies: sAnimations.registry.socialShare.prototype.xmlDependencies .concat(['/website_forum/static/src/xml/website_forum_share_templates.xml']), - read_events: {}, + events: {}, /** * @override * @param {Object} parent - * @param {boolean} editableMode + * @param {Object} options * @param {string} targetType */ - init: function (parent, editableMode, targetType) { + init: function (parent, options, targetType) { this._super.apply(this, arguments); this.targetType = targetType; }, @@ -71,7 +71,7 @@ var ForumShare = sAnimations.registry.socialShare.extend({ sAnimations.registry.websiteForumShare = sAnimations.Class.extend({ selector: '.website_forum', - read_events: { + events: { 'click :not(.karma_required).oe_social_share_call': '_onShareCallClick', }, diff --git a/addons/website_links/static/src/js/website_links.js b/addons/website_links/static/src/js/website_links.js index afe64642f47..ec77790bc00 100644 --- a/addons/website_links/static/src/js/website_links.js +++ b/addons/website_links/static/src/js/website_links.js @@ -339,7 +339,7 @@ var RecentLinks = Widget.extend({ sAnimations.registry.websiteLinks = sAnimations.Class.extend({ selector: '.o_website_links_create_tracked_url', - read_events: { + events: { 'click #filter-newest-links': '_onFilterNewestLinksClick', 'click #filter-most-clicked-links': '_onFilterMostClickedLinksClick', 'click #filter-recently-used-links': '_onFilterRecentlyUsedLinksClick', diff --git a/addons/website_links/static/src/js/website_links_charts.js b/addons/website_links/static/src/js/website_links_charts.js index 08ea40f1bed..5fcc343cede 100644 --- a/addons/website_links/static/src/js/website_links_charts.js +++ b/addons/website_links/static/src/js/website_links_charts.js @@ -150,7 +150,7 @@ var PieChart = Widget.extend({ sAnimations.registry.websiteLinksCharts = sAnimations.Class.extend({ selector: '.o_website_links_chart', - read_events: { + events: { 'click .graph-tabs li a': '_onGraphTabClick', 'click .copy-to-clipboard': '_onCopyToClipboardClick', }, diff --git a/addons/website_links/static/src/js/website_links_code_editor.js b/addons/website_links/static/src/js/website_links_code_editor.js index 3d550983e7a..d8d2f86a1a6 100644 --- a/addons/website_links/static/src/js/website_links_code_editor.js +++ b/addons/website_links/static/src/js/website_links_code_editor.js @@ -8,7 +8,7 @@ var _t = core._t; sAnimations.registry.websiteLinksCodeEditor = sAnimations.Class.extend({ selector: '#wrapwrap:has(.o_website_links_edit_code)', - read_events: { + events: { 'click .o_website_links_edit_code': '_onEditCodeClick', 'click .o_website_links_cancel_edit': '_onCancelEditClick', 'submit #edit-code-form': '_onEditCodeFormSubmit', diff --git a/addons/website_mail/static/src/js/follow.js b/addons/website_mail/static/src/js/follow.js index 0893c998ff1..7e72e5e5a4e 100644 --- a/addons/website_mail/static/src/js/follow.js +++ b/addons/website_mail/static/src/js/follow.js @@ -5,6 +5,7 @@ var sAnimation = require('website.content.snippets.animation'); sAnimation.registry.follow = sAnimation.Class.extend({ selector: '.js_follow', + disabledInEditableMode: false, start: function () { var self = this; diff --git a/addons/website_mail_channel/static/src/js/website_mail_channel.js b/addons/website_mail_channel/static/src/js/website_mail_channel.js index 84571336dfb..b30f9c583e3 100644 --- a/addons/website_mail_channel/static/src/js/website_mail_channel.js +++ b/addons/website_mail_channel/static/src/js/website_mail_channel.js @@ -5,7 +5,7 @@ var sAnimations = require('website.content.snippets.animation'); sAnimations.registry.websiteMailChannel = sAnimations.Class.extend({ selector: '#wrapwrap', - read_events: { + events: { 'click .o_mg_link_hide': '_onHideLinkClick', 'click .o_mg_link_show': '_onShowLinkClick', 'click button.o_mg_read_more': '_onReadMoreClick', diff --git a/addons/website_mail_channel/static/src/js/website_mail_channel.snippet.js b/addons/website_mail_channel/static/src/js/website_mail_channel.snippet.js index b8fd3761fc9..7ac4319a88b 100644 --- a/addons/website_mail_channel/static/src/js/website_mail_channel.snippet.js +++ b/addons/website_mail_channel/static/src/js/website_mail_channel.snippet.js @@ -5,6 +5,7 @@ var sAnimation = require('website.content.snippets.animation'); sAnimation.registry.follow_alias = sAnimation.Class.extend({ selector: ".js_follow_alias", + disabledInEditableMode: false, start: function () { var self = this; this.is_user = false; diff --git a/addons/website_mass_mailing/static/src/js/website_mass_mailing.js b/addons/website_mass_mailing/static/src/js/website_mass_mailing.js index e30f824693d..66a260264eb 100644 --- a/addons/website_mass_mailing/static/src/js/website_mass_mailing.js +++ b/addons/website_mass_mailing/static/src/js/website_mass_mailing.js @@ -6,6 +6,8 @@ var sAnimation = require('website.content.snippets.animation'); sAnimation.registry.subscribe = sAnimation.Class.extend({ selector: ".js_subscribe", + disabledInEditableMode: false, + start: function () { var self = this; @@ -65,6 +67,8 @@ sAnimation.registry.subscribe = sAnimation.Class.extend({ sAnimation.registry.newsletter_popup = sAnimation.Class.extend({ selector: ".o_newsletter_popup", + disabledInEditableMode: false, + start: function () { var self = this; diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js index 94e9c54a312..9ac6a8f4237 100644 --- a/addons/website_sale/static/src/js/website_sale.js +++ b/addons/website_sale/static/src/js/website_sale.js @@ -9,7 +9,7 @@ var timeout; sAnimations.registry.websiteSaleCartLink = sAnimations.Class.extend({ selector: '#top_menu a[href$="/shop/cart"]', - read_events: { + events: { 'mouseenter': '_onMouseEnter', 'mouseleave': '_onMouseLeave', }, @@ -18,11 +18,6 @@ sAnimations.registry.websiteSaleCartLink = sAnimations.Class.extend({ * @override */ start: function () { - var def = this._super.apply(this, arguments); - if (this.editableMode) { - return def; - } - this.$el.popover({ trigger: 'manual', animation: true, @@ -34,7 +29,7 @@ sAnimations.registry.websiteSaleCartLink = sAnimations.Class.extend({ placement: 'auto', template: '