(function(){"use strict";/** * @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */if(!Joomla)throw new Error("Joomla API was not initialised properly");Joomla.Update=window.Joomla.Update||{stat_total:0,stat_files:0,stat_inbytes:0,stat_outbytes:0,password:null,totalsize:0,ajax_url:null,return_url:null,cached_instance:null,genericErrorMessage:function(e){var t=document.getElementById("errorDialogLabel"),a=document.getElementById("errorDialogMessage"),o=document.getElementById("joomlaupdate-progress"),r=document.getElementById("joomlaupdate-error");t.innerHTML=Joomla.Text._("COM_JOOMLAUPDATE_ERRORMODAL_HEAD_GENERIC"),a.innerHTML=e,e.toLowerCase()==="invalid login"&&(a.innerHTML=Joomla.Text._("COM_JOOMLAUPDATE_ERRORMODAL_BODY_INVALIDLOGIN")),o.classList.add("d-none"),r.classList.remove("d-none")},handleErrorResponse:function(e){var t=e.status===403,a=document.getElementById("errorDialogLabel"),o=document.getElementById("errorDialogMessage"),r=document.getElementById("joomlaupdate-progress"),l=document.getElementById("joomlaupdate-error");t?(a.innerHTML=Joomla.Text._("COM_JOOMLAUPDATE_ERRORMODAL_HEAD_FORBIDDEN"),o.innerHTML=Joomla.Text._("COM_JOOMLAUPDATE_ERRORMODAL_BODY_FORBIDDEN")):(a.innerHTML=Joomla.Text._("COM_JOOMLAUPDATE_ERRORMODAL_HEAD_SERVERERROR"),o.innerHTML=Joomla.Text._("COM_JOOMLAUPDATE_ERRORMODAL_BODY_SERVERERROR")),r.classList.add("d-none"),l.classList.remove("d-none")},startExtract:function(){Joomla.Update.stat_files=0,Joomla.Update.stat_inbytes=0,Joomla.Update.stat_outbytes=0,Joomla.Update.cached_instance=null,document.getElementById("extbytesin").innerText=Joomla.Update.formatBytes(Joomla.Update.stat_inbytes),document.getElementById("extbytesout").innerText=Joomla.Update.formatBytes(Joomla.Update.stat_outbytes),document.getElementById("extfiles").innerText=Joomla.Update.stat_files;var e=new FormData;e.append("task","startExtract"),e.append("password",Joomla.Update.password),Joomla.request({url:Joomla.Update.ajax_url,data:e,method:"POST",perform:!0,onSuccess:function(a){try{var o=JSON.parse(a);Joomla.Update.stepExtract(o)}catch(r){Joomla.Update.genericErrorMessage(r.message)}},onError:Joomla.Update.handleErrorResponse})},stepExtract:function(e){if(e.status===!1){Joomla.Update.genericErrorMessage(e.message);return}var t=document.getElementById("progress-bar"),a=document.getElementById("update-title");if(Joomla.Update.stat_inbytes=e.bytesIn,Joomla.Update.stat_percent=e.percent,Joomla.Update.stat_percent=Joomla.Update.stat_percent||100*(Joomla.Update.stat_inbytes/Joomla.Update.totalsize),Joomla.Update.stat_outbytes=e.bytesOut,Joomla.Update.stat_files=e.files,Joomla.Update.stat_percent<100?(t.classList.remove("bg-success"),t.style.width=Joomla.Update.stat_percent+"%",t.setAttribute("aria-valuenow",Joomla.Update.stat_percent)):Joomla.Update.stat_percent>=100&&(t.classList.add("bg-success"),t.style.width="100%",t.setAttribute("aria-valuenow",100)),t.innerText=Joomla.Update.stat_percent.toFixed(1)+"%",document.getElementById("extbytesin").innerText=Joomla.Update.formatBytes(Joomla.Update.stat_inbytes),document.getElementById("extbytesout").innerText=Joomla.Update.formatBytes(Joomla.Update.stat_outbytes),document.getElementById("extfiles").innerText=Joomla.Update.stat_files,e.done){t.classList.add("bg-success"),t.style.width="100%",t.setAttribute("aria-valuenow",100),a.innerHTML=Joomla.Text._("COM_JOOMLAUPDATE_UPDATING_COMPLETE"),Joomla.Update.finalizeUpdate();return}window.setTimeout(function(){Joomla.Update.delayedStepExtract(e.instance)},50)},delayedStepExtract:function(e){Joomla.Update.cached_instance=e;var t=new FormData;t.append("task","stepExtract"),t.append("password",Joomla.Update.password),e&&t.append("instance",e),Joomla.request({url:Joomla.Update.ajax_url,data:t,method:"POST",perform:!0,onSuccess:function(o){try{var r=JSON.parse(o);Joomla.Update.stepExtract(r)}catch(l){Joomla.Update.genericErrorMessage(l.message)}},onError:Joomla.Update.handleErrorResponse})},finalizeUpdate:function(){var e=new FormData;e.append("task","finalizeUpdate"),e.append("password",Joomla.Update.password),Joomla.request({url:Joomla.Update.ajax_url,data:e,method:"POST",perform:!0,onSuccess:function(){window.location=Joomla.Update.return_url},onError:Joomla.Update.handleErrorResponse})},formatBytes:function(e,t){if(t===void 0&&(t=2),e===0)return"0 "+Joomla.Text._("JLIB_SIZE_BYTES");var a=1024,o=t<0?0:t,r=[Joomla.Text._("JLIB_SIZE_BYTES"),Joomla.Text._("JLIB_SIZE_KB"),Joomla.Text._("JLIB_SIZE_MB"),Joomla.Text._("JLIB_SIZE_GB"),Joomla.Text._("JLIB_SIZE_TB"),Joomla.Text._("JLIB_SIZE_PB"),Joomla.Text._("JLIB_SIZE_EB"),Joomla.Text._("JLIB_SIZE_ZB"),Joomla.Text._("JLIB_SIZE_YB")],l=Math.floor(Math.log(e)/Math.log(a));return parseFloat((e/Math.pow(a,l)).toFixed(o))+" "+r[l]},resumeButtonHandler:function(e){e.preventDefault(),document.getElementById("joomlaupdate-progress").classList.remove("d-none"),document.getElementById("joomlaupdate-error").classList.add("d-none"),Joomla.Update.cached_instance===!1?Joomla.Update.startExtract():Joomla.Update.delayedStepExtract(Joomla.Update.cached_instance)},restartButtonHandler:function(e){e.preventDefault(),document.getElementById("joomlaupdate-progress").classList.remove("d-none"),document.getElementById("joomlaupdate-error").classList.add("d-none"),Joomla.Update.startExtract()}};var d=document.getElementById("joomlaupdate-resume"),m=document.getElementById("joomlaupdate-restart");d&&d.addEventListener("click",Joomla.Update.resumeButtonHandler),m&&m.addEventListener("click",Joomla.Update.restartButtonHandler);var n=Joomla.getOptions("joomlaupdate");n&&Object.keys(n).length&&(Joomla.Update.password=n.password,Joomla.Update.totalsize=n.totalsize,Joomla.Update.ajax_url=n.ajax_url,Joomla.Update.return_url=n.return_url,Joomla.Update.startExtract())})();