| 1 |
import { _t } from "@web/core/l10n/translation"; |
| 2 |
import { Dropdown } from "@web/core/dropdown/dropdown"; |
| 3 |
import { rpc } from "@web/core/network/rpc"; |
| 4 |
import { registry } from "@web/core/registry"; |
| 5 |
import { useAutofocus, useService } from "@web/core/utils/hooks"; |
| 6 |
import { Component, useState } from "@odoo/owl"; |
| 7 |
|
| 8 |
const cogMenuRegistry = registry.category("cogMenu"); |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
export class AddToBoard extends Component { |
| 24 |
static template = "board.AddToBoard"; |
| 25 |
static components = { Dropdown }; |
| 26 |
static props = {}; |
| 27 |
|
| 28 |
setup() { |
| 29 |
this.notification = useService("notification"); |
| 30 |
this.state = useState({ name: this.env.config.getDisplayName() }); |
| 31 |
|
| 32 |
useAutofocus(); |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
async addToBoard() { |
| 40 |
const { domain, globalContext } = this.env.searchModel; |
| 41 |
const { context, groupBys, orderBy } = this.env.searchModel.getPreFavoriteValues(); |
| 42 |
const contextToSave = { |
| 43 |
...Object.fromEntries( |
| 44 |
Object.entries(globalContext).filter( |
| 45 |
(entry) => !entry[0].startsWith("search_default_") |
| 46 |
) |
| 47 |
), |
| 48 |
...context, |
| 49 |
orderedBy: orderBy, |
| 50 |
group_by: groupBys, |
| 51 |
dashboard_merge_domains_contexts: false, |
| 52 |
}; |
| 53 |
|
| 54 |
const result = await rpc("/board/add_to_dashboard", { |
| 55 |
action_id: this.env.config.actionId || false, |
| 56 |
context_to_save: contextToSave, |
| 57 |
domain, |
| 58 |
name: this.state.name, |
| 59 |
view_mode: this.env.config.viewType, |
| 60 |
}); |
| 61 |
|
| 62 |
if (result) { |
| 63 |
this.notification.add( |
| 64 |
_t("Please refresh your browser for the changes to take effect."), |
| 65 |
{ |
| 66 |
title: _t("ā%sā added to dashboard", this.state.name), |
| 67 |
type: "warning", |
| 68 |
} |
| 69 |
); |
| 70 |
this.state.name = this.env.config.getDisplayName(); |
| 71 |
} else { |
| 72 |
this.notification.add(_t("Could not add filter to dashboard"), { |
| 73 |
type: "danger", |
| 74 |
}); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
onInputKeydown(ev) { |
| 86 |
if (ev.key === "Enter") { |
| 87 |
ev.preventDefault(); |
| 88 |
this.addToBoard(); |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
export const addToBoardItem = { |
| 94 |
Component: AddToBoard, |
| 95 |
groupNumber: 20, |
| 96 |
isDisplayed: ({ config }) => { |
| 97 |
const { actionType, actionId, viewType } = config; |
| 98 |
return actionType === "ir.actions.act_window" && actionId && viewType !== "form"; |
| 99 |
}, |
| 100 |
}; |
| 101 |
|
| 102 |
cogMenuRegistry.add("add-to-board", addToBoardItem, { sequence: 10 }); |