summaryrefslogtreecommitdiff
path: root/addons/mail_bot/static/src/components
diff options
context:
space:
mode:
authorDidier (did) <did@odoo.com>2020-08-26 12:13:02 +0000
committerSébastien Theys <seb@odoo.com>2020-08-26 12:47:12 +0000
commitbde23b82029507e525cf55d11b050af5f820a06b (patch)
tree419ca10b98197553ed7283a19b0c35cb672b4a66 /addons/mail_bot/static/src/components
parent2e783a68b544515258af077e1cc63402f5b7f9c8 (diff)
[IMP] mail, mail_bot: move notif request and OdooBot name into mail
task-2282334 closes odoo/odoo#56584 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/mail_bot/static/src/components')
-rw-r--r--addons/mail_bot/static/src/components/messaging_menu/messaging_menu.js27
-rw-r--r--addons/mail_bot/static/src/components/messaging_menu/messaging_menu.xml8
-rw-r--r--addons/mail_bot/static/src/components/messaging_menu/messaging_menu_tests.js175
-rw-r--r--addons/mail_bot/static/src/components/notification_alert/notification_alert.js52
-rw-r--r--addons/mail_bot/static/src/components/notification_alert/notification_alert.xml14
-rw-r--r--addons/mail_bot/static/src/components/notification_list/notification_list.js44
-rw-r--r--addons/mail_bot/static/src/components/notification_list/notification_list.xml13
-rw-r--r--addons/mail_bot/static/src/components/notification_request/notification_request.js90
-rw-r--r--addons/mail_bot/static/src/components/notification_request/notification_request.scss73
-rw-r--r--addons/mail_bot/static/src/components/notification_request/notification_request.xml31
10 files changed, 0 insertions, 527 deletions
diff --git a/addons/mail_bot/static/src/components/messaging_menu/messaging_menu.js b/addons/mail_bot/static/src/components/messaging_menu/messaging_menu.js
deleted file mode 100644
index c1deec24095..00000000000
--- a/addons/mail_bot/static/src/components/messaging_menu/messaging_menu.js
+++ /dev/null
@@ -1,27 +0,0 @@
-odoo.define('mail_bot/static/src/components/messaging_menu/messaging_menu,js', function (require) {
-'use strict';
-
-const components = {
- MessagingMenu: require('mail/static/src/components/messaging_menu/messaging_menu.js'),
-};
-
-const { patch } = require('web.utils');
-
-patch(components.MessagingMenu, 'mail_bot/static/src/components/messaging_menu/messaging_menu,js', {
-
- //--------------------------------------------------------------------------
- // Handlers
- //--------------------------------------------------------------------------
-
- /**
- * @private
- */
- _onOdoobotRequestClicked() {
- const device = this.messagingMenu.messaging.device;
- if (!device.isMobile) {
- this.messagingMenu.close();
- }
- },
-});
-
-});
diff --git a/addons/mail_bot/static/src/components/messaging_menu/messaging_menu.xml b/addons/mail_bot/static/src/components/messaging_menu/messaging_menu.xml
deleted file mode 100644
index a6eb2cf2cd9..00000000000
--- a/addons/mail_bot/static/src/components/messaging_menu/messaging_menu.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<templates xml:space="preserve">
- <t t-inherit="mail.MessagingMenu" t-inherit-mode="extension">
- <xpath expr="//NotificationList" position="attributes">
- <attribute name="t-on-o-odoobot-request-clicked" t-translation="off">_onOdoobotRequestClicked</attribute>
- </xpath>
- </t>
-</templates>
diff --git a/addons/mail_bot/static/src/components/messaging_menu/messaging_menu_tests.js b/addons/mail_bot/static/src/components/messaging_menu/messaging_menu_tests.js
deleted file mode 100644
index 98cd47a8932..00000000000
--- a/addons/mail_bot/static/src/components/messaging_menu/messaging_menu_tests.js
+++ /dev/null
@@ -1,175 +0,0 @@
-odoo.define('mail_bot/static/src/components/messaging_menu/messaging_menu_tests.js', function (require) {
-"use strict";
-
-const {
- afterEach,
- afterNextRender,
- beforeEach,
- start,
-} = require('mail/static/src/utils/test_utils.js');
-
-QUnit.module('mail_bot', {}, function () {
-QUnit.module('components', {}, function () {
-QUnit.module('messaging_menu', {}, function () {
-QUnit.module('messaging_menu_tests.js', {
- beforeEach() {
- beforeEach(this);
-
- this.start = async params => {
- let { widget } = await start(Object.assign({}, params, {
- data: this.data,
- hasMessagingMenu: true,
- }));
- this.widget = widget;
- };
- },
- afterEach() {
- afterEach(this);
- },
-});
-
-QUnit.test('rendering with OdooBot has a request (default)', async function (assert) {
- assert.expect(4);
-
- await this.start({
- env: {
- browser: {
- Notification: {
- permission: 'default',
- },
- },
- },
- });
-
- assert.ok(
- document.querySelector('.o_MessagingMenu_counter'),
- "should display a notification counter next to the messaging menu for OdooBot request"
- );
- assert.strictEqual(
- document.querySelector('.o_MessagingMenu_counter').textContent,
- "1",
- "should display a counter of '1' next to the messaging menu"
- );
-
- await afterNextRender(() =>
- document.querySelector('.o_MessagingMenu_toggler').click()
- );
- assert.containsOnce(
- document.body,
- '.o_NotificationRequest',
- "should display a notification in the messaging menu"
- );
- assert.strictEqual(
- document.querySelector('.o_NotificationRequest_name').textContent.trim(),
- 'OdooBot has a request',
- "notification should display that OdooBot has a request"
- );
-});
-
-QUnit.test('rendering without OdooBot has a request (denied)', async function (assert) {
- assert.expect(2);
-
- await this.start({
- env: {
- browser: {
- Notification: {
- permission: 'denied',
- },
- },
- },
- });
-
- assert.containsNone(
- document.body,
- '.o_MessagingMenu_counter',
- "should not display a notification counter next to the messaging menu"
- );
-
- await afterNextRender(() =>
- document.querySelector('.o_MessagingMenu_toggler').click()
- );
- assert.containsNone(
- document.body,
- '.o_NotificationRequest',
- "should display no notification in the messaging menu"
- );
-});
-
-QUnit.test('rendering without OdooBot has a request (accepted)', async function (assert) {
- assert.expect(2);
-
- await this.start({
- env: {
- browser: {
- Notification: {
- permission: 'granted',
- },
- },
- },
- });
-
- assert.containsNone(
- document.body,
- '.o_MessagingMenu_counter',
- "should not display a notification counter next to the messaging menu"
- );
-
- await afterNextRender(() =>
- document.querySelector('.o_MessagingMenu_toggler').click()
- );
- assert.containsNone(
- document.body,
- '.o_NotificationRequest',
- "should display no notification in the messaging menu"
- );
-});
-
-QUnit.test('respond to notification prompt (denied)', async function (assert) {
- assert.expect(3);
-
- await this.start({
- env: {
- browser: {
- Notification: {
- permission: 'default',
- async requestPermission() {
- this.permission = 'denied';
- return this.permission;
- },
- },
- },
- },
- });
-
- await afterNextRender(() =>
- document.querySelector('.o_MessagingMenu_toggler').click()
- );
- await afterNextRender(() =>
- document.querySelector('.o_NotificationRequest').click()
- );
- assert.containsOnce(
- document.body,
- '.toast .o_notification_content',
- "should display a toast notification with the deny confirmation"
- );
- assert.containsNone(
- document.body,
- '.o_MessagingMenu_counter',
- "should not display a notification counter next to the messaging menu"
- );
-
- await afterNextRender(() =>
- document.querySelector('.o_MessagingMenu_toggler').click()
- );
- assert.containsNone(
- document.body,
- '.o_NotificationRequest',
- "should display no notification in the messaging menu"
- );
-});
-
-});
-});
-});
-
-});
diff --git a/addons/mail_bot/static/src/components/notification_alert/notification_alert.js b/addons/mail_bot/static/src/components/notification_alert/notification_alert.js
deleted file mode 100644
index 4cfcbc362a8..00000000000
--- a/addons/mail_bot/static/src/components/notification_alert/notification_alert.js
+++ /dev/null
@@ -1,52 +0,0 @@
-odoo.define('mail_bot/static/src/components/notification_alert/notification_alert.js', function (require) {
-'use strict';
-
-const useStore = require('mail/static/src/component_hooks/use_store/use_store.js');
-
-const { Component } = owl;
-
-class NotificationAlert extends Component {
-
- /**
- * @override
- */
- constructor(...args) {
- super(...args);
- useStore(props => {
- const isMessagingInitialized = this.env.isMessagingInitialized();
- return {
- isMessagingInitialized,
- isNotificationBlocked: this.isNotificationBlocked,
- };
- });
- }
-
- //--------------------------------------------------------------------------
- // Public
- //--------------------------------------------------------------------------
-
- /**
- * @returns {boolean}
- */
- get isNotificationBlocked() {
- if (!this.env.isMessagingInitialized()) {
- return false;
- }
- const windowNotification = this.env.browser.Notification;
- return (
- windowNotification &&
- windowNotification.permission !== "granted" &&
- !this.env.messaging.isNotificationPermissionDefault()
- );
- }
-
-}
-
-Object.assign(NotificationAlert, {
- props: {},
- template: 'mail_bot.NotificationAlert',
-});
-
-return NotificationAlert;
-
-});
diff --git a/addons/mail_bot/static/src/components/notification_alert/notification_alert.xml b/addons/mail_bot/static/src/components/notification_alert/notification_alert.xml
deleted file mode 100644
index e9b3eef9331..00000000000
--- a/addons/mail_bot/static/src/components/notification_alert/notification_alert.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<templates xml:space="preserve">
-
- <t t-name="mail_bot.NotificationAlert" owl="1">
- <div class="o_NotificationAlert">
- <t t-if="env.isMessagingInitialized()">
- <center t-if="isNotificationBlocked" class="o_notification_alert alert alert-primary">
- Odoo Push notifications have been blocked. Go to your browser settings to allow them.
- </center>
- </t>
- </div>
- </t>
-
-</templates>
diff --git a/addons/mail_bot/static/src/components/notification_list/notification_list.js b/addons/mail_bot/static/src/components/notification_list/notification_list.js
deleted file mode 100644
index c0fa47930c9..00000000000
--- a/addons/mail_bot/static/src/components/notification_list/notification_list.js
+++ /dev/null
@@ -1,44 +0,0 @@
-odoo.define('mail_bot/static/src/components/notification_list/notification_list.js', function (require) {
-'use strict';
-
-const components = {
- mail: {
- NotificationList: require('mail/static/src/components/notification_list/notification_list.js'),
- },
- mail_bot: {
- NotificationRequest: require('mail_bot/static/src/components/notification_request/notification_request.js'),
- },
-};
-
-const { patch } = require('web.utils');
-
-Object.assign(components.mail.NotificationList.components, components.mail_bot);
-
-patch(components.mail.NotificationList, 'mail_bot/static/src/components/notification_list/notification_list.js', {
-
- //--------------------------------------------------------------------------
- // Private
- //--------------------------------------------------------------------------
-
- /**
- * Override so that 'OdooBot has a request' is included at the top of the
- * list.
- *
- * @override
- */
- _useStoreSelector(props) {
- const res = this._super(...arguments);
- if (
- props.filter === 'all' &&
- this.env.messaging.isNotificationPermissionDefault()
- ) {
- res.notifications.unshift({
- type: 'odoobotRequest',
- uniqueId: `odoobotRequest`,
- });
- }
- return res;
- }
-});
-
-});
diff --git a/addons/mail_bot/static/src/components/notification_list/notification_list.xml b/addons/mail_bot/static/src/components/notification_list/notification_list.xml
deleted file mode 100644
index da2a28ee090..00000000000
--- a/addons/mail_bot/static/src/components/notification_list/notification_list.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<templates xml:space="preserve">
- <t t-inherit="mail.NotificationList" t-inherit-mode="extension">
- <xpath expr="//*[@name='separatorCondition']" position="before">
- <t t-if="notification.type === 'odoobotRequest'">
- <NotificationRequest
- class="o_NotificationList_notificationRequest"
- t-att-class="{ 'o-mobile': env.messaging.device.isMobile }"
- />
- </t>
- </xpath>
- </t>
-</templates>
diff --git a/addons/mail_bot/static/src/components/notification_request/notification_request.js b/addons/mail_bot/static/src/components/notification_request/notification_request.js
deleted file mode 100644
index ef9639c688b..00000000000
--- a/addons/mail_bot/static/src/components/notification_request/notification_request.js
+++ /dev/null
@@ -1,90 +0,0 @@
-odoo.define('mail_bot/static/src/components/notification_request/notification_request.js', function (require) {
-'use strict';
-
-const components = {
- PartnerImStatusIcon: require('mail/static/src/components/partner_im_status_icon/partner_im_status_icon.js'),
-};
-const useStore = require('mail/static/src/component_hooks/use_store/use_store.js');
-
-const { Component } = owl;
-
-class NotificationRequest extends Component {
-
- /**
- * @override
- */
- constructor(...args) {
- super(...args);
- useStore(props => {
- return {
- isDeviceMobile: this.env.messaging.device.isMobile,
- partnerRoot: this.env.messaging.partnerRoot
- ? this.env.messaging.partnerRoot.__state
- : undefined,
- };
- });
- }
-
- //--------------------------------------------------------------------------
- // Public
- //--------------------------------------------------------------------------
-
- /**
- * @returns {string}
- */
- getHeaderText() {
- return _.str.sprintf(
- this.env._t("%s has a request"),
- this.env.messaging.partnerRoot.nameOrDisplayName
- );
- }
-
- //--------------------------------------------------------------------------
- // Private
- //--------------------------------------------------------------------------
-
- /**
- * Handle the response of the user when prompted whether push notifications
- * are granted or denied.
- *
- * @private
- * @param {string} value
- */
- _handleResponseNotificationPermission(value) {
- // manually force recompute because the permission is not in the store
- this.env.messaging.messagingMenu.update();
- if (value !== 'granted') {
- this.env.services['bus_service'].sendNotification(
- this.env._t("Permission denied"),
- this.env._t("Odoo will not have the permission to send native notifications on this device.")
- );
- }
- }
-
- //--------------------------------------------------------------------------
- // Handlers
- //--------------------------------------------------------------------------
-
- /**
- * @private
- */
- _onClick() {
- const windowNotification = this.env.browser.Notification;
- const def = windowNotification && windowNotification.requestPermission();
- if (def) {
- def.then(this._handleResponseNotificationPermission.bind(this));
- }
- this.trigger('o-odoobot-request-clicked');
- }
-
-}
-
-Object.assign(NotificationRequest, {
- components,
- props: {},
- template: 'mail_bot.NotificationRequest',
-});
-
-return NotificationRequest;
-
-});
diff --git a/addons/mail_bot/static/src/components/notification_request/notification_request.scss b/addons/mail_bot/static/src/components/notification_request/notification_request.scss
deleted file mode 100644
index 8d4b38db848..00000000000
--- a/addons/mail_bot/static/src/components/notification_request/notification_request.scss
+++ /dev/null
@@ -1,73 +0,0 @@
-// ------------------------------------------------------------------
-// Layout
-// ------------------------------------------------------------------
-
-.o_NotificationRequest {
- @include o-mail-notification-list-item-layout();
-}
-
-.o_NotificationRequest_content {
- @include o-mail-notification-list-item-content-layout();
-}
-
-.o_NotificationRequest_core {
- @include o-mail-notification-list-item-core-layout();
-}
-
-.o_NotificationRequest_coreItem {
- @include o-mail-notification-list-item-core-item-layout();
-}
-
-.o_NotificationRequest_header {
- @include o-mail-notification-list-item-header-layout();
-}
-
-.o_NotificationRequest_image {
- @include o-mail-notification-list-item-image-layout();
-}
-
-.o_NotificationRequest_imageContainer {
- @include o-mail-notification-list-item-image-container-layout();
-}
-
-.o_NotificationRequest_inlineText {
- @include o-mail-notification-list-item-inline-text-layout();
-}
-
-.o_NotificationRequest_name {
- @include o-mail-notification-list-item-name-layout();
-}
-
-.o_NotificationRequest_partnerImStatusIcon {
- @include o-mail-notification-list-item-partner-im-status-icon-layout();
-}
-
-.o_NotificationRequest_sidebar {
- @include o-mail-notification-list-item-sidebar-layout();
-}
-
-// ------------------------------------------------------------------
-// Style
-// ------------------------------------------------------------------
-
-.o_NotificationRequest {
- @include o-mail-notification-list-item-style();
-
- &:hover {
- .o_NotificationRequest_partnerImStatusIcon {
- @include o-mail-notification-list-item-hover-partner-im-status-icon-style();
- }
- }
-}
-
-.o_NotificationRequest_core {
- @include o-mail-notification-list-item-core-style();
-}
-
-.o_NotificationRequest_name {
- @include o-mail-notification-list-item-bold-style();
-}
-
-.o_NotificationRequest_partnerImStatusIcon {
- @include o-mail-notification-list-item-partner-im-status-icon-style();
-}
diff --git a/addons/mail_bot/static/src/components/notification_request/notification_request.xml b/addons/mail_bot/static/src/components/notification_request/notification_request.xml
deleted file mode 100644
index 10b22bac2cd..00000000000
--- a/addons/mail_bot/static/src/components/notification_request/notification_request.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<templates xml:space="preserve">
-
- <t t-name="mail_bot.NotificationRequest" owl="1">
- <div class="o_NotificationRequest" t-on-click="_onClick">
- <div class="o_NotificationRequest_sidebar">
- <div class="o_NotificationRequest_imageContainer o_NotificationRequest_sidebarItem">
- <img class="o_NotificationRequest_image rounded-circle" src="/mail/static/src/img/odoobot.png" alt="Avatar of OdooBot"/>
- <PartnerImStatusIcon
- class="o_NotificationRequest_partnerImStatusIcon"
- t-att-class="{ 'o-mobile': env.messaging.device.isMobile }"
- partnerLocalId="env.messaging.partnerRoot.localId"
- />
- </div>
- </div>
- <div class="o_NotificationRequest_content">
- <div class="o_NotificationRequest_header">
- <span class="o_NotificationRequest_name" t-att-class="{ 'o-mobile': env.messaging.device.isMobile }">
- <t t-esc="getHeaderText()"/>
- </span>
- </div>
- <div class="o_NotificationRequest_core">
- <span class="o_NotificationRequest_coreItem o_NotificationRequest_inlineText">
- Enable desktop notifications to chat.
- </span>
- </div>
- </div>
- </div>
- </t>
-
-</templates>