From a7d5bb103586b2c133265ba251174c0544ae2fff Mon Sep 17 00:00:00 2001 From: Dhruv Patel Date: Mon, 26 Jul 2021 10:27:27 +0000 Subject: [PATCH] [FIX] website_forum: restore karma guidelines link in notifications The link was added as text instead of HTML since the notification/t-raw refactoring. task-2601633 closes odoo/odoo#74276 X-original-commit: 3b5b460f20295983582946bfd841211884456cc5 Signed-off-by: Quentin Smetz (qsm) Co-authored-by: qsm-odoo --- .../static/src/js/website_forum.js | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/addons/website_forum/static/src/js/website_forum.js b/addons/website_forum/static/src/js/website_forum.js index 8b5dec34d9c..42fcdb64044 100644 --- a/addons/website_forum/static/src/js/website_forum.js +++ b/addons/website_forum/static/src/js/website_forum.js @@ -230,28 +230,35 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({ * @param {Event} ev */ _onKarmaRequiredClick: function (ev) { - var $karma = $(ev.currentTarget); - var karma = $karma.data('karma'); - var forum_id = $('#wrapwrap').data('forum_id'); + const karma = parseInt(ev.currentTarget.dataset.karma); if (!karma) { return; } + ev.preventDefault(); - var msg = karma + ' ' + _t("karma is required to perform this action. "); - var title = _t("Karma Error"); - if (forum_id) { - msg += '' + _t("Read the guidelines to know how to gain karma.") + ''; - } - if (session.is_website_user) { - msg = _t("Sorry you must be logged in to perform this action"); - title = _t("Access Denied"); - } - this.displayNotification({ - message: msg, - title: title, - sticky: false, + const forumID = parseInt(document.getElementById('wrapwrap').dataset.forum_id); + const notifOptions = { type: "warning", - }); + sticky: false, + }; + if (session.is_website_user) { + notifOptions.title = _t("Access Denied"); + notifOptions.message = _t("Sorry you must be logged in to perform this action"); + } else { + notifOptions.title = _t("Karma Error"); + // FIXME this translation is bad, the number should be part of the + // translation, to fix in the appropriate version + notifOptions.message = `${karma} ${_t("karma is required to perform this action. ")}`; + if (forumID) { + notifOptions.messageIsHtml = true; + const linkLabel = _.escape(_t("Read the guidelines to know how to gain karma.")); + notifOptions.message = ` + ${_.escape(notifOptions.message)}
+ ${linkLabel} + `; + } + } + this.displayNotification(notifOptions); }, /** * @private