summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/services
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/mail/static/src/services
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/mail/static/src/services')
-rw-r--r--addons/mail/static/src/services/chat_window_service/chat_window_service.js104
-rw-r--r--addons/mail/static/src/services/dialog_service/dialog_service.js101
2 files changed, 205 insertions, 0 deletions
diff --git a/addons/mail/static/src/services/chat_window_service/chat_window_service.js b/addons/mail/static/src/services/chat_window_service/chat_window_service.js
new file mode 100644
index 00000000..8a11c202
--- /dev/null
+++ b/addons/mail/static/src/services/chat_window_service/chat_window_service.js
@@ -0,0 +1,104 @@
+odoo.define('mail/static/src/services/chat_window_service/chat_window_service.js', function (require) {
+'use strict';
+
+const components = {
+ ChatWindowManager: require('mail/static/src/components/chat_window_manager/chat_window_manager.js'),
+};
+
+const AbstractService = require('web.AbstractService');
+const { bus, serviceRegistry } = require('web.core');
+
+const ChatWindowService = AbstractService.extend({
+ /**
+ * @override {web.AbstractService}
+ */
+ start() {
+ this._super(...arguments);
+ this._webClientReady = false;
+ this._listenHomeMenu();
+ },
+ /**
+ * @private
+ */
+ destroy() {
+ if (this.component) {
+ this.component.destroy();
+ this.component = undefined;
+ }
+ },
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ * @returns {Node}
+ */
+ _getParentNode() {
+ return document.querySelector('body');
+ },
+ /**
+ * @private
+ */
+ _listenHomeMenu() {
+ bus.on('hide_home_menu', this, this._onHideHomeMenu.bind(this));
+ bus.on('show_home_menu', this, this._onShowHomeMenu.bind(this));
+ bus.on('web_client_ready', this, this._onWebClientReady.bind(this));
+ },
+ /**
+ * @private
+ */
+ async _mount() {
+ if (this.component) {
+ this.component.destroy();
+ this.component = undefined;
+ }
+ const ChatWindowManagerComponent = components.ChatWindowManager;
+ this.component = new ChatWindowManagerComponent(null);
+ const parentNode = this._getParentNode();
+ await this.component.mount(parentNode);
+ },
+
+ //--------------------------------------------------------------------------
+ // Handlers
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ */
+ async _onHideHomeMenu() {
+ if (!this._webClientReady) {
+ return;
+ }
+ if (document.querySelector('.o_ChatWindowManager')) {
+ return;
+ }
+ await this._mount();
+ },
+ /**
+ * @private
+ */
+ async _onShowHomeMenu() {
+ if (!this._webClientReady) {
+ return;
+ }
+ if (document.querySelector('.o_ChatWindowManager')) {
+ return;
+ }
+ await this._mount();
+ },
+ /**
+ * @private
+ */
+ async _onWebClientReady() {
+ await this._mount();
+ this._webClientReady = true;
+ },
+});
+
+serviceRegistry.add('chat_window', ChatWindowService);
+
+return ChatWindowService;
+
+});
diff --git a/addons/mail/static/src/services/dialog_service/dialog_service.js b/addons/mail/static/src/services/dialog_service/dialog_service.js
new file mode 100644
index 00000000..88762a29
--- /dev/null
+++ b/addons/mail/static/src/services/dialog_service/dialog_service.js
@@ -0,0 +1,101 @@
+odoo.define('mail/static/src/services/dialog_service/dialog_service.js', function (require) {
+'use strict';
+
+const components = {
+ DialogManager: require('mail/static/src/components/dialog_manager/dialog_manager.js'),
+};
+
+const AbstractService = require('web.AbstractService');
+const { bus, serviceRegistry } = require('web.core');
+
+const DialogService = AbstractService.extend({
+ /**
+ * @override {web.AbstractService}
+ */
+ start() {
+ this._super(...arguments);
+ this._webClientReady = false;
+ this._listenHomeMenu();
+ },
+ /**
+ * @private
+ */
+ destroy() {
+ if (this.component) {
+ this.component.destroy();
+ this.component = undefined;
+ }
+ },
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ * @returns {Node}
+ */
+ _getParentNode() {
+ return document.querySelector('body');
+ },
+ /**
+ * @private
+ */
+ _listenHomeMenu() {
+ bus.on('hide_home_menu', this, this._onHideHomeMenu.bind(this));
+ bus.on('show_home_menu', this, this._onShowHomeMenu.bind(this));
+ bus.on('web_client_ready', this, this._onWebClientReady.bind(this));
+ },
+ /**
+ * @private
+ */
+ async _mount() {
+ if (this.component) {
+ this.component.destroy();
+ this.component = undefined;
+ }
+ const DialogManagerComponent = components.DialogManager;
+ this.component = new DialogManagerComponent(null);
+ const parentNode = this._getParentNode();
+ await this.component.mount(parentNode);
+ },
+
+ //--------------------------------------------------------------------------
+ // Handlers
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ */
+ async _onHideHomeMenu() {
+ if (!this._webClientReady) {
+ return;
+ }
+ if (document.querySelector('.o_DialogManager')) {
+ return;
+ }
+ await this._mount();
+ },
+ async _onShowHomeMenu() {
+ if (!this._webClientReady) {
+ return;
+ }
+ if (document.querySelector('.o_DialogManager')) {
+ return;
+ }
+ await this._mount();
+ },
+ /**
+ * @private
+ */
+ async _onWebClientReady() {
+ await this._mount();
+ this._webClientReady = true;
+ }
+});
+
+serviceRegistry.add('dialog', DialogService);
+
+return DialogService;
+
+});