From bac460d5bd2d0c2541182ceea9c2929bca378e81 Mon Sep 17 00:00:00 2001 From: "ajay javiya (OpenERP)" Date: Tue, 25 Mar 2014 16:34:28 +0530 Subject: [PATCH] [IMP] : ask name and email to anonymus user -> write name as author instead of anonymus in inline discussion [ADD] :add 'publish/unpublish' feature on inline comments [FIX] : nline discuss does not work on smaller devices bzr revid: aja@tinyerp.com-20140325110428-sxvcsq2wdkptr3m3 --- addons/website_blog/controllers/main.py | 32 +++++-- .../src/js/website_blog.inline.discussion.js | 84 +++++++++++++++---- .../static/src/js/website_blog.js | 7 +- .../xml/website_blog.inline.discussion.xml | 14 +++- 4 files changed, 109 insertions(+), 28 deletions(-) diff --git a/addons/website_blog/controllers/main.py b/addons/website_blog/controllers/main.py index c1e65e2a518..40a70025d17 100644 --- a/addons/website_blog/controllers/main.py +++ b/addons/website_blog/controllers/main.py @@ -214,7 +214,8 @@ class WebsiteBlog(http.Controller): body=post.get('comment'), type='comment', subtype='mt_comment', - author_id=False, + email_from = "%s <%s>" % (post.get('name'), post.get('email')), + author_id=user.partner_id.id if request.session.uid else False, discussion=post.get('discussion'), context=dict(context, mail_create_nosubcribe=True)) return message_id @@ -237,13 +238,13 @@ class WebsiteBlog(http.Controller): user = request.registry['res.users'].browse(cr, uid, uid, context=context) id = self._blog_post_message(user, blog_post_id, **post) mail_obj = request.registry.get('mail.message') - post = mail_obj.browse(cr, SUPERUSER_ID, id) + blog_post = mail_obj.browse(cr, SUPERUSER_ID, id) values = { - "author_name": post.author_id and post.author_id.name or _('Anonymous'), - "date": post.date, - "body": html2plaintext(post.body), - "author_image": post.author_id and \ - ("data:image/png;base64,%s" % post.author_id.image) or \ + "author_name": blog_post.author_id and blog_post.author_id.name or post.get('name'), + "date": blog_post.date, + "body": html2plaintext(blog_post.body), + "author_image": blog_post.author_id and \ + ("data:image/png;base64,%s" % blog_post.author_id.image) or \ '/website_blog/static/src/img/anonymous.png', } return values @@ -280,16 +281,26 @@ class WebsiteBlog(http.Controller): cr, uid, context = request.cr, request.uid, request.context mail_obj = request.registry.get('mail.message') values = [] - ids = mail_obj.search(cr, SUPERUSER_ID, [('res_id', '=', int(post_id)) ,('model','=','blog.post'), ('discussion', '=', discussion)]) + publish = False + domain = [('res_id', '=', int(post_id)) ,('model','=','blog.post'), ('discussion', '=', discussion)] + #check current user belongs to website publisher group + if request.registry['res.users'].has_group(cr, uid, 'base.group_website_publisher'): + publish = True + else: + domain.append(('website_published', '=', True)) + ids = mail_obj.search(cr, SUPERUSER_ID, domain) if ids: for post in mail_obj.browse(cr, SUPERUSER_ID, ids, context=context): values.append({ + "id": post.id, "author_name": post.author_id and post.author_id.name or _('Anonymous'), "author_image": post.author_id and \ ("data:image/png;base64,%s" % post.author_id.image) or \ '/website_blog/static/src/img/anonymous.png', "date": post.date, 'body': html2plaintext(post.body), + 'website_published' : post.website_published, + 'publish' : publish, }) return values @@ -297,6 +308,11 @@ class WebsiteBlog(http.Controller): def change_bg(self, post_id=0, image=None, **post): post_obj = request.registry.get('blog.post') values = {'content_image' : image} + ids = post_obj.write(request.cr, request.uid, [int(post_id)], values, request.context) return [] + @http.route('/blog/get_user/', type='json', auth="public", website=True) + def get_user(self, **post): + return [False if request.session.uid else True] + diff --git a/addons/website_blog/static/src/js/website_blog.inline.discussion.js b/addons/website_blog/static/src/js/website_blog.inline.discussion.js index bed198efad7..965fa6749d4 100644 --- a/addons/website_blog/static/src/js/website_blog.inline.discussion.js +++ b/addons/website_blog/static/src/js/website_blog.inline.discussion.js @@ -15,6 +15,7 @@ position: 'right', post_id: $('#blog_post_name').attr('data-blog-id'), content : false, + public_user: false, }; self.settings = $.extend({}, defaults, options); self.do_render(self); @@ -33,6 +34,17 @@ if($(event.target).parents('#discussions_wrapper, .main-discussion-link-wrp').length === 0) { self.hide_discussion(); } + if(!$(event.target).hasClass('discussion-link') && !$(event.target).parents('.popover').length){ + if($('.move_discuss').length){ + $('.js_discuss').removeClass('move_discuss'); + $('.js_discuss').animate({ + 'marginLeft': "+=40%" + }); + $('#discussions_wrapper').animate({ + 'marginLeft': "+=250px" + }); + } + } }); }, prepare_data : function(identifier) { @@ -82,6 +94,15 @@ a.delegate('a.discussion-link', "click", function(e) { e.preventDefault(); + if(!$('.move_discuss').length){ + $('.js_discuss').addClass('move_discuss'); + $('.js_discuss').animate({ + 'marginLeft': "-=40%" + }); + $('#discussions_wrapper').animate({ + 'marginLeft': "-=250px" + }); + } if ($(this).is('.active')) { e.stopPropagation(); self.hide_discussion(); @@ -100,7 +121,6 @@ elt.append(qweb.render("website.blog_discussion.popover", {'identifier': identifier , 'options': self.settings})); var comment = ''; self.prepare_data(identifier).then(function(data){ - console.log(identifier, data); _.each(data, function(res){ comment += qweb.render("website.blog_discussion.comment", {'res': res}); }); @@ -125,23 +145,55 @@ self.post_discussion(identifier); }); }, + validate : function(public_user){ + var comment = $(".popover textarea#inline_comment").val(); + if (public_user){ + var author_name = $('.popover input#author_name').val(); + var author_email = $('.popover input#author_email').val(); + if(!comment || !author_name || !author_email){ + if (!author_name) + $('div#author_name').addClass('has-error'); + else + $('div#author_name').removeClass('has-error'); + if (!author_email) + $('div#author_email').addClass('has-error'); + else + $('div#author_email').removeClass('has-error'); + if(!comment) + $('div#inline_comment').addClass('has-error'); + else + $('div#inline_comment').removeClass('has-error'); + return false + } + } + else if(!comment) { + $('div#inline_comment').addClass('has-error'); + return false + } + $("div#inline_comment").removeClass('has-error'); + $('div#author_name').removeClass('has-error'); + $('div#author_email').removeClass('has-error'); + $(".popover textarea#inline_comment").val(''); + $('.popover input#author_name').val(''); + $('.popover input#author_email').val(''); + return [comment, author_name, author_email] + }, post_discussion : function(identifier) { var self = this; - var val = $(".popover #comment").val() - if(val){ - $(".popover #comment").removeClass('danger'); - openerp.jsonRpc("/blogpost/post_discussion", 'call', { - 'blog_post_id': self.settings.post_id, - 'discussion': self.discus_identifier, - 'comment': val, - }).then(function(res){ - $(".popover ul.media-list").prepend(qweb.render("website.blog_discussion.comment", {'res': res})) - $(".popover #comment").val('') - var ele = $('a[data-discus-identifier="'+ self.discus_identifier +'"]'); - ele.text(_.isNaN(parseInt(ele.text())) ? 1 : parseInt(ele.text())+1) - ele.addClass('has-comments'); - }); - } + var val = self.validate(self.settings.public_user) + if(!val) return + openerp.jsonRpc("/blogpost/post_discussion", 'call', { + 'blog_post_id': self.settings.post_id, + 'discussion': self.discus_identifier, + 'comment': val[0], + 'name' : val[1], + 'email': val[2], + }).then(function(res){ + $(".popover ul.media-list").prepend(qweb.render("website.blog_discussion.comment", {'res': res})) + var ele = $('a[data-discus-identifier="'+ self.discus_identifier +'"]'); + ele.text(_.isNaN(parseInt(ele.text())) ? 1 : parseInt(ele.text())+1) + ele.addClass('has-comments'); + }); }, hide_discussion : function() { var self = this; diff --git a/addons/website_blog/static/src/js/website_blog.js b/addons/website_blog/static/src/js/website_blog.js index 67f8d1067ef..17efda08dcb 100644 --- a/addons/website_blog/static/src/js/website_blog.js +++ b/addons/website_blog/static/src/js/website_blog.js @@ -13,7 +13,6 @@ $(document).ready(function() { window.location.href = newLocation; }); } - function animate(event) { event.stopImmediatePropagation(); var target = $(this.hash); @@ -26,8 +25,10 @@ $(document).ready(function() { var content = $(".js_discuss #blog_content p"); if(content){ - $('#discussions_wrapper').empty(); - new openerp.website.blog_discussion({'content' : content}); + openerp.jsonRpc("/blog/get_user/", 'call', {}).then(function(data){ + $('#discussions_wrapper').empty(); + new openerp.website.blog_discussion({'content' : content, 'public_user':data[0]}); + }); } $('.js_header').css('min-height', $(window).height()); diff --git a/addons/website_blog/static/src/xml/website_blog.inline.discussion.xml b/addons/website_blog/static/src/xml/website_blog.inline.discussion.xml index e44b4b0a0d7..e62a5fea3f8 100644 --- a/addons/website_blog/static/src/xml/website_blog.inline.discussion.xml +++ b/addons/website_blog/static/src/xml/website_blog.inline.discussion.xml @@ -5,6 +5,10 @@
+
+ + +
@@ -18,7 +22,15 @@