MozReview: Move status flag dropdown to review bar (Bug 1294323). r?glob draft
authorDavid Walsh <dwalsh@mozilla.com>
Fri, 21 Oct 2016 14:38:17 -0500
changeset 170 b1370dd19901e0c44a2da3bac207401bd5037762
parent 134 263571e34d45e33d59dec46827e818c11323366b
push idunknown
push userunknown
push dateunknown
reviewersglob
bugs1294323
MozReview: Move status flag dropdown to review bar (Bug 1294323). r?glob MozReview-Commit-ID: 1j9bkcUBEdY
reviewboard/reviewboard/static/rb/js/views/draftReviewBannerView_mozreview.js
--- a/reviewboard/reviewboard/static/rb/js/views/draftReviewBannerView_mozreview.js
+++ b/reviewboard/reviewboard/static/rb/js/views/draftReviewBannerView_mozreview.js
@@ -14,16 +14,18 @@ RB.DraftReviewBannerView = Backbone.View
     },
 
     /*
      * MozReview: Elements required to hold dropdown dialog
      */
     _$dialogContainer: $('#review-banner-dialog-container'),
     _$bannerContainer: $('#review-banner-dialog'),
 
+    _hookViews: [],
+
     /*
      * Returns the height of the banner.
      */
     getHeight: function() {
         return this._$banner.outerHeight();
     },
 
     render: function() {
@@ -45,26 +47,64 @@ RB.DraftReviewBannerView = Backbone.View
         model.on('saved destroyed', function() {
             this._$buttons.prop('disabled', false);
         }, this);
 
         model.on('publishError', function(errorText) {
             alert(errorText);
         });
 
+        // This only applies to when the review bar stars displayed
+        // i.e. someone started a review, didn't submit, and refreshed the page
+        $(document).on('mozreview_review_flag_ready', _.bind(function() {
+            if (!this.$el.is(':hidden')) {
+                // This trick borrowed from ReviewDialogView to load extra data
+                this.model.set('loaded', false);
+                this.model.ready();
+
+                this.addHooks();
+            }
+        }, this));
+
         return this;
     },
 
+    addHooks: function() {
+        /*
+         * MozReview: Show review flag dropdown
+         */
+        if (this._hookViews.length != 0) return;
+
+        RB.DraftDialogHook.each(function(hook) {
+            var HookView = hook.get('viewType'),
+                hookView = new HookView({
+                    model: this.model
+                });
+
+            this._hookViews.push(hookView);
+            hookView.$el.addClass('banner-status-flag').insertBefore(this._editButton);
+            hookView.render();
+        }, this);
+    },
+
+    removeHooks: function() {
+        _.each(this._hookViews, function(hookView) {
+            hookView.remove();
+        });
+        this._hookViews = [];
+    },
+
     /*
      * Shows the banner.
      *
      * The banner will appear to slide down from the top of the page.
      */
     show: function() {
         if (this.$el.is(':hidden')) {
+            this.addHooks();
             this.$el.slideDown();
             this._$banner
                 .hide()
                 .slideDown();
         }
     },
 
     /*
@@ -119,27 +159,34 @@ RB.DraftReviewBannerView = Backbone.View
     _onEditReviewClicked: function() {
         /* MozReview: RDV instance will be be called by another method
         RB.ReviewDialogView.create({
             review: this.model,
             reviewRequestEditor: this.options.reviewRequestEditor
         });
         */
 
-        if(this._$dialogContainer.hasClass('show-dialog')) {
+        if(this.isDialogOpen()) {
           this._onHideDialog();
         }
         else {
           this._onShowDialog();
         }
 
         return false;
     },
 
     /*
+     * MozReview: Returns open or closed state of review dialog
+     */
+    isDialogOpen: function() {
+        return this._$dialogContainer.hasClass('show-dialog');
+    },
+
+    /*
      * MozReview: Sets a max-height on the dropdown to avoid overflow
      */
     _setDialogHeight: function() {
       if(this._$bannerContainer) {
         this._$bannerContainer.css('max-height', (window.innerHeight - 80) + 'px');
       }
     },
 
@@ -177,17 +224,17 @@ RB.DraftReviewBannerView = Backbone.View
     },
 
     /*
      * Handler for the Publish button.
      *
      * Publishes the review.
      */
     _onPublishClicked: function() {
-      if(this._RDVInstance) {
+      if(this._RDVInstance && this.isDialogOpen()) {
         this._RDVInstance._saveReview(true);
       }
       else {
         this.model.publish({
           attrs: ['public']
         });
       }