Skip to content

Commit

Permalink
'notifications' have been changed in the odoo 12
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafis Bikbov committed Nov 28, 2018
1 parent 385fcdc commit 6bea08c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
6 changes: 2 additions & 4 deletions web_debranding/static/src/js/bot.js
Expand Up @@ -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);
}
});
});
55 changes: 29 additions & 26 deletions web_debranding/static/src/js/native_notifications.js
Expand Up @@ -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 6bea08c

Please sign in to comment.