/** * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @licenseGNU General Public License version 2 or later; see LICENSE.txt*/var Joomla =window.Joomla|| {};
!(function (Joomla) {
"use strict";
var inProgress =false;
Joomla.sampledataAjax=function(type, steps, step) {
if (step > steps) {
document.querySelector('.sampledata-'+ type +' .row-title').innerHTML+='<span class="fa fa-check"> </span>';
document.querySelector('.sampledata-progress-'+ type).classList.add('d-none');
inProgress =false;
return;
}
var stepLi =document.createElement('li');
var stepLiP =document.createElement('li');
var stepLiPImg =document.createElement('img');
var progress =document.querySelector(".sampledata-progress-"+ type +" progress");
stepLi.classList.add('sampledata-steps-'+ type +'-'+ step);
stepLiP.classList.add('loader-image');
stepLiP.classList.add('text-center');
stepLiPImg.src=window.modSampledataIconProgress;
stepLiPImg.setAttribute('width', 30);
stepLiPImg.setAttribute('height', 30);
stepLiP.appendChild(stepLiPImg);
stepLi.appendChild(stepLiP);
document.querySelector("div.sampledata-progress-"+ type +" ul").appendChild(stepLi);
Joomla.request({
url:window.modSampledataUrl,
method :'POST',
data: {
type: type,
plugin:'SampledataApplyStep'+ step,
step: step
},
perform :true,
onSuccess:function (response, xhr) {
var response =JSON.parse(response);
stepLi.querySelector('.loader-image').remove();
if (response.success&&response.data&&response.data.length>0) {
var success, value, resultClass, $msg;
// Display all messages that we gotfor(var i =0, l =response.data.length; i < l; i++) {
value =response.data[i];
success =value.success;
resultClass = success ?'success':'error';
var divEl =document.createElement('div');
divEl.innerHTML=value.message;
divEl.classList.add('alert');
divEl.classList.add('alert-'+ resultClass);
stepLi.appendChild(divEl);
}
// Update progressprogress.value= step/steps;
// Move on next stepif (success) {
step++;
Joomla.sampledataAjax(type, steps, step);
}
} else {
// Display error alertJoomla.renderMessages({'error': [Joomla.JText._('MOD_SAMPLEDATA_INVALID_RESPONSE')]}, '.sampledata-steps-'+ type +'-'+ step);
inProgress =false;
}
},
onError:function (xhr) {
alert('Something went wrong! Please close and reopen the browser and try again!');
}
});
};
Joomla.sampledataApply=function(el) {
var type =el.getAttribute('data-type');
var steps =el.getAttribute('data-steps');
// Check whether the work in progress or we alredy proccessed with current itemif (inProgress) {
return;
}
if (el.getAttribute('data-processed')) {
alert(Joomla.JText._('MOD_SAMPLEDATA_ITEM_ALREADY_PROCESSED'));
return;
}
// Make sure that use run this not by random clicking on the page linksif (!confirm(Joomla.JText._('MOD_SAMPLEDATA_CONFIRM_START'))) {
returnfalse;
}
// Turn on the progress containerdocument.querySelector('.sampledata-progress-'+ type).classList.remove('d-none');
el.setAttribute('data-processed', true);
inProgress =true;
Joomla.sampledataAjax(type, steps, 1);
returnfalse;
};
})(Joomla);
@laneo here is some vanilla js: