[IMP] : inline discussion,
-> hide inline comment from chatter bzr revid: aja@tinyerp.com-20140208123838-v5c6ooie69gh5eyu
This commit is contained in:
parent
102dea251c
commit
79a5666c4c
|
@ -241,7 +241,7 @@ class WebsiteBlog(http.Controller):
|
|||
type='comment',
|
||||
subtype='mt_comment',
|
||||
author_id=user.partner_id.id,
|
||||
tag_id=post.get('tag_id'),
|
||||
discussion=post.get('discussion'),
|
||||
context=dict(context, mail_create_nosubcribe=True))
|
||||
return werkzeug.utils.redirect(request.httprequest.referrer + "#comments")
|
||||
|
||||
|
@ -271,34 +271,11 @@ 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('/blog_post/post', type='json', auth="public", website=True)
|
||||
def getPost(self, blog=None, **post):
|
||||
blog = request.registry.get('blog.post').browse(request.cr, SUPERUSER_ID, int(blog))
|
||||
values = {
|
||||
"image": blog.content_image,
|
||||
"date": blog.create_date ,
|
||||
"author": blog.create_uid.name,
|
||||
"author_image": "data:image/png;base64,%s" % blog.create_uid.image,
|
||||
"title": blog.name,
|
||||
"title_secondary": "It's not too hard, really.",
|
||||
"content": blog.content,
|
||||
}
|
||||
return [values]
|
||||
|
||||
@http.route('/blog_post/change_layout', type='json', auth="public", website=True)
|
||||
def check_layout(self, **post):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
view_obj = request.registry.get('ir.ui.view')
|
||||
view_data = view_obj.search_read(cr, SUPERUSER_ID, [('name','=','Blog Cover')],['inherit_id', 'inherit_option_id'])[0]
|
||||
if view_data['inherit_id']:
|
||||
return [True]
|
||||
return []
|
||||
|
||||
@http.route('/blog_post/comments', type='json', auth="public", website=True)
|
||||
def getcomments(self, blog=None, tag_id=None, **post):
|
||||
@http.route('/blogpost/discussion', type='json', auth="public", website=True)
|
||||
def discussion(self, post_id=0, discussion=None, **post):
|
||||
mail_obj = request.registry.get('mail.message')
|
||||
values = []
|
||||
ids = mail_obj.search(request.cr, SUPERUSER_ID, [('res_id', '=', int(blog)) ,('model','=','blog.post'), ('tag_id', '=', tag_id)])
|
||||
ids = mail_obj.search(request.cr, SUPERUSER_ID, [('res_id', '=', int(post_id)) ,('model','=','blog.post'), ('discussion', '=', discussion)])
|
||||
if ids:
|
||||
for post in mail_obj.browse(request.cr, SUPERUSER_ID, ids):
|
||||
values.append({
|
||||
|
@ -308,4 +285,3 @@ class WebsiteBlog(http.Controller):
|
|||
'author_image': "data:image/png;base64,%s" % post.author_id.image,
|
||||
})
|
||||
return values
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ class MailMessage(osv.Model):
|
|||
_inherit = 'mail.message'
|
||||
|
||||
_columns = {
|
||||
'tag_id': fields.char('Tag'),
|
||||
'discussion': fields.char('Discussion Unique Name'),
|
||||
}
|
||||
|
||||
class BlogPost(osv.Model):
|
||||
|
@ -125,7 +125,7 @@ class BlogPost(osv.Model):
|
|||
'website_message_ids': fields.one2many(
|
||||
'mail.message', 'res_id',
|
||||
domain=lambda self: [
|
||||
'&', ('model', '=', self._name), ('type', '=', 'comment')
|
||||
'&', '&', ('model', '=', self._name), ('type', '=', 'comment') , ('discussion', '=', False)
|
||||
],
|
||||
string='Website Messages',
|
||||
help="Website communication history",
|
||||
|
|
|
@ -53,10 +53,10 @@
|
|||
}
|
||||
.disqussion:hover a, .disqussion.hovered a {
|
||||
opacity: 1;
|
||||
background: #999999;
|
||||
background: #57AD68;
|
||||
}
|
||||
.disqussion:hover a:after, .disqussion.hovered a:after {
|
||||
border-top-color: #999999;
|
||||
border-top-color: #57AD68;
|
||||
}
|
||||
|
||||
#disqussions_wrapper {
|
||||
|
@ -65,20 +65,6 @@
|
|||
left: 0;
|
||||
}
|
||||
|
||||
#disqus_thread.positioned {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
padding: 5px 15px 0 15px;
|
||||
-webkit-box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.disqussion-highlight #disqus_thread.positioned {
|
||||
background: #fff;
|
||||
z-index: 9;
|
||||
}
|
||||
|
||||
#disqussions_overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
|
@ -90,8 +76,8 @@
|
|||
display: none;
|
||||
}
|
||||
|
||||
.disqussion-highlighted {
|
||||
position: relative;
|
||||
background: #fff;
|
||||
z-index: 9;
|
||||
.disqussion .popover-content {
|
||||
max-height: 250px;
|
||||
width: 250px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
|
|
@ -1,189 +1,137 @@
|
|||
//global vars.
|
||||
var disqus_identifier;
|
||||
var disqus_url;
|
||||
|
||||
(function($) {
|
||||
|
||||
var settings = {};
|
||||
|
||||
$.fn.extend({
|
||||
inlineDisqussions: function(options) {
|
||||
inlineDisqussions: function(options) {
|
||||
// Set up defaults
|
||||
var defaults = {
|
||||
identifier: 'name',
|
||||
position: 'right',
|
||||
post_id: $('h1').attr('data-oe-id'),
|
||||
};
|
||||
|
||||
// Set up defaults
|
||||
var defaults = {
|
||||
identifier: 'name',
|
||||
position: 'right',
|
||||
background: 'white',
|
||||
maxWidth: 9999
|
||||
};
|
||||
// Overwrite default options with user provided ones.
|
||||
settings = $.extend({}, defaults, options);
|
||||
|
||||
// Overwrite default options with user provided ones.
|
||||
settings = $.extend({}, defaults, options);
|
||||
// Append #disqus_thread to body if it doesn't exist yet.
|
||||
if ($('#disqussions_wrapper').length === 0) {
|
||||
$('<div id="disqussions_wrapper"></div>').appendTo($('body'));
|
||||
}
|
||||
|
||||
// Append #disqus_thread to body if it doesn't exist yet.
|
||||
if ($('#disqussions_wrapper').length === 0) {
|
||||
$('<div id="disqussions_wrapper"></div>').appendTo($('body'));
|
||||
}
|
||||
if ($('#disqus_thread').length === 0) {
|
||||
$('<div id="disqus_thread"></div>').appendTo('#disqussions_wrapper');
|
||||
}
|
||||
else {
|
||||
mainThreadHandler();
|
||||
}
|
||||
// Attach a discussion to each paragraph.
|
||||
$(this).each(function(i) {
|
||||
disqussionNotesHandler(i, $(this));
|
||||
});
|
||||
|
||||
// Attach a discussion to each paragraph.
|
||||
$(this).each(function(i) {
|
||||
disqussionNotesHandler(i, $(this));
|
||||
});
|
||||
|
||||
// Hide the discussion.
|
||||
$('html').click(function(event) {
|
||||
if($(event.target).parents('#disqussions_wrapper, .main-disqussion-link-wrp').length === 0) {
|
||||
hideDisqussion();
|
||||
// Hide the discussion.
|
||||
$('html').click(function(event) {
|
||||
if($(event.target).parents('#disqussions_wrapper, .main-disqussion-link-wrp').length === 0) {
|
||||
hideDisqussion();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
var disqussionNotesHandler = function(i, node) {
|
||||
|
||||
var identifier;
|
||||
// You can force a specific identifier by adding an attribute to the paragraph.
|
||||
if (node.attr('data-disqus-identifier')) {
|
||||
identifier = node.attr('data-disqus-identifier');
|
||||
}
|
||||
else {
|
||||
while ($('[data-disqus-identifier="' + settings.identifier + '-' + i + '"]').length > 0) {
|
||||
i++;
|
||||
}
|
||||
identifier = settings.identifier + '-' + i;
|
||||
}
|
||||
// Create the discussion note.
|
||||
var a = $('<a class="disqussion-link" />')
|
||||
.attr('href', window.location.pathname + settings.identifier + '-' + i + '#comment')
|
||||
.attr('data-disqus-identifier', identifier)
|
||||
.attr('data-disqus-url', window.location.href + settings.identifier + '-' + i)
|
||||
.attr('data-disqus-position', settings.position)
|
||||
.text('+')
|
||||
.attr('data-contentwrapper','.mycontent')
|
||||
.wrap('<div class="disqussion" />')
|
||||
.parent()
|
||||
.appendTo('#disqussions_wrapper');
|
||||
a.css({
|
||||
'top': node.offset().top,
|
||||
'left': settings.position == 'right' ? node.offset().left + node.outerWidth() : node.offset().left - a.outerWidth()
|
||||
});
|
||||
|
||||
node.attr('data-disqus-identifier', identifier).mouseover(function() {
|
||||
a.addClass("hovered");
|
||||
}).mouseout(function() {
|
||||
a.removeClass("hovered");
|
||||
});
|
||||
|
||||
// Load the relative discussion.
|
||||
a.delegate('a.disqussion-link', "click", function(e) {
|
||||
e.preventDefault();
|
||||
var disqussionNotesHandler = function(i, node) {
|
||||
|
||||
if ($(this).is('.active')) {
|
||||
e.stopPropagation();
|
||||
hideDisqussion();
|
||||
}
|
||||
else {
|
||||
loadDisqus($(this), function(source) {
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var mainThreadHandler = function() {
|
||||
|
||||
// Create the discussion note.
|
||||
if ($('a.main-disqussion-link').length === 0) {
|
||||
|
||||
var a = $('<a class="main-disqussion-link" />')
|
||||
.attr('href', window.location.pathname + '#disqus_thread')
|
||||
.text('Comments')
|
||||
.wrap('<h2 class="main-disqussion-link-wrp" />')
|
||||
.parent()
|
||||
.insertBefore('#disqus_thread');
|
||||
|
||||
// Load the relative discussion.
|
||||
a.delegate('a.main-disqussion-link', "click", function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
if ($(this).is('.active')) {
|
||||
e.stopPropagation();
|
||||
var identifier;
|
||||
// You can force a specific identifier by adding an attribute to the paragraph.
|
||||
if (node.attr('data-disqus-identifier')) {
|
||||
identifier = node.attr('data-disqus-identifier');
|
||||
}
|
||||
else {
|
||||
loadDisqus($(this), function(source) {
|
||||
});
|
||||
while ($('[data-disqus-identifier="' + settings.identifier + '-' + i + '"]').length > 0) {
|
||||
i++;
|
||||
}
|
||||
identifier = settings.identifier + '-' + i;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
openerp.jsonRpc("/blogpost/discussion/", 'call', {
|
||||
'post_id': settings.post_id,
|
||||
'discussion':identifier,
|
||||
}).then(function(data){
|
||||
prepareDisquseLink(data,identifier,node);
|
||||
});
|
||||
};
|
||||
|
||||
var loadDisqus = function(source, callback) {
|
||||
var prepareDisquseLink = function(data,identifier,node) {
|
||||
|
||||
var identifier = source.attr('data-disqus-identifier');
|
||||
var url = source.attr('data-disqus-url');
|
||||
var body = $(document.body).find('h1')
|
||||
var id = body.attr('data-oe-id');
|
||||
disqus_identifier = identifier;
|
||||
disqus_url = url;
|
||||
|
||||
var comment = '';
|
||||
openerp.jsonRpc("/blog_post/comments/", 'call', {
|
||||
'blog': id,
|
||||
'tag_id':identifier,
|
||||
})
|
||||
.then(function (data) {
|
||||
if(!data)
|
||||
return;
|
||||
_.map(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">\
|
||||
<span>'+res.author_name+'</span> <small>on <span>'+res.date+'</span></small>\
|
||||
</h5>\
|
||||
</div>\
|
||||
</div>\
|
||||
</li><li><small class="text-muted">'+res.body+'</small></li><hr/>'
|
||||
});
|
||||
$('.content').html('<ul class="media-list">'+comment+'</ul>')
|
||||
});
|
||||
|
||||
$('a[data-disqus-identifier="'+identifier+'"]').append('<div class="mycontent hidden"><form id="comment" action="/blogpost/comment" method="POST"><input name="tag_id" value="'+ identifier +'" type="hidden"/><input name="blog_post_id" value="'+id+'" type="hidden"/><textarea rows="3" id="comment" name="comment" placeholder="Write a comment..."/><br/><button id="submit" type="submit" class="btn btn-primary btn-xs mb8 mt4">Post</button></form><div class="content"/></div>')
|
||||
|
||||
// $('#submit').click(function() {
|
||||
// console.log('aaaaaa',$('p[data-disqus-identifier="'+identifier+'"]'))
|
||||
// $('p[data-disqus-identifier="'+identifier+'"]').attr('data-count','2');
|
||||
// debugger;
|
||||
// });
|
||||
$('a[data-disqus-identifier="'+identifier+'"]').popover({
|
||||
html:true,
|
||||
placement:'right',
|
||||
content:function(){
|
||||
return $($(this).data('contentwrapper')).html();
|
||||
}
|
||||
});
|
||||
|
||||
// Add 'active' class.
|
||||
$('a.disqussion-link, a.main-disqussion-link').removeClass('active').filter(source).addClass('active');
|
||||
$('a[data-disqus-identifier="'+identifier+'"]').popover('hide').filter(source).popover('show');
|
||||
callback(source);
|
||||
};
|
||||
var a = $('<a class="disqussion-link" />')
|
||||
.attr('data-disqus-identifier', identifier)
|
||||
.attr('data-disqus-position', settings.position)
|
||||
.text(data.length > 0 ? data.length : '+')
|
||||
.attr('data-contentwrapper','.mycontent')
|
||||
.wrap('<div class="disqussion" />')
|
||||
.parent()
|
||||
.appendTo('#disqussions_wrapper');
|
||||
a.css({
|
||||
'top': node.offset().top,
|
||||
'left': settings.position == 'right' ? node.offset().left + node.outerWidth() : node.offset().left - a.outerWidth()
|
||||
});
|
||||
|
||||
node.attr('data-disqus-identifier', identifier).mouseover(function() {
|
||||
a.addClass("hovered");
|
||||
}).mouseout(function() {
|
||||
a.removeClass("hovered");
|
||||
});
|
||||
|
||||
a.delegate('a.disqussion-link', "click", function(e) {
|
||||
e.preventDefault();
|
||||
if ($(this).is('.active')) {
|
||||
e.stopPropagation();
|
||||
hideDisqussion();
|
||||
}
|
||||
else {
|
||||
loadDisqus(data, $(this), function(source) {});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var loadDisqus = function(data, source, callback) {
|
||||
var identifier = source.attr('data-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>\
|
||||
<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/>'
|
||||
});
|
||||
$('.discussion_history').html('<ul class="media-list">'+comment+'</ul>');
|
||||
createPopOver(elt);
|
||||
|
||||
// Add 'active' class.
|
||||
$('a.disqussion-link, a.main-disqussion-link').removeClass('active').filter(source).addClass('active');
|
||||
elt.popover('hide').filter(source).popover('show');
|
||||
callback(source);
|
||||
};
|
||||
|
||||
var createPopOver = function (elt) {
|
||||
elt.popover({
|
||||
placement:'right',
|
||||
trigger:'manual',
|
||||
html:true, content:function(){
|
||||
return $($(this).data('contentwrapper')).html();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var hideDisqussion = function() {
|
||||
$('a.disqussion-link').removeClass('active');
|
||||
};
|
||||
|
||||
var hideDisqussion = function() {
|
||||
$('a[data-disqus-identifier="'+disqus_identifier+'"]').popover('hide')
|
||||
$('a.disqussion-link').removeClass('active');
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
|
||||
$(document).ready(function() {
|
||||
$("#blog_content p").inlineDisqussions();
|
||||
});
|
||||
|
|
@ -1,4 +1,7 @@
|
|||
$(document).ready(function() {
|
||||
|
||||
$("#blog_content p").inlineDisqussions(); //Allow inline comments on blog post
|
||||
|
||||
$('.js_next').click(function(event) {
|
||||
event.preventDefault();
|
||||
var translationValue = $('.cover_footer').get(0).getBoundingClientRect().top;
|
||||
|
|
Loading…
Reference in New Issue