Permalink
Browse files

'notifications' have been changed in the odoo 12

  • Loading branch information...
RafiZz committed Nov 27, 2018
1 parent 188e895 commit c087141aead07bb4a4b37c6ad7e1b42f7e9d8e78
Showing with 31 additions and 30 deletions.
  1. +2 −4 web_debranding/static/src/js/bot.js
  2. +29 −26 web_debranding/static/src/js/native_notifications.js
@@ -14,13 +14,11 @@ odoo.define('web_debranding.bot', function (require) {
}
return this._super.apply(this, arguments);
},

getAvatarSource: function () {
var res = this._super.apply(this, arguments);
if (res === '/mail/static/src/img/odoo_o.png') {
if (this._isOdoobotAuthor()) {
return '/web/binary/company_logo?company_id=' + session.company_id;
}
return res;
return this._super.apply(this, arguments);
}
});
});
@@ -6,36 +6,39 @@ odoo.define('web_debranding.native_notifications', function (require) {

require('web_debranding.base');
var session = require('web.session');
var BusService = require('bus.BusService');
var core = require('web.core');
var utils = require('mail.utils');
var bus = require('bus.bus').bus;

var _t = core._t;

var _send_native_notification = function (title, content) {
var notification = new Notification(title, {body: content, icon: '/web/binary/company_logo?company_id=' + session.company_id});
notification.onclick = function () {
window.focus();
if (this.cancel) {
this.cancel();
} else if (this.close) {
this.close();
BusService.include({
sendNotification: function (title, content, callback) {
if (title === _t('Yay, push notifications are enabled!') || title === _t('Permission denied')) {
content = content.replace(/Odoo/ig, odoo.debranding_new_name);
}
};
};

var send_notification_super = utils.send_notification;
utils.send_notification = function (widget, title, content) {
if (title === 'Permission granted' || title === 'Permission denied') {
content = content.replace(/Odoo/ig, odoo.debranding_new_name);
}
if (Notification && Notification.permission === "granted") {
if (bus.is_master) {
_send_native_notification(title, content);
if (window.Notification && Notification.permission === "granted") {
if (BusService.isMasterTab()) {
this._sendNativeNotification(title, content, callback);
}
} else {
this._super(title, content, callback);
}
} else {
send_notification_super(widget, title, content);
}
};
},
_sendNativeNotification: function (title, content, callback) {
var notification = new Notification(title, {body: content, icon: '/web/binary/company_logo?company_id=' + session.company_id});
notification.onclick = function () {
window.focus();
if (this.cancel) {
this.cancel();
} else if (this.close) {
this.close();
}
if (callback) {
// eslint-disable-next-line
callback();
}
};
},
});

return BusService;
});

0 comments on commit c087141

Please sign in to comment.