Current File : /home/pacjaorg/.trash/media.1/mod_sampledata/js/sampledata-process.min.js |
/**
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/const SampleData={inProgress:!1},sampledataAjax=(e,r,a)=>{const i=`index.php?option=com_ajax&format=json&group=sampledata&${Joomla.getOptions("csrf.token")}=1`,o=document.createElement("div");o.classList.add(`sampledata-steps-${e}-${a}`),o.setAttribute("role","region"),o.setAttribute("aria-live","polite");const c=document.createElement("p");c.classList.add("loader-image");const n=document.createElement("joomla-core-loader");n.setAttribute("inline",!0),n.setAttribute("size",60),n.setAttribute("color","transparent"),c.appendChild(n),o.appendChild(c),document.querySelector(`.sampledata-progress-${e}`).appendChild(o),Joomla.request({url:`${i}&type=${e}&plugin=SampledataApplyStep${a}&step=${a}`,method:"GET",perform:!0,onSuccess:A=>{const m=o.querySelector(".loader-image");m.parentNode.removeChild(m);let l={};try{l=JSON.parse(A)}catch{Joomla.renderMessages({error:[Joomla.Text._("MOD_SAMPLEDATA_INVALID_RESPONSE")]},`.sampledata-steps-${e}-${a}`),SampleData.inProgress=!1;return}let p="",d;if(l.success&&l.data&&l.data.length>0){const s=document.querySelector(`.sampledata-progress-${e} .progress-bar`);if(l.data.forEach(t=>{t!==null&&(d=t.success,p=d?"bg-success":"bg-danger",d?Joomla.renderMessages({message:[t.message]},`.sampledata-steps-${e}-${a}`,!1,3e3):Joomla.renderMessages({error:[t.message]},`.sampledata-steps-${e}-${a}`,!1))}),s.innerText=`${a}/${r}`,s.style.width=`${a/r*100}%`,s.setAttribute("aria-valuemin",0),s.setAttribute("aria-valuemax",100),s.setAttribute("aria-valuenow",a/r*100),s.classList.add(p),d&&a<=r){const t=a+1;if(t<=r)sampledataAjax(e,r,t);else{const u=document.querySelector(`.sampledata-progress-${e}`);u.parentNode.removeChild(u),Joomla.renderMessages({message:[Joomla.Text._("MOD_SAMPLEDATA_COMPLETED")]}),window.scroll({top:0,left:0,behavior:"smooth"}),SampleData.inProgress=!1}}}else Joomla.renderMessages({error:[Joomla.Text._("MOD_SAMPLEDATA_INVALID_RESPONSE")]}),window.scroll({top:0,left:0,behavior:"smooth"}),SampleData.inProgress=!1},onError:()=>{Joomla.renderMessages({error:[Joomla.Text._("MOD_SAMPLEDATA_ERROR_RESPONSE")]}),window.scroll({top:0,left:0,behavior:"smooth"}),SampleData.inProgress=!1}})},sampledataApply=e=>{const r=e.getAttribute("data-type"),a=e.getAttribute("data-steps");if(!SampleData.inProgress){if(e.getAttribute("data-processed")){alert(Joomla.Text._("MOD_SAMPLEDATA_ITEM_ALREADY_PROCESSED")),SampleData.inProgress=!1;return}return window.confirm(Joomla.Text._("MOD_SAMPLEDATA_CONFIRM_START"))&&(document.querySelectorAll(`.sampledata-progress-${r}`).forEach(i=>{i.classList.remove("d-none")}),e.setAttribute("data-processed",!0),SampleData.inProgress=!0,sampledataAjax(r,a,1)),!1}},sampleDataWrapper=document.getElementById("sample-data-wrapper");sampleDataWrapper&&sampleDataWrapper.querySelectorAll(".apply-sample-data").forEach(e=>{e.addEventListener("click",({currentTarget:r})=>sampledataApply(r))});