/** * @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */if(!window.Joomla)throw new Error("Joomla API was not properly initialised");const initRunner=()=>{const t=Joomla.getOptions("system.paths"),l=Joomla.getOptions("com_scheduler.test-task.token"),T=`${t?`${t.base}/index.php`:window.location.pathname}?option=com_ajax&format=json&plugin=RunSchedulerTest&group=system&id=%d${l?`&${l}=1`:""}`,e=document.getElementById("scheduler-test-modal"),c=` <h4 class="scheduler-headline">${Joomla.Text._("COM_SCHEDULER_TEST_RUN_TASK")}</h4> <div>${Joomla.Text._("COM_SCHEDULER_TEST_RUN_STATUS_STARTED")}</div> <div class="mt-3 text-center"><span class="fa fa-spinner fa-spin fa-lg"></span></div> `,_=d=>d.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,"$1<br>$2"),m=d=>{const i=d.relatedTarget,s=parseInt(i.dataset.id,10),{title:S}=i.dataset;e.querySelector(".modal-title").innerHTML=Joomla.Text._("COM_SCHEDULER_TEST_RUN_TITLE").replace("%d",s.toString()),e.querySelector(".modal-body > div").innerHTML=c.replace("%s",S),Joomla.request({url:T.replace("%d",s.toString()),onSuccess:(n,r)=>{[].slice.call(e.querySelectorAll(".modal-body > div > div")).forEach(a=>{a.parentNode.removeChild(a)});const o=JSON.parse(n);if(o&&o.success&&o.data){if(e.querySelector(".modal-body > div").innerHTML+=`<div>${Joomla.Text._("COM_SCHEDULER_TEST_RUN_STATUS_COMPLETED")}</div>`,o.data.duration>0&&(e.querySelector(".modal-body > div").innerHTML+=`<div>${Joomla.Text._("COM_SCHEDULER_TEST_RUN_DURATION").replace("%s",o.data.duration.toFixed(2))}</div>`),o.data.output){const a=Joomla.sanitizeHtml(o.data.output,null,_);e.querySelector(".modal-body > div").innerHTML+=`<div>${Joomla.Text._("COM_SCHEDULER_TEST_RUN_OUTPUT").replace("%s",a)}</div>`}}else e.querySelector(".modal-body > div").innerHTML+=`<div>${Joomla.Text._("COM_SCHEDULER_TEST_RUN_STATUS_TERMINATED")}</div>`,e.querySelector(".modal-body > div").innerHTML+=`<div>${Joomla.Text._("COM_SCHEDULER_TEST_RUN_OUTPUT").replace("%s",Joomla.Text._("JLIB_JS_AJAX_ERROR_OTHER").replace("%s",r.status))}</div>`},onError:n=>{e.querySelector(".modal-body > div").innerHTML+=`<div>${Joomla.Text._("COM_SCHEDULER_TEST_RUN_STATUS_TERMINATED")}</div>`;const r=Joomla.ajaxErrorsMessages(n);e.querySelector(".modal-body > div").innerHTML+=`<div>${Joomla.Text._("COM_SCHEDULER_TEST_RUN_OUTPUT").replace("%s",r.error)}</div>`}})},E=()=>{window.location.href=`${t?`${t.base}/index.php`:window.location.pathname}?option=com_scheduler&view=tasks`};e&&(e.addEventListener("show.bs.modal",m),e.addEventListener("hidden.bs.modal",E)),document.removeEventListener("DOMContentLoaded",initRunner)};document.addEventListener("DOMContentLoaded",initRunner);