? Pending

User tests: Successful: Unsuccessful:

avatar laoneo
laoneo
7 Feb 2018

Fixes the sampledate success part. @Bakual can you please test if it works an on J3?

avatar laoneo laoneo - open - 7 Feb 2018
avatar laoneo laoneo - change - 7 Feb 2018
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 7 Feb 2018
Category Modules Administration JavaScript
avatar dgt41
dgt41 - comment - 7 Feb 2018

@laneo here is some vanilla js:

/**
 * @copyright  Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
 * @license    GNU 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 got
					for(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 progress
					progress.value = step/steps;

					// Move on next step
					if (success) {
						step++;
						Joomla.sampledataAjax(type, steps, step);
					}

				} else {
					// Display error alert
					Joomla.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 item
		if (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 links
		if (!confirm(Joomla.JText._('MOD_SAMPLEDATA_CONFIRM_START'))) {
			return false;
		}

		// Turn on the progress container
		document.querySelector('.sampledata-progress-' + type).classList.remove('d-none');
		el.setAttribute('data-processed', true);

		inProgress = true;
		Joomla.sampledataAjax(type, steps, 1);
		return false;
	};

})(Joomla);
avatar C-Lodder
C-Lodder - comment - 7 Feb 2018

Just use the code from here: #19269

Was rewritten in Vanilla and fixed the UI

avatar laoneo
laoneo - comment - 8 Feb 2018

@C-Lodder can you not reopen yours and I will close mine? Makes more sense instead of duplicating your effort.

avatar C-Lodder
C-Lodder - comment - 8 Feb 2018

@laoneo done. Will fix the conflicts later on today

avatar laoneo
laoneo - comment - 8 Feb 2018

Closing in favor of #19269. Please test it that we can get it in.

avatar laoneo laoneo - change - 8 Feb 2018
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2018-02-08 08:28:37
Closed_By laoneo
Labels Added: ?
avatar laoneo laoneo - close - 8 Feb 2018

Add a Comment

Login with GitHub to post a comment