(function(){"use strict";/** * @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");var _=function c(){var t=Joomla.getOptions("system.paths"),i=Joomla.getOptions("com_scheduler.test-task.token"),u=(t?t.base+"/index.php":window.location.pathname)+"?option=com_ajax&format=json&plugin=RunSchedulerTest&group=system&id=%d"+(i?"&"+i+"=1":""),e=document.getElementById("scheduler-test-modal"),m=` <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> `,v=function(a){return a.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,"$1<br>$2")},E=function(a){var l=a.relatedTarget,s=parseInt(l.dataset.id,10),p=l.dataset.title;e.querySelector(".modal-title").innerHTML=Joomla.Text._("COM_SCHEDULER_TEST_RUN_TITLE").replace("%d",s.toString()),e.querySelector(".modal-body > div").innerHTML=m.replace("%s",p),Joomla.request({url:u.replace("%d",s.toString()),onSuccess:function(r,n){[].slice.call(e.querySelectorAll(".modal-body > div > div")).forEach(function(T){T.parentNode.removeChild(T)});var o=JSON.parse(r);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){var U=Joomla.sanitizeHtml(o.data.output,null,v);e.querySelector(".modal-body > div").innerHTML+="<div>"+Joomla.Text._("COM_SCHEDULER_TEST_RUN_OUTPUT").replace("%s",U)+"</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",n.status))+"</div>"},onError:function(r){e.querySelector(".modal-body > div").innerHTML+="<div>"+Joomla.Text._("COM_SCHEDULER_TEST_RUN_STATUS_TERMINATED")+"</div>";var n=Joomla.ajaxErrorsMessages(r);e.querySelector(".modal-body > div").innerHTML+="<div>"+Joomla.Text._("COM_SCHEDULER_TEST_RUN_OUTPUT").replace("%s",n.error)+"</div>"}})},S=function(){window.location.href=(t?t.base+"/index.php":window.location.pathname)+"?option=com_scheduler&view=tasks"};e&&(e.addEventListener("show.bs.modal",E),e.addEventListener("hidden.bs.modal",S)),document.removeEventListener("DOMContentLoaded",c)};document.addEventListener("DOMContentLoaded",_)})();