odoo18/addons/project/static/src/project_sharing/project_sharing.js

74 lines
2.5 KiB
JavaScript

/** @odoo-module **/
import { useBus, useService } from '@web/core/utils/hooks';
import { ActionContainer } from '@web/webclient/actions/action_container';
import { MainComponentsContainer } from "@web/core/main_components_container";
import { useOwnDebugContext } from "@web/core/debug/debug_context";
import { session } from '@web/session';
import { Component, useEffect, useExternalListener, useState } from "@odoo/owl";
export class ProjectSharingWebClient extends Component {
static props = {};
static components = { ActionContainer, MainComponentsContainer };
static template = "project.ProjectSharingWebClient";
setup() {
window.parent.document.body.style.margin = "0"; // remove the margin in the parent body
this.actionService = useService('action');
useOwnDebugContext({ categories: ["default"] });
this.state = useState({
fullscreen: false,
});
useBus(this.env.bus, "ACTION_MANAGER:UI-UPDATED", (mode) => {
if (mode !== "new") {
this.state.fullscreen = mode === "fullscreen";
}
});
useEffect(
() => {
this._showView();
},
() => []
);
useExternalListener(window, "click", this.onGlobalClick, { capture: true });
}
async _showView() {
const { action_name, action_context, project_id, project_name, open_task_action } = session;
const action = await this.actionService.loadAction(action_name, {
active_id: project_id,
});
action.display_name = project_name;
await this.actionService.doAction(
action,
{
clearBreadcrumbs: true,
additionalContext: {
active_id: project_id,
...action_context,
}
}
);
if (open_task_action) {
await this.actionService.doAction(open_task_action);
}
}
/**
* @param {MouseEvent} ev
*/
onGlobalClick(ev) {
// When a ctrl-click occurs inside an <a href/> element
// we let the browser do the default behavior and
// we do not want any other listener to execute.
if (
ev.ctrlKey &&
((ev.target instanceof HTMLAnchorElement && ev.target.href) ||
(ev.target instanceof HTMLElement && ev.target.closest("a[href]:not([href=''])")))
) {
ev.stopImmediatePropagation();
return;
}
}
}