summaryrefslogtreecommitdiff
path: root/addons/website_forum/static
diff options
context:
space:
mode:
authorOkan SUMER (osu) <osu@odoo.com>2020-03-19 09:42:59 +0000
committerJeremy Kersten <jke@odoo.com>2020-05-14 18:27:00 +0000
commit645056554ee38b5b96aeb53b6ed59cdb8e41b74c (patch)
treefd3da254310ab1051a54d0376b5773b78bca3b85 /addons/website_forum/static
parentb86902040169c612544cd710c6b0025c8b43ddbe (diff)
[IMP] website_forum: frontend improvements and corrections
This commit adds new features and corrects some others in the frontend of website_forum app. - In the "about" section of a forum, use the s_accordion instead of a custom one for the first 3 elements, the last one is on a new page accessible from a link below the accordion - Cut the description after a specific amount of characters in the page where all forum are listed - In that same view, create options that show the number of post and the last post a forum has. Create an option to render forums in list view - Allow the user to cancel his vote (down or up) - Hide the answer box in the post view. Make it appear when the user click on the "answer" button - Use a JS public widget to validate a Post form (new, save, comment) - Enable the modification of a forum's image from the frontend - Hide Solved/Unsolved categories in "Discussion" forums - Disable the possibility to add snippets to an answer - Corrections of tours that broke after these modifications Part of https://github.com/odoo/odoo/pull/46634 task-2201708
Diffstat (limited to 'addons/website_forum/static')
-rw-r--r--addons/website_forum/static/src/js/tours/website_forum.js8
-rw-r--r--addons/website_forum/static/src/js/website_forum.js70
-rw-r--r--addons/website_forum/static/src/js/website_forum.share.js18
-rw-r--r--addons/website_forum/static/tests/tours/website_forum_question.js8
4 files changed, 84 insertions, 20 deletions
diff --git a/addons/website_forum/static/src/js/tours/website_forum.js b/addons/website_forum/static/src/js/tours/website_forum.js
index b8bd5c67a11..55f57457ae6 100644
--- a/addons/website_forum/static/src/js/tours/website_forum.js
+++ b/addons/website_forum/static/src/js/tours/website_forum.js
@@ -39,7 +39,13 @@ odoo.define("website_forum.tour_forum", function (require) {
extra_trigger: 'div.modal.modal_shown',
trigger: ".modal-header button.close",
auto: true,
- }, {
+ },
+ {
+ trigger: "a:contains(\"Answer\").collapsed",
+ content: _t("Click to answer."),
+ position: "bottom",
+ },
+ {
trigger: ".note-editable p",
content: _t("Put your answer here."),
position: "bottom",
diff --git a/addons/website_forum/static/src/js/website_forum.js b/addons/website_forum/static/src/js/website_forum.js
index 5b22fa03c01..dcbca2e364a 100644
--- a/addons/website_forum/static/src/js/website_forum.js
+++ b/addons/website_forum/static/src/js/website_forum.js
@@ -27,6 +27,7 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({
'click .o_wforum_favourite_toggle': '_onFavoriteQuestionClick',
'click .comment_delete': '_onDeleteCommentClick',
'click .js_close_intro': '_onCloseIntroClick',
+ 'submit .js_wforum_submit_form:has(:not(.karma_required).o_wforum_submit_post)': '_onSubmitForm',
},
/**
@@ -164,6 +165,12 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({
});
});
+ this.$('#post_reply').on('shown.bs.collapse', function (e) {
+ $('html').animate({
+ scrollTop: $('#post_reply').offset().top - ($(window).innerHeight() - $('#post_reply').innerHeight())
+ }, 500);
+ });
+
return this._super.apply(this, arguments);
},
@@ -172,6 +179,59 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({
//--------------------------------------------------------------------------
/**
+ *
+ * @override
+ * @param {Event} ev
+ */
+ _onSubmitForm: function (ev) {
+ let validForm = true;
+
+ let $form = $(ev.currentTarget);
+ let $title = $form.find('input[name=post_name]');
+ let $textarea = $form.find('textarea[name=content]');
+ // It's not really in the textarea that the user write at first
+ let textareaContent = $form.find('.o_wysiwyg_wrapper .note-editable.panel-body').text().trim();
+
+ if ($title.length && $title[0].required) {
+ if ($title.val()) {
+ $title.removeClass('is-invalid');
+ } else {
+ $title.addClass('is-invalid');
+ validForm = false;
+ }
+ }
+
+ // Because the textarea is hidden, we add the red or green border to its container
+ if ($textarea[0].required) {
+ let $textareaContainer = $form.find('.o_wysiwyg_wrapper .note-editor.panel.panel-default');
+ if (!textareaContent.length) {
+ $textareaContainer.addClass('border border-danger rounded-top');
+ validForm = false;
+ } else {
+ $textareaContainer.removeClass('border border-danger rounded-top');
+ }
+ }
+
+ if (validForm) {
+ // Stores social share data to display modal on next page.
+ if ($form.has('.oe_social_share_call').length) {
+ sessionStorage.setItem('social_share', JSON.stringify({
+ targetType: $(ev.currentTarget).find('.o_wforum_submit_post').data('social-target-type'),
+ }));
+ }
+ } else {
+ ev.preventDefault();
+ setTimeout(function() {
+ var $buttons = $(ev.currentTarget).find('button[type="submit"], a.a-submit');
+ _.each($buttons, function (btn) {
+ let $btn = $(btn);
+ $btn.find('i').remove();
+ $btn.prop('disabled', false);
+ });
+ }, 0);
+ }
+ },
+ /**
* @private
* @param {Event} ev
*/
@@ -317,10 +377,20 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({
if (userVote === 1) {
$voteUp.addClass('text-success');
$voteCount.addClass('text-success');
+ $voteDown.removeClass('karma_required');
}
if (userVote === -1) {
$voteDown.addClass('text-danger');
$voteCount.addClass('text-danger');
+ $voteUp.removeClass('karma_required');
+ }
+ if (userVote === 0) {
+ if (!$voteDown.data('can-downvote')) {
+ $voteDown.addClass('karma_required');
+ }
+ if (!$voteUp.data('can-upvote')) {
+ $voteUp.addClass('karma_required');
+ }
}
$voteCount.html(data['vote_count']).addClass('o_forum_vote_animate');
}
diff --git a/addons/website_forum/static/src/js/website_forum.share.js b/addons/website_forum/static/src/js/website_forum.share.js
index 0545d775a81..68a2b8f3b72 100644
--- a/addons/website_forum/static/src/js/website_forum.share.js
+++ b/addons/website_forum/static/src/js/website_forum.share.js
@@ -76,9 +76,6 @@ var ForumShare = publicWidget.registry.socialShare.extend({
publicWidget.registry.websiteForumShare = publicWidget.Widget.extend({
selector: '.website_forum',
- events: {
- 'click :not(.karma_required).oe_social_share_call': '_onShareCallClick',
- },
/**
* @override
@@ -98,20 +95,5 @@ publicWidget.registry.websiteForumShare = publicWidget.Widget.extend({
return this._super.apply(this, arguments);
},
-
- //--------------------------------------------------------------------------
- // Handlers
- //--------------------------------------------------------------------------
-
- /**
- * Stores social share data to display modal on next page.
- *
- * @private
- */
- _onShareCallClick: function (ev) {
- sessionStorage.setItem('social_share', JSON.stringify({
- targetType: $(ev.currentTarget).data('social-target-type'),
- }));
- },
});
});
diff --git a/addons/website_forum/static/tests/tours/website_forum_question.js b/addons/website_forum/static/tests/tours/website_forum_question.js
index b2f549aed83..be292067db6 100644
--- a/addons/website_forum/static/tests/tours/website_forum_question.js
+++ b/addons/website_forum/static/tests/tours/website_forum_question.js
@@ -35,7 +35,13 @@ odoo.define('website_forum.tour_forum_question', function (require) {
content: "Close modal once modal animation is done.",
extra_trigger: 'div.modal.modal_shown',
trigger: ".modal-header button.close",
- }, {
+ },
+ {
+ trigger: "a:contains(\"Answer\").collapsed",
+ content: "Click to answer.",
+ position: "bottom",
+ },
+ {
content: "Put your answer here.",
trigger: '.note-editable p',
run: 'text First Answer',