[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/com_scheduler/js/ -> admin-view-run-test-task-es5.js (source)

   1  (function () {
   2    'use strict';
   3  
   4    /**
   5     * @copyright   (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
   6     * @license     GNU General Public License version 2 or later; see LICENSE.txt
   7     */
   8  
   9    /**
  10     * Provides the manual-run functionality for tasks over the com_scheduler administrator backend.
  11     *
  12     * @package  Joomla.Components
  13     * @subpackage Scheduler.Tasks
  14     *
  15     * @since    4.1.0
  16     */
  17    if (!window.Joomla) {
  18      throw new Error('Joomla API was not properly initialised');
  19    }
  20  
  21    var initRunner = function initRunner() {
  22      var paths = Joomla.getOptions('system.paths');
  23      var token = Joomla.getOptions('com_scheduler.test-task.token');
  24      var uri = (paths ? paths.base + "/index.php" : window.location.pathname) + "?option=com_ajax&format=json&plugin=RunSchedulerTest&group=system&id=%d" + (token ? "&" + token + "=1" : '');
  25      var modal = document.getElementById('scheduler-test-modal'); // Task output template
  26  
  27      var template = "\n    <h4 class=\"scheduler-headline\">" + Joomla.Text._('COM_SCHEDULER_TEST_RUN_TASK') + "</h4>\n    <div>" + Joomla.Text._('COM_SCHEDULER_TEST_RUN_STATUS_STARTED') + "</div>\n    <div class=\"mt-3 text-center\"><span class=\"fa fa-spinner fa-spin fa-lg\"></span></div>\n  ";
  28  
  29      var sanitiseTaskOutput = function sanitiseTaskOutput(text) {
  30        return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1<br>$2');
  31      }; // Trigger the task through a GET request, populate the modal with output on completion.
  32  
  33  
  34      var triggerTaskAndShowOutput = function triggerTaskAndShowOutput(e) {
  35        var button = e.relatedTarget;
  36        var id = parseInt(button.dataset.id, 10);
  37        var title = button.dataset.title;
  38        modal.querySelector('.modal-title').innerHTML = Joomla.Text._('COM_SCHEDULER_TEST_RUN_TITLE').replace('%d', id.toString());
  39        modal.querySelector('.modal-body > div').innerHTML = template.replace('%s', title);
  40        Joomla.request({
  41          url: uri.replace('%d', id.toString()),
  42          onSuccess: function onSuccess(data, xhr) {
  43            [].slice.call(modal.querySelectorAll('.modal-body > div > div')).forEach(function (el) {
  44              el.parentNode.removeChild(el);
  45            });
  46            var output = JSON.parse(data);
  47  
  48            if (output && output.success && output.data) {
  49              modal.querySelector('.modal-body > div').innerHTML += "<div>" + Joomla.Text._('COM_SCHEDULER_TEST_RUN_STATUS_COMPLETED') + "</div>";
  50  
  51              if (output.data.duration > 0) {
  52                modal.querySelector('.modal-body > div').innerHTML += "<div>" + Joomla.Text._('COM_SCHEDULER_TEST_RUN_DURATION').replace('%s', output.data.duration.toFixed(2)) + "</div>";
  53              }
  54  
  55              if (output.data.output) {
  56                var result = Joomla.sanitizeHtml(output.data.output, null, sanitiseTaskOutput); // Can use an indication for non-0 exit codes
  57  
  58                modal.querySelector('.modal-body > div').innerHTML += "<div>" + Joomla.Text._('COM_SCHEDULER_TEST_RUN_OUTPUT').replace('%s', result) + "</div>";
  59              }
  60            } else {
  61              modal.querySelector('.modal-body > div').innerHTML += "<div>" + Joomla.Text._('COM_SCHEDULER_TEST_RUN_STATUS_TERMINATED') + "</div>";
  62              modal.querySelector('.modal-body > div').innerHTML += "<div>" + Joomla.Text._('COM_SCHEDULER_TEST_RUN_OUTPUT').replace('%s', Joomla.Text._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status)) + "</div>";
  63            }
  64          },
  65          onError: function onError(xhr) {
  66            modal.querySelector('.modal-body > div').innerHTML += "<div>" + Joomla.Text._('COM_SCHEDULER_TEST_RUN_STATUS_TERMINATED') + "</div>";
  67            var msg = Joomla.ajaxErrorsMessages(xhr);
  68            modal.querySelector('.modal-body > div').innerHTML += "<div>" + Joomla.Text._('COM_SCHEDULER_TEST_RUN_OUTPUT').replace('%s', msg.error) + "</div>";
  69          }
  70        });
  71      };
  72  
  73      var reloadOnClose = function reloadOnClose() {
  74        window.location.href = (paths ? paths.base + "/index.php" : window.location.pathname) + "?option=com_scheduler&view=tasks";
  75      };
  76  
  77      modal.addEventListener('show.bs.modal', triggerTaskAndShowOutput);
  78      modal.addEventListener('hidden.bs.modal', reloadOnClose);
  79      document.removeEventListener('DOMContentLoaded', initRunner);
  80    };
  81  
  82    document.addEventListener('DOMContentLoaded', initRunner);
  83  
  84  })();


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer