[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 (function () { 2 'use strict'; 3 4 /** 5 * @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org> 6 * @license GNU General Public License version 2 or later; see LICENSE.txt 7 */ 8 var SampleData = { 9 inProgress: false 10 }; 11 12 var sampledataAjax = function sampledataAjax(type, steps, step) { 13 // Get variables 14 var baseUrl = "index.php?option=com_ajax&format=json&group=sampledata&" + Joomla.getOptions('csrf.token') + "=1"; 15 var options = Joomla.getOptions('sample-data'); // Create list 16 17 var list = document.createElement('div'); 18 list.classList.add("sampledata-steps-" + type + "-" + step); 19 list.setAttribute('role', 'region'); 20 list.setAttribute('aria-live', 'polite'); // Create paragraph 21 22 var para = document.createElement('p'); 23 para.classList.add('loader-image'); 24 para.classList.add('text-center'); // Create image 25 26 var img = document.createElement('img'); 27 img.setAttribute('src', options.icon); 28 img.setAttribute('width', 30); 29 img.setAttribute('height', 30); // Append everything 30 31 para.appendChild(img); 32 list.appendChild(para); 33 document.querySelector(".sampledata-progress-" + type).appendChild(list); 34 Joomla.request({ 35 url: baseUrl + "&type=" + type + "&plugin=SampledataApplyStep" + step + "&step=" + step, 36 method: 'GET', 37 perform: true, 38 onSuccess: function onSuccess(resp) { 39 // Remove loader image 40 var loader = list.querySelector('.loader-image'); 41 loader.parentNode.removeChild(loader); 42 var response = {}; 43 44 try { 45 response = JSON.parse(resp); 46 } catch (e) { 47 Joomla.renderMessages({ 48 error: [Joomla.Text._('MOD_SAMPLEDATA_INVALID_RESPONSE')] 49 }, ".sampledata-steps-" + type + "-" + step); 50 SampleData.inProgress = false; 51 return; 52 } 53 54 var progressClass = ''; 55 var success; 56 57 if (response.success && response.data && response.data.length > 0) { 58 var progress = document.querySelector(".sampledata-progress-" + type + " .progress-bar"); // Display all messages that we got 59 60 response.data.forEach(function (value) { 61 if (value === null) { 62 return; 63 } // eslint-disable-next-line prefer-destructuring 64 65 66 success = value.success; 67 progressClass = success ? 'bg-success' : 'bg-danger'; // Display success alert 68 69 if (success) { 70 Joomla.renderMessages({ 71 message: [value.message] 72 }, ".sampledata-steps-" + type + "-" + step, false, 3000); 73 } else { 74 Joomla.renderMessages({ 75 error: [value.message] 76 }, ".sampledata-steps-" + type + "-" + step, false); 77 } 78 }); // Update progress 79 80 progress.innerText = step + "/" + steps; 81 progress.style.width = step / steps * 100 + "%"; 82 progress.setAttribute('aria-valuemin', 0); 83 progress.setAttribute('aria-valuemax', 100); 84 progress.setAttribute('aria-valuenow', step / steps * 100); 85 progress.classList.add(progressClass); // Move on next step 86 87 if (success && step <= steps) { 88 var stepNew = step + 1; 89 90 if (stepNew <= steps) { 91 sampledataAjax(type, steps, stepNew); 92 } else { 93 var bar = document.querySelector(".sampledata-progress-" + type); 94 bar.parentNode.removeChild(bar); 95 Joomla.renderMessages({ 96 message: [Joomla.Text._('MOD_SAMPLEDATA_COMPLETED')] 97 }); 98 window.scroll({ 99 top: 0, 100 left: 0, 101 behavior: 'smooth' 102 }); 103 SampleData.inProgress = false; 104 } 105 } 106 } else { 107 // Display error alert 108 Joomla.renderMessages({ 109 error: [Joomla.Text._('MOD_SAMPLEDATA_INVALID_RESPONSE')] 110 }); 111 window.scroll({ 112 top: 0, 113 left: 0, 114 behavior: 'smooth' 115 }); 116 SampleData.inProgress = false; 117 } 118 }, 119 onError: function onError() { 120 Joomla.renderMessages({ 121 error: ['Something went wrong! Please close and reopen the browser and try again!'] 122 }); 123 window.scroll({ 124 top: 0, 125 left: 0, 126 behavior: 'smooth' 127 }); 128 SampleData.inProgress = false; 129 } 130 }); 131 }; 132 133 var sampledataApply = function sampledataApply(element) { 134 var type = element.getAttribute('data-type'); 135 var steps = element.getAttribute('data-steps'); // Check whether the work in progress or we already processed with current item 136 137 if (SampleData.inProgress) { 138 return; 139 } 140 141 if (element.getAttribute('data-processed')) { 142 alert(Joomla.Text._('MOD_SAMPLEDATA_ITEM_ALREADY_PROCESSED')); 143 SampleData.inProgress = false; 144 return; 145 } // Make sure that use run this not by random clicking on the page links 146 // @todo use the CE Modal here 147 148 149 if (!window.confirm(Joomla.Text._('MOD_SAMPLEDATA_CONFIRM_START'))) { 150 // eslint-disable-next-line consistent-return 151 return false; 152 } // Turn on the progress container 153 154 155 var progressElements = [].slice.call(document.querySelectorAll(".sampledata-progress-" + type)); 156 progressElements.forEach(function (progressElement) { 157 progressElement.classList.remove('d-none'); 158 }); 159 element.getAttribute('data-processed', true); 160 SampleData.inProgress = true; 161 sampledataAjax(type, steps, 1); // eslint-disable-next-line consistent-return 162 163 return false; 164 }; 165 166 var sampleDataWrapper = document.getElementById('sample-data-wrapper'); 167 168 if (sampleDataWrapper) { 169 var links = [].slice.call(sampleDataWrapper.querySelectorAll('.apply-sample-data')); 170 links.forEach(function (link) { 171 link.addEventListener('click', function (_ref) { 172 var currentTarget = _ref.currentTarget; 173 return sampledataApply(currentTarget); 174 }); 175 }); 176 } 177 178 })();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |