services
data_display
action
Odoo 19 services — action (webclient)
Live preview
Interactive
Source excerpt
web/static/src/webclient/actions/action_service.js
import { _t } from "@web/core/l10n/translation";
import { browser } from "@web/core/browser/browser";
import { makeContext } from "@web/core/context";
import { useDebugCategory } from "@web/core/debug/debug_context";
import { evaluateExpr } from "@web/core/py_js/py";
import { rpc, rpcBus } from "@web/core/network/rpc";
import { registry } from "@web/core/registry";
import { user } from "@web/core/user";
import { Deferred, KeepLast } from "@web/core/utils/concurrency";
import { useBus, useService } from "@web/core/utils/hooks";
import { View, ViewNotFoundError } from "@web/views/view";
import { ActionDialog } from "./action_dialog";
import { ReportAction } from "./reports/report_action";
import { UPDATE_METHODS } from "@web/core/orm_service";
import { CallbackRecorder } from "@web/search/action_hook";
import { ControlPanel } from "@web/search/control_panel/control_panel";
import { PATH_KEYS, router as _router } from "@web/core/browser/router";
import {
Component,
markup,
onMounted,
onWillUnmount,
onError,
useChildSubEnv,
xml,
reactive,
status,
} from "@odoo/owl";
import { downloadReport, getReportUrl } from "./reports/utils";
import { zip } from "@web/core/utils/arrays";
import { isHtmlEmpty } from "@web/core/utils/html";
import { omit, pick, shallowEqual } from "@web/core/utils/objects";
import { session } from "@web/session";
import { exprToBoolean } from "@web/core/utils/strings";
class BlankComponent extends Component {
static props = ["onMounted", "withControlPanel", "*"];
static template = "web.BlankComponent";
static components = { ControlPanel };
setup() {
useChildSubEnv({ config: { breadcrumbs: [], noBreadcrumbs: true } });
onMounted(() => this.props.onMounted());
}
}
const actionHandlersRegistry = registry.category("action_handlers");
const actionRegistry = registry.category("actions");
/** @typedef {number|false} ActionId */
/** @typedef {Object} ActionDescription */
/** @typedef {"current" | "fullscreen" | "new" | "main" | "self"} ActionMode */
/** @typedef {string} ActionTag */
/** @typedef {string} ActionXMLId */
/** @typedef {Object} Context */
/** @typedef {Function} CallableFunction */
/** @typedef {string} ViewType */
/** @typedef {ActionId|ActionXMLId|ActionTag|ActionDescription} ActionRequest */
/**
* @typedef {Object} ActionOptions
* @property {Context} [additionalContext]
* @property {boolean} [clearBreadcrumbs]
* @property {CallableFunction} [onClose]
* @property {Object} [props]
* @property {ViewType} [viewType]
* @property {"replaceCurrentAction" | "replacePreviousAction"} [stackPosition]
* @property {number} [index]
* @property {boolean} [newWindow]
* @property {boolean} [forceLeave]
*/
export async function clearUncommittedChanges(env, { forceLeave } = {}) {
const callbacks = [];
env.bus.trigger("CLEAR-UNCOMMITTED-CHANGES", callbacks);
const res = await Promise.all(callbacks.map((fn) => fn({ forceLeave })));
return !res.includes(false);
}
export const standardActionServiceProps = {
action: Object, // prop added by _getActionInfo
actionId: { type: Number, optional: true }, // prop added by _getActionInfo
className: { type: String, optional: true }, // prop added by the ActionContainer
globalState: { type: Object, optional: true }, // prop added by _updateUI
state: { type: Object, optional: true }, // prop added by _updateUI
resId: { type: [Number, Boolean], optional: true },
updateActionState: { type: Function, optional: true },
};
function parseActiveIds(ids) {
const activeIds = [];
if (typeof ids === "string") {
activeIds.push(...ids.split(",").map(Number));
} else if (typeof ids === "number") {
activeIds.push(ids);
}
return activeIds;
}
const DIALOG_SIZES = {
"extra-large": "xl",
large: "lg",
medium: "md",
small: "sm",
};
// -----------------------------------------------------------------------------
// Errors
// -----------------------------------------------------------------------------
export class ControllerNotFoundError extends Error {}
export class InvalidButtonParamsError extends Error {}
// -----------------------------------------------------------------------------
// ActionManager (Service)
// -----------------------------------------------------------------------------
Registry / API
- Registry name
action- Category
services- Module
web- Slug
action- Nav group
data_display