From c925ada7dafaad54798b38b5e4b89eb44c7f25d6 Mon Sep 17 00:00:00 2001 From: "Michael (mcm)" Date: Thu, 28 Sep 2023 09:52:17 +0200 Subject: [PATCH] [IMP] *: replace some odoo classes by native ones This commit replaces some odoo classes by native ones. They are simple classes with no big extensions or not at all. task 3439226 closes odoo/odoo#137116 Related: odoo/enterprise#48154 Signed-off-by: Mathieu Duckerts-Antoine (dam) --- .../event/static/src/js/tours/event_steps.js | 10 ++++------ .../static/src/js/recaptcha.js | 17 ++++++++-------- .../static/src/js/tours/purchase_steps.js | 10 ++++------ .../static/src/js/tours/purchase_stock.js | 7 ++----- .../web/static/src/legacy/js/core/mixins.js | 19 +++++++++--------- .../static/src/js/tours/event_tour.js | 7 ++----- .../website_event_booth_exhibitor_steps.js | 20 +++++++++---------- .../website_event_booth_sale_exhibitor.js | 3 ++- 8 files changed, 40 insertions(+), 53 deletions(-) diff --git a/addons/event/static/src/js/tours/event_steps.js b/addons/event/static/src/js/tours/event_steps.js index dbbb355666c..2646b43ac10 100644 --- a/addons/event/static/src/js/tours/event_steps.js +++ b/addons/event/static/src/js/tours/event_steps.js @@ -1,13 +1,11 @@ /** @odoo-module **/ -import Class from "@web/legacy/js/core/class"; +class EventAdditionalTourSteps { -var EventAdditionalTourSteps = Class.extend({ - - _get_website_event_steps: function () { + _get_website_event_steps() { return [false]; - }, + } -}); +} export default EventAdditionalTourSteps; diff --git a/addons/google_recaptcha/static/src/js/recaptcha.js b/addons/google_recaptcha/static/src/js/recaptcha.js index 61c8d7fe487..3a03c1bf555 100644 --- a/addons/google_recaptcha/static/src/js/recaptcha.js +++ b/addons/google_recaptcha/static/src/js/recaptcha.js @@ -1,30 +1,29 @@ /** @odoo-module **/ -import Class from "@web/legacy/js/core/class"; import { session } from "@web/session"; import { loadJS } from "@web/core/assets"; import { _t } from "@web/core/l10n/translation"; -export const ReCaptcha = Class.extend({ +export class ReCaptcha { /** * @override */ - init: function () { + constructor() { this._publicKey = session.recaptcha_public_key; - }, + } /** * Loads the recaptcha libraries. * * @returns {Promise|boolean} promise if libs are loading else false if the reCaptcha key is empty. */ - loadLibs: function () { + loadLibs() { if (this._publicKey) { this._recaptchaReady = loadJS(`https://www.recaptcha.net/recaptcha/api.js?render=${encodeURIComponent(this._publicKey)}`) .then(() => new Promise(resolve => window.grecaptcha.ready(() => resolve()))); return this._recaptchaReady.then(() => !!document.querySelector('.grecaptcha-badge')); } return false; - }, + } /** * Returns an object with the token if reCaptcha call succeeds * If no key is set an object with a message is returned @@ -33,7 +32,7 @@ export const ReCaptcha = Class.extend({ * @param {string} action * @returns {Promise|Object} */ - getToken: async function (action) { + async getToken(action) { if (!this._publicKey) { return { message: _t("No recaptcha site key set."), @@ -49,8 +48,8 @@ export const ReCaptcha = Class.extend({ error: _t("The recaptcha site key is invalid."), }; } - }, -}); + } +} export default { ReCaptcha: ReCaptcha, diff --git a/addons/purchase/static/src/js/tours/purchase_steps.js b/addons/purchase/static/src/js/tours/purchase_steps.js index e6f79b49621..69af0acb737 100644 --- a/addons/purchase/static/src/js/tours/purchase_steps.js +++ b/addons/purchase/static/src/js/tours/purchase_steps.js @@ -1,16 +1,14 @@ /** @odoo-module **/ -import Class from "@web/legacy/js/core/class"; - -var PurchaseAdditionalTourSteps = Class.extend({ - _get_purchase_stock_steps: function () { +class PurchaseAdditionalTourSteps { + _get_purchase_stock_steps() { return [ { auto: true, // Useless final step to trigger congratulation message trigger: ".o_purchase_order", }, ]; - }, -}); + } +} export default PurchaseAdditionalTourSteps; diff --git a/addons/purchase_stock/static/src/js/tours/purchase_stock.js b/addons/purchase_stock/static/src/js/tours/purchase_stock.js index ccbe851fe7b..4ddbf92c4a2 100644 --- a/addons/purchase_stock/static/src/js/tours/purchase_stock.js +++ b/addons/purchase_stock/static/src/js/tours/purchase_stock.js @@ -3,12 +3,9 @@ import { _t } from "@web/core/l10n/translation"; import PurchaseAdditionalTourSteps from "@purchase/js/tours/purchase_steps"; +import { patch } from "@web/core/utils/patch"; -PurchaseAdditionalTourSteps.include({ - - init: function() { - this._super.apply(this, arguments); - }, +patch(PurchaseAdditionalTourSteps.prototype, { _get_purchase_stock_steps: function () { this._super.apply(this, arguments); diff --git a/addons/web/static/src/legacy/js/core/mixins.js b/addons/web/static/src/legacy/js/core/mixins.js index c4b1a760e44..cfad2af7473 100644 --- a/addons/web/static/src/legacy/js/core/mixins.js +++ b/addons/web/static/src/legacy/js/core/mixins.js @@ -1,6 +1,5 @@ /** @odoo-module **/ -import Class from "@web/legacy/js/core/class"; import { floatIsZero } from "@web/core/utils/numbers"; /** @@ -148,8 +147,8 @@ OdooEvent.prototype.is_stopped = function () { * http://backbonejs.org * */ -var Events = Class.extend({ - on : function (events, callback, context) { +class Events { + on(events, callback, context) { var ev; events = events.split(/\s+/); var calls = this._callbacks || (this._callbacks = {}); @@ -161,9 +160,9 @@ var Events = Class.extend({ list.tail = tail.next = {}; } return this; - }, + } - off : function (events, callback, context) { + off(events, callback, context) { var ev, calls, node; if (!events) { delete this._callbacks; @@ -183,9 +182,9 @@ var Events = Class.extend({ } } return this; - }, + } - callbackList: function () { + callbackList() { var lst = []; for (const [eventName, el] of Object.entries(this._callbacks || {})) { var node = el; @@ -194,9 +193,9 @@ var Events = Class.extend({ } } return lst; - }, + } - trigger : function (events) { + trigger(events) { var event, node, calls, tail, args, all, rest; if (!(calls = this._callbacks)) return this; @@ -227,7 +226,7 @@ var Events = Class.extend({ } return this; } -}); +} /** * Mixin containing an event system. Events are also registered by specifying the target object diff --git a/addons/website_event/static/src/js/tours/event_tour.js b/addons/website_event/static/src/js/tours/event_tour.js index 99346991c2c..879c574a60d 100644 --- a/addons/website_event/static/src/js/tours/event_tour.js +++ b/addons/website_event/static/src/js/tours/event_tour.js @@ -4,12 +4,9 @@ import { _t } from "@web/core/l10n/translation"; import EventAdditionalTourSteps from "@event/js/tours/event_steps"; import { markup } from "@odoo/owl"; +import { patch } from "@web/core/utils/patch"; -EventAdditionalTourSteps.include({ - - init: function() { - this._super.apply(this, arguments); - }, +patch(EventAdditionalTourSteps.prototype, { _get_website_event_steps: function () { this._super.apply(this, arguments); diff --git a/addons/website_event_booth_exhibitor/static/tests/tours/website_event_booth_exhibitor_steps.js b/addons/website_event_booth_exhibitor/static/tests/tours/website_event_booth_exhibitor_steps.js index 019b5b23b18..8f034f91a80 100644 --- a/addons/website_event_booth_exhibitor/static/tests/tours/website_event_booth_exhibitor_steps.js +++ b/addons/website_event_booth_exhibitor/static/tests/tours/website_event_booth_exhibitor_steps.js @@ -1,16 +1,14 @@ /** @odoo-module **/ - import Class from "@web/legacy/js/core/class"; +class FinalSteps { - var FinalSteps = Class.extend({ + _getSteps() { + return [{ + trigger: 'h3:contains("Booth Registration completed!")', + run: function() {}, + }]; + } - _getSteps: function () { - return [{ - trigger: 'h3:contains("Booth Registration completed!")', - run: function() {}, - }]; - }, +} - }); - - export default FinalSteps; +export default FinalSteps; diff --git a/addons/website_event_booth_sale_exhibitor/static/tests/tours/website_event_booth_sale_exhibitor.js b/addons/website_event_booth_sale_exhibitor/static/tests/tours/website_event_booth_sale_exhibitor.js index e7536dac7a1..c32bf9e3293 100644 --- a/addons/website_event_booth_sale_exhibitor/static/tests/tours/website_event_booth_sale_exhibitor.js +++ b/addons/website_event_booth_sale_exhibitor/static/tests/tours/website_event_booth_sale_exhibitor.js @@ -1,9 +1,10 @@ /** @odoo-module **/ +import { patch } from "@web/core/utils/patch"; import FinalSteps from "@website_event_booth_exhibitor/../tests/tours/website_event_booth_exhibitor_steps"; import wsTourUtils from '@website_sale/js/tours/tour_utils'; -FinalSteps.include({ +patch(FinalSteps.prototype, { _getSteps: function () { return [