diff --git a/addons/website_forum/controllers/main.py b/addons/website_forum/controllers/main.py index 86145ae8add..2e7338b0183 100644 --- a/addons/website_forum/controllers/main.py +++ b/addons/website_forum/controllers/main.py @@ -243,13 +243,20 @@ class website_forum(http.Controller): def register_question(self, forum, **question): cr, uid, context = request.cr, request.uid, request.context create_context = dict(context) + + tags = question.get('question_tags').strip('[]').replace('"','').split(",") + tag_ids = request.registry['website.forum.tag'].search(cr, uid, [('name', 'in', tags)], context=context) + question_tags = [] + for tag in tag_ids: + question_tags.append((4,tag)) + new_question_id = request.registry['website.forum.post'].create( request.cr, request.uid, { 'user_id': uid, 'forum_id': forum.id, 'name': question.get('question_name'), 'content': question.get('question_content'), - #'tags' : question.get('question_tags'), + 'tags' : question_tags, 'state': 'active', 'active': True, }, context=create_context) @@ -414,8 +421,13 @@ class website_forum(http.Controller): @http.route('/forum//edit/question/', type='http', auth="user", multilang=True, website=True) def edit_question(self, forum, post, **kwarg): + tags = "" + for tag_name in post.tags: + tags += tag_name.name + "," + values = { 'post': post, + 'tags': tags, 'forum': forum, 'searches': kwarg, 'notifications': self._get_notifications(), @@ -424,10 +436,16 @@ class website_forum(http.Controller): @http.route('/forum//question/savequestion/', type='http', auth="user", multilang=True, methods=['POST'], website=True) def save_edited_question(self, forum, **post): - request.registry['website.forum.post'].write( request.cr, request.uid, [int(post.get('post_id'))], { + cr, uid, context = request.cr, request.uid, request.context + tags = post.get('question_tag').strip('[]').replace('"','').split(",") + tag_ids = request.registry['website.forum.tag'].search(cr, uid, [('name', 'in', tags)], context=context) + question_tags = [(6, 0, tag_ids)] + + request.registry['website.forum.post'].write(cr, uid, [int(post.get('post_id'))], { 'content': post.get('answer_content'), 'name': post.get('question_name'), - }, context=request.context) + 'tags' : question_tags, + }, context=context) return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.get('post_id'))) @http.route('/forum//answer//edit/', type='http', auth="user", multilang=True, website=True) @@ -539,3 +557,7 @@ class website_forum(http.Controller): request.registry['website.forum.post'].unlink(request.cr, request.uid, [post.id], context=request.context) return self.post_comment(forum, post.parent_id.id, **values) + @http.route('/forum/get_tags/', type='json', auth="public", multilang=True, methods=['POST'], website=True) + def tag_read(self, **kwarg): + tags = request.registry['website.forum.tag'].search_read(request.cr, request.uid, [],['name'], context=request.context) + return [ tag['name'] for tag in tags] diff --git a/addons/website_forum/static/src/css/website_forum.css b/addons/website_forum/static/src/css/website_forum.css index b88ab71619b..5263b7beb79 100644 --- a/addons/website_forum/static/src/css/website_forum.css +++ b/addons/website_forum/static/src/css/website_forum.css @@ -44,3 +44,15 @@ .oe_answer_false { color: #999 } + +.text-core .text-wrap textarea, .text-core .text-wrap input, .text-core .text-wrap .text-dropdown, .text-core .text-wrap .text-prompt, .text-core .text-wrap .text-tags .text-tag .text-button { + font: 1.2em "Helvetica Neue",Helvetica,Arial,sans-serif !important; +} + +.text-core .text-wrap .text-tags .text-tag .text-button { + height: 1.2em !important; +} + +#question_tag{ + width: 825px !important; +} \ No newline at end of file diff --git a/addons/website_forum/static/src/js/website_forum.editor.js b/addons/website_forum/static/src/js/website_forum.editor.js index 485cf6f41ef..7291a3b35ab 100644 --- a/addons/website_forum/static/src/js/website_forum.editor.js +++ b/addons/website_forum/static/src/js/website_forum.editor.js @@ -111,4 +111,16 @@ $(document).ready(function () { return true; }); + openerp.jsonRpc('/forum/get_tags/','call' ,{}).then(function(data){ + var previous_tags = $("#question_tag").val(); + $("#question_tag").val(""); + var array_of_tags = previous_tags.split(","); + $('#question_tag').textext({ + plugins : 'tags suggestions autocomplete', + tagsItems : array_of_tags, + suggestions :data, + }); + return true; + }); + }); \ No newline at end of file diff --git a/addons/website_forum/views/website_forum.xml b/addons/website_forum/views/website_forum.xml index 427dea1767b..287696da024 100644 --- a/addons/website_forum/views/website_forum.xml +++ b/addons/website_forum/views/website_forum.xml @@ -14,6 +14,7 @@ --> +