| 1 |
import { Component, xml } from "@odoo/owl"; |
| 2 |
import { registry } from "@web/core/registry"; |
| 3 |
|
| 4 |
class Alert extends Component { |
| 5 |
static template = xml` |
| 6 |
<div t-attf-class="alert pos-navbar-height fixed-top p-1 rounded-0 alert-{{props.type}} fade show d-flex align-items-center justify-content-center" role="alert"> |
| 7 |
<strong class="flex-grow-1 text-center" t-esc="props.message" /> |
| 8 |
</div> |
| 9 |
`; |
| 10 |
static props = { |
| 11 |
message: String, |
| 12 |
type: { |
| 13 |
type: String, |
| 14 |
optional: true, |
| 15 |
validate: (type) => ["info", "warning", "danger", "success"].includes(type), |
| 16 |
}, |
| 17 |
}; |
| 18 |
static defaultProps = { |
| 19 |
type: "info", |
| 20 |
}; |
| 21 |
} |
| 22 |
|
| 23 |
export const alertService = { |
| 24 |
dependencies: ["overlay"], |
| 25 |
start(env, { overlay }) { |
| 26 |
let dismiss = undefined; |
| 27 |
|
| 28 |
const add = (message, options = {}, overlayOptions = {}) => { |
| 29 |
dismiss?.(); |
| 30 |
dismiss = overlay.add( |
| 31 |
Alert, |
| 32 |
{ |
| 33 |
message, |
| 34 |
...options, |
| 35 |
}, |
| 36 |
overlayOptions |
| 37 |
); |
| 38 |
}; |
| 39 |
|
| 40 |
return { add, dismiss: () => dismiss?.() }; |
| 41 |
}, |
| 42 |
}; |
| 43 |
|
| 44 |
registry.category("services").add("alert", alertService); |