[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
This commit is contained in:
ajay javiya (OpenERP)
2014-03-25 16:34:28 +05:30
parent ce4a8347a8
commit bac460d5bd
4 changed files with 109 additions and 28 deletions
+24 -8
View File
@@ -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]
@@ -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;
@@ -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());
@@ -5,6 +5,10 @@
<div class="pull-left">
<img class="media-object img-circle" t-att-src="res.author_image" style="width: 30px;"/>
</div>
<div t-attf-class="pull-right btn-group js_publish_management #{res.website_published and 'css_published' or 'css_unpublished'} #{res.publish ? '' : 'hidden'}" data-object="mail.message" t-att-data-id="res.id">
<button class="btn btn-danger btn-xs js_publish_btn">Not Published</button>
<button class="btn btn-success btn-xs js_publish_btn">Published</button>
</div>
<div class="media-body">
<div t-esc='res.body'/>
<small class="text-muted">
@@ -18,7 +22,15 @@
<div class="mycontent hidden">
<input name="discussion" t-att-value="identifier" type="hidden"/>
<input name="blog_post_id" t-att-value="options.post_id" type="hidden"/>
<textarea class="mb8 form-control" rows="2" id="comment" placeholder="Write a comment..."/>
<div id="inline_comment">
<textarea class="mb8 form-control" rows="2" id="inline_comment" placeholder="Write a comment..."/>
</div>
<div id="author_name">
<input id="author_name" name="user_name" t-attf-class="form-control #{options.public_user ? '' : 'hidden'}" placeholder="Your name..."/>
</div>
<div id="author_email">
<input id="author_email" name="user_email" t-attf-class="mt8 form-control #{options.public_user ? '' : 'hidden'}" placeholder="Your Email..."/>
</div>
<button id='comment_post' class="btn btn-primary btn-xs mb8">Post</button>
<div class="discussion_history"/>
</div>