[ADD]lib for paragraph level comment
bzr revid: mba@tinyerp.com-20140206133539-n9iisqwgexifty6u
This commit is contained in:
@@ -237,6 +237,7 @@ class WebsiteBlog(http.Controller):
|
||||
type='comment',
|
||||
subtype='mt_comment',
|
||||
author_id=user.partner_id.id,
|
||||
tag_id=post.get('tag_id'),
|
||||
context=dict(context, mail_create_nosubcribe=True))
|
||||
return werkzeug.utils.redirect(request.httprequest.referrer + "#comments")
|
||||
|
||||
@@ -288,3 +289,21 @@ class WebsiteBlog(http.Controller):
|
||||
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):
|
||||
blog = request.registry.get('blog.post').browse(request.cr, SUPERUSER_ID, int(blog))
|
||||
values = []
|
||||
mail_obj = request.registry.get('mail.message');
|
||||
for mail in blog.website_message_ids:
|
||||
ids = mail_obj.search(request.cr, SUPERUSER_ID, [('id', '=', mail.id), ('tag_id', '=', tag_id)])
|
||||
if ids:
|
||||
post = mail_obj.browse(request.cr, SUPERUSER_ID, ids[0])
|
||||
values.append({
|
||||
"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
|
||||
|
||||
|
||||
@@ -57,7 +57,12 @@ class BlogTag(osv.Model):
|
||||
'blog.post', string='Posts',
|
||||
),
|
||||
}
|
||||
class MailMessage(osv.Model):
|
||||
_inherit = 'mail.message'
|
||||
|
||||
_columns = {
|
||||
'tag_id': fields.char('Tag'),
|
||||
}
|
||||
|
||||
class BlogPost(osv.Model):
|
||||
_name = "blog.post"
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
.disqussion {
|
||||
padding: 5px 10px 10px;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
line-height: 16px;
|
||||
font-size: 13px;
|
||||
font-weight: bold;
|
||||
font-family: sans-serif;
|
||||
text-align: center;
|
||||
z-index: 7;
|
||||
}
|
||||
.disqussion a {
|
||||
opacity: 1;
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
width: 20px;
|
||||
height: 17px;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
background: #bbbbbb;
|
||||
-webkit-border-radius: 2px;
|
||||
-moz-border-radius: 2px;
|
||||
-ms-border-radius: 2px;
|
||||
-o-border-radius: 2px;
|
||||
border-radius: 2px;
|
||||
-webkit-transition: all 0.5s;
|
||||
-moz-transition: all 0.5s;
|
||||
-o-transition: all 0.5s;
|
||||
transition: all 0.5s;
|
||||
}
|
||||
.disqussion a.has-comments {
|
||||
opacity: .8;
|
||||
}
|
||||
.disqussion-contain:hover .disqussion a {
|
||||
opacity: 1;
|
||||
}
|
||||
.disqussion a:after {
|
||||
border-left: 7px solid transparent;
|
||||
border-top: 7px solid #bbbbbb;
|
||||
left: 19px;
|
||||
top: 22px;
|
||||
height: 0;
|
||||
width: 0;
|
||||
display: block;
|
||||
content: " ";
|
||||
position: absolute;
|
||||
-webkit-transition: all 0.5s;
|
||||
-moz-transition: all 0.5s;
|
||||
-o-transition: all 0.5s;
|
||||
transition: all 0.5s;
|
||||
}
|
||||
.disqussion:hover a, .disqussion.hovered a {
|
||||
opacity: 1;
|
||||
background: #999999;
|
||||
}
|
||||
.disqussion:hover a:after, .disqussion.hovered a:after {
|
||||
border-top-color: #999999;
|
||||
}
|
||||
|
||||
#disqussions_wrapper {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
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;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
z-index: 8;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.disqussion-highlighted {
|
||||
position: relative;
|
||||
background: #fff;
|
||||
z-index: 9;
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
// Disqus global vars.
|
||||
var disqus_identifier;
|
||||
var disqus_url;
|
||||
|
||||
(function($) {
|
||||
|
||||
jQuery(document).ready(function() {
|
||||
jQuery("main p").inlineDisqussions();
|
||||
});
|
||||
|
||||
var settings = {};
|
||||
|
||||
$.fn.extend({
|
||||
inlineDisqussions: function(options) {
|
||||
|
||||
// Set up defaults
|
||||
var defaults = {
|
||||
identifier: 'name',
|
||||
displayCount: true,
|
||||
highlighted: false,
|
||||
position: 'right',
|
||||
background: 'white',
|
||||
maxWidth: 9999
|
||||
};
|
||||
|
||||
// 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'));
|
||||
}
|
||||
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));
|
||||
});
|
||||
|
||||
// Display comments count.
|
||||
if (settings.displayCount) {
|
||||
// loadDisqusCounter();
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
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();
|
||||
}
|
||||
else {
|
||||
loadDisqus($(this), function(source) {
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var loadDisqus = function(source, callback) {
|
||||
|
||||
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 self = this;
|
||||
var p = '';
|
||||
openerp.jsonRpc("/blog_post/comments/", 'call', {
|
||||
'blog': id,
|
||||
'tag_id':identifier,
|
||||
})
|
||||
.then(function (data) {
|
||||
if(!data)
|
||||
return;
|
||||
_.map(data, function(res){
|
||||
p += '<div><img class="img-circle oe_inline" style="width: 25%; margin-right:10px;" src="' + res.author_image + '"/><h5 class="media-heading"><span>'+res.author_name+'</span><small> on <span>'+res.date+'</span></small></h5><span>'+res.body+'</span></div>'
|
||||
});
|
||||
$('.content').html(p)
|
||||
});
|
||||
|
||||
$('#disqussions_wrapper').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 class="form-control" rows="3" id="comment" name="comment" placeholder="Write a comment..."/><br/><button id="submit" type="submit" class="btn btn-primary mt8">Post</button></form><div class="content"/></div>')
|
||||
|
||||
$('.disqussion-link').popover({
|
||||
html:true,
|
||||
placement:'right',
|
||||
content:function(){
|
||||
return $($(this).data('contentwrapper')).html();
|
||||
}
|
||||
});
|
||||
// $('#submit').click(function() {
|
||||
// $('p[data-disqus-identifier="'+identifier+'"]').attr('data-count','2');
|
||||
// debugger;
|
||||
// });
|
||||
|
||||
// Add 'active' class.
|
||||
$('a.disqussion-link, a.main-disqussion-link').removeClass('active').filter(source).addClass('active');
|
||||
callback(source);
|
||||
|
||||
};
|
||||
|
||||
// var loadDisqusCounter = function() {
|
||||
//
|
||||
// // Append the Disqus count script to <head>.
|
||||
// var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true;
|
||||
// s.src = '//' + disqus_shortname + '.disqus.com/count.js';
|
||||
// $('head').append(s);
|
||||
//
|
||||
// // Add class to discussions that already have comments.
|
||||
// window.setTimeout(function() {
|
||||
// $('.disqussion-link').filter(function() {
|
||||
// return $(this).text().match(/[1-9]/g);
|
||||
// }).addClass("has-comments");
|
||||
// }, 1000);
|
||||
//
|
||||
// };
|
||||
|
||||
var hideDisqussion = function() {
|
||||
|
||||
$('.disqussion-link').popover('hide')
|
||||
$('a.disqussion-link').removeClass('active');
|
||||
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
@@ -8,6 +8,8 @@
|
||||
<script type="text/javascript" src="/website_blog/static/src/js/website.tour.blog.js"></script>
|
||||
<script type="text/javascript" src="/website_blog/static/lib/contentshare.js"></script>
|
||||
<script type="text/javascript" src="/website_blog/static/lib/page-transitions/js/app.js"></script>
|
||||
<script type="text/javascript" src="/website_blog/static/lib/inlineDisqussions/inlineDisqussions.js"></script>
|
||||
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
@@ -364,6 +366,7 @@
|
||||
<t t-set="head">
|
||||
<link rel='stylesheet' href='/website_blog/static/src/css/website_blog.css'/>
|
||||
<link rel='stylesheet' href='/website_blog/static/lib/page-transitions/css/styles.css'/>
|
||||
<link rel='stylesheet' href='/website_blog/static/lib/inlineDisqussions/inlineDisqussions.css'/>
|
||||
</t>
|
||||
<div id="wrap" class="js_blog">
|
||||
<t t-raw="0"/>
|
||||
|
||||
Reference in New Issue
Block a user