[REF] purchase: convert toaster button widget

Part-of: odoo/odoo#97234
This commit is contained in:
Dardenne Florent (dafl)
2022-08-02 15:49:50 +02:00
parent 7b7ece114a
commit fc7b8bccb0
3 changed files with 39 additions and 0 deletions
+2
View File
@@ -38,6 +38,7 @@
'application': True,
'assets': {
'web.assets_backend': [
'purchase/static/src/toaster_button/*',
'purchase/static/src/scss/purchase.scss',
'purchase/static/src/js/purchase_dashboard.js',
'purchase/static/src/js/purchase_toaster_button.js',
@@ -49,6 +50,7 @@
'purchase/static/src/js/purchase_portal_sidebar.js',
],
'web.assets_qweb': [
'purchase/static/src/toaster_button/*.xml',
'purchase/static/src/xml/**/*',
],
},
@@ -0,0 +1,27 @@
/** @odoo-module */
import { registry } from "@web/core/registry";
import { useService } from "@web/core/utils/hooks";
const { Component } = owl;
class ButtonWithNotification extends Component {
setup() {
this.orm = useService("orm");
this.notification = useService("notification");
}
async onClick() {
const result = await this.orm.call(this.props.record.resModel, this.props.method, [this.props.record.resId]);
const message = result.toast_message;
this.notification.add(message, { type: "success" });
}
}
ButtonWithNotification.template = "purchase.ButtonWithNotification";
ButtonWithNotification.extractProps = ({ attrs }) => {
return {
method: attrs.button_name,
title: attrs.title,
};
};
registry.category("view_widgets").add("toaster_button", ButtonWithNotification);
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<template>
<t t-name="purchase.ButtonWithNotification" owl="1">
<button t-on-click="onClick" t-att-name="props.method" type="button" class="btn oe_inline btn-link" t-att-title="props.title">
<i class="fa fa-fw o_button_icon fa-info-circle"></i>
</button>
</t>
</template>