[MIG] web_notify: Migration to 15.0

This commit is contained in:
Aiendry Sarkar
2022-08-15 10:47:32 +05:30
committed by David
parent b44b23499e
commit dd92d61f30
12 changed files with 158 additions and 217 deletions

View File

@@ -0,0 +1,14 @@
odoo.define("web_notify.Notification", function (require) {
"use strict";
const {Notification} = require("@web/core/notifications/notification");
const {patch} = require("web.utils");
patch(Notification.props, "webNotifyProps", {
type: {
type: String,
optional: true,
validate: (t) =>
["warning", "danger", "success", "info", "default"].includes(t),
},
});
});

View File

@@ -0,0 +1,47 @@
odoo.define("web_notify.NotificationService", function (require) {
"use strict";
const {browser} = require("@web/core/browser/browser");
const {registry} = require("@web/core/registry");
const webNotificationService = {
dependencies: ["notification"],
start(env, {notification}) {
let webNotifTimeouts = {};
/**
* Displays the web notification on user's screen
*/
function displaywebNotification(notifications) {
Object.values(webNotifTimeouts).forEach((notif) =>
browser.clearTimeout(notif)
);
webNotifTimeouts = {};
notifications.forEach(function (notif) {
browser.setTimeout(function () {
notification.add(notif.message, {
title: notif.title,
type: notif.type,
sticky: notif.sticky,
className: notif.className,
});
});
});
}
env.bus.on("WEB_CLIENT_READY", null, async () => {
const legacyEnv = owl.Component.env;
legacyEnv.services.bus_service.onNotification(this, (notifications) => {
for (const {payload, type} of notifications) {
if (type === "web.notify") {
displaywebNotification(payload);
}
}
});
legacyEnv.services.bus_service.startPolling();
});
},
};
registry.category("services").add("webNotification", webNotificationService);
});

View File

@@ -1,61 +0,0 @@
odoo.define("web_notify.WebClient", function (require) {
"use strict";
var WebClient = require("web.WebClient");
var session = require("web.session");
require("bus.BusService");
WebClient.include({
show_application: function () {
var res = this._super();
this.start_polling();
return res;
},
start_polling: function () {
this.channel_success = "notify_success_" + session.uid;
this.channel_danger = "notify_danger_" + session.uid;
this.channel_warning = "notify_warning_" + session.uid;
this.channel_info = "notify_info_" + session.uid;
this.channel_default = "notify_default_" + session.uid;
this.all_channels = [
this.channel_success,
this.channel_danger,
this.channel_warning,
this.channel_info,
this.channel_default,
];
this.call("bus_service", "startPolling");
if (this.call("bus_service", "isMasterTab")) {
this.call("bus_service", "addChannel", this.channel_success);
this.call("bus_service", "addChannel", this.channel_danger);
this.call("bus_service", "addChannel", this.channel_warning);
this.call("bus_service", "addChannel", this.channel_info);
this.call("bus_service", "addChannel", this.channel_default);
}
this.call("bus_service", "on", "notification", this, this.bus_notification);
},
bus_notification: function (notifications) {
var self = this;
_.each(notifications, function (notification) {
var channel = notification[0];
var message = notification[1];
if (
self.all_channels !== null &&
self.all_channels.indexOf(channel) > -1
) {
self.on_message(message);
}
});
},
on_message: function (message) {
return this.call("notification", "notify", {
type: message.type,
title: message.title,
message: message.message,
sticky: message.sticky,
className: message.className,
});
},
});
});

View File

@@ -1,26 +0,0 @@
odoo.define("web_notify.Notification", function (require) {
"use strict";
var Notification = require("web.Notification");
Notification.include({
icon_mapping: {
success: "fa-thumbs-up",
danger: "fa-exclamation-triangle",
warning: "fa-exclamation",
info: "fa-info",
default: "fa-lightbulb-o",
},
init: function () {
this._super.apply(this, arguments);
// Delete default classes
this.className = this.className.replace(" o_error", "");
// Add custom icon and custom class
this.icon =
this.type in this.icon_mapping
? this.icon_mapping[this.type]
: this.icon_mapping.default;
this.className += " o_" + this.type;
},
});
});

View File

@@ -1,24 +0,0 @@
.o_notification_manager {
.o_notification {
&.o_success {
color: white;
background-color: theme-color("success");
}
&.o_danger {
color: white;
background-color: theme-color("danger");
}
&.o_warning {
color: white;
background-color: theme-color("warning");
}
&.o_info {
color: white;
background-color: theme-color("info");
}
&.o_default {
color: black;
background-color: theme-color("default");
}
}
}