From 3288f07eaa23961f075139ba957485b5ccca93d0 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Tue, 18 Nov 2014 14:31:36 +0100 Subject: [PATCH] [FIX] website_forum: Use if_dom_contains to check if we need to load js Fix bug where _tag_to_write_vals was called like old API but model converter was new api Move IsKarmaValid and Load CKE only in website_forum context --- addons/website_forum/controllers/main.py | 4 +- .../static/src/js/website_forum.js | 38 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/addons/website_forum/controllers/main.py b/addons/website_forum/controllers/main.py index 95e604aeda4..03416f436ef 100644 --- a/addons/website_forum/controllers/main.py +++ b/addons/website_forum/controllers/main.py @@ -223,7 +223,7 @@ class WebsiteForum(http.Controller): else: question_tag_ids.append((0, 0, {'name': tag, 'forum_id': forum.id})) elif tag_version == "select2": - question_tag_ids = forum._tag_to_write_vals(cr, uid, post.get('question_tags', ''), context=context) + question_tag_ids = forum._tag_to_write_vals(post.get('question_tags', '')) new_question_id = request.registry['forum.post'].create( request.cr, request.uid, { @@ -413,7 +413,7 @@ class WebsiteForum(http.Controller): question_tags.append(new_tag) tags_val = [(6, 0, question_tags)] elif tag_version == "select2": # new version - tags_val = forum._tag_to_write_vals(cr, uid, kwargs.get('question_tag', ''), context=context) + tags_val = forum._tag_to_write_vals(kwargs.get('question_tag', '')) vals = { 'tag_ids': tags_val, diff --git a/addons/website_forum/static/src/js/website_forum.js b/addons/website_forum/static/src/js/website_forum.js index 49aa2fc29ba..3e632e3c412 100644 --- a/addons/website_forum/static/src/js/website_forum.js +++ b/addons/website_forum/static/src/js/website_forum.js @@ -1,5 +1,5 @@ $(document).ready(function () { - if ($('.website_forum').length){ + openerp.website.if_dom_contains('.website_forum', function () { $('.karma_required').on('click', function (ev) { var karma = $(ev.currentTarget).data('karma'); if (karma) { @@ -217,24 +217,24 @@ $(document).ready(function () { var editor = CKEDITOR.instances['content']; editor.on('instanceReady', CKEDITORLoadComplete); } - } + + IsKarmaValid = function(eventNumber, minKarma){ + "use strict"; + if(parseInt($("#karma").val()) >= minKarma){ + CKEDITOR.tools.callFunction(eventNumber,this); + return false; + } else { + alert("Sorry you need more than " + minKarma + " Karma."); + } + }; + + CKEDITORLoadComplete = function(){ + "use strict"; + $('.cke_button__link').attr('onclick','IsKarmaValid(33,30)'); + $('.cke_button__unlink').attr('onclick','IsKarmaValid(37,30)'); + $('.cke_button__image').attr('onclick','IsKarmaValid(41,30)'); + }; + }); }); - -function IsKarmaValid(eventNumber,minKarma){ - "use strict"; - if(parseInt($("#karma").val()) >= minKarma){ - CKEDITOR.tools.callFunction(eventNumber,this); - return false; - } else { - alert("Sorry you need more than " + minKarma + " Karma."); - } -} - -function CKEDITORLoadComplete(){ - "use strict"; - $('.cke_button__link').attr('onclick','IsKarmaValid(33,30)'); - $('.cke_button__unlink').attr('onclick','IsKarmaValid(37,30)'); - $('.cke_button__image').attr('onclick','IsKarmaValid(41,30)'); -}