[IMP] website_blog: group the get_discussion in one request(get_discussionS), that...
authorJeremy Kersten <jke@odoo.com>
Tue, 29 Jul 2014 10:05:50 +0000 (12:05 +0200)
committerJeremy Kersten <jke@odoo.com>
Tue, 29 Jul 2014 10:05:50 +0000 (12:05 +0200)
addons/website_blog/controllers/main.py
addons/website_blog/static/src/js/website_blog.inline.discussion.js

index a9331c5..12fd63f 100644 (file)
@@ -244,7 +244,6 @@ class WebsiteBlog(http.Controller):
         cr, uid, context = request.cr, request.uid, request.context
         blog_post = request.registry['blog.post']
         partner_obj = request.registry['res.partner']
-        thread_obj = request.registry['mail.thread']
 
         if uid != request.website.user_id.id:
             partner_ids = [user.partner_id.id]
@@ -343,6 +342,14 @@ class WebsiteBlog(http.Controller):
             return ids
         return self._get_discussion_detail(ids, publish, **post)
 
+    @http.route('/blogpost/get_discussions/', type='json', auth="public", website=True)
+    def discussions(self, post_id=0, paths=None, count=False, **post):
+        ret = []
+        for path in paths:
+            result = self.discussion(post_id=post_id, path=path, count=count, **post)
+            ret.append({"path": path, "val": result})
+        return ret
+
     @http.route('/blogpost/change_background', type='json', auth="public", website=True)
     def change_bg(self, post_id=0, image=None, **post):
         if not post_id:
index 56851c3..426016f 100644 (file)
@@ -25,9 +25,8 @@
                 $('<div id="discussions_wrapper"></div>').insertAfter($('#blog_content'));
             }
             // Attach a discussion to each paragraph.
-            $(self.settings.content).each(function(i) {
-                self.discussion_handler(i, $(this));
-            });
+            self.discussions_handler(self.settings.content);
+
             // Hide the discussion.
             $('html').click(function(event) {
                 if($(event.target).parents('#discussions_wrapper, .main-discussion-link-wrp').length === 0) {
                 'count': comment_count, //if true only get length of total comment, display on discussion thread.
             })
         },
-        discussion_handler : function(i, node) {
+        prepare_multi_data : function(identifiers, comment_count) {
             var self = this;
-            var identifier = node.attr('data-chatter-id');
-            if (identifier) {
-                self.prepare_data(identifier, true).then( function (data) {
-                    self.prepare_discuss_link(data, identifier, node);
+            return openerp.jsonRpc("/blogpost/get_discussions/", 'call', {
+                'post_id': self.settings.post_id,
+                'paths': identifiers,
+                'count': comment_count, //if true only get length of total comment, display on discussion thread.
+            })
+        },
+        discussions_handler: function() {
+            var self = this;
+            var node_by_id = {};
+            $(self.settings.content).each(function(i) {
+                var node = $(this);
+                var identifier = node.attr('data-chatter-id');
+                if (identifier) {
+                    node_by_id[identifier] = node;
+                }
+            });
+            self.prepare_multi_data(_.keys(node_by_id), true).then( function (multi_data) {
+                _.forEach(multi_data, function(data) {
+                    self.prepare_discuss_link(data.val, data.path, node_by_id[data.path]);
                 });
-            }
+            });
         },
         prepare_discuss_link :  function(data, identifier, node) {
             var self = this;