[REF] web, *: remove legacy patch
This commit removes legacy patch/unpatch functions and adapts their use by using the modern patch. There was also a custom patch function used in tests which has been replaced too. closes odoo/odoo#130867 Related: odoo/design-themes#685 Related: odoo/enterprise#45271 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -2,11 +2,11 @@
|
||||
|
||||
import { Messaging } from "@mail/core/common/messaging_service";
|
||||
|
||||
import { patch } from '@web/legacy/js/core/utils';
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(Messaging.prototype, "hr", {
|
||||
patch(Messaging.prototype, {
|
||||
setup(...args) {
|
||||
this._super(...args);
|
||||
super.setup(...args);
|
||||
this.store.employees = {};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -2,15 +2,14 @@
|
||||
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
import { ThreadService } from "@mail/core/common/thread_service";
|
||||
import { patch } from '@web/legacy/js/core/utils';
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
/** @type {import("@mail/core/common/thread_service").ThreadService} */
|
||||
const threadServicePatch = {
|
||||
async getChat(person) {
|
||||
const { employeeId } = person;
|
||||
const _super = this._super.bind(this);
|
||||
if (!employeeId) {
|
||||
return _super(person);
|
||||
return super.getChat(person);
|
||||
}
|
||||
let employee = this.store.employees[employeeId];
|
||||
if (!employee) {
|
||||
@@ -49,8 +48,8 @@ const threadServicePatch = {
|
||||
);
|
||||
return;
|
||||
}
|
||||
return _super({ userId: employee.user_id });
|
||||
return super.getChat({ userId: employee.user_id });
|
||||
},
|
||||
};
|
||||
|
||||
patch(ThreadService.prototype, "hr", threadServicePatch);
|
||||
patch(ThreadService.prototype, threadServicePatch);
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
nextTick,
|
||||
patchWithCleanup,
|
||||
} from "@web/../tests/helpers/utils";
|
||||
import * as legacyTestUtils from "@web/../tests/legacy/helpers/test_utils";
|
||||
import { assets } from "@web/core/assets";
|
||||
import { Wysiwyg } from '@web_editor/js/wysiwyg/wysiwyg';
|
||||
|
||||
@@ -47,7 +46,7 @@ QUnit.module('field html', (hooks) => {
|
||||
serverData = { models };
|
||||
setupViewRegistries();
|
||||
|
||||
legacyTestUtils.mock.patch(Wysiwyg.prototype, {
|
||||
patchWithCleanup(Wysiwyg.prototype, {
|
||||
async _getColorpickerTemplate() {
|
||||
return weTestUtils.COLOR_PICKER_TEMPLATE;
|
||||
},
|
||||
@@ -61,9 +60,6 @@ QUnit.module('field html', (hooks) => {
|
||||
},
|
||||
});
|
||||
});
|
||||
hooks.afterEach(() => {
|
||||
legacyTestUtils.mock.unpatch(Wysiwyg.prototype);
|
||||
});
|
||||
|
||||
QUnit.test('save arch and html', async function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
import wTourUtils from "@website/js/tours/tour_utils";
|
||||
|
||||
import { FileSelectorControlPanel } from "@web_editor/components/media_dialog/file_selector";
|
||||
import { patch, unpatch } from '@web/legacy/js/core/utils';
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
let patchWithError = false;
|
||||
const patchMediaDialog = () => patch(FileSelectorControlPanel.prototype, 'test_website.mock_image_widgets', {
|
||||
const patchMediaDialog = () => patch(FileSelectorControlPanel.prototype, {
|
||||
async onChangeFileInput() {
|
||||
const getFileFromB64 = (fileData) => {
|
||||
const binary = atob(fileData[2]);
|
||||
@@ -17,7 +17,7 @@ const patchMediaDialog = () => patch(FileSelectorControlPanel.prototype, 'test_w
|
||||
}
|
||||
return new File([arr], fileData[1], {type: fileData[0]});
|
||||
};
|
||||
|
||||
|
||||
let files = [
|
||||
getFileFromB64(['image/vnd.microsoft.icon', 'icon.ico', "AAABAAEAAQEAAAEAIAAwAAAAFgAAACgAAAABAAAAAgAAAAEAIAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAA=="]),
|
||||
getFileFromB64(['image/webp', 'image.webp', "UklGRhwAAABXRUJQVlA4TBAAAAAvE8AEAAfQhuh//wMR0f8A"]),
|
||||
@@ -36,13 +36,13 @@ const patchMediaDialog = () => patch(FileSelectorControlPanel.prototype, 'test_w
|
||||
}
|
||||
});
|
||||
|
||||
const unpatchMediaDialog = () => unpatch(FileSelectorControlPanel.prototype, 'test_website.mock_image_widgets');
|
||||
let unpatchMediaDialog = null;
|
||||
|
||||
const setupSteps = [{
|
||||
content: "reload to load patch",
|
||||
trigger: ".o_website_preview",
|
||||
run: () => {
|
||||
patchMediaDialog();
|
||||
unpatchMediaDialog = patchMediaDialog();
|
||||
},
|
||||
}, {
|
||||
content: "drop a snippet",
|
||||
|
||||
@@ -205,8 +205,6 @@ var diacriticsMap = {
|
||||
'\u0225': 'z','\u0240': 'z','\u2C6C': 'z','\uA763': 'z',
|
||||
};
|
||||
|
||||
const patchMap = new WeakMap();
|
||||
|
||||
/**
|
||||
* Helper function returning an extraction handler to use on array elements to
|
||||
* return a certain attribute or mutated form of the element.
|
||||
@@ -735,82 +733,6 @@ const utils = {
|
||||
return acc;
|
||||
}, []);
|
||||
},
|
||||
/**
|
||||
* Patch an object and return a function that remove the patch
|
||||
* when called.
|
||||
*
|
||||
* @param {Object} obj Object to patch
|
||||
* @param {string} patchName
|
||||
* @param {Object} patch
|
||||
*/
|
||||
patch:function (obj, patchName, patch) {
|
||||
if (!patchMap.has(obj)) {
|
||||
patchMap.set(obj, {
|
||||
original: {},
|
||||
patches: [],
|
||||
});
|
||||
}
|
||||
const objDesc = patchMap.get(obj);
|
||||
if (objDesc.patches.some(p => p.name === patchName)) {
|
||||
throw new AlreadyDefinedPatchError(`Patch ${patchName} is already defined`);
|
||||
}
|
||||
objDesc.patches.push({
|
||||
name: patchName,
|
||||
patch,
|
||||
});
|
||||
|
||||
for (const k in patch) {
|
||||
let prevDesc = null;
|
||||
let proto = obj;
|
||||
do {
|
||||
prevDesc = Object.getOwnPropertyDescriptor(proto, k);
|
||||
proto = Object.getPrototypeOf(proto);
|
||||
} while (!prevDesc && proto);
|
||||
|
||||
const newDesc = Object.getOwnPropertyDescriptor(patch, k);
|
||||
if (!objDesc.original.hasOwnProperty(k)) {
|
||||
objDesc.original[k] = Object.getOwnPropertyDescriptor(obj, k);
|
||||
}
|
||||
|
||||
if (prevDesc) {
|
||||
const patchedFnName = `${k} (patch ${patchName})`;
|
||||
|
||||
if (prevDesc.value && typeof newDesc.value === "function") {
|
||||
makeIntermediateFunction("value", prevDesc, newDesc, patchedFnName);
|
||||
}
|
||||
if (prevDesc.get || prevDesc.set) {
|
||||
// get and set are defined together. If they are both defined
|
||||
// in the previous descriptor but only one in the new descriptor
|
||||
// then the other will be undefined so we need to apply the
|
||||
// previous descriptor in the new one.
|
||||
newDesc.get = newDesc.get || prevDesc.get;
|
||||
newDesc.set = newDesc.set || prevDesc.set;
|
||||
if (prevDesc.get && typeof newDesc.get === "function") {
|
||||
makeIntermediateFunction("get", prevDesc, newDesc, patchedFnName);
|
||||
}
|
||||
if (prevDesc.set && typeof newDesc.set === "function") {
|
||||
makeIntermediateFunction("set", prevDesc, newDesc, patchedFnName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperty(obj, k, newDesc);
|
||||
}
|
||||
|
||||
function makeIntermediateFunction(key, prevDesc, newDesc, patchedFnName) {
|
||||
const _superFn = prevDesc[key];
|
||||
const patchFn = newDesc[key];
|
||||
newDesc[key] = {
|
||||
[patchedFnName](...args) {
|
||||
const prevSuper = this._super;
|
||||
this._super = _superFn.bind(this);
|
||||
const result = patchFn.call(this, ...args);
|
||||
this._super = prevSuper;
|
||||
return result;
|
||||
}
|
||||
}[patchedFnName];
|
||||
}
|
||||
},
|
||||
/**
|
||||
* performs a half up rounding with a fixed amount of decimals, correcting for float loss of precision
|
||||
* See the corresponding float_round() in server/tools/float_utils.py for more info
|
||||
@@ -1016,42 +938,6 @@ const utils = {
|
||||
});
|
||||
return casesensetive ? str : str.toLowerCase();
|
||||
},
|
||||
/**
|
||||
* We define here an unpatch function. This is mostly useful if we want to
|
||||
* remove a patch. For example, for testing purposes
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @param {string} patchName
|
||||
* @returns {Object} the removed patch
|
||||
*/
|
||||
unpatch: function (obj, patchName) {
|
||||
const objDesc = patchMap.get(obj);
|
||||
if (!objDesc || !objDesc.patches.some(p => p.name === patchName)) {
|
||||
throw new UnknownPatchError(`Could not find patch ${patchName}`);
|
||||
}
|
||||
patchMap.delete(obj);
|
||||
|
||||
// Restore original methods on the prototype and the class.
|
||||
for (const k in objDesc.original) {
|
||||
if (objDesc.original[k] === undefined) {
|
||||
delete obj[k];
|
||||
} else {
|
||||
Object.defineProperty(obj, k, objDesc.original[k]);
|
||||
}
|
||||
}
|
||||
|
||||
// Re-apply the patches except the one to remove.
|
||||
let removedPatch;
|
||||
for (const patchDesc of objDesc.patches) {
|
||||
if (patchDesc.name !== patchName) {
|
||||
utils.patch(obj, patchDesc.name, patchDesc.patch);
|
||||
} else {
|
||||
removedPatch = patchDesc.patch;
|
||||
}
|
||||
}
|
||||
|
||||
return removedPatch;
|
||||
},
|
||||
/**
|
||||
* @param {any} node
|
||||
* @param {any} strip_whitespace
|
||||
@@ -1168,10 +1054,8 @@ const utils = {
|
||||
},
|
||||
};
|
||||
|
||||
export const patch = utils.patch
|
||||
export const confine = utils.confine
|
||||
export const traverse = utils.traverse
|
||||
export const unpatch = utils.unpatch
|
||||
export const is_email = utils.is_email
|
||||
export const sprintf = utils.sprintf
|
||||
export const groupBy = utils.groupBy
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
import legacyUtils from "@web/legacy/js/core/utils";
|
||||
|
||||
function makeBaseClass(assert, assertInSetup) {
|
||||
class BaseClass {
|
||||
@@ -1200,27 +1199,5 @@ QUnit.module("utils", () => {
|
||||
|
||||
assert.verifySteps(["patched", "original"]);
|
||||
});
|
||||
|
||||
QUnit.test("patch an object with a legacy patch", async function (assert) {
|
||||
const a = {
|
||||
doSomething() {
|
||||
assert.step("a");
|
||||
},
|
||||
};
|
||||
legacyUtils.patch(a, "a.patch.legacy", {
|
||||
doSomething() {
|
||||
this._super();
|
||||
assert.step("a.patch.legacy");
|
||||
},
|
||||
});
|
||||
patch(a, {
|
||||
doSomething() {
|
||||
super.doSomething();
|
||||
assert.step("a.patch");
|
||||
},
|
||||
});
|
||||
a.doSomething();
|
||||
assert.verifySteps(["a", "a.patch.legacy", "a.patch"]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -11,8 +11,6 @@
|
||||
|
||||
import { patchDate } from "@web/../tests/helpers/utils";
|
||||
|
||||
import { uniqueId } from "@web/core/utils/functions";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public functions
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -70,94 +68,7 @@ function legacyPatchDate(year, month, day, hours, minutes, seconds) {
|
||||
return function () {}; // all calls to that function are now useless
|
||||
}
|
||||
|
||||
var patches = {};
|
||||
/**
|
||||
* Patches a given Class or Object with the given properties.
|
||||
*
|
||||
* @param {Class|Object} target
|
||||
* @param {Object} props
|
||||
*/
|
||||
function patch(target, props) {
|
||||
var patchID = uniqueId("patch_");
|
||||
target.__patchID = patchID;
|
||||
patches[patchID] = {
|
||||
target: target,
|
||||
otherPatchedProps: [],
|
||||
ownPatchedProps: [],
|
||||
};
|
||||
if (target.prototype) {
|
||||
Object.keys(props).forEach((key) => {
|
||||
if (target.prototype.hasOwnProperty(key)) {
|
||||
patches[patchID].ownPatchedProps.push({
|
||||
key: key,
|
||||
initialValue: target.prototype[key],
|
||||
});
|
||||
} else {
|
||||
patches[patchID].otherPatchedProps.push(key);
|
||||
}
|
||||
});
|
||||
target.include(props);
|
||||
} else {
|
||||
for (const [key, value] of Object.entries(props)) {
|
||||
if (key in target) {
|
||||
var oldValue = target[key];
|
||||
patches[patchID].ownPatchedProps.push({
|
||||
key: key,
|
||||
initialValue: oldValue,
|
||||
});
|
||||
if (typeof value === 'function') {
|
||||
target[key] = function () {
|
||||
var oldSuper = this._super;
|
||||
this._super = oldValue;
|
||||
var result = value.apply(this, arguments);
|
||||
if (oldSuper === undefined) {
|
||||
delete this._super;
|
||||
} else {
|
||||
this._super = oldSuper;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
} else {
|
||||
target[key] = value;
|
||||
}
|
||||
} else {
|
||||
patches[patchID].otherPatchedProps.push(key);
|
||||
target[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpatches a given Class or Object.
|
||||
*
|
||||
* @param {Class|Object} target
|
||||
*/
|
||||
function unpatch(target) {
|
||||
var patchID = target.__patchID;
|
||||
var patch = patches[patchID];
|
||||
if (target.prototype) {
|
||||
patch.ownPatchedProps.forEach((p) => {
|
||||
target.prototype[p.key] = p.initialValue;
|
||||
});
|
||||
patch.otherPatchedProps.forEach((key) => {
|
||||
delete target.prototype[key];
|
||||
});
|
||||
} else {
|
||||
patch.ownPatchedProps.forEach((p) => {
|
||||
target[p.key] = p.initialValue;
|
||||
});
|
||||
patch.otherPatchedProps.forEach((key) => {
|
||||
delete target[key];
|
||||
});
|
||||
}
|
||||
delete patches[patchID];
|
||||
delete target.__patchID;
|
||||
}
|
||||
|
||||
export default {
|
||||
intercept: intercept,
|
||||
patchDate: legacyPatchDate,
|
||||
patch: patch,
|
||||
unpatch: unpatch,
|
||||
};
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import ajax from "@web/legacy/js/core/ajax";
|
||||
import { MockServer } from "@web/../tests/helpers/mock_server";
|
||||
import testUtils from "@web/../tests/legacy/helpers/test_utils";
|
||||
import * as coreUtils from "@web/core/utils/patch";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
import * as OdooEditorLib from "@web_editor/js/editor/odoo-editor/src/OdooEditor";
|
||||
import { Wysiwyg } from '@web_editor/js/wysiwyg/wysiwyg';
|
||||
import options from "@web_editor/js/editor/snippets.options";
|
||||
@@ -94,7 +93,7 @@ const SNIPPETS_TEMPLATE = `
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
coreUtils.patch(MockServer.prototype, {
|
||||
patch(MockServer.prototype, {
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -145,32 +144,6 @@ options.registry.option_test = options.Class.extend({
|
||||
},
|
||||
});
|
||||
|
||||
function patch() {
|
||||
testUtils.mock.patch(ajax, {
|
||||
loadAsset: function (xmlId) {
|
||||
if (xmlId === 'template.assets') {
|
||||
return Promise.resolve({
|
||||
cssLibs: [],
|
||||
cssContents: ['body {background-color: red;}']
|
||||
});
|
||||
}
|
||||
if (xmlId === 'template.assets_all_style') {
|
||||
return Promise.resolve({
|
||||
cssLibs: $('link[href]:not([type="image/x-icon"])').map(function () {
|
||||
return $(this).attr('href');
|
||||
}).get(),
|
||||
cssContents: ['body {background-color: red;}']
|
||||
});
|
||||
}
|
||||
throw 'Wrong template';
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function unpatch() {
|
||||
testUtils.mock.unpatch(ajax);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} data
|
||||
* @returns {object}
|
||||
@@ -819,8 +792,6 @@ export default {
|
||||
testKeyboard: testKeyboard,
|
||||
select: select,
|
||||
keydown: keydown,
|
||||
patch: patch,
|
||||
unpatch: unpatch,
|
||||
getGridHtml: getGridHtml,
|
||||
getTableHtml: getTableHtml,
|
||||
getRegularGridHtml: getRegularGridHtml,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { patch } from '@web/legacy/js/core/utils';
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
import { KeepLast } from "@web/core/utils/concurrency";
|
||||
import { MediaDialog, TABS } from '@web_editor/components/media_dialog/media_dialog';
|
||||
import { ImageSelector } from '@web_editor/components/media_dialog/image_selector';
|
||||
@@ -38,9 +38,9 @@ UnsplashError.components = {
|
||||
UnsplashCredentials,
|
||||
};
|
||||
|
||||
patch(ImageSelector.prototype, 'image_selector_unsplash', {
|
||||
patch(ImageSelector.prototype, {
|
||||
setup() {
|
||||
this._super();
|
||||
super.setup();
|
||||
this.unsplash = useService('unsplash');
|
||||
this.keepLastUnsplash = new KeepLast();
|
||||
|
||||
@@ -69,20 +69,20 @@ patch(ImageSelector.prototype, 'image_selector_unsplash', {
|
||||
|
||||
get canLoadMore() {
|
||||
if (this.state.searchService === 'all') {
|
||||
return this._super() || this.state.needle && !this.state.isMaxed && !this.state.unsplashError;
|
||||
return super.canLoadMore || this.state.needle && !this.state.isMaxed && !this.state.unsplashError;
|
||||
} else if (this.state.searchService === 'unsplash') {
|
||||
return this.state.needle && !this.state.isMaxed && !this.state.unsplashError;
|
||||
}
|
||||
return this._super();
|
||||
return super.canLoadMore;
|
||||
},
|
||||
|
||||
get hasContent() {
|
||||
if (this.state.searchService === 'all') {
|
||||
return this._super() || !!this.state.unsplashRecords.length;
|
||||
return super.hasContent || !!this.state.unsplashRecords.length;
|
||||
} else if (this.state.searchService === 'unsplash') {
|
||||
return !!this.state.unsplashRecords.length;
|
||||
}
|
||||
return this._super();
|
||||
return super.hasContent;
|
||||
},
|
||||
|
||||
get errorTitle() {
|
||||
@@ -104,7 +104,7 @@ patch(ImageSelector.prototype, 'image_selector_unsplash', {
|
||||
},
|
||||
|
||||
get isFetching() {
|
||||
return this._super() || this.state.isFetchingUnsplash;
|
||||
return super.isFetching || this.state.isFetchingUnsplash;
|
||||
},
|
||||
|
||||
get combinedRecords() {
|
||||
@@ -168,7 +168,7 @@ patch(ImageSelector.prototype, 'image_selector_unsplash', {
|
||||
},
|
||||
|
||||
async loadMore(...args) {
|
||||
await this._super(...args);
|
||||
await super.loadMore(...args);
|
||||
return this.keepLastUnsplash.add(this.fetchUnsplashRecords(this.state.unsplashRecords.length)).then(({ records, isMaxed }) => {
|
||||
// This is never reached if another search or loadMore occurred.
|
||||
this.state.unsplashRecords.push(...records);
|
||||
@@ -177,7 +177,7 @@ patch(ImageSelector.prototype, 'image_selector_unsplash', {
|
||||
},
|
||||
|
||||
async search(...args) {
|
||||
await this._super(...args);
|
||||
await super.search(...args);
|
||||
await this.searchUnsplash();
|
||||
},
|
||||
|
||||
@@ -212,15 +212,14 @@ ImageSelector.components = {
|
||||
UnsplashError,
|
||||
};
|
||||
|
||||
patch(MediaDialog.prototype, 'media_dialog_unsplash', {
|
||||
patch(MediaDialog.prototype, {
|
||||
setup() {
|
||||
this._super();
|
||||
super.setup();
|
||||
|
||||
this.uploadService = useService('upload');
|
||||
},
|
||||
|
||||
async save() {
|
||||
const _super = this._super.bind(this);
|
||||
const selectedImages = this.selectedMedia[TABS.IMAGES.id];
|
||||
if (selectedImages) {
|
||||
const unsplashRecords = selectedImages.filter(media => media.mediaType === 'unsplashRecord');
|
||||
@@ -231,13 +230,13 @@ patch(MediaDialog.prototype, 'media_dialog_unsplash', {
|
||||
});
|
||||
}
|
||||
}
|
||||
return _super(...arguments);
|
||||
return super.save(...arguments);
|
||||
},
|
||||
});
|
||||
|
||||
patch(uploadService, 'upload_service_unsplash', {
|
||||
patch(uploadService, {
|
||||
start(env, { rpc }) {
|
||||
const service = this._super(...arguments);
|
||||
const service = super.start(...arguments);
|
||||
return {
|
||||
...service,
|
||||
async uploadUnsplashRecords(records, { resModel, resId }, onUploaded) {
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
/** @odoo-module **/
|
||||
import { patch } from '@web/legacy/js/core/utils';
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
import { WebsitePreview } from '@website/client_actions/website_preview/website_preview';
|
||||
|
||||
patch(WebsitePreview.prototype, 'website_preview_test_mode', {
|
||||
patch(WebsitePreview.prototype, {
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
import { BurgerMenu } from '@web/webclient/burger_menu/burger_menu';
|
||||
import { useService } from '@web/core/utils/hooks';
|
||||
import { registry } from "@web/core/registry";
|
||||
import { patch } from '@web/legacy/js/core/utils';
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
const websiteSystrayRegistry = registry.category('website_systray');
|
||||
|
||||
patch(BurgerMenu.prototype, 'website_burger_menu', {
|
||||
patch(BurgerMenu.prototype, {
|
||||
setup() {
|
||||
this._super();
|
||||
super.setup();
|
||||
this.websiteCustomMenus = useService('website_custom_menus');
|
||||
|
||||
if (!websiteSystrayRegistry.contains('burger_menu')) {
|
||||
@@ -21,7 +21,7 @@ patch(BurgerMenu.prototype, 'website_burger_menu', {
|
||||
* @override
|
||||
*/
|
||||
get currentAppSections() {
|
||||
const currentAppSections = this._super();
|
||||
const currentAppSections = super.currentAppSections;
|
||||
if (this.currentApp && this.currentApp.xmlid === 'website.menu_website_configuration') {
|
||||
return this.websiteCustomMenus.addCustomMenus(currentAppSections).filter(section => section.childrenTree.length);
|
||||
}
|
||||
@@ -43,7 +43,7 @@ patch(BurgerMenu.prototype, 'website_burger_menu', {
|
||||
this.websiteCustomMenus.open(menu);
|
||||
this._closeBurger();
|
||||
} else {
|
||||
this._super(menu);
|
||||
super._onMenuClicked(menu);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
import { NavBar } from '@web/webclient/navbar/navbar';
|
||||
import { useService, useBus } from '@web/core/utils/hooks';
|
||||
import { registry } from "@web/core/registry";
|
||||
import { patch } from '@web/legacy/js/core/utils';
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
const websiteSystrayRegistry = registry.category('website_systray');
|
||||
const { useEffect } = owl;
|
||||
|
||||
patch(NavBar.prototype, 'website_navbar', {
|
||||
patch(NavBar.prototype, {
|
||||
setup() {
|
||||
this._super();
|
||||
super.setup();
|
||||
this.websiteService = useService('website');
|
||||
this.websiteCustomMenus = useService('website_custom_menus');
|
||||
|
||||
@@ -55,14 +55,14 @@ patch(NavBar.prototype, 'website_navbar', {
|
||||
.filter((item) => ('isDisplayed' in item ? item.isDisplayed(this.env) : true))
|
||||
.reverse();
|
||||
}
|
||||
return this._super();
|
||||
return super.systrayItems;
|
||||
},
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
get currentAppSections() {
|
||||
const currentAppSections = this._super();
|
||||
const currentAppSections = super.currentAppSections;
|
||||
if (this.currentApp && this.currentApp.xmlid === 'website.menu_website_configuration') {
|
||||
return this.websiteCustomMenus.addCustomMenus(currentAppSections).filter(section => section.childrenTree.length);
|
||||
}
|
||||
@@ -77,6 +77,6 @@ patch(NavBar.prototype, 'website_navbar', {
|
||||
if (websiteMenu) {
|
||||
return this.websiteCustomMenus.open(menu);
|
||||
}
|
||||
return this._super(menu);
|
||||
return super.onNavBarDropdownItemSelection(menu);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -2,18 +2,18 @@
|
||||
|
||||
import { WysiwygAdapterComponent } from "@website/components/wysiwyg_adapter/wysiwyg_adapter";
|
||||
import websiteTourUtils from "@website/js/tours/tour_utils";
|
||||
import { patch, unpatch } from '@web/legacy/js/core/utils';
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
const patchWysiwygAdapter = () => patch(WysiwygAdapterComponent.prototype, 'snippets_all_drag_and_drop.wysiwyg_adapter', {
|
||||
const patchWysiwygAdapter = () => patch(WysiwygAdapterComponent.prototype, {
|
||||
_trigger_up(ev) {
|
||||
this._super(...arguments);
|
||||
super._trigger_up(...arguments);
|
||||
if (ev.name === 'snippet_removed') {
|
||||
$('body').attr('test-dd-snippet-removed', true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const unpatchWysiwygAdapter = () => unpatch(WysiwygAdapterComponent.prototype, 'snippets_all_drag_and_drop.wysiwyg_adapter');
|
||||
let unpatchWysiwygAdapter = null;
|
||||
|
||||
import { registry } from "@web/core/registry";
|
||||
|
||||
@@ -89,7 +89,7 @@ registry.category("web_tour.tours").add("snippets_all_drag_and_drop", {
|
||||
if (steps.length < 220) {
|
||||
console.error(`This test is not behaving as it should, got only ${steps.length} steps.`);
|
||||
}
|
||||
patchWysiwygAdapter();
|
||||
unpatchWysiwygAdapter = patchWysiwygAdapter();
|
||||
},
|
||||
},
|
||||
// This first step is needed as it will be used later for inner snippets
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { NewContentModal, MODULE_STATUS } from '@website/systray_items/new_content';
|
||||
import { patch } from '@web/legacy/js/core/utils';
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(NewContentModal.prototype, 'website_blog_new_content', {
|
||||
patch(NewContentModal.prototype, {
|
||||
setup() {
|
||||
this._super();
|
||||
super.setup();
|
||||
|
||||
const newBlogElement = this.state.newContentElements.find(element => element.moduleXmlId === 'base.module_website_blog');
|
||||
newBlogElement.createNewContent = () => this.onAddContent('website_blog.blog_post_action_add', true);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { NewContentModal, MODULE_STATUS } from '@website/systray_items/new_content';
|
||||
import { patch } from '@web/legacy/js/core/utils';
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(NewContentModal.prototype, 'website_event_new_content', {
|
||||
patch(NewContentModal.prototype, {
|
||||
setup() {
|
||||
this._super();
|
||||
super.setup();
|
||||
|
||||
const newEventElement = this.state.newContentElements.find(element => element.moduleXmlId === 'base.module_website_event');
|
||||
newEventElement.createNewContent = () => this.onAddContent('website_event.event_event_action_add', true);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { NewContentModal, MODULE_STATUS } from '@website/systray_items/new_content';
|
||||
import { patch } from '@web/legacy/js/core/utils';
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(NewContentModal.prototype, 'website_forum_new_content', {
|
||||
patch(NewContentModal.prototype, {
|
||||
setup() {
|
||||
this._super();
|
||||
super.setup();
|
||||
|
||||
const newForumElement = this.state.newContentElements.find(element => element.moduleXmlId === 'base.module_website_forum');
|
||||
newForumElement.createNewContent = () => this.onAddContent('website_forum.forum_forum_action_add');
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { NewContentModal, MODULE_STATUS } from '@website/systray_items/new_content';
|
||||
import { patch } from '@web/legacy/js/core/utils';
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(NewContentModal.prototype, 'website_hr_recruitment_new_content', {
|
||||
patch(NewContentModal.prototype, {
|
||||
setup() {
|
||||
this._super();
|
||||
super.setup();
|
||||
|
||||
const newJobElement = this.state.newContentElements.find(element => element.moduleXmlId === 'base.module_website_hr_recruitment');
|
||||
newJobElement.createNewContent = () => this.createNewJob();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { NewContentModal, MODULE_STATUS } from '@website/systray_items/new_content';
|
||||
import { patch } from '@web/legacy/js/core/utils';
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(NewContentModal.prototype, 'website_livechat_new_content', {
|
||||
patch(NewContentModal.prototype, {
|
||||
setup() {
|
||||
this._super();
|
||||
super.setup();
|
||||
|
||||
const newChannelElement = this.state.newContentElements.find(element => element.moduleXmlId === 'base.module_website_livechat');
|
||||
newChannelElement.createNewContent = () => this.onAddContent('website_livechat.im_livechat_channel_action_add');
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { WysiwygAdapterComponent } from '@website/components/wysiwyg_adapter/wysiwyg_adapter';
|
||||
import { patch } from '@web/legacy/js/core/utils';
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
// TODO this whole patch actually seems unnecessary. The bug it solved seems
|
||||
// to stay solved if this is removed. To investigate.
|
||||
patch(WysiwygAdapterComponent.prototype, 'website_sale_wysiwyg_adapter', {
|
||||
patch(WysiwygAdapterComponent.prototype, {
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
_getContentEditableAreas() {
|
||||
const array = this._super(...arguments);
|
||||
const array = super._getContentEditableAreas(...arguments);
|
||||
return array.filter(el => {
|
||||
// TODO should really review this system of "ContentEditableAreas +
|
||||
// ReadOnlyAreas", here the "products_header" stuff is duplicated in
|
||||
@@ -24,7 +24,7 @@ patch(WysiwygAdapterComponent.prototype, 'website_sale_wysiwyg_adapter', {
|
||||
* @override
|
||||
*/
|
||||
_getReadOnlyAreas() {
|
||||
const readOnlyEls = this._super(...arguments);
|
||||
const readOnlyEls = super._getReadOnlyAreas(...arguments);
|
||||
return [...readOnlyEls].concat(
|
||||
$(this.websiteService.pageDocument).find("#wrapwrap").find('.oe_website_sale .products_header, .oe_website_sale .products_header a').toArray()
|
||||
);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { NewContentModal, MODULE_STATUS } from '@website/systray_items/new_content';
|
||||
import { patch } from '@web/legacy/js/core/utils';
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(NewContentModal.prototype, 'website_sale_new_content', {
|
||||
patch(NewContentModal.prototype, {
|
||||
setup() {
|
||||
this._super();
|
||||
super.setup();
|
||||
|
||||
const newProductElement = this.state.newContentElements.find(element => element.moduleXmlId === 'base.module_website_sale');
|
||||
newProductElement.createNewContent = () => this.onAddContent('website_sale.product_product_action_add', true);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import PublicWidget from '@web/legacy/js/public/public_widget';
|
||||
import { patch } from '@web/legacy/js/core/utils';
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
import core from "@web/legacy/js/services/core";
|
||||
|
||||
const _t = core._t;
|
||||
|
||||
patch(PublicWidget.registry.websiteSaleDelivery, 'addons/website_sale_loyalty_delivery/statis/src/js/website_sale_loyalty_delivery.js', {
|
||||
patch(PublicWidget.registry.websiteSaleDelivery, {
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -14,8 +14,8 @@ patch(PublicWidget.registry.websiteSaleDelivery, 'addons/website_sale_loyalty_de
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
_handleCarrierUpdateResult: async function (carrierInput) {
|
||||
await this._super.apply(this, arguments);
|
||||
async _handleCarrierUpdateResult(carrierInput) {
|
||||
await super._handleCarrierUpdateResult(...arguments);
|
||||
if (this.result.new_amount_order_discounted) {
|
||||
// Update discount of the order
|
||||
$('#order_discounted').html(this.result.new_amount_order_discounted);
|
||||
@@ -24,8 +24,8 @@ patch(PublicWidget.registry.websiteSaleDelivery, 'addons/website_sale_loyalty_de
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
_handleCarrierUpdateResultBadge: function (result) {
|
||||
this._super.apply(this, arguments);
|
||||
_handleCarrierUpdateResultBadge(result) {
|
||||
super._handleCarrierUpdateResultBadge(...arguments);
|
||||
if (result.new_amount_order_discounted) {
|
||||
// We are in freeshipping, so every carrier is Free but we don't
|
||||
// want to replace error message by 'Free'
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
import { WebsiteEditorComponent } from '@website/components/editor/editor';
|
||||
import { WebsiteTranslator } from '@website/components/translator/translator';
|
||||
import { patch } from '@web/legacy/js/core/utils';
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(WebsiteEditorComponent.prototype, 'website_slides_editor', {
|
||||
patch(WebsiteEditorComponent.prototype, {
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
@@ -14,12 +14,12 @@ patch(WebsiteEditorComponent.prototype, 'website_slides_editor', {
|
||||
this.websiteContext.edition = false;
|
||||
this.websiteService.goToWebsite({path: `${pathname}?fullscreen=0`, edition: true});
|
||||
} else {
|
||||
this._super(...arguments);
|
||||
super.publicRootReady(...arguments);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
patch(WebsiteTranslator.prototype, 'website_slides_translator', {
|
||||
patch(WebsiteTranslator.prototype, {
|
||||
/**
|
||||
* When editing translations of a slide in fullscreen mode: force fullscreen off.
|
||||
* Indeed, the fullscreen layout is not fit for content edition.
|
||||
@@ -36,7 +36,7 @@ patch(WebsiteTranslator.prototype, 'website_slides_translator', {
|
||||
translation: true
|
||||
});
|
||||
} else {
|
||||
this._super(...arguments);
|
||||
super.publicRootReady(...arguments);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { NewContentModal, MODULE_STATUS } from '@website/systray_items/new_content';
|
||||
import { patch } from '@web/legacy/js/core/utils';
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
patch(NewContentModal.prototype, 'website_slides_new_content', {
|
||||
patch(NewContentModal.prototype, {
|
||||
setup() {
|
||||
this._super();
|
||||
super.setup();
|
||||
|
||||
const newSlidesChannelElement = this.state.newContentElements.find(element => element.moduleXmlId === 'base.module_website_slides');
|
||||
newSlidesChannelElement.createNewContent = () => this.onAddContent('website_slides.slide_channel_action_add');
|
||||
|
||||
Reference in New Issue
Block a user