Reputation: 1598
I'm looking to develop a module for odoo which will add a button to synchronize some data with an external feed. I've managed to get the basic behavior up and running, but ideally, I would like to show a notification when the (long-running) process starts/finishes.
The basic premise is that I have this ListController and from there I'm trying to figure out how to show a notification. Like when you browse to a different view there is this Loading
on the top.
Looking at the github respository there seems to be a NotificationManager
which is instantiated by AbstractWebClient
. And from the odoo javascript presentation they talked about trigger_up
to propegate calls upwards. The display_notification was in their presentation as an example- but for some reason it does nothing.
Can anybody give me some pointers in the right direction how can i get the notification to work?
odoo.define('test.sync', function (require) {
"use strict";
var core = require('web.core');
var rpc = require('web.rpc');
var Dialog = require('web.Dialog');
var ListController = require('web.ListController');
ListController.include({
renderButtons: function($node) {
this._super.apply(this, arguments);
if (this.$buttons) {
let filter_button = this.$buttons.find('.sync_button');
filter_button && filter_button.click(this.proxy('do_sync')) ;
}
},
do_sync: function () {
this.trigger_up('display_notification', { title: 'Move Zig', message: 'All your bases are belong to us' });
}
});
})
Upvotes: 2
Views: 2049
Reputation: 365
For version 16 you have to use notification service,
// in setup
this.notificationService = useService("notification");
this.actionService = useService("action");
// later
this.notificationService.add("You closed a deal!", {
title: "Congrats",
type: "success",
buttons: [
{
name: "See your Commission",
onClick: () => {
this.actionService.doAction("commission_action");
},
},
],
});
reference here
Upvotes: 1
Reputation: 1277
Inside the controller, or the renderer just write this:
this.do_notify('title', 'message :)');
See the documentation here. Basically the do_notify and do_warn methods are defined in the ServiceMixin class, which is inherited by the abstract controller and renderer by default ::I think::
Upvotes: 1