[IMP]paragraph level comment posting comment not reoload add in dom
bzr revid: mba@tinyerp.com-20140212103301-ql4r4ewa3q5rgxzv
This commit is contained in:
parent
f52ba6927e
commit
f2f7e75137
|
@ -224,9 +224,8 @@ class WebsiteBlog(http.Controller):
|
|||
'next_post' : request.registry['blog.post'].browse(cr, uid, next_blog_id, context=context)
|
||||
}
|
||||
return request.website.render("website_blog.blog_post_complete", values)
|
||||
|
||||
@http.route(['/blogpost/comment'], type='http', auth="public", methods=['POST'], website=True)
|
||||
def blog_post_comment(self, blog_post_id=0, **post):
|
||||
|
||||
def _blog_post_message(self, blog_post_id=0, **post):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
if post.get('comment'):
|
||||
user = request.registry['res.users'].browse(cr, SUPERUSER_ID, uid, context=context)
|
||||
|
@ -235,7 +234,7 @@ class WebsiteBlog(http.Controller):
|
|||
if group_id in [group.id for group in group_ids]:
|
||||
blog_post = request.registry['blog.post']
|
||||
blog_post.check_access_rights(cr, uid, 'read')
|
||||
blog_post.message_post(
|
||||
message_id = blog_post.message_post(
|
||||
cr, SUPERUSER_ID, int(blog_post_id),
|
||||
body=post.get('comment'),
|
||||
type='comment',
|
||||
|
@ -243,8 +242,27 @@ class WebsiteBlog(http.Controller):
|
|||
author_id=user.partner_id.id,
|
||||
discussion=post.get('discussion'),
|
||||
context=dict(context, mail_create_nosubcribe=True))
|
||||
return message_id
|
||||
|
||||
@http.route(['/blogpost/comment'], type='http', auth="public", methods=['POST'], website=True)
|
||||
def blog_post_comment(self, blog_post_id=0, **post):
|
||||
self._blog_post_message(blog_post_id, **post)
|
||||
return werkzeug.utils.redirect(request.httprequest.referrer + "#comments")
|
||||
|
||||
@http.route(['/blogpost/post_discussion'], type='json', auth="public", website=True)
|
||||
def post_discussion(self, blog_post_id=0, **post):
|
||||
id = self._blog_post_message(blog_post_id, **post)
|
||||
mail_obj = request.registry.get('mail.message')
|
||||
values = []
|
||||
post = mail_obj.browse(request.cr, SUPERUSER_ID, id)
|
||||
values = {
|
||||
"author_name": post.author_id.name,
|
||||
"date": post.date,
|
||||
"body": post.body,
|
||||
"author_image": "data:image/png;base64,%s" % post.author_id.image,
|
||||
}
|
||||
return values
|
||||
|
||||
@http.route('/blogpost/new', type='http', auth="public", website=True, multilang=True)
|
||||
def blog_post_create(self, blog_id, **post):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
|
@ -271,7 +289,7 @@ class WebsiteBlog(http.Controller):
|
|||
new_blog_post_id = request.registry['blog.post'].copy(cr, uid, blog_post_id, {}, context=create_context)
|
||||
return werkzeug.utils.redirect("/blogpost/%s/?enable_editor=1" % new_blog_post_id)
|
||||
|
||||
@http.route('/blogpost/discussion', type='json', auth="public", website=True)
|
||||
@http.route('/blogpost/get_discussion', type='json', auth="public", website=True)
|
||||
def discussion(self, post_id=0, discussion=None, **post):
|
||||
mail_obj = request.registry.get('mail.message')
|
||||
values = []
|
||||
|
|
|
@ -47,7 +47,7 @@ var disqus_identifier;
|
|||
}
|
||||
identifier = settings.identifier + '-' + i;
|
||||
}
|
||||
openerp.jsonRpc("/blogpost/discussion/", 'call', {
|
||||
openerp.jsonRpc("/blogpost/get_discussion/", 'call', {
|
||||
'post_id': settings.post_id,
|
||||
'discussion':identifier,
|
||||
}).then(function(data){
|
||||
|
@ -89,6 +89,33 @@ var disqus_identifier;
|
|||
});
|
||||
};
|
||||
|
||||
var disqussionPostHandler = function() {
|
||||
console.log('identifier',disqus_identifier)
|
||||
openerp.jsonRpc("/blogpost/post_discussion", 'call', {
|
||||
'blog_post_id': settings.post_id,
|
||||
'discussion': disqus_identifier,
|
||||
'comment': $(".popover #comment").val(),
|
||||
}).then(function(res){
|
||||
$(".popover ul.media-list").prepend(comments(res))
|
||||
$(".popover #comment").val('')
|
||||
ele = $('a[data-disqus-identifier="'+disqus_identifier+'"]');
|
||||
ele.text(_.isNaN(parseInt(ele.text())) ? 1 : parseInt(ele.text())+1)
|
||||
});
|
||||
};
|
||||
|
||||
var comments = function(res){
|
||||
return '<li class="media">\
|
||||
<div class="media-body">\
|
||||
<img class="media-object pull-left img-circle" src="'+ res.author_image + '" style="width: 30px; margin-right: 5px;"/>\
|
||||
<div class="media-body">\
|
||||
<h5 class="media-heading">\
|
||||
<small><span>'+res.author_name+'</span> on <span>'+res.date+'</span></small>\
|
||||
</h5>\
|
||||
</div>\
|
||||
</div>\
|
||||
</li><li><h6>'+res.body+'</h6></li><hr class="mb0 mt0"/>'
|
||||
}
|
||||
|
||||
var loadDisqus = function(data, source, callback) {
|
||||
var identifier = source.attr('data-disqus-identifier');
|
||||
$('a[data-disqus-identifier="'+disqus_identifier+'"]').popover('destroy')
|
||||
|
@ -96,26 +123,15 @@ var disqus_identifier;
|
|||
var elt = $('a[data-disqus-identifier="'+identifier+'"]');
|
||||
elt.append('\
|
||||
<div class="mycontent hidden">\
|
||||
<form id="comment" action="/blogpost/comment" method="POST">\
|
||||
<input name="discussion" value="'+ identifier +'" type="hidden"/>\
|
||||
<input name="blog_post_id" value="'+ settings.post_id +'" type="hidden"/>\
|
||||
<textarea class="mb8 form-control" rows="2" name="comment" placeholder="Write a comment..."/>\
|
||||
<button id="submit" type="submit" class="btn btn-primary btn-xs mb8 mt4">Post</button>\
|
||||
</form>\
|
||||
<textarea class="mb8 form-control" rows="2" id="comment" placeholder="Write a comment..."/>\
|
||||
<button id="comment_post" class="btn btn-primary btn-xs mb8 mt4">Post</button>\
|
||||
<div class="discussion_history"/>\
|
||||
</div>')
|
||||
var comment = '';
|
||||
_.each(data, function(res){
|
||||
comment += '<li class="media">\
|
||||
<div class="media-body">\
|
||||
<img class="media-object pull-left img-circle" src="'+ res.author_image + '" style="width: 30px; margin-right: 5px;"/>\
|
||||
<div class="media-body">\
|
||||
<h5 class="media-heading">\
|
||||
<small><span>'+res.author_name+'</span> on <span>'+res.date+'</span></small>\
|
||||
</h5>\
|
||||
</div>\
|
||||
</div>\
|
||||
</li><li><h6>'+res.body+'</h6></li><hr/>'
|
||||
comment += comments(res)
|
||||
});
|
||||
$('.discussion_history').html('<ul class="media-list">'+comment+'</ul>');
|
||||
createPopOver(elt);
|
||||
|
@ -133,7 +149,9 @@ var disqus_identifier;
|
|||
html:true, content:function(){
|
||||
return $($(this).data('contentwrapper')).html();
|
||||
}
|
||||
});
|
||||
}).parent().delegate('button#comment_post', 'click', function() {
|
||||
disqussionPostHandler();
|
||||
});;
|
||||
};
|
||||
|
||||
var hideDisqussion = function() {
|
||||
|
|
Loading…
Reference in New Issue