合并企业版代码(未测试,先提交到测试分支)

This commit is contained in:
qihao.gong@jikimo.com
2023-04-14 17:42:23 +08:00
parent 7a7b3d7126
commit d28525526a
1300 changed files with 513579 additions and 5426 deletions

View File

@@ -0,0 +1,48 @@
/** @odoo-module */
import { device } from "web.config";
import * as LegacyControlPanel from "web.ControlPanel";
import { useBackButton } from "web_mobile.hooks";
import { patch } from "@web/core/utils/patch";
import { ControlPanel } from "@web/search/control_panel/control_panel";
if (device.isMobile) {
patch(LegacyControlPanel.prototype, "web_mobile", {
setup() {
this._super(...arguments);
useBackButton(this._onBackButton.bind(this), () => this.state.showMobileSearch);
},
//---------------------------------------------------------------------
// Handlers
//---------------------------------------------------------------------
/**
* close mobile search on back-button
* @private
*/
_onBackButton() {
this._resetSearchState();
},
});
patch(ControlPanel.prototype, "web_mobile", {
setup() {
this._super(...arguments);
useBackButton(this._onBackButton.bind(this), () => this.state.showMobileSearch);
},
//---------------------------------------------------------------------
// Handlers
//---------------------------------------------------------------------
/**
* close mobile search on back-button
* @private
*/
_onBackButton() {
this.resetSearchState();
},
});
}

View File

@@ -0,0 +1,79 @@
odoo.define("web_mobile.Dialog", function (require) {
"use strict";
var Dialog = require("web.Dialog");
var mobileMixins = require("web_mobile.mixins");
Dialog.include(
_.extend({}, mobileMixins.BackButtonEventMixin, {
//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
/**
* Close the current dialog on 'backbutton' event.
*
* @private
* @override
* @param {Event} ev
*/
_onBackButton: function () {
this.close();
},
})
);
});
odoo.define("web_mobile.OwlDialog", function (require) {
"use strict";
const OwlDialog = require("web.OwlDialog");
const { useBackButton } = require("web_mobile.hooks");
const { patch } = require("web.utils");
patch(OwlDialog.prototype, "web_mobile", {
setup() {
this._super(...arguments);
useBackButton(this._onBackButton.bind(this));
},
//---------------------------------------------------------------------
// Handlers
//---------------------------------------------------------------------
/**
* Close dialog on back-button
* @private
*/
_onBackButton() {
this._close();
},
});
});
odoo.define("web_mobile.Popover", function (require) {
"use strict";
const Popover = require("web.Popover");
const { useBackButton } = require("web_mobile.hooks");
const { patch } = require("web.utils");
patch(Popover.prototype, "web_mobile", {
setup() {
this._super(...arguments);
useBackButton(this._onBackButton.bind(this), () => this.state.displayed);
},
//---------------------------------------------------------------------
// Handlers
//---------------------------------------------------------------------
/**
* Close popover on back-button
* @private
*/
_onBackButton() {
this._close();
},
});
});

View File

@@ -0,0 +1,145 @@
odoo.define('web_mobile.mixins', function (require) {
"use strict";
const session = require('web.session');
const mobile = require('web_mobile.core');
/**
* Mixin to setup lifecycle methods and allow to use 'backbutton' events sent
* from the native application.
*
* @mixin
* @name BackButtonEventMixin
*
*/
var BackButtonEventMixin = {
/**
* Register event listener for 'backbutton' event when attached to the DOM
*/
on_attach_callback: function () {
mobile.backButtonManager.addListener(this, this._onBackButton);
},
/**
* Unregister event listener for 'backbutton' event when detached from the DOM
*/
on_detach_callback: function () {
mobile.backButtonManager.removeListener(this, this._onBackButton);
},
//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
/**
* @private
* @param {Event} ev 'backbutton' type event
*/
_onBackButton: function () {},
};
/**
* Mixin to hook into the controller record's saving method and
* trigger the update of the user's account details on the mobile app.
*
* @mixin
* @name UpdateDeviceAccountControllerMixin
*
*/
const UpdateDeviceAccountControllerMixin = {
/**
* @override
*/
async save() {
const changedFields = await this._super(...arguments);
await session.updateAccountOnMobileDevice();
return changedFields;
},
};
/**
* Trigger the update of the user's account details on the mobile app as soon as
* the session is correctly initialized.
*/
session.is_bound.then(() => session.updateAccountOnMobileDevice());
return {
BackButtonEventMixin: BackButtonEventMixin,
UpdateDeviceAccountControllerMixin,
};
});
odoo.define('web_mobile.hooks', function (require) {
"use strict";
const { backButtonManager } = require('web_mobile.core');
const { onMounted, onPatched, onWillUnmount, useComponent } = owl;
/**
* This hook provides support for executing code when the back button is pressed
* on the mobile application of Odoo. This actually replaces the default back
* button behavior so this feature should only be enabled when it is actually
* useful.
*
* The feature is either enabled on mount or, using the `shouldEnable` function
* argument as condition, when the component is patched. In both cases,
* the feature is automatically disabled on unmount.
*
* @param {function} func the function to execute when the back button is
* pressed. The function is called with the custom event as param.
* @param {function} [shouldEnable] the function to execute when the DOM is
* patched to check if the backbutton should be enabled or disabled ;
* if undefined will be enabled on mount and disabled on unmount.
*/
function useBackButton(func, shouldEnable) {
const component = useComponent();
let isEnabled = false;
/**
* Enables the func listener, overriding default back button behavior.
*/
function enable() {
backButtonManager.addListener(component, func);
isEnabled = true;
}
/**
* Disables the func listener, restoring the default back button behavior if
* no other listeners are present.
*/
function disable() {
backButtonManager.removeListener(component);
isEnabled = false;
}
onMounted(() => {
if (shouldEnable && !shouldEnable()) {
return;
}
enable();
});
onPatched(() => {
if (!shouldEnable) {
return;
}
const shouldBeEnabled = shouldEnable();
if (shouldBeEnabled && !isEnabled) {
enable();
} else if (!shouldBeEnabled && isEnabled) {
disable();
}
});
onWillUnmount(() => {
if (isEnabled) {
disable();
}
});
}
return {
useBackButton,
};
});

View File

@@ -0,0 +1,18 @@
/** @odoo-module **/
import mobile from "web_mobile.core";
import { download } from "@web/core/network/download";
const _download = download._download;
download._download = async function (options) {
if (mobile.methods.downloadFile) {
if (odoo.csrf_token) {
options.csrf_token = odoo.csrf_token;
}
mobile.methods.downloadFile(options);
return Promise.resolve();
} else {
return _download.apply(this, arguments);
}
};

View File

@@ -0,0 +1,89 @@
odoo.define('web_mobile.Session', function (require) {
"use strict";
const core = require('web.core');
const Session = require('web.Session');
const mobile = require('web_mobile.core');
const DEFAULT_AVATAR_SIZE = 128;
/*
Android webview not supporting post download and odoo is using post method to download
so here override get_file of session and passed all data to native mobile downloader
ISSUE: https://code.google.com/p/android/issues/detail?id=1780
*/
Session.include({
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
/**
* @override
*/
get_file: function (options) {
if (mobile.methods.downloadFile) {
if (core.csrf_token) {
options.csrf_token = core.csrf_token;
}
mobile.methods.downloadFile(options);
// There is no need to wait downloadFile because we delegate this to
// Download Manager Service where error handling will be handled correclty.
// On our side, we do not want to block the UI and consider the request
// as success.
if (options.success) { options.success(); }
if (options.complete) { options.complete(); }
return true;
} else {
return this._super.apply(this, arguments);
}
},
/**
* Update the user's account details on the mobile app
*
* @returns {Promise}
*/
async updateAccountOnMobileDevice() {
if (!mobile.methods.updateAccount) {
return;
}
const base64Avatar = await this.fetchAvatar();
return mobile.methods.updateAccount({
avatar: base64Avatar.substring(base64Avatar.indexOf(',') + 1),
name: this.name,
username: this.username,
});
},
/**
* Fetch current user's avatar as PNG image
*
* @returns {Promise} resolved with the dataURL, or rejected if the file is
* empty or if an error occurs.
*/
fetchAvatar() {
const url = this.url('/web/image', {
model: 'res.users',
field: 'image_medium',
id: this.uid,
});
return new Promise((resolve, reject) => {
const canvas = document.createElement('canvas');
canvas.width = DEFAULT_AVATAR_SIZE;
canvas.height = DEFAULT_AVATAR_SIZE;
const context = canvas.getContext('2d');
const image = new Image();
image.addEventListener('load', () => {
context.drawImage(image, 0, 0, DEFAULT_AVATAR_SIZE, DEFAULT_AVATAR_SIZE);
resolve(canvas.toDataURL('image/png'));
});
image.addEventListener('error', reject);
image.src = url;
});
},
});
});