!function(){var t;t=jQuery,Craft.AssetIndexesUtility=Garnish.Base.extend({$trigger:null,$form:null,totalActions:null,completedActions:null,loadingActions:null,queue:null,cacheImages:!1,sessionId:null,init:function(s){this.$form=t("#"+s),this.$trigger=t("input.submit",this.$form),this.$status=t(".utility-status",this.$form),this.addListener(this.$form,"submit","onSubmit")},onSubmit:function(t){var s=this;t.preventDefault(),this.$trigger.hasClass("disabled")||(this.progressBar?this.progressBar.resetProgressBar():this.progressBar=new Craft.ProgressBar(this.$status,!0),this.totalActions=0,this.loadingActions=0,this.completedActions=0,this.queue=[],this.progressBar.$progressBar.removeClass("hidden"),this.progressBar.$progressBarStatus.removeClass("hidden"),this.progressBar.$progressBar.velocity("stop").velocity({opacity:1},{complete:function(){var t=Garnish.getPostData(s.$form),e=Craft.expandPostArray(t);e.start=!0,s.cacheImages=e.cacheImages,Craft.postActionRequest("utilities/asset-index-perform-action",{params:e},(function(t){if(t.indexingData){s.sessionId=t.indexingData.sessionId;for(var e=0;e<t.indexingData.volumes.length;e++)for(var i=t.indexingData.volumes[e],o=0;o<i.total;o++)s.queue.push({process:!0,sessionId:s.sessionId,volumeId:i.volumeId,cacheImages:s.cacheImages}),s.totalActions++;s.totalActions>0?s.processIndexing():s.finishIndexing()}}))}}),this.$allDone&&this.$allDone.css("opacity",0),this.$trigger.addClass("disabled"),this.$trigger.trigger("blur"))},updateProgressBar:function(){this.progressBar.setItemCount(this.totalActions),this.progressBar.setProcessedItemCount(this.completedActions),this.progressBar.updateProgressBar()},processIndexing:function(){var t=this;if(this.completedActions+this.loadingActions<this.totalActions&&this.loadingActions<Craft.AssetIndexesUtility.maxConcurrentActions){this.loadingActions++;var s=this.queue.shift();Craft.postActionRequest("utilities/asset-index-perform-action",{params:s},(function(s){t.loadingActions--,t.completedActions++,t.updateProgressBar(),s&&s.error&&alert(s.error),t.completedActions==t.totalActions?t.finishIndexing():t.processIndexing()})),this.processIndexing()}},showConfirmDialog:function(s){var e=t('<form class="modal fitted confirmmodal"/>').appendTo(Garnish.$bod),i=t('<div class="body"/>').appendTo(e).html(s.confirm),o=t('<footer class="footer"/>').appendTo(e),a=t('<div class="buttons right"/>').appendTo(o);if(s.showDelete){var r=t("<button/>",{type:"button",class:"btn",text:Craft.t("app","Keep them")}).appendTo(a);t("<button/>",{type:"submit",class:"btn submit",text:Craft.t("app","Delete them")}).appendTo(a),this.addListener(r,"click",(function(){n.hide(),this.onComplete()}))}else t("<button/>",{type:"submit",class:"btn submit",text:Craft.t("app","OK")}).appendTo(a);Craft.initUiElements(i);var n=new Garnish.Modal(e,{hideOnEsc:!1,hideOnShadeClick:!1});this.addListener(e,"submit",(function(e){e.preventDefault(),n.settings.onHide=t.noop,n.hide();var o=Garnish.getPostData(i),a=Craft.expandPostArray(o);t.extend(a,s.params),a.finish=!0,Craft.postActionRequest("utilities/asset-index-perform-action",{params:a},t.noop),this.onComplete()}))},finishIndexing:function(){var t=this,s={sessionId:this.sessionId,overview:!0};Craft.postActionRequest("utilities/asset-index-perform-action",{params:s},(function(s){s.confirm?(t.hideProgressBar(),t.showConfirmDialog(s)):t.onComplete()}))},hideProgressBar:function(){this.progressBar.$progressBarStatus.addClass("hidden"),this.progressBar.$progressBar.velocity({opacity:0},{duration:"fast"})},onComplete:function(){this.hideProgressBar(),this.$allDone||(this.$allDone=t('<div class="alldone" data-icon="done" />').appendTo(this.$status),this.$allDone.css("opacity",0),this.$allDone.velocity({opacity:1},{duration:"fast"}),this.$trigger.removeClass("disabled"),this.$trigger.trigger("focus"))}},{maxConcurrentActions:3})}();
//# sourceMappingURL=AssetIndexesUtility.js.map