From 353ea9fb220cbb3c9bea639f74ef59afded73f7a Mon Sep 17 00:00:00 2001 From: "Mahendra Barad (OpenERP)" Date: Thu, 6 Feb 2014 19:05:39 +0530 Subject: [PATCH] [ADD]lib for paragraph level comment bzr revid: mba@tinyerp.com-20140206133539-n9iisqwgexifty6u --- addons/website_blog/controllers/main.py | 19 ++ addons/website_blog/models/website_blog.py | 5 + .../inlineDisqussions/inlineDisqussions.css | 97 +++++++++ .../inlineDisqussions/inlineDisqussions.js | 204 ++++++++++++++++++ .../views/website_blog_templates.xml | 3 + 5 files changed, 328 insertions(+) create mode 100644 addons/website_blog/static/lib/inlineDisqussions/inlineDisqussions.css create mode 100644 addons/website_blog/static/lib/inlineDisqussions/inlineDisqussions.js diff --git a/addons/website_blog/controllers/main.py b/addons/website_blog/controllers/main.py index 2b004eb9c20..35d2ae35951 100644 --- a/addons/website_blog/controllers/main.py +++ b/addons/website_blog/controllers/main.py @@ -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 + diff --git a/addons/website_blog/models/website_blog.py b/addons/website_blog/models/website_blog.py index 90a1c07f617..69e3cf53f37 100644 --- a/addons/website_blog/models/website_blog.py +++ b/addons/website_blog/models/website_blog.py @@ -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" diff --git a/addons/website_blog/static/lib/inlineDisqussions/inlineDisqussions.css b/addons/website_blog/static/lib/inlineDisqussions/inlineDisqussions.css new file mode 100644 index 00000000000..f9c7cc777b3 --- /dev/null +++ b/addons/website_blog/static/lib/inlineDisqussions/inlineDisqussions.css @@ -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; +} diff --git a/addons/website_blog/static/lib/inlineDisqussions/inlineDisqussions.js b/addons/website_blog/static/lib/inlineDisqussions/inlineDisqussions.js new file mode 100644 index 00000000000..180b7da680f --- /dev/null +++ b/addons/website_blog/static/lib/inlineDisqussions/inlineDisqussions.js @@ -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) { + $('
').appendTo($('body')); + } + if ($('#disqus_thread').length === 0) { + $('
').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 = $('') + .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('
') + .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 = $('') + .attr('href', window.location.pathname + '#disqus_thread') + .text('Comments') + .wrap('