From afbbf75ec9c141a47c9db5b1953e2f6c65b2d325 Mon Sep 17 00:00:00 2001 From: "Arthur Detroux (ard)" Date: Wed, 21 Jun 2023 07:33:14 +0000 Subject: [PATCH] [MOV] web: moving the RootWidget definition after PublicWidget In the next commit, the PublicWidget class will be made independent of the legacy Widget class. Therefore, the RootWidget cannot be defined before the PublicWidget as it will extend the PublicWidget rather than the legacy Widget. This commit moves its definition after the PublicWidget definition. task-3249625 Part-of: odoo/odoo#117210 --- .../src/legacy/js/public/public_widget.js | 180 +++++++++--------- 1 file changed, 90 insertions(+), 90 deletions(-) diff --git a/addons/web/static/src/legacy/js/public/public_widget.js b/addons/web/static/src/legacy/js/public/public_widget.js index ff30fb00347..df26afc8522 100644 --- a/addons/web/static/src/legacy/js/public/public_widget.js +++ b/addons/web/static/src/legacy/js/public/public_widget.js @@ -7,96 +7,6 @@ import dom from 'web.dom'; import Widget from 'web.Widget'; -/** - * Specialized Widget which automatically instantiates child widgets to attach - * to internal DOM elements once it is started. The widgets to instantiate are - * known thanks to a linked registry which contains info about the widget - * classes and jQuery selectors to use to find the elements to attach them to. - * - * @todo Merge with 'PublicWidget' ? - */ -var RootWidget = Widget.extend({ - /** - * @constructor - */ - init: function () { - this._super.apply(this, arguments); - this._widgets = []; - }, - /** - * @override - * @see _attachComponents - */ - start: function () { - var defs = [this._super.apply(this, arguments)]; - - defs.push(this._attachComponents()); - this._getRegistry().on("UPDATE", this, ({ operation, value }) => { - if (operation === "add") { - this._attachComponent(value); - } - }); - - return Promise.all(defs); - }, - - //-------------------------------------------------------------------------- - // Private - //-------------------------------------------------------------------------- - - /** - * Instantiates a child widget according to the given registry data. - * - * @private - * @param {Object} childInfo - * @param {function} childInfo.Widget - the widget class to instantiate - * @param {string} childInfo.selector - * the jQuery selector to use to find the internal DOM element which - * needs to be attached to the instantiated widget - * @param {jQuery} [$from] - only check DOM elements which are descendant of - * the given one. If not given, use this.$el. - * @returns {Deferred} - */ - _attachComponent: function (childInfo, $from) { - var self = this; - var $elements = dom.cssFind($from || this.$el, childInfo.selector); - var defs = Array.from($elements).map((element) => { - var w = new childInfo.Widget(self); - self._widgets.push(w); - return w.attachTo(element); - }); - return Promise.all(defs); - }, - /** - * Instantiates the child widgets that need to be according to the linked - * registry. - * - * @private - * @param {jQuery} [$from] - only check DOM elements which are descendant of - * the given one. If not given, use this.$el. - * @returns {Deferred} - */ - _attachComponents: function ($from) { - var self = this; - var childInfos = this._getRegistry().getAll(); - var defs = childInfos.map((childInfo) => { - return self._attachComponent(childInfo, $from); - }); - return Promise.all(defs); - }, - /** - * Returns the `RootWidgetRegistry` instance that is linked to this - * `RootWidget` instance. - * - * @abstract - * @private - * @returns {RootWidgetRegistry} - */ - _getRegistry: function () {}, -}); - -//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - /** * Provides a way for executing code once a website DOM element is loaded in the * dom. @@ -257,6 +167,96 @@ var PublicWidget = Widget.extend({ //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +/** + * Specialized Widget which automatically instantiates child widgets to attach + * to internal DOM elements once it is started. The widgets to instantiate are + * known thanks to a linked registry which contains info about the widget + * classes and jQuery selectors to use to find the elements to attach them to. + * + * @todo Merge with 'PublicWidget' ? + */ +var RootWidget = Widget.extend({ + /** + * @constructor + */ + init: function () { + this._super.apply(this, arguments); + this._widgets = []; + }, + /** + * @override + * @see _attachComponents + */ + start: function () { + var defs = [this._super.apply(this, arguments)]; + + defs.push(this._attachComponents()); + this._getRegistry().on("UPDATE", this, ({ operation, value }) => { + if (operation === "add") { + this._attachComponent(value); + } + }); + + return Promise.all(defs); + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * Instantiates a child widget according to the given registry data. + * + * @private + * @param {Object} childInfo + * @param {function} childInfo.Widget - the widget class to instantiate + * @param {string} childInfo.selector + * the jQuery selector to use to find the internal DOM element which + * needs to be attached to the instantiated widget + * @param {jQuery} [$from] - only check DOM elements which are descendant of + * the given one. If not given, use this.$el. + * @returns {Deferred} + */ + _attachComponent: function (childInfo, $from) { + var self = this; + var $elements = dom.cssFind($from || this.$el, childInfo.selector); + var defs = Array.from($elements).map((element) => { + var w = new childInfo.Widget(self); + self._widgets.push(w); + return w.attachTo(element); + }); + return Promise.all(defs); + }, + /** + * Instantiates the child widgets that need to be according to the linked + * registry. + * + * @private + * @param {jQuery} [$from] - only check DOM elements which are descendant of + * the given one. If not given, use this.$el. + * @returns {Deferred} + */ + _attachComponents: function ($from) { + var self = this; + var childInfos = this._getRegistry().getAll(); + var defs = childInfos.map((childInfo) => { + return self._attachComponent(childInfo, $from); + }); + return Promise.all(defs); + }, + /** + * Returns the `RootWidgetRegistry` instance that is linked to this + * `RootWidget` instance. + * + * @abstract + * @private + * @returns {RootWidgetRegistry} + */ + _getRegistry: function () {}, +}); + +//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + /** * The registry object contains the list of widgets that should be instantiated * thanks to their selector property if any.