WIP enable inline comments via admin setting (bug 1115707) r!smacleod draft
authorbyron jones <glob@mozilla.com>
Thu, 25 Aug 2016 14:53:45 +0800
changeset 9470 b484ed741398627e76bb925a6d74301a013f8a26
parent 9469 ff48d7ea8908901dee9c04e32e61e5fe26af9a8a
push id1188
push userbjones@mozilla.com
push dateThu, 01 Sep 2016 13:14:49 +0000
bugs1115707
WIP enable inline comments via admin setting (bug 1115707) r!smacleod Bind the inline comments view to the admin setting. MozReview-Commit-ID: Ddnv4eu3k2f
reviewboard/reviewboard/static/rb/js/diffviewer/views/diffReviewableView.js
reviewboard/reviewboard/templates/diffviewer/view_diff.html
--- a/reviewboard/reviewboard/static/rb/js/diffviewer/views/diffReviewableView.js
+++ b/reviewboard/reviewboard/static/rb/js/diffviewer/views/diffReviewableView.js
@@ -34,16 +34,24 @@ RB.DiffReviewableView = RB.AbstractRevie
         'click .diff-expand-btn': '_onExpandChunkClicked',
         'mouseup': '_onMouseUp'
     },
 
     /*
      * Initializes the reviewable for a file's diff.
      */
     initialize: function() {
+        // MozReview: use inline-comments when enabled
+        if ($('#show_comments_inline').data('enabled')) {
+            this.commentBlockView = RB.InlineCommentView;
+            this.commentsInline = true;
+        } else {
+            this.commentsInline = false;
+        }
+
         _super(this).initialize.call(this);
 
         _.bindAll(this, '_updateCollapseButtonPos', '_onWindowResize');
 
         this._selector = new RB.TextCommentRowSelector({
             el: this.el,
             reviewableView: this
         });
@@ -188,18 +196,26 @@ RB.DiffReviewableView = RB.AbstractRevie
             endRowEl = rowEls[1];
 
             /*
              * Note that endRow might be null if it exists in a collapsed
              * region, so we can get away with just using beginRow if we
              * need to.
              */
             commentBlockView.setRows($(beginRowEl), $(endRowEl || beginRowEl));
-            commentBlockView.$el.appendTo(
-                commentBlockView.$beginRow[0].cells[0]);
+
+            // MozReview: inline comments need to be injected into the DOM
+            // differently from comment bubbles.
+            if (this.commentsInline) {
+                commentBlockView.$el.insertAfter(commentBlockView.$endRow);
+            } else {
+                commentBlockView.$el.appendTo(
+                    commentBlockView.$beginRow[0].cells[0]);
+            }
+
             this._visibleCommentBlockViews.push(commentBlockView);
 
             prevBeginRowIndex = beginRowEl.rowIndex;
         } else {
             this._hiddenCommentBlockViews.push(commentBlockView);
         }
 
         return prevBeginRowIndex;
--- a/reviewboard/reviewboard/templates/diffviewer/view_diff.html
+++ b/reviewboard/reviewboard/templates/diffviewer/view_diff.html
@@ -20,16 +20,23 @@
 <h2>{% trans "There was an internal error displaying the diff." %}</h2>
 <p><b>{% blocktrans %}Details:</b> {{error}}{% endblocktrans %}</p>
 {%    if request.user.is_superuser %}
 {%     if trace %}<pre>{{trace|escape}}</pre>{% endif %}
 {%    endif %}
 {%   enderrorbox %}
 {%  else %}{# !error #}
 
+{# MozReview: add inline comments templates %}
+{% if siteconfig_settings.diffviewer_show_comments_inline %}
+{%  include "diffviewer/inline_comments.html" %}
+{% endif %}
+<div id="show_comments_inline"
+ data-enabled="{% if siteconfig_settings.diffviewer_show_comments_inline %}true{% else %}false{% endif %}">
+
 <div id="review_request">
  <div id="review_request_banners"></div>
 {% display_review_request_trophies review_request %}
 
 {%   box "review-request" %}
  <div class="review-request-header">
   <ul class="actions page-tabs">
    <li><a href="{{review_request.get_absolute_url}}">{% trans "Reviews" %}</a></li>