| 1 |
import { session } from "@web/session"; |
| 2 |
import { standardWidgetProps } from "@web/views/widgets/standard_widget_props"; |
| 3 |
import { Component } from "@odoo/owl"; |
| 4 |
import { registry } from "@web/core/registry"; |
| 5 |
|
| 6 |
const LINK_REGEX = new RegExp("^https?://"); |
| 7 |
|
| 8 |
export class DocumentationLink extends Component { |
| 9 |
static template = "web.DocumentationLink"; |
| 10 |
static props = { |
| 11 |
...standardWidgetProps, |
| 12 |
record: { type: Object, optional: 1 }, // The record is not needed in this widget |
| 13 |
path: { type: String }, |
| 14 |
label: { type: String, optional: 1 }, |
| 15 |
icon: { type: String, optional: 1 }, |
| 16 |
alertLink: { type: Boolean, optional: 1 }, |
| 17 |
}; |
| 18 |
|
| 19 |
get url() { |
| 20 |
if (LINK_REGEX.test(this.props.path)) { |
| 21 |
return this.props.path; |
| 22 |
} else { |
| 23 |
const serverVersion = session.server_version_info.includes("final") |
| 24 |
? `${session.server_version_info[0]}.${session.server_version_info[1]}`.replace( |
| 25 |
"~", |
| 26 |
"-" |
| 27 |
) |
| 28 |
: "master"; |
| 29 |
return "https://www.odoo.com/documentation/" + serverVersion + this.props.path; |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
get classes() { |
| 34 |
let classes = "o_doc_link me-2"; |
| 35 |
if (this.props.alertLink){ |
| 36 |
classes += " alert-link"; |
| 37 |
} |
| 38 |
return classes; |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
export const documentationLink = { |
| 43 |
component: DocumentationLink, |
| 44 |
extractProps: ({ attrs }) => { |
| 45 |
const { path, label, icon, alert_link } = attrs; |
| 46 |
return { |
| 47 |
path, |
| 48 |
label, |
| 49 |
icon, |
| 50 |
alertLink: Boolean(alert_link), |
| 51 |
}; |
| 52 |
}, |
| 53 |
additionalClasses: ["d-inline"], |
| 54 |
}; |
| 55 |
|
| 56 |
registry.category("view_widgets").add("documentation_link", documentationLink); |