Skip to content
Permalink
Browse files

[IMP] website_forum: revamp design

Part of #35749
task-2024197
  • Loading branch information...
stefanorigano authored and qsm-odoo committed Aug 29, 2019
1 parent f6c8a2f commit 88179aa653fd2d8f51c7f1a6d825f85c709eba66
@@ -73,10 +73,13 @@ def sitemap_forum(env, rule, qs):
'''/forum/<model("forum.forum"):forum>/tag/<model("forum.tag"):tag>/questions''',
'''/forum/<model("forum.forum"):forum>/tag/<model("forum.tag"):tag>/questions/page/<int:page>''',
], type='http', auth="public", website=True, sitemap=sitemap_forum)
def questions(self, forum, tag=None, page=1, filters='all', sorting=None, search='', **post):
def questions(self, forum, tag=None, page=1, filters='all', my=None, sorting=None, search='', **post):
if not forum.can_access_from_current_website():
raise werkzeug.exceptions.NotFound()

website_domain = request.website.website_domain()
forums_count = request.env['forum.forum'].search_count(website_domain)

Post = request.env['forum.post']

domain = [('forum_id', '=', forum.id), ('parent_id', '=', False), ('state', '=', 'active')]
@@ -86,8 +89,19 @@ def questions(self, forum, tag=None, page=1, filters='all', sorting=None, search
domain += [('tag_ids', 'in', tag.id)]
if filters == 'unanswered':
domain += [('child_ids', '=', False)]
elif filters == 'followed':
domain += [('message_partner_ids', '=', request.env.user.partner_id.id)]
elif filters == 'solved':
domain += [('has_validated_answer', '=', True)]
elif filters == 'unsolved':
domain += [('has_validated_answer', '=', False)]

user = request.env.user

if my == 'mine':
domain += [('create_uid', '=', user.id)]
elif my == 'followed':
domain += [('message_partner_ids', '=', user.partner_id.id)]
elif my == 'favourites':
domain += [('favourite_ids', 'in', user.id)]

if sorting:
# check that sorting is valid
@@ -128,8 +142,10 @@ def questions(self, forum, tag=None, page=1, filters='all', sorting=None, search
'pager': pager,
'tag': tag,
'filters': filters,
'my': my,
'sorting': sorting,
'search': search,
'forums_count': forums_count
})
return request.render("website_forum.forum_index", values)

@@ -153,10 +169,9 @@ def tags(self, forum, tag_char=None, **post):
first_char_tag = forum.get_tags_first_char()
first_char_list = [(t, t.lower()) for t in first_char_tag if t.isalnum()]
first_char_list.insert(0, (_('All'), 'all'))
# get active first char tag
active_char_tag = first_char_list[1][1] if len(first_char_list) > 1 else 'all'
if tag_char:
active_char_tag = tag_char.lower()

active_char_tag = tag_char and tag_char.lower() or 'all'

# generate domain for searched tags
domain = [('forum_id', '=', forum.id), ('posts_count', '>', 0)]
order_by = 'name'
@@ -282,7 +297,7 @@ def forum_post(self, forum, **post):
user = request.env.user
if not user.email or not tools.single_email_re.match(user.email):
return werkzeug.utils.redirect("/forum/%s/user/%s/edit?email_required=1" % (slug(forum), request.session.uid))
values = self._prepare_user_values(forum=forum, searches={}, header={'ask_hide': True})
values = self._prepare_user_values(forum=forum, searches={}, header={'ask_hide': True}, new_question=True)
return request.render("website_forum.new_question", values)

@http.route(['/forum/<model("forum.forum"):forum>/new',
@@ -349,6 +364,7 @@ def post_edit(self, forum, post, **kwargs):
values.update({
'tags': tags,
'post': post,
'is_edit': True,
'is_answer': bool(post.parent_id),
'searches': kwargs,
'content': post.name,
@@ -518,8 +534,8 @@ def open_partner(self, forum, partner_id=0, **post):
# -----------------------------------

@http.route(['/forum/<model("forum.forum"):forum>/user/<int:user_id>'], type='http', auth="public", website=True)
def view_user_forum_profile(self, forum, user_id, **post):
return werkzeug.utils.redirect('/profile/user/' + str(user_id) + '?forum_id=' + str(forum.id))
def view_user_forum_profile(self, forum, user_id, forum_origin, **post):
return werkzeug.utils.redirect('/profile/user/' + str(user_id) + '?forum_id=' + str(forum.id) + '&forum_origin=' + str(forum_origin))

def _prepare_user_profile_values(self, user, **post):
values = super(WebsiteForum, self)._prepare_user_profile_values(user, **post)
@@ -3,6 +3,9 @@
<data noupdate="1">
<record id="forum_help" model="forum.forum">
<field name="name">Help</field>
<field name="description">This community is for professionals and enthusiasts of our products and services.
Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.
</field>
</record>

<record id="menu_website_forums" model="website.menu">
@@ -1,5 +1,3 @@
<h1 class="o_page_header">Guidelines</h1>

<div id="accordion">
<div class="card mb-2 bg-100">
<a href="#collapseOne" class="card-header" id="headingOne" data-toggle="collapse" aria-expanded="false" aria-controls="collapseOne">
@@ -37,16 +37,11 @@ def _get_default_faq(self):
help='Questions mode: only one answer allowed\n Discussions mode: multiple answers allowed')
active = fields.Boolean(default=True)
faq = fields.Html('Guidelines', default=_get_default_faq, translate=html_translate, sanitize=False)
description = fields.Text(
'Description',
translate=True,
default=lambda s: _('This community is for professionals and enthusiasts of our products and services. '
'Share and discuss the best content and new marketing ideas, '
'build your professional profile and become a better marketer together.'))
description = fields.Text('Description', translate=True)
welcome_message = fields.Html(
'Welcome Message',
translate=True,
default="""<section class="bg-info shadow">
default="""<section>
<div class="container py-5">
<div class="row">
<div class="col-lg-12">
@@ -57,7 +52,7 @@ def _get_default_faq(self):
</p>
</div>
<div class="col text-center mt-3">
<a href="#" class="js_close_intro btn btn-outline-light">Hide Intro</a>
<a href="#" class="js_close_intro btn btn-outline-light mr-2">Hide Intro</a>
<a class="btn btn-light forum_register_url" href="/web/login">Register</a>
</div>
</div>
@@ -22,7 +22,7 @@ odoo.define("website_forum.tour_forum", function (require) {
content: _t("Click <em>Continue</em> to create the forum."),
position: "right",
}, {
trigger: ".btn-lg.btn-block",
trigger: ".o_forum_ask_btn",
position: "left",
content: _t("Ask the question in this forum by clicking on the button."),
}, {
@@ -67,7 +67,7 @@ odoo.define("website_forum.tour_forum", function (require) {
trigger: ".modal-header button.close",
auto: true,
}, {
trigger: "a[data-karma=\"20\"]:first",
trigger: ".accept_answer[data-karma=\"20\"]:first",
content: _t("Click here to accept this answer."),
position: "right",
}]);
@@ -22,11 +22,8 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({
'click .flag:not(.karma_required)': '_onFlagAlertClick',
'click .vote_up:not(.karma_required), .vote_down:not(.karma_required)': '_onVotePostClick',
'click .o_js_validation_queue a[href*="/validate"]': '_onValidationQueueClick',
'click .accept_answer:not(.karma_required)': '_onAcceptAnswerClick',
'click .validate_answer [data-href]': '_onAcceptAnswerClick',
'mouseenter .validate_answer [data-href]': '_onRemoveValidAnswerMouse',
'mouseleave .validate_answer [data-href]': '_onRemoveValidAnswerMouse',
'click .favourite_question': '_onFavoriteQuestionClick',
'click .o_wforum_validate_toggler:not(.karma_required)': '_onAcceptAnswerClick',
'click .o_wforum_favourite_toggle': '_onFavoriteQuestionClick',
'click .comment_delete': '_onDeleteCommentClick',
'click .js_close_intro': '_onCloseIntroClick',
},
@@ -49,6 +46,10 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({
);
$('.forum_register_url').attr('href', forumLogin);

// Initialize forum's tooltips
this.$('[data-toggle="tooltip"]').tooltip({delay: 0});
this.$('[data-toggle="popover"]').popover({offset: 8});

$('input.js_select2').select2({
tags: true,
tokenSeparators: [',', ' ', '_'],
@@ -120,16 +121,20 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({
['font', ['bold', 'italic', 'underline', 'clear']],
['para', ['ul', 'ol', 'paragraph']],
['table', ['table']],
['view', ['codeview']],
];
if (hasFullEdit) {
toolbar.push(['insert', ['linkPlugin', 'mediaPlugin']]);
}
toolbar.push(['history', ['undo', 'redo']]);

var options = {
height: 150,
height: 200,
minHeight: 80,
toolbar: toolbar,
styleWithSpan: false,
// Remove huge titles from the style list
styleTags: ['p', 'blockquote', 'pre', 'h4', 'h5', 'h6'],
recordInfo: {
context: self._getContext(),
res_model: 'forum.post',
@@ -159,6 +164,15 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({
}
});

_.each(this.$('.o_wforum_bio_popover'), authorBox => {
$(authorBox).popover({
trigger: 'hover',
offset: 10,
animation: false,
html: true,
});
});

return this._super.apply(this, arguments);
},

@@ -296,17 +310,14 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({
sticky: false,
});
} else {
$link.parent().find('.vote_count').html(data.vote_count);
if (data.user_vote === 0) {
$link.parent().find('.text-success').removeClass('text-success');
$link.parent().find('.text-warning').removeClass('text-warning');
} else {
if (data.user_vote === 1) {
$link.addClass('text-success');
} else {
$link.addClass('text-warning');
}
}
var newClass = $link.data('active-class');

$link.addClass('disabled ' + newClass)
.siblings().removeClass('text-success text-danger text-muted disabled o_forum_vote_animate');

setTimeout(function () {
$link.siblings('.vote_count').html(data.vote_count).addClass('o_forum_vote_animate ' + newClass);
}, 0);
}
});
},
@@ -333,11 +344,11 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({
* @param {Event} ev
*/
_onAcceptAnswerClick: function (ev) {
var self = this;
ev.preventDefault();
var self = this;
var $acceptAnswerLinks = this.$('.accept_answer');
var $link = $(ev.currentTarget);
var target = $link.data('target');

this._rpc({
route: $link.data('href'),
}).then(function (data) {
@@ -352,42 +363,20 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({
sticky: false,
});
} else {
$acceptAnswerLinks.removeClass('oe_answer_true')
.addClass('oe_answer_false');
$link.toggleClass('oe_answer_true', !!data)
.toggleClass('oe_answer_false', !data);

// TODO in master, review the utility of this function...
self._onCheckAnswerStatus(ev);
_.each(self.$('.forum_answer'), function (answer) {
var $answer = $(answer);
var isCorrect = $answer.is(target) && data;
var $toggler = $answer.find('.o_wforum_validate_toggler');
var newHelper = isCorrect ? $toggler.data('helper-decline') : $toggler.data('helper-accept');

// If we are removing an accepted answer, reload the page as the
// design is quite different with or without an accepted answer.
if ($link.closest('.validate_answer').length) {
window.location.reload();
}
$answer.toggleClass('o_wforum_answer_correct', isCorrect);
$toggler.tooltip('dispose')
.attr('data-original-title', newHelper)
.tooltip({delay: 0});
});
}
});
},
/**
* @private
* @param {Event} ev
*/
_onRemoveValidAnswerMouse: function (ev) {
var hover = (ev.type === 'mouseenter');
$(ev.currentTarget).find('.fa')
.toggleClass('fa-times-circle text-danger', hover)
.toggleClass('fa-check-circle text-success', !hover);
},
/**
* @private
* @param {Event} ev
*/
_onCheckAnswerStatus: function (ev) {
_.each(this.$('.accept_answer'), function (link) {
var $link = $(link);
$link.toggleClass('text-success', $link.hasClass('oe_answer_true'));
});
},
/**
* @private
* @param {Event} ev
@@ -398,7 +387,8 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({
this._rpc({
route: $link.data('href'),
}).then(function (data) {
$link.toggleClass('forum_favourite_question', !!data);
$link.toggleClass('o_wforum_gold fa-star', data)
.toggleClass('fa-star-o text-muted', !data);
});
},
/**
@@ -408,10 +398,20 @@ publicWidget.registry.websiteForum = publicWidget.Widget.extend({
_onDeleteCommentClick: function (ev) {
ev.preventDefault();
var $link = $(ev.currentTarget);
var $container = $link.closest('.o_wforum_post_comments_container');

this._rpc({
route: $link.closest('form').attr('action'),
}).then(function () {
$link.parents('.comment').first().remove();
$link.parents('.o_wforum_post_comment').first().remove();

if ($container.find('.o_wforum_post_comment').length > 0) {
$container.find('.o_wforum_comments_count').text(function () {
return parseInt($(this).text()) - 1;
});
} else {
$container.find('.o_wforum_comments_count_header').remove();
}
});
},
/**

0 comments on commit 88179aa

Please sign in to comment.
You can’t perform that action at this time.