summaryrefslogtreecommitdiff
path: root/addons/website_forum/static/src
diff options
context:
space:
mode:
authorfja-odoo <fja@odoo.com>2019-06-11 12:27:05 +0000
committerfja-odoo <fja@odoo.com>2019-06-28 08:53:53 +0000
commit6e55a3a49666484c38345ba85b14441dc3056ec2 (patch)
tree35f489d2e66eca339b8c54aabbf5acb908ad1fe7 /addons/website_forum/static/src
parente26d23cb971757787238d05ffaad34619c886dde (diff)
[IMP] website_forum: display forum errors with notif
Previously the Forum errors were handled with a popover, now the errors will be consistent with the crash_manager and display a toast notification via the show_warning method. Also the KarmaError were previously not displaying the karma needed to perform the action. Now it will display the amount in the error message. The CrashManager show_warning method will now take an options dictionary as a second argument to override it's default behaviour. Part of https://github.com/odoo/odoo/pull/32132 task-1894820
Diffstat (limited to 'addons/website_forum/static/src')
-rw-r--r--addons/website_forum/static/src/js/website_forum.js92
-rw-r--r--addons/website_forum/static/src/scss/website_forum.scss6
2 files changed, 35 insertions, 63 deletions
diff --git a/addons/website_forum/static/src/js/website_forum.js b/addons/website_forum/static/src/js/website_forum.js
index 51cae0cc28f..e25be65ba48 100644
--- a/addons/website_forum/static/src/js/website_forum.js
+++ b/addons/website_forum/static/src/js/website_forum.js
@@ -2,12 +2,12 @@ odoo.define('website_forum.website_forum', function (require) {
'use strict';
var core = require('web.core');
+var crash_manager = require('web.crash_manager');
var Wysiwyg = require('web_editor.wysiwyg.root');
var publicWidget = require('web.public.widget');
var session = require('web.session');
var utils = require('web.utils');
var qweb = core.qweb;
-var WebsiteProfile = require('website_profile.website_profile');
var _t = core._t;
@@ -185,20 +185,20 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({
}
ev.preventDefault();
var msg = karma + ' ' + _t("karma is required to perform this action. ");
+ var title = _t("Karma Error");
if (forum_id) {
msg += '<a class="alert-link" href="/forum/' + forum_id + '/faq">' + _t("Read the guidelines to know how to gain karma.") + '</a>';
}
if (session.is_website_user) {
msg = _t("Sorry you must be logged in to perform this action");
+ title = _t("Access Denied");
}
- var $warning = $('<div class="alert alert-danger alert-dismissible oe_forum_alert" id="karma_alert">' +
- '<button type="button" class="close notification_close" data-dismiss="alert">&times;</button>' +
- msg + '</div>');
- var $voteAlert = $('#karma_alert');
- if ($voteAlert.length) {
- $voteAlert.remove();
- }
- $karma.after($warning);
+ crash_manager.show_warning({
+ message: msg,
+ title: title,
+ }, {
+ sticky: false,
+ });
},
/**
* @private
@@ -281,35 +281,20 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({
route: $link.data('href') || ($link.attr('href') !== '#' && $link.attr('href')) || $link.closest('form').attr('action'),
}).then(function (data) {
if (data.error) {
- var $warning;
+ var message;
if (data.error === 'anonymous_user') {
- $warning = $(
- '<div class="alert alert-danger alert-dismissable oe_forum_alert" id="flag_alert">' +
- '<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">&times;</button>' +
- _t("Sorry you must be logged to flag a post") +
- '</div>'
- );
+ message = _t("Sorry you must be logged to flag a post");
} else if (data.error === 'post_already_flagged') {
- $warning = $(
- '<div class="alert alert-danger alert-dismissable oe_forum_alert" id="flag_alert">' +
- '<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">&times;</button>' +
- _t("This post is already flagged") +
- '<button type="button" class="close notification_close" t-att-id="notification.id" data-dismiss="alert" aria-label="Close">&times;</button>' +
- '</div>'
- );
+ message = _t("This post is already flagged");
} else if (data.error === 'post_non_flaggable') {
- $warning = $(
- '<div class="alert alert-danger alert-dismissable oe_forum_alert" id="flag_alert">' +
- '<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">&times;</button>' +
- _t("This post can not be flagged") +
- '<button type="button" class="close notification_close" t-att-id="notification.id" data-dismiss="alert" aria-label="Close">&times;</button>' +
- '</div>'
- );
- }
- var $flagAlert = $link.parent().find('#flag_alert');
- if ($flagAlert.length === 0) {
- $link.parent().append($warning);
+ message = _t("This post can not be flagged");
}
+ crash_manager.show_warning({
+ message: message,
+ title: _t("Access Denied"),
+ }, {
+ sticky: false,
+ });
} else if (data.success) {
var elem = $link;
if (data.success === 'post_flagged_moderator') {
@@ -337,22 +322,18 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({
route: $link.data('href'),
}).then(function (data) {
if (data.error) {
- var $warning;
+ var message;
if (data.error === 'own_post') {
- $warning = $('<div class="alert alert-danger alert-dismissable oe_forum_alert" id="vote_alert">' +
- '<button type="button" class="close notification_close" data-dismiss="alert">&times;</button>' +
- _t('Sorry, you cannot vote for your own posts') +
- '</div>');
+ message = _t('Sorry, you cannot vote for your own posts');
} else if (data.error === 'anonymous_user') {
- $warning = $('<div class="alert alert-danger alert-dismissable oe_forum_alert" id="vote_alert">' +
- '<button type="button" class="close notification_close" data-dismiss="alert">&times;</button>' +
- _t('Sorry you must be logged to vote') +
- '</div>');
- }
- var $voteAlert = $link.parent().find('#vote_alert');
- if ($voteAlert.length === 0) {
- $link.parent().append($warning);
+ message = _t('Sorry you must be logged to vote');
}
+ crash_manager.show_warning({
+ message: message,
+ title: _t("Access Denied"),
+ }, {
+ sticky: false,
+ });
} else {
$link.parent().find('.vote_count').html(data.vote_count);
if (data.user_vote === 0) {
@@ -398,17 +379,14 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({
}).then(function (data) {
if (data.error) {
if (data.error === 'anonymous_user') {
- var $warning = $(
- '<div class="alert alert-danger alert-dismissable" id="correct_answer_alert" style="position:absolute; margin-top: -30px; margin-left: 90px;">' +
- '<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">&times;</button>' +
- _t("Sorry, anonymous users cannot choose correct answer.") +
- '</div>'
- );
- }
- var $correctAnswerAlert = $link.parent().find('#correct_answer_alert');
- if ($correctAnswerAlert.length === 0) {
- $link.parent().append($warning);
+ var message = _t("Sorry, anonymous users cannot choose correct answer.");
}
+ crash_manager.show_warning({
+ message: message,
+ title: _t("Access Denied"),
+ }, {
+ sticky: false,
+ });
} else {
$link.toggleClass('oe_answer_true', !!data)
.toggleClass('oe_answer_false', !data);
diff --git a/addons/website_forum/static/src/scss/website_forum.scss b/addons/website_forum/static/src/scss/website_forum.scss
index 018bf679e8a..b6186a77d6e 100644
--- a/addons/website_forum/static/src/scss/website_forum.scss
+++ b/addons/website_forum/static/src/scss/website_forum.scss
@@ -135,12 +135,6 @@ $bronze: #eea91e;
}
}
- .oe_forum_alert {
- position: absolute;
- width: 300px;
- z-index: 9999;
- }
-
.oe_forum_email_required {
position: absolute;
margin-top: 155px;