!function(){var e,t;e=this,t=function(e,t){"use strict";var i;let s=t.spina(i=class s extends RB.FloatingBannerView{static className="banner";static events={"click .discard-button":"_onDiscardClicked","click .publish-button":"_onPublishClicked"};static modelEvents={publishError:"_onPublishError",saved:"_onSaved","saving destroying":"_onSavingOrDestroying"};static template=_.template(`<h1>${gettext("This reply is a draft.")}</h1>
<p>${gettext("Be sure to publish when finished.")}</p>
<span class="banner-actions">
 <input type="button" value="${gettext("Publish")}"
        class="publish-button" />
 <input type="button" value="${gettext("Discard")}"
        class="discard-button" />
</span>
<% if (showSendEmail) { %>
 <label>
  <input type="checkbox" class="send-email" checked />
  ${gettext("Send E-Mail")}
</label>
<% } %>`);#reviewRequestEditor;initialize(e){super.initialize(e),this.#reviewRequestEditor=e.reviewRequestEditor}onInitialRender(){super.onInitialRender(),this.$el.html(s.template({showSendEmail:this.#reviewRequestEditor.get("showSendEmail")}))}_onPublishClicked(){var e=this.$(".send-email");this.model.publish({trivial:1===e.length&&!e.is(":checked")})}_onDiscardClicked(){this.model.destroy()}_onPublishError(e){alert(e)}_onSavingOrDestroying(){this.$("input").prop("disabled",!0)}_onSaved(){this.$("input").prop("disabled",!1)}})||i,a=t.spina(i=class a extends t.BaseView{static className="banner";static template=_.template(`<h1><%- draftText %></h1>
<p><%- reminderText %></p>`);onInitialRender(){this.$el.html(a.template({draftText:gettext("This reply is a draft."),reminderText:gettext("Be sure to publish when finished.")}))}})||i;t={ReviewReplyDraftBannerView:s,ReviewReplyDraftStaticBannerView:a};e.ReviewRequestPage=t,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})},"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@beanbag/spina")):"function"==typeof define&&define.amd?define(["exports","@beanbag/spina"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).RB=e.RB||{},e.Spina),RB.ReviewRequestPage.Entry=Backbone.Model.extend({defaults:{addedTimestamp:null,collapsed:!1,etag:null,page:null,reviewRequestEditor:null,typeID:null,updatedTimestamp:null},parse(e){return{id:e.id,collapsed:e.collapsed,addedTimestamp:_.isDate(e.addedTimestamp)?e.addedTimestamp:moment.utc(e.addedTimestamp).toDate(),etag:e.etag||null,updatedTimestamp:_.isDate(e.updatedTimestamp)?e.updatedTimestamp:moment.utc(e.updatedTimestamp).toDate(),typeID:e.typeID,reviewRequestEditor:e.reviewRequestEditor}},isUpdated(e){var t=moment.utc(e.updatedTimestamp).toDate(),e=e.etag||null,i=this.get("etag")||null;return t>this.get("updatedTimestamp")||e!==i},beforeApplyUpdate(e){},afterApplyUpdate(e){},watchUpdates(e){this.get("page").watchEntryUpdates(this,e)},stopWatchingUpdates(){this.get("page").stopWatchingEntryUpdates(this)}}),RB.ReviewRequestPage.ReviewEntry=RB.ReviewRequestPage.Entry.extend({defaults:_.defaults({diffCommentsData:[],review:null},RB.ReviewRequestPage.Entry.prototype.defaults),parse(e){var t=e.reviewRequestEditor.get("reviewRequest"),i=e.reviewData;return _.extend(RB.ReviewRequestPage.Entry.prototype.parse.call(this,e),{diffCommentsData:e.diffCommentsData,review:t.createReview(i.id,{authorName:i.authorName,bodyBottom:i.bodyBottom,bodyTop:i.bodyTop,public:i.public,shipIt:i.shipIt})})}}),RB.ReviewRequestPage.ReviewReplyEditor=Backbone.Model.extend({defaults:{anchorPrefix:null,contextID:null,contextType:null,commentID:null,hasDraft:!1,replyObject:null,review:null,reviewReply:null,richText:null,text:""},replyClasses:{diff_comments:RB.DiffCommentReply,screenshot_comments:RB.ScreenshotCommentReply,file_attachment_comments:RB.FileAttachmentCommentReply,general_comments:RB.GeneralCommentReply},initialize(){this.on("change:reviewReply",this._setupReviewReply,this),this._setupReviewReply()},async save(){var e,t=this.get("contextType"),i=this.get("reviewReply");let s,a,r;"body_top"===t?(s="bodyTop",a="bodyTopRichText",r=i):"body_bottom"===t?(s="bodyBottom",a="bodyBottomRichText",r=i):(s="text",a="richText",(r=this.get("replyObject"))||(e=this.replyClasses[t],console.assert(e,"Unexpected context type '%s'",t),r=new e({parentObject:i,replyToID:this.get("contextID"),id:this.get("commentID")}))),this.set("replyObject",r),this.trigger("saving"),await r.ready();t=this.get("text");t?(r.set(s,t),r.set(a,this.get("richText")),r.set({forceTextType:"html",includeTextTypes:"raw"}),await r.save({attrs:[s,a,"forceTextType","includeTextTypes","replyToID"]}),this.set({hasDraft:!0,text:r.get(s),richText:!0}),this.trigger("textUpdated"),this.trigger("saved")):await this.resetStateIfEmpty()},async resetStateIfEmpty(){var e,t;""===this.get("text").strip()&&(!(e=this.get("replyObject"))||e.isNew()?await this._resetState():"body_top"===(t=this.get("contextType"))||"body_bottom"===t?await this._resetState(!0):(await e.destroy(),await this._resetState()))},_setupReviewReply(){var e=this.get("reviewReply"),t=this.previous("reviewReply");t&&t.off(null,null,this),this.listenTo(e,"destroyed",async()=>{this.trigger("discarded"),await this._resetState(),this.trigger("discarded-finished")}),this.listenTo(e,"published",async()=>{this.trigger("published"),await this._resetState(!1),this.trigger("published-finished")})},async _resetState(e){this.set({commentID:null,hasDraft:!1,replyObject:null}),!1!==e&&await this.get("reviewReply").discardIfEmpty(),this.trigger("resetState")}}),RB.ReviewRequestPage.ReviewRequestPage=RB.ReviewablePage.extend({WATCH_UPDATED_BACKOFF_MULTIPLIER:1.15,WATCH_UPDATED_POLL_CAP_MS:1e4,defaults:_.defaults({updatesURL:null},RB.ReviewablePage.prototype.defaults),initialize(){RB.ReviewablePage.prototype.initialize.apply(this,arguments),this._watchedEntries={},this._watchedUpdatesPeriodMS=null,this._watchedUpdatesTimeout=null,this._watchedUpdatesLastScheduleTime=null,this._watchedUpdatesLastTimestamp=null,this.entries=new Backbone.Collection([],{model:RB.ReviewRequestPage.Entry})},parse(e){return _.extend({updatesURL:e.updatesURL},RB.ReviewablePage.prototype.parse.call(this,e))},addEntry(e){e.set("page",this),this.entries.add(e)},watchEntryUpdates(e,t){(null===this._watchedUpdatesPeriodMS||t<this._watchedUpdatesPeriodMS)&&(null!==this._watchedUpdatesTimeout&&Date.now()-this._watchedUpdatesLastScheduleTime>t&&(clearTimeout(this._watchedUpdatesTimeout),this._watchedUpdatesTimeout=null),this._watchedUpdatesPeriodMS=t),this._watchedEntries[e.id]={entry:e,periodMS:t},this._watchedUpdatesLastTimestamp=null,this._scheduleCheckUpdates()},stopWatchingEntryUpdates(e){if(this._watchedEntries.hasOwnProperty(e.id))if(delete this._watchedEntries[e.id],this._watchedUpdatesPeriodMS=null,_.isEmpty(this._watchedEntries))null!==this._watchedUpdatesTimeout&&(clearTimeout(this._watchedUpdatesTimeout),this._watchedUpdatesTimeout=null),this._watchedUpdatesLastScheduleTime=null;else for(var t in this._watchedEntries)this._watchedEntries.hasOwnProperty(t)&&(t=this._watchedEntries[t].periodMS,this._watchedUpdatesPeriodMS=null===this._watchedUpdatesPeriodMS?t:Math.min(this._watchedUpdatesPeriodMS,t))},_scheduleCheckUpdates(){null===this._watchedUpdatesTimeout&&null!==this._watchedUpdatesPeriodMS&&(this._watchedUpdatesLastScheduleTime=Date.now(),this._watchedUpdatesTimeout=setTimeout(()=>{this._watchedUpdatesTimeout=null,this._loadUpdates({entries:_.pluck(this._watchedEntries,"entry"),onDone:e=>{0===e&&(this._watchedUpdatesPeriodMS=Math.round(Math.min(this.WATCH_UPDATED_POLL_CAP_MS,this._watchedUpdatesPeriodMS*this.WATCH_UPDATED_BACKOFF_MULTIPLIER))),this._scheduleCheckUpdates()}})},this._watchedUpdatesPeriodMS))},_loadUpdates(){let t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};var e=this.get("updatesURL"),i={},s=t.entries||[],a=[];if(0<s.length){for(let e=0;e<s.length;e++){var r=s[e],n=r.get("typeID");i.hasOwnProperty(n)||(i[n]=[]),i[n].push(r.id)}var o,l,d=[];for(o in i)i.hasOwnProperty(o)&&(i[o].sort((e,t)=>e-t),l=i[o].join(","),d.push(o+":"+l));a.push("entries="+d.join(";"))}var h=this._watchedUpdatesLastTimestamp,h=(null!==h&&a.push("since="+h.toISOString()),a.sort(),0<a.length?"?"+a.join("&"):"");Backbone.sync("read",this,{url:e+h,dataType:"arraybuffer",noActivityIndicator:!0,success:e=>this._processUpdatesFromPayload(e,t.onDone)})},_processUpdatesFromPayload(t,r){if(0===t.byteLength)r(0);else{var n=new DataView(t),o=n.byteLength;let e=0,i=0,s=0,a=!1;for(var l=(e,t)=>{"entry"===e.type?this._processEntryUpdate(e,t):this._reloadFromUpdate(null,e,t),e.hasOwnProperty("updatedTimestamp")&&(t=moment.utc(e.updatedTimestamp).toDate(),null===(e=this._watchedUpdatesLastTimestamp)||e<t)&&(this._watchedUpdatesLastTimestamp=t),s++,a&&s===i&&(this.trigger("updatesProcessed"),_.isFunction(r))&&r(s)};!a;){var d=this._processUpdateFromPayload(t,n,e);i++,e=d.pos,a=e>=o,d.load(l)}}},_processUpdateFromPayload(s,e,t){const a=e.getUint32(t,!0),r=t+=4,n=(t+=a,e.getUint32(t,!0)),o=t+=4;return{pos:t+=n,load(i){var e=new Blob([s.slice(r,r+a)]),t=new Blob([s.slice(o,o+n)]);RB.DataUtils.readManyBlobsAsStrings([e,t],(e,t)=>i(JSON.parse(e),t))}}},_processEntryUpdate(e,t){var i=this.entries.get(e.entryID);i&&(console.assert(i.get("typeID")===e.entryType),i.isUpdated(e))&&this._reloadFromUpdate(i,e,t)},_reloadFromUpdate(e,t,i){this.trigger("applyingUpdate:"+t.type,t,i),e&&(this.trigger(`applyingUpdate:${t.type}:`+e.id,t,i),_.isFunction(e.beforeApplyUpdate)&&e.beforeApplyUpdate(t),e.set(e.parse(_.extend({},e.attributes,t.modelData,{etag:t.etag,updatedTimestamp:t.updatedTimestamp}))),this.trigger(`appliedModelUpdate:${t.type}:`+e.id,t,i),_.isFunction(e.afterApplyUpdate)&&e.afterApplyUpdate(t),this.trigger(`appliedUpdate:${t.type}:`+e.id,t,i)),this.trigger("appliedUpdate:"+t.type,t,i)}}),RB.ReviewRequestPage.StatusUpdatesEntry=RB.ReviewRequestPage.Entry.extend({defaults(){return _.defaults({diffCommentsData:[],localSitePrefix:null,pendingStatusUpdates:!1,reviewRequestId:null,reviews:[]},RB.ReviewRequestPage.Entry.prototype.defaults)},parse(e){const t=e.reviewRequestEditor.get("reviewRequest");var i=(e.reviewsData||[]).map(e=>t.createReview(e.id,{bodyBottom:e.bodyBottom,bodyTop:e.bodyTop,public:e.public,shipIt:e.shipIt}));return _.extend(RB.ReviewRequestPage.Entry.prototype.parse.call(this,e),{diffCommentsData:e.diffCommentsData,localSitePrefix:t.get("localSitePrefix"),pendingStatusUpdates:e.pendingStatusUpdates,reviewRequestId:t.id,reviews:i})}});{const i=RB.ReviewRequestPage.StatusUpdatesEntry;RB.ReviewRequestPage.ChangeEntry=i.extend({defaults(){return _.defaults({commits:null},i.prototype.defaults.call(this))},parse(e){var t=e.commits?new RB.DiffCommitCollection(e.commits,{parse:!0}):null;return _.extend(i.prototype.parse.call(this,e),{commits:t})}})}RB.ReviewRequestPage.EntryView=Backbone.View.extend({events:{"click .collapse-button":"_onToggleCollapseClicked"},render(){return this._$box=this.$(".review-request-page-entry-contents"),this._$expandCollapseButton=this.$(".collapse-button .rb-icon"),this._$box.hasClass("collapsed")?this._$expandCollapseButton.addClass("rb-icon-expand-review"):this._$expandCollapseButton.addClass("rb-icon-collapse-review"),this},isCollapsed(){return this._$box.hasClass("collapsed")},expand(){this._$box.removeClass("collapsed"),this._$expandCollapseButton.removeClass("rb-icon-expand-review").addClass("rb-icon-collapse-review"),this.model.set("collapsed",!1)},collapse(){this._$box.addClass("collapsed"),this._$expandCollapseButton.removeClass("rb-icon-collapse-review").addClass("rb-icon-expand-review"),this.model.set("collapsed",!0)},beforeApplyUpdate(e){},afterApplyUpdate(e){},_onToggleCollapseClicked(){this.isCollapsed()?this.expand():this.collapse()}});{const s=RB.ReviewRequestPage.EntryView;RB.ReviewRequestPage.BaseStatusUpdatesEntryView=s.extend({CHECK_UPDATES_MS:2e3,events:_.defaults({"click .status-update-request-run":"_onRequestRunClicked"},s.prototype.events),initialize(){s.prototype.initialize.apply(this,arguments),this._reviewViews=null},beforeApplyUpdate(){this.model.stopWatchingUpdates();var t=RB.PageManager.getPage().diffFragmentQueue,i=this.model.get("diffCommentsData")||[];for(let e=0;e<i.length;e++)t.saveFragment(i[e][0])},render(){return s.prototype.render.call(this),this._reviewViews=this.model.get("reviews").map(e=>{var t=this.$("#review"+e.id),e=new RB.ReviewRequestPage.ReviewView({el:t,model:e,entryModel:this.model,$bannerFloatContainer:t,$bannerParent:t.children(".banners"),bannerNoFloatContainerClass:"collapsed"});return e.render(),this.setupReviewView(e),e}),this.model.get("pendingStatusUpdates")&&this.model.watchUpdates(this.CHECK_UPDATES_MS),this},setupReviewView(e){},_onRequestRunClicked(e){var e=$(e.target),t=e.data("statusUpdateId"),i=this.model.get("reviewRequestId");RB.apiCall({type:"PUT",prefix:this.model.get("localSitePrefix")||"",path:`/review-requests/${i}/status-updates/${t}/`,buttons:e,data:{state:"request-run"},success:()=>{this.model.stopWatchingUpdates(),this.model.watchUpdates(0)}})}})}{const a=RB.ReviewRequestPage.BaseStatusUpdatesEntryView;RB.ReviewRequestPage.ChangeEntryView=a.extend({initialize(e){a.prototype.initialize.apply(this,arguments);var t=this.model.get("reviewRequestEditor");this.reviewRequest=t.get("reviewRequest"),this.reviewRequestEditorView=e.reviewRequestEditorView,this._commitListView=null,this._$boxStatus=null,this._$fixItLabel=null},render(){a.prototype.render.call(this),this._$boxStatus=this.$(".box-status"),this._$fixItLabel=$('<label class="fix-it-label">').hide().appendTo(this.$(".labels-container")),RB.formatText(this.$(".changedesc-text"),{bugTrackerURL:this.reviewRequest.get("bugTrackerURL"),isHTMLEncoded:!0}),this._updateLabels(),_.each(this.$(".diff-index tr"),e=>{var e=$(e),t=new RB.DiffComplexityIconView({numInserts:e.data("insert-count"),numDeletes:e.data("delete-count"),numReplaces:e.data("replace-count"),totalLines:e.data("total-line-count")});e.find(".diff-file-icon").empty().append(t.$el),t.render()}),_.each(this.$(".file-container"),e=>{var e=$(e),t=e.find(".file-caption .edit"),i=this.reviewRequest.draft.createFileAttachment({id:e.data("file-id")});t.hasClass("empty-caption")||i.set("caption",t.text()),this.reviewRequestEditorView.buildFileAttachmentThumbnail(i,null,{$el:e,canEdit:!1})});var e=this.model.get("commits");return e&&(this._commitListView=new RB.DiffCommitListView({el:this.$(".commit-list-container"),model:new RB.DiffCommitList({commits:e,diffHistory:new RB.CommitHistoryDiffEntryCollection})})),this},setupReviewView(e){this.listenTo(e,"openIssuesChanged",this._updateLabels)},_updateLabels(){var e;this._reviewViews.some(e=>e.hasOpenIssues())?(e=this._reviewViews.reduce((e,t)=>e+t.getOpenIssueCount(),0),this._$boxStatus.addClass("has-issues"),this._$fixItLabel.empty().append($('<span class="open-issue-count">').text(interpolate(gettext("%s failed"),[e]))).append(document.createTextNode(gettext("Fix it!"))).show().css({opacity:1,left:0})):(this._$fixItLabel.css({opacity:0,left:"-100px"}),this._$boxStatus.removeClass("has-issues"))}})}RB.ReviewRequestPage.InitialStatusUpdatesEntryView=RB.ReviewRequestPage.BaseStatusUpdatesEntryView.extend(),RB.ReviewRequestPage.IssueSummaryTableView=Backbone.View.extend({events:{"change .rb-c-issue-summary-table__reviewer-filter":"_onReviewerChanged","click thead th":"_onHeaderClicked","click .rb-c-tabs__tab":"_onTabChanged","click tbody tr[data-issue-id]":"_onIssueClicked"},stateToSelectorMap:{open:".-is-open",dropped:".-is-dropped",resolved:".-is-resolved",verifying:".-is-verifying-resolved, .-is-verifying-dropped",all:""},statusIconsMap:{open:"rb-icon-issue-open",dropped:"rb-icon-issue-dropped",resolved:"rb-icon-issue-resolved",verifying:"rb-icon-issue-verifying"},COLUMN_DESCRIPTION:1,COLUMN_REVIEWER:2,COLUMN_LAST_UPDATED:3,_noIssuesTemplate:_.template(`<tr class="rb-c-issue-summary-table__no-issues">
 <td colspan="5"><em><%- text %></em></td>
</tr>`),initialize(){this.statusFilterState=null,this.reviewerFilterState=null,this.reviewerToSelectorMap=null,this.commentIDToRowMap={},this._lastWindowWidth=null,this._$window=$(window),this._$currentTab=null,_.bindAll(this,"_onWindowResize")},render(){var e=this.$(".rb-c-issue-summary-table");console.assert(1===e.length),this._$header=e.children(".rb-c-review-request-field-tabular__header"),this._$tabs=this._$header.children(".rb-c-tabs"),this._$filters=this._$header.children(".rb-c-review-request-field-tabular__filters"),this._$reviewerFilter=this._$filters.children(".rb-c-issue-summary-table__reviewer-filter"),this._$table=e.children(".rb-c-review-request-field-tabular__data"),this._$thead=this._$table.children("thead"),this._$tbody=this._$table.children("tbody"),this._$reviewerHeader=this._$thead.find(`tr :nth-child(${this.COLUMN_REVIEWER})`);let t=!1;return(this._$noIssues=null)===this.statusFilterState?(this._$currentTab=this.$(".rb-c-tabs__tab.-is-active"),console.assert(1===this._$currentTab.length),this.statusFilterState=this._$currentTab.data("issue-state")):(this.$(".rb-c-tabs__tab.-is-active").removeClass("-is-active"),this._$currentTab=this.$(".rb-c-tabs__tab"+`[data-issue-state=${this.statusFilterState}]`).addClass("-is-active"),t=!0),this._buildMaps(),null===this.reviewerFilterState?this.reviewerFilterState=this._$reviewerFilter.val():(this._$reviewerFilter.val(this.reviewerFilterState),t=!0),t?(this._resetFilters(),this._applyFilters()):this._checkIssues(),this.stopListening(this.model,"issueStatusUpdated"),this.listenTo(this.model,"issueStatusUpdated",this._onIssueStatusChanged),this._$window.off("resize",this._onWindowResize),this._$window.on("resize",this._onWindowResize),this._onWindowResize(),this.$(".user").user_infobox(),this.$("time.timesince").timesince(),Djblets.enableRetinaImages(this.$el),this},_resetFilters(){this._getIssueRows().filter(".-is-hidden").removeClass("-is-hidden")},_applyFilters(){var e=this.stateToSelectorMap[this.statusFilterState]+this.reviewerToSelectorMap[this.reviewerFilterState];e&&this._getIssueRows().not(e).addClass("-is-hidden"),this._checkIssues(),this._updateReviewersPos()},_updateReviewersPos(){this._$reviewerHeader.is(":visible")?this._$filters.css({left:this._$reviewerHeader.offset().left-this._$table.offset().left+this._$reviewerHeader.getExtents("p","l")}):this._$filters.css("left","")},_checkIssues(){if(null!==this._$noIssues&&(this._$noIssues.remove(),this._$noIssues=null),this._$thead.show(),0===this._getIssueRows().not(".-is-hidden").length){var t=this.reviewerFilterState,i=this.statusFilterState;let e;"all"!==t?"open"===i?e=interpolate(gettext("There are no open issues from %s"),[t]):"verifying"===i?e=interpolate(gettext("There are no issues waiting for verification from %s"),[t]):"dropped"===i?e=interpolate(gettext("There are no dropped issues from %s"),[t]):"resolved"===i&&(e=interpolate(gettext("There are no resolved issues from %s"),[t])):"open"===i?e=gettext("There are no open issues"):"verifying"===i?e=gettext("There are no issues waiting for verification"):"dropped"===i?e=gettext("There are no dropped issues"):"resolved"===i&&(e=gettext("There are no resolved issues")),this._$thead.hide(),this._$noIssues=$(this._noIssuesTemplate({text:e})).appendTo(this._$tbody)}},_getIssueRows(){return this._$tbody.children().not(".rb-c-issue-summary-table__no-issues")},_sortByCol(o,l){this._$tbody.html(this._getIssueRows().sort((e,t)=>{var e=$(e),t=$(t),i=e.children(`td:nth-child(${o})`),s=t.children(`td:nth-child(${o})`);let a,r;r=o===this.COLUMN_LAST_UPDATED?(a=s.children("time").attr("datetime"),i.children("time").attr("datetime")):(a=i.text().strip().toLowerCase(),s.text().strip().toLowerCase()),a===r&&(i=e.data("issue-id"),s=t.data("issue-id"),r=l?(a=i,s):(a=s,i));let n;return n=a<r?-1:a>r?1:0,n=l?n:-n}))},_buildMaps(){this._$reviewerFilter.children().not('[value="all"]').remove(),this.reviewerToSelectorMap={all:""},_.each(this._getIssueRows(),e=>{e=$(e),e=(this.commentIDToRowMap[e.data("issue-id")]=e).data("reviewer");_.has(this.reviewerToSelectorMap,e)||(this.reviewerToSelectorMap[e]=`[data-reviewer="${e}"]`,this._$reviewerFilter.append($("<option>").text(e).val(e)))})},_onIssueStatusChanged(e,t,i){var s=this.commentIDToRowMap[e.id],e=e.get("issueStatus"),t=(RB.scrollManager.markForUpdate(this.$el),s.removeClass("-is-"+t).addClass("-is-"+e).find(".rb-icon").removeClass(this.statusIconsMap[t]).addClass(this.statusIconsMap[e]),this.statusFilterState!==e&&"all"!==this.statusFilterState?s.addClass("-is-hidden"):s.removeClass("-is-hidden"),this._$tabs.children(`[data-issue-state=${t}]`).find(".rb-c-issue-summary-table__counter")),e=this._$tabs.children(`[data-issue-state=${e}]`).find(".rb-c-issue-summary-table__counter");t.text(parseInt(t.text(),10)-1),e.text(parseInt(e.text(),10)+1),s.find("time").attr("datetime",new Date(i).toISOString()).text(i).timesince(),this._checkIssues(),this._updateReviewersPos(),RB.scrollManager.markUpdated(this.$el)},_onHeaderClicked(e){e.stopPropagation(),0!==this._getIssueRows().not(".-is-hidden").length&&this._sortByCol($(e.target).parent().children().index(e.target)+1,!e.shiftKey)},_onIssueClicked(e){"A"!==e.target.tagName&&(e.stopPropagation(),e=$(e.currentTarget),this.trigger("issueClicked",{commentType:e.data("comment-type"),commentID:e.data("issue-id"),commentURL:e.data("comment-href")}))},_onTabChanged(e){e=$(e.currentTarget);this._$currentTab.removeClass("-is-active"),this._resetFilters(),this.statusFilterState=e.data("issue-state"),this._applyFilters(),e.addClass("-is-active"),this._$currentTab=e},_onReviewerChanged(){this._resetFilters(),this.reviewerFilterState=this._$reviewerFilter.val(),this._applyFilters()},_onWindowResize(){var e=this._$window.width();e!==this._lastWindowWidth&&this._updateReviewersPos(),this._lastWindowWidth=e}});{const r=RB.ReviewRequestPage.EntryView;RB.ReviewRequestPage.ReviewEntryView=r.extend({events:_.defaults({"click .revoke-ship-it":"_revokeShipIt"},r.prototype.events),initialize(e){r.prototype.initialize.call(this,e),this.reviewRequestEditorView=e.reviewRequestEditorView,this._reviewView=null,this._draftBannerShown=!1,this._$boxStatus=null,this._$fixItLabel=null,this._$shipItLabel=null},beforeApplyUpdate(){var t=RB.PageManager.getPage().diffFragmentQueue,i=this.model.get("diffCommentsData");for(let e=0;e<i.length;e++)t.saveFragment(i[e][0])},render(){return r.prototype.render.call(this),this._reviewView=new RB.ReviewRequestPage.ReviewView({el:this.el,model:this.model.get("review"),entryModel:this.model,$bannerFloatContainer:this._$box,$bannerParent:this.$(".banners"),bannerNoFloatContainerClass:"collapsed",reviewRequestEditorView:this.reviewRequestEditorView}),this._$boxStatus=this.$(".box-status"),this._$fixItLabel=this._$boxStatus.find(".fix-it-label"),this._$shipItLabel=this._$boxStatus.find(".ship-it-label"),this.listenTo(this._reviewView,"hasDraftChanged",e=>this.$el.toggleClass("has-draft",e)),this.listenTo(this._reviewView,"openIssuesChanged",this._updateLabels),this._reviewView.render(),this._updateLabels(),this},getReviewReplyEditorView(e,t){return this._reviewView.getReviewReplyEditorView(e,t)},_updateLabels(){this._updateLabel(this._$fixItLabel,this._reviewView.hasOpenIssues(),"has-issues"),this._updateLabel(this._$shipItLabel,this.model.get("review").get("shipIt"),"ship-it")},_updateLabel(e,t,i){t?(this._$boxStatus.addClass(i),e.show().css({opacity:1,left:0})):(e.css({opacity:0,left:"-100px"}),this._$boxStatus.removeClass(i))},async _revokeShipIt(){this._$boxStatus.addClass("revoking-ship-it");var t=RB.ReviewRequestPage.ReviewEntryView.strings.revokeShipItConfirm;if(confirm(t)){t=this.model.get("review");await t.ready(),t.set("shipIt",!1);try{await t.save({attrs:["shipIt","includeTextTypes"]})}catch(e){return t.set("shipIt",!0),this._clearRevokingShipIt(),void alert(e.xhr.responseJSON.err.msg)}this._updateLabels(),setTimeout(()=>this._clearRevokingShipIt(),900)}else this._clearRevokingShipIt()},_clearRevokingShipIt(){this._$boxStatus.removeClass("revoking-ship-it")}},{strings:{revokeShipItConfirm:gettext("Are you sure you want to revoke this Ship It?\n\nThis cannot be undone.")}})}RB.ReviewRequestPage.ReviewReplyEditorView=Backbone.View.extend({commentTemplate:_.template(`<li <% if (isDraft) { %>class="draft"<% } %>
    <% if (commentID) { %>data-comment-id="<%= commentID %>"<% } %>>
 <% if (anchorName) { %>
  <a class="comment-anchor" name="<%- anchorName %>"></a>
  <div class="floating-anchor">
   <a href="#<%- anchorName %>"
      class="fa fa-link fa-flip-horizontal"></a>
  </div>
 <% } %>
 <div class="comment-author">
  <label for="<%= id %>">
   <div class="avatar-container"><%= avatarHTML %></div>
   <div class="user-reply-info">
    <a href="<%= userPageURL %>" class="user"><%- fullName %></a>
<% if (timestamp) { %>
    <span class="timestamp">
     <time class="timesince" datetime="<%= timestampISO %>">
<%= timestamp %></time>
    </span>
<% } %>
   </div>
  </label>
 </div>
 <div>
  <pre id="<%= id %>" class="comment-text reviewtext"><%- text %></pre>
 </div>
</li>`),events:{"click .add_comment_link":"_onAddCommentClicked"},initialize(e){this.options=e,this._$addCommentLink=null,this._$draftComment=null,this._$editor=null,this._$commentsList=null,this._inlineEditorView=null},render(){this._$addCommentLink=this.$(".add_comment_link"),this._$commentsList=this.$(".reply-comments");var e,t,i=this._$commentsList.children(".draft");0!==i.length&&(e=i.find("time"),t=i.find(".reviewtext"),this.model.set({commentID:i.data("comment-id"),text:t.html(),timestamp:new Date(e.attr("datetime")),richText:t.hasClass("rich-text"),hasDraft:!0}),this._createCommentEditor(i)),this.listenTo(this.model,"textUpdated",()=>{var e;this._$editor&&(e=this.model.get("review").get("parentObject"),RB.formatText(this._$editor,{newText:this.model.get("text"),richText:this.model.get("richText"),bugTrackerURL:e.get("bugTrackerURL")}))}),this.model.on("resetState",()=>{this._$draftComment&&this._$draftComment.fadeOut(()=>{this._$draftComment.remove(),this._$draftComment=null}),this._$addCommentLink.fadeIn()}),this.model.on("published",this._onPublished,this)},openCommentEditor(){this._createCommentEditor(this._makeCommentElement()),this._inlineEditorView.startEdit()},needsSave(){return this._inlineEditorView&&this._inlineEditorView.isDirty()},async save(){var e,t=this._inlineEditorView.submit({preventEvents:!0});t&&((e=this.options.reviewRequestEditor)&&e.decr("editCount"),this.model.set({richText:this._inlineEditorView.textEditor.richText,text:t}),await this.model.save())},_createCommentEditor(e){const t=this.options.reviewRequestEditor,i=(this._$draftComment=e,this._$editor=e.find("pre.reviewtext"),new RB.RichTextInlineEditorView({editIconClass:"rb-icon rb-icon-edit",el:this._$editor,formClass:"inline-comment-editor",hasRawValue:!0,multiline:!0,notifyUnchangedCompletion:!0,rawValue:this._$editor.data("raw-value")||"",textEditorOptions:{richText:this._$editor.hasClass("rich-text")}}));i.render(),this.listenTo(i,"beginEdit",()=>{t&&t.incr("editCount")}),this.listenTo(i,"complete",e=>{t&&t.decr("editCount"),this.model.set({richText:i.textEditor.richText,text:e}),this.model.save()}),this.listenTo(i,"cancel",()=>{t&&t.decr("editCount"),this.model.resetStateIfEmpty()}),this._inlineEditorView=i,this._$editor.removeAttr("data-raw-value"),this._$addCommentLink.hide()},_makeCommentElement(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=RB.UserSession.instance,i=this.model.get("review").get("parentObject"),s=e.now||moment().utcOffset(t.get("timezoneOffset")),t=$(this.commentTemplate(_.extend({anchorName:null,id:_.uniqueId("draft_comment_"),text:"",commentID:null,userPageURL:t.get("userPageURL"),fullName:t.get("fullName"),avatarHTML:t.getAvatarHTML(32),isDraft:!0,timestampISO:s.format(),timestamp:s.format("MMMM Do, YYYY, h:mm ")+(s.hour()<12?"a.m.":"p.m.")},e))).find(".user").user_infobox().end().find("time.timesince").timesince().end();return Djblets.enableRetinaImages(t),e.text&&RB.formatText(t.find(".reviewtext"),{newText:e.text,richText:e.richText,bugTrackerURL:i.get("bugTrackerURL")}),t.appendTo(this._$commentsList),t},_onAddCommentClicked(e){e.preventDefault(),e.stopPropagation(),this.openCommentEditor()},_onPublished(){var e;this._$draftComment&&((e=this.model).get("contextType"),this._$draftComment.replaceWith(this._makeCommentElement({anchorName:e.get("anchorPrefix")+e.get("replyObject").id,commentID:e.get("commentID"),text:e.get("text"),richText:e.get("richText"),isDraft:!1})),this._$draftComment=null)}});{const n={diff:"",file:"f",screenshot:"s"};RB.ReviewRequestPage.ReviewRequestPageView=RB.ReviewablePageView.extend({events:_.extend({"click #collapse-all":"_onCollapseAllClicked","click #expand-all":"_onExpandAllClicked"},RB.ReviewablePageView.prototype.events),initialize(){RB.ReviewablePageView.prototype.initialize.apply(this,arguments),this._entryViews=[],this._entryViewsByID={},this._rendered=!1,this._issueSummaryTableView=null;var e=this.model.get("reviewRequest");this.diffFragmentQueue=new RB.DiffFragmentQueueView({reviewRequestPath:e.get("reviewURL"),containerPrefix:"comment_container",queueName:"diff_fragments",el:document.getElementById("content"),diffFragmentViewOptions:{collapsible:!0}}),this.listenTo(this.model,"updatesProcessed",()=>this.diffFragmentQueue.loadFragments()),this.listenTo(this.model,"applyingUpdate:entry",(e,t)=>{var i=e.entryID;const s=this._entryViewsByID[i],a=s.isCollapsed();this._onApplyingUpdate(s,e),this.listenToOnce(this.model,"appliedModelUpdate:entry:"+i,(e,t)=>this._reloadView(s,t)),this.listenToOnce(this.model,"appliedUpdate:entry:"+i,e=>{this._onAppliedUpdate(s,e),a?s.collapse():s.expand()})})},render(){return RB.ReviewablePageView.prototype.render.call(this),this._entryViews.forEach(e=>e.render()),this._onHashChanged(),"onhashchange"in window&&(window.onhashchange=this._onHashChanged.bind(this)),this.diffFragmentQueue.loadFragments(),this._issueSummaryTableView=new RB.ReviewRequestPage.IssueSummaryTableView({el:$("#issue-summary"),model:this.model.commentIssueManager}),this._issueSummaryTableView.render(),this.listenTo(this._issueSummaryTableView,"issueClicked",this._onIssueClicked),this.listenTo(this.model,"appliedUpdate:issue-summary-table",(e,t)=>{this._reloadView(this._issueSummaryTableView,t)}),this._rendered=!0,this},addEntryView(e){var t=e.model;this._entryViews.push(e),this._entryViewsByID[t.id]=e,this.model.addEntry(t),this._rendered&&e.render()},queueLoadDiff(e,t,i){this.diffFragmentQueue.queueLoad(e,t,i)},openCommentEditor(t,i){for(let e=0;e<this._entryViews.length;e++){var s=this._entryViews[e],s=_.isFunction(s.getReviewReplyEditorView)?s.getReviewReplyEditorView(t,i):null;if(s){s.openCommentEditor();break}}},_reloadView(e,t){var i=e.$el,t=$(t);e.setElement(t),i.replaceWith(t),e.render()},_onApplyingUpdate(e,t){e&&_.isFunction(e.beforeApplyUpdate)&&e.beforeApplyUpdate(t)},_onAppliedUpdate(e,t){e&&_.isFunction(e.afterApplyUpdate)&&e.afterApplyUpdate(t)},_onHashChanged(){var e=RB.getLocationHash();let t=null;if(t=""!==e?e.includes("comment")?`a[name=${e}]`:"#"+e:t)for(let e=0;e<this._entryViews.length;e++){var i=this._entryViews[e],s=i.$(t);if(0<s.length){i.expand(),RB.scrollManager.scrollToElement(s);break}}},_onCollapseAllClicked(e){e.preventDefault(),e.stopPropagation(),this._entryViews.forEach(e=>e.collapse())},_onExpandAllClicked(e){e.preventDefault(),e.stopPropagation(),this._entryViews.forEach(e=>e.expand())},_onIssueClicked(e){const t=`#${n[e.commentType]}comment`+e.commentID;this._entryViews.forEach(e=>{0<e.$el.find(t).length&&e.expand()}),RB.navigateTo(e.commentURL)}})}RB.ReviewRequestPage.ReviewView=Backbone.View.extend({initialize(e){this.options=e,this.entryModel=e.entryModel,this.reviewRequestEditorView=e.reviewRequestEditorView,this._bannerView=null,this._draftBannerShown=!1,this._openIssueCount=0,this._reviewReply=null,this._replyEditors=[],this._replyEditorViews=[],this._replyDraftsCount=0,this._diffFragmentViews=[],this._$reviewComments=null,this._$bodyTop=null,this._$bodyBottom=null,this.model.set("includeTextTypes","html,raw,markdown"),this._setupNewReply(),this.listenTo(this.entryModel,"change:collapsed",()=>{this.entryModel.get("collapsed")||this._diffFragmentViews.forEach(e=>e.hideControls(!1))})},render(){const i=this.entryModel.get("reviewRequestEditor");this._$reviewComments=this.$(".review-comments");var e=this._$reviewComments.find(".review-comment-details .review-comment"),t=(this._$bodyTop=e.find(".body_top"),this._$bodyBottom=e.find(".body_bottom"),this._replyDraftsCount=0,this.on("hasDraftChanged",e=>{var t;RB.EnabledFeatures.unifiedBanner&&(t=RB.UnifiedBannerView.getInstance(!1))&&t.model.updateReplyDraftState(this._reviewReply,e),e?this._showReplyDraftBanner():this._hideReplyDraftBanner()}),_.each(this._$reviewComments.find(".issue-indicator"),e=>{var t,i=$(".issue-state",e);0<i.length&&(t=i.data("issue-status"),RB.BaseComment.isStateOpen(t)&&this._openIssueCount++,(e=new RB.CommentIssueBarView({el:e,reviewID:this.model.id,canVerify:i.data("can-verify"),commentID:i.data("comment-id"),commentType:i.data("comment-type"),interactive:i.data("interactive"),issueStatus:t})).render(),this.listenTo(e,"statusChanged",(e,t)=>{e=RB.BaseComment.isStateOpen(e),t=RB.BaseComment.isStateOpen(t);e!==t&&(t?this._openIssueCount++:this._openIssueCount--),this.trigger("openIssuesChanged")}))}),_.each(this.$(".comment-section"),e=>{var t=$(e),t=new RB.ReviewRequestPage.ReviewReplyEditor({anchorPrefix:t.data("reply-anchor-prefix"),contextID:t.data("context-id"),contextType:t.data("context-type"),review:this.model,reviewReply:this._reviewReply}),e=new RB.ReviewRequestPage.ReviewReplyEditorView({el:e,model:t,reviewRequestEditor:i});e.render(),this.listenTo(t,"change:hasDraft",(e,t)=>{t?(this._replyDraftsCount++,this.trigger("hasDraftChanged",!0)):(this._replyDraftsCount--,0===this._replyDraftsCount&&this.trigger("hasDraftChanged",!1))}),this._replyEditors.push(t),this._replyEditorViews.push(e),this.reviewRequestEditorView&&this.reviewRequestEditorView.addReviewReplyEditorView(e),t.get("hasDraft")&&this._replyDraftsCount++}),this.trigger("hasDraftChanged",0<this._replyDraftsCount),this._diffFragmentViews=[],RB.PageManager.getPage()),s=this.entryModel.get("diffCommentsData");for(let e=0;e<s.length;e++){var a=s[e];t.queueLoadDiff(a[0],a[1],e=>this._diffFragmentViews.push(e))}const r=this.model.get("parentObject").get("bugTrackerURL");return _.each(this.$("pre.reviewtext"),e=>{RB.formatText($(e),{bugTrackerURL:r})}),this.listenTo(this.model,"change:bodyTop",this._onBodyTopChanged),this.listenTo(this.model,"change:bodyBottom",this._onBodyBottomChanged),this.listenTo(this.model,"change:bodyTopRichText",this._onBodyTopRichTextChanged),this.listenTo(this.model,"change:bodyBottomRichText",this._onBodyBottomRichTextChanged),this},_onBodyTopChanged(){this._$bodyTop.html(this.model.get("htmlTextFields").bodyTop)},_onBodyTopRichTextChanged(){this.model.get("bodyTopRichText")?this._$bodyTop.addClass("rich-text"):this._$bodyTop.removeClass("rich-text")},_onBodyBottomChanged(){var e=this.model.get("htmlTextFields").bodyBottom;this._$bodyBottom.html(e).closest("li").toggle(e&&0<e.length)},_onBodyBottomRichTextChanged(){this.model.get("bodyBottomRichText")?this._$bodyBottom.addClass("rich-text"):this._$bodyBottom.removeClass("rich-text")},hasOpenIssues(){return 0<this._openIssueCount},getOpenIssueCount(){return this._openIssueCount},getReviewReplyEditorView(t,i){return void 0===i&&(i=null),_.find(this._replyEditorViews,e=>{e=e.model;return e.get("contextID")===i&&e.get("contextType")===t})},getReviewReply(){return this._reviewReply},_setupNewReply(t){t=t||this.model.createReply(),null!==this._reviewReply&&(this.stopListening(this._reviewReply),this._replyEditors.forEach(e=>e.set("reviewReply",t)),this.trigger("hasDraftChanged",!1)),this.listenTo(t,"destroyed published",()=>this._setupNewReply()),this._reviewReply=t},_showReplyDraftBanner(){this._draftBannerShown||(RB.EnabledFeatures.unifiedBanner?this._bannerView=new RB.ReviewRequestPage.ReviewReplyDraftStaticBannerView({model:this._reviewReply}):this._bannerView=new RB.ReviewRequestPage.ReviewReplyDraftBannerView({model:this._reviewReply,$floatContainer:this.options.$bannerFloatContainer,noFloatContainerClass:this.options.bannerNoFloatContainerClass,reviewRequestEditor:this.entryModel.get("reviewRequestEditor")}),this._bannerView.render(),this._bannerView.$el.appendTo(this.options.$bannerParent),this._draftBannerShown=!0)},_hideReplyDraftBanner(){this._draftBannerShown&&(this._bannerView.remove(),this._bannerView=null,this._draftBannerShown=!1)}})}.call(this);
