clone for mozreview modification (
bug 1275865) r?davidwalsh
MozReview-Commit-ID: EOYdgXTb4Mu
new file mode 100644
--- /dev/null
+++ b/reviewboard/reviewboard/static/rb/js/views/abstractReviewableView_mozreview.js
@@ -0,0 +1,129 @@
+/*
+ * Abstract base for review UIs.
+ *
+ * This provides all the basics for creating a review UI. It does the
+ * work of loading in comments, creating views, and displaying comment dialogs,
+ */
+RB.AbstractReviewableView = Backbone.View.extend({
+ /*
+ * The AbstractCommentBlockView subclass that will be instantiated for
+ * rendering comment blocks.
+ */
+ commentBlockView: null,
+
+ /* The list type (as a string) for passing to CommentDlg. */
+ commentsListName: null,
+
+ /*
+ * Initializes AbstractReviewableView.
+ */
+ initialize: function(options) {
+ options = options || {};
+
+ console.assert(this.commentBlockView,
+ 'commentBlockView must be defined by the subclass');
+ console.assert(this.commentsListName,
+ 'commentsListName must be defined by the subclass');
+
+ this.commentDlg = null;
+ this._activeCommentBlock = null;
+ this.renderedInline = options.renderedInline || false;
+ },
+
+ /*
+ * Renders the reviewable to the page.
+ *
+ * This will call the subclass's renderContent(), and then handle
+ * rendering each comment block on the reviewable.
+ */
+ render: function() {
+ this.renderContent();
+
+ this.model.commentBlocks.each(this._addCommentBlockView, this);
+ this.model.commentBlocks.on('add', this._addCommentBlockView, this);
+
+ return this;
+ },
+
+ /*
+ * Renders the content of the reviewable.
+ *
+ * This should be overridden by subclasses.
+ */
+ renderContent: function() {
+ },
+
+ /*
+ * Creates a new comment in a comment block and opens it for editing.
+ */
+ createAndEditCommentBlock: function(opts) {
+ var defaultCommentBlockFields =
+ _.result(this.model, 'defaultCommentBlockFields');
+
+ if (defaultCommentBlockFields.length === 0 &&
+ this.model.reviewableIDField) {
+ console.log('Deprecation notice: Reviewable subclass is missing ' +
+ 'defaultCommentBlockFields. Rename reviewableIDField ' +
+ 'to defaultCommentBlockFields, and make it a list.');
+ defaultCommentBlockFields = [this.model.reviewableIDField];
+ }
+
+ /* As soon as we add the comment block, show the dialog. */
+ this.once('commentBlockViewAdded', function(commentBlockView) {
+ this.showCommentDlg(commentBlockView);
+ }, this);
+
+ _.extend(opts,
+ _.pick(this.model.attributes, defaultCommentBlockFields));
+ this.model.createCommentBlock(opts);
+ },
+
+ /*
+ * Shows the comment details dialog for a comment block.
+ */
+ showCommentDlg: function(commentBlockView) {
+ var commentBlock = commentBlockView.model;
+
+ commentBlock.ensureDraftComment();
+
+ if (this._activeCommentBlock === commentBlock) {
+ return;
+ }
+
+ this.stopListening(this.commentDlg, 'closed');
+ this.commentDlg = RB.CommentDialogView.create({
+ comment: commentBlock.get('draftComment'),
+ publishedComments: commentBlock.get('serializedComments'),
+ publishedCommentsType: this.commentsListName,
+ position: function(dlg) {
+ commentBlockView.positionCommentDlg(dlg);
+ }
+ });
+ this._activeCommentBlock = commentBlock;
+
+ this.listenTo(this.commentDlg, 'closed', function() {
+ this.commentDlg = null;
+ this._activeCommentBlock = null;
+ });
+ },
+
+ /*
+ * Adds a CommentBlockView for the given CommentBlock.
+ *
+ * This will create a view for the block, render it, listen for clicks
+ * in order to show the comment dialog, and then emit
+ * 'commentBlockViewAdded'.
+ */
+ _addCommentBlockView: function(commentBlock) {
+ var commentBlockView = new this.commentBlockView({
+ model: commentBlock
+ });
+
+ commentBlockView.on('clicked', function() {
+ this.showCommentDlg(commentBlockView);
+ }, this);
+
+ commentBlockView.render();
+ this.trigger('commentBlockViewAdded', commentBlockView);
+ }
+});
--- a/reviewboard/reviewboard/staticbundles.py
+++ b/reviewboard/reviewboard/staticbundles.py
@@ -201,17 +201,17 @@ PIPELINE_JS = dict({
'rb/js/models/textBasedReviewableModel.js',
'rb/js/models/uploadDiffModel.js',
'rb/js/pages/models/diffViewerPageModel.js',
'rb/js/pages/views/reviewablePageView_mozreview.js',
'rb/js/pages/views/reviewRequestPageView.js',
'rb/js/pages/views/diffViewerPageView.js',
'rb/js/utils/textUtils.js',
'rb/js/views/abstractCommentBlockView.js',
- 'rb/js/views/abstractReviewableView.js',
+ 'rb/js/views/abstractReviewableView_mozreview.js',
'rb/js/views/collapsableBoxView.js',
'rb/js/views/commentDialogView_mozreview.js',
'rb/js/views/commentIssueBarView.js',
'rb/js/views/diffFragmentQueueView.js',
'rb/js/views/dndUploaderView.js',
'rb/js/views/draftReviewBannerView_mozreview.js',
'rb/js/views/uploadAttachmentView.js',
'rb/js/views/revisionSelectorView.js',