[IMP] web, *: display rpc warnings with toasts
* = test_website, partner_autocomplete - All the rpc warnings are now displayed using the notification system of https://github.com/odoo/odoo/commit/b94395b50175925fc7d1bd3655e5facb78a8ba2b - test_website is up to date Part of https://github.com/odoo/odoo/pull/32132 task-1894820
This commit is contained in:
@@ -81,7 +81,13 @@ odoo.define('partner_autocomplete.tests', function (require) {
|
||||
return this._getOdooSuggestions(value);
|
||||
},
|
||||
do_notify: function (title, message, sticky, className) {
|
||||
return this.displayNotification(title, message, 'warning', true, 'o_partner_autocomplete_test_notify');
|
||||
return this.displayNotification({
|
||||
type: 'warning',
|
||||
title: title,
|
||||
message: message,
|
||||
sticky: sticky,
|
||||
className: 'o_partner_autocomplete_test_notify'
|
||||
});
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,43 +14,43 @@ tour.register('test_error_website', {
|
||||
trigger: 'a[href="/test_user_error_json"]',
|
||||
}, {
|
||||
content: "rpc user error modal has message",
|
||||
extra_trigger: 'div.o_dialog_warning.modal-body:contains("This is a user rpc test")',
|
||||
trigger: 'button.btn.btn-primary',
|
||||
extra_trigger: 'div.toast-body:contains("This is a user rpc test")',
|
||||
trigger: 'button.o_notification_close',
|
||||
}, {
|
||||
content: "trigger rpc access error",
|
||||
trigger: 'a[href="/test_access_error_json"]',
|
||||
}, {
|
||||
content: "rpc access error modal has message",
|
||||
extra_trigger: 'div.o_dialog_warning.modal-body:contains("This is an access rpc test")',
|
||||
trigger: 'button.btn.btn-primary',
|
||||
extra_trigger: 'div.toast-body:contains("This is an access rpc test")',
|
||||
trigger: 'button.o_notification_close',
|
||||
}, {
|
||||
content: "trigger validation rpc error",
|
||||
trigger: 'a[href="/test_validation_error_json"]',
|
||||
}, {
|
||||
content: "rpc validation error modal has message",
|
||||
extra_trigger: 'div.o_dialog_warning.modal-body:contains("This is a validation rpc test")',
|
||||
trigger: 'button.btn.btn-primary',
|
||||
extra_trigger: 'div.toast-body:contains("This is a validation rpc test")',
|
||||
trigger: 'button.o_notification_close',
|
||||
}, {
|
||||
content: "trigger rpc missing error",
|
||||
trigger: 'a[href="/test_missing_error_json"]',
|
||||
}, {
|
||||
content: "rpc missing error modal has message",
|
||||
extra_trigger: 'div.o_dialog_warning.modal-body:contains("This is a missing rpc test")',
|
||||
trigger: 'button.btn.btn-primary',
|
||||
extra_trigger: 'div.toast-body:contains("This is a missing rpc test")',
|
||||
trigger: 'button.o_notification_close',
|
||||
}, {
|
||||
content: "trigger rpc error 403",
|
||||
trigger: 'a[href="/test_access_denied_json"]',
|
||||
}, {
|
||||
content: "rpc error 403 modal has message",
|
||||
extra_trigger: 'div.o_dialog_warning.modal-body:contains("This is an access denied rpc test")',
|
||||
trigger: 'button.btn.btn-primary',
|
||||
extra_trigger: 'div.toast-body:contains("This is an access denied rpc test")',
|
||||
trigger: 'button.o_notification_close',
|
||||
}, {
|
||||
content: "trigger rpc missing error",
|
||||
trigger: 'a[href="/test_karma_error_json"]',
|
||||
}, {
|
||||
content: "rpc missing error modal has message",
|
||||
extra_trigger: 'div.o_dialog_warning.modal-body:contains("This is a karma rpc test")',
|
||||
trigger: 'button.btn.btn-primary',
|
||||
extra_trigger: 'div.toast-body:contains("This is a karma rpc test")',
|
||||
trigger: 'button.o_notification_close',
|
||||
}, {
|
||||
content: "trigger rpc error 500",
|
||||
trigger: 'a[href="/test_internal_error_json"]',
|
||||
|
||||
@@ -331,7 +331,7 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi
|
||||
* @private
|
||||
*/
|
||||
_onConnectionLost: function () {
|
||||
this.connectionNotificationID = this.call('notification', 'notify', {
|
||||
this.connectionNotificationID = this.displayNotification({
|
||||
title: _t('Connection lost'),
|
||||
message: _t('Trying to reconnect...'),
|
||||
sticky: true
|
||||
@@ -345,7 +345,8 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi
|
||||
_onConnectionRestored: function () {
|
||||
if (this.connectionNotificationID) {
|
||||
this.call('notification', 'close', this.connectionNotificationID);
|
||||
this.call('notification', 'notify', {
|
||||
this.displayNotification({
|
||||
type: 'info',
|
||||
title: _t('Connection restored'),
|
||||
message: _t('You are back online'),
|
||||
sticky: false
|
||||
|
||||
@@ -225,34 +225,42 @@ var ServicesMixin = {
|
||||
/**
|
||||
* Displays a notification.
|
||||
*
|
||||
* @param {string} title
|
||||
* @param {string} [message]
|
||||
* @param {string} [type='warning'] 'info', 'success', 'warning', 'danger' or ''
|
||||
* @param {boolean} [sticky=false]
|
||||
* @param {string} [className]
|
||||
* @param {Object} options
|
||||
* @param {string} options.title
|
||||
* @param {string} [options.subtitle]
|
||||
* @param {string} [options.message]
|
||||
* @param {string} [options.type='warning'] 'info', 'success', 'warning', 'danger' or ''
|
||||
* @param {boolean} [options.sticky=false]
|
||||
* @param {string} [options.className]
|
||||
*/
|
||||
displayNotification: function (title, message, type, sticky, className) {
|
||||
return this.call('notification', 'notify', {
|
||||
type: type,
|
||||
displayNotification: function (options) {
|
||||
return this.call('notification', 'notify', options);
|
||||
},
|
||||
/**
|
||||
* @deprecated will be removed as soon as the notification system is reviewed
|
||||
* @see displayNotification
|
||||
*/
|
||||
do_notify: function (title, message, sticky, className) {
|
||||
return this.displayNotification({
|
||||
type: 'warning',
|
||||
title: title,
|
||||
message: message,
|
||||
sticky: sticky,
|
||||
className: className,
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @deprecated will be removed as soon as the notification system is reviewed
|
||||
* @see displayNotification
|
||||
*/
|
||||
do_notify: function (title, message, sticky, className) {
|
||||
return this.displayNotification(title, message, 'warning', sticky, className);
|
||||
},
|
||||
/**
|
||||
* @deprecated will be removed as soon as the notification system is reviewed
|
||||
* @see displayNotification
|
||||
*/
|
||||
do_warn: function (title, message, sticky, className) {
|
||||
return this.displayNotification(title, message, 'danger', sticky, className);
|
||||
return this.displayNotification({
|
||||
type: 'danger',
|
||||
title: title,
|
||||
message: message,
|
||||
sticky: sticky,
|
||||
className: className,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@ odoo.define('web.CrashManager', function (require) {
|
||||
var ajax = require('web.ajax');
|
||||
var core = require('web.core');
|
||||
var Dialog = require('web.Dialog');
|
||||
var mixins = require('web.mixins');
|
||||
var ServicesMixin = require('web.ServicesMixin');
|
||||
var ServiceProviderMixin = require('web.ServiceProviderMixin');
|
||||
var Widget = require('web.Widget');
|
||||
|
||||
var _t = core._t;
|
||||
@@ -75,12 +78,14 @@ var WarningDialog = CrashManagerDialog.extend({
|
||||
},
|
||||
});
|
||||
|
||||
var CrashManager = core.Class.extend({
|
||||
var CrashManager = core.Class.extend(mixins.EventDispatcherMixin, ServicesMixin, ServiceProviderMixin,{
|
||||
init: function () {
|
||||
var self = this;
|
||||
this.active = true;
|
||||
this.isConnected = true;
|
||||
|
||||
mixins.EventDispatcherMixin.init.call(this);
|
||||
|
||||
// crash manager integration
|
||||
core.bus.on('rpc_error', this, this.rpc_error);
|
||||
window.onerror = function (message, file, line, col, error) {
|
||||
@@ -139,6 +144,7 @@ var CrashManager = core.Class.extend({
|
||||
ev.preventDefault();
|
||||
}
|
||||
});
|
||||
ServiceProviderMixin.init.call(this);
|
||||
},
|
||||
enable: function () {
|
||||
this.active = true;
|
||||
@@ -192,7 +198,7 @@ var CrashManager = core.Class.extend({
|
||||
data: _.extend({}, error.data,
|
||||
{
|
||||
message: error.data.arguments[1],
|
||||
title: error.data.arguments[0] !== 'Warning' ? (" - " + error.data.arguments[0]) : '',
|
||||
title: error.data.arguments[0] !== 'Warning' ? error.data.arguments[0] : '',
|
||||
})
|
||||
});
|
||||
}
|
||||
@@ -213,14 +219,11 @@ var CrashManager = core.Class.extend({
|
||||
data: _.extend({}, error.data,
|
||||
{
|
||||
message: error.data.arguments[0],
|
||||
title: map_title[error.data.exception_type] !== 'Warning' ? (" - " + map_title[error.data.exception_type]) : '',
|
||||
title: map_title[error.data.exception_type] !== 'Warning' ? map_title[error.data.exception_type] : '',
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
this.show_warning(error);
|
||||
//InternalError
|
||||
|
||||
} else {
|
||||
this.show_error(error);
|
||||
}
|
||||
@@ -230,12 +233,14 @@ var CrashManager = core.Class.extend({
|
||||
return;
|
||||
}
|
||||
var message = error.data ? error.data.message : error.message;
|
||||
return new WarningDialog(this, {
|
||||
title: _.str.capitalize(error.type) || _t("Odoo Warning"),
|
||||
subtitle: error.data.title,
|
||||
}, {
|
||||
var title = _.str.capitalize(error.type) || _t("Oops Something went wrong !");
|
||||
var subtitle = error.data ? error.data.title : error.title;
|
||||
this.displayNotification({
|
||||
title: title,
|
||||
message: message,
|
||||
}).open();
|
||||
subtitle: subtitle,
|
||||
sticky: true,
|
||||
});
|
||||
},
|
||||
show_error: function (error) {
|
||||
if (!this.active) {
|
||||
|
||||
@@ -60,6 +60,7 @@ var NotificationService = AbstractService.extend({
|
||||
* @param {function} [params.Notification] javascript class of a notification
|
||||
* to instantiate by default use 'web.Notification'
|
||||
* @param {string} params.title notification title
|
||||
* @param {string} params.subtitle notification subtitle
|
||||
* @param {string} params.message notification main message
|
||||
* @param {string} params.type 'notification' or 'warning'
|
||||
* @param {boolean} [params.sticky=false] if true, the notification will stay
|
||||
|
||||
@@ -25,6 +25,7 @@ var Notification = Widget.extend({
|
||||
* @param {Widget} parent
|
||||
* @param {Object} params
|
||||
* @param {string} params.title
|
||||
* @param {string} params.subtitle
|
||||
* @param {string} [params.message]
|
||||
* @param {string} [params.type='warning'] 'info', 'success', 'warning', 'danger' or ''
|
||||
* @param {boolean} [params.sticky=false] if true, the notification will
|
||||
@@ -41,6 +42,7 @@ var Notification = Widget.extend({
|
||||
init: function (parent, params) {
|
||||
this._super.apply(this, arguments);
|
||||
this.title = params.title;
|
||||
this.subtitle = params.subtitle;
|
||||
this.message = params.message;
|
||||
this.buttons = params.buttons || [];
|
||||
this.sticky = !!this.buttons.length || !!params.sticky;
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
<span class="d-inline" aria-hidden="true">&times;</span>
|
||||
</button>
|
||||
</div>
|
||||
<div t-if="widget.message or widget.buttons.length" class="toast-body">
|
||||
<div t-if="widget.message or widget.subtitle or widget.buttons.length" class="toast-body">
|
||||
<strong t-if="widget.subtitle" t-raw="widget.subtitle"
|
||||
class="o_notification_subtitle"/>
|
||||
<div t-if="widget.message" t-raw="widget.message"
|
||||
class="o_notification_content"/>
|
||||
<div t-if="widget.buttons.length" class="mt-2 o_notification_buttons">
|
||||
|
||||
Reference in New Issue
Block a user