en-GB.mod_sampledata.ini
en-GB.mod_sampledata.sys.ini
diff --git a/administrator/modules/mod_sampledata/tmpl/default.php b/administrator/modules/mod_sampledata/tmpl/default.php
index 852130bc2281b..b7ea484fc5da6 100644
--- a/administrator/modules/mod_sampledata/tmpl/default.php
+++ b/administrator/modules/mod_sampledata/tmpl/default.php
@@ -11,52 +11,16 @@
JHtml::_('jquery.framework');
JHtml::_('bootstrap.tooltip');
+JHtml::_('script', 'mod_sampledata/sampledata-process.js', false, true);
-$url = 'index.php?option=com_ajax&format=json&group=sampledata';
-$js = '
-function applySampledataAjax(type, steps, step) {
- if (step <= steps) {
- jQuery("div.sampledata-progress-" + type + " ul").append("
");
- jQuery.get(
- "' . $url . '&type=" + type + "&plugin=SampledataApplyStep" + step,
- function(response) {
- var success = false;
- if (response.data.length > 0) {
- jQuery.each(
- response.data,
- function(index, value) {
- var successClass = "error";
- if (value.success) {
- success = true;
- successClass = "success";
- jQuery(".sampledata-progress-" + type + " progress").val(step/steps);
- }
- jQuery("li.sampledata-steps-" + type + "-" + step).removeClass("center");
- jQuery("li.sampledata-steps-" + type + "-" + step).addClass("alert alert-" + successClass);
- jQuery("li.sampledata-steps-" + type + "-" + step).html(value.message);
- }
- );
- if (success) {
- step++;
- applySampledataAjax(type, steps, step);
- }
- } else {
- jQuery(".sampledata-progress-" + type + " progress").val(0);
- jQuery("li.sampledata-steps-" + type + "-" + step).addClass("alert alert-error");
- jQuery("li.sampledata-steps-" + type + "-" + step).html("' . JText::_('MOD_SAMPLEDATA_INVALID_RESPONSE') . '");
- }
- }
- );
- }
-}
-function applySampledata(type, steps) {
- var step = 1;
- jQuery(".sampledata-" + type).after("");
- jQuery(".sampledata-" + type).after("");
- applySampledataAjax(type, steps, step);
-}';
+JText::script('MOD_SAMPLEDATA_CONFIRM_START');
+JText::script('MOD_SAMPLEDATA_ITEM_ALREADY_PROCESSED');
+JText::script('MOD_SAMPLEDATA_INVALID_RESPONSE');
-JFactory::getDocument()->addScriptDeclaration($js);
+JFactory::getDocument()->addScriptDeclaration('
+ var modSampledataUrl = "index.php?option=com_ajax&format=json&group=sampledata",
+ modSampledataIconProgress = "' . JUri::root(true) . '/media/jui/img/ajax-loader.gif";
+');
?>
@@ -64,7 +28,7 @@ function applySampledata(type, steps) {
$item) : ?>
+
+
+
+
diff --git a/media/mod_sampledata/js/sampledata-process.js b/media/mod_sampledata/js/sampledata-process.js
new file mode 100644
index 0000000000000..f32632b2d016f
--- /dev/null
+++ b/media/mod_sampledata/js/sampledata-process.js
@@ -0,0 +1,96 @@
+/**
+ * @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE.txt
+ */
+
+!(function ($) {
+ "use strict";
+
+ var inProgress = false;
+
+ var sampledataAjax = function(type, steps, step) {
+ if (step > steps) {
+ $('.sampledata-' + type + ' .row-title').append(' ');
+ inProgress = false;
+ return;
+ }
+ var stepClass = 'sampledata-steps-' + type + '-' + step,
+ $stepLi = $('
'),
+ $progress = $(".sampledata-progress-" + type + " progress");
+
+ $("div.sampledata-progress-" + type + " ul").append($stepLi);
+
+ var request = $.ajax({
+ url: window.modSampledataUrl,
+ type: 'POST',
+ dataType: 'json',
+ data: {
+ type: type,
+ plugin: 'SampledataApplyStep' + step,
+ step: step
+ }
+ });
+ request.done(function(response){
+ $stepLi.children('.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';
+ $stepLi.append($('', {
+ html: value.message,
+ 'class': 'alert alert-' + resultClass,
+ }));
+ }
+
+ // Update progress
+ $progress.val(step/steps);
+
+ // Move on next step
+ if (success) {
+ step++;
+ sampledataAjax(type, steps, step);
+ }
+
+ } else {
+ $stepLi.addClass('alert alert-error');
+ $stepLi.html(Joomla.JText._('MOD_SAMPLEDATA_INVALID_RESPONSE'));
+ inProgress = false;
+ }
+ });
+ request.fail(function(jqXHR, textStatus){
+ alert('Something went wrong! Please reboot the Windows and try again!');
+ });
+ };
+
+ window.sampledataApply = function(el) {
+ var $el = $(el), type = $el.data('type'), steps = $el.data('steps');
+
+ // Check whether the work in progress or we alredy proccessed with current item
+ if (inProgress) {
+ return;
+ }
+ if ($el.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
+ $('.sampledata-progress-' + type).show();
+ $el.data('processed', true)
+
+ inProgress = true;
+ sampledataAjax(type, steps, 1);
+ return false;
+ };
+
+})(jQuery);