mirror of
https://github.com/joomla-extensions/patchtester.git
synced 2025-01-03 07:12:36 +00:00
Restructure JavaScript
This commit is contained in:
parent
e436fb7a22
commit
60b48e2236
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
/** @var \PatchTester\View\Pulls\PullsHtmlView $this */
|
/** @var \PatchTester\View\Pulls\PullsHtmlView $this */
|
||||||
|
|
||||||
|
\JHtml::_('behavior.core');
|
||||||
\JHtml::_('bootstrap.tooltip');
|
\JHtml::_('bootstrap.tooltip');
|
||||||
\JHtml::_('formbehavior.chosen', 'select');
|
\JHtml::_('formbehavior.chosen', 'select');
|
||||||
\JHtml::_('stylesheet', 'com_patchtester/octicons.css', array(), true);
|
\JHtml::_('stylesheet', 'com_patchtester/octicons.css', array(), true);
|
||||||
|
@ -1,67 +1,99 @@
|
|||||||
jQuery(function () {
|
/**
|
||||||
var path = 'index.php?option=com_patchtester&tmpl=component&format=json';
|
* Patch testing component for the Joomla! CMS
|
||||||
|
*
|
||||||
|
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2016 Open Source Matters, Inc. All rights reserved.
|
||||||
|
* @license GNU General Public License version 2 or later
|
||||||
|
*/
|
||||||
|
|
||||||
function initialize() {
|
if (typeof jQuery === 'undefined') {
|
||||||
offset = 0;
|
throw new Error('PatchFetcher JavaScript requires jQuery')
|
||||||
progress = 0;
|
}
|
||||||
path = path + '&' + jQuery('#patchtester-token').attr('name') + '=1';
|
|
||||||
getRequest('startfetch');
|
|
||||||
};
|
|
||||||
|
|
||||||
function getRequest(task) {
|
if (typeof Joomla === 'undefined') {
|
||||||
jQuery.ajax({
|
throw new Error('PatchFetcher JavaScript requires the Joomla core JavaScript API')
|
||||||
type: "GET",
|
}
|
||||||
url: path,
|
|
||||||
data: 'task=' + task,
|
|
||||||
dataType: 'json',
|
|
||||||
success: handleResponse,
|
|
||||||
error: handleFailure
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function handleResponse(json, resp) {
|
!function (jQuery, Joomla, window) {
|
||||||
try {
|
'use strict';
|
||||||
if (json === null) {
|
|
||||||
throw resp;
|
|
||||||
}
|
|
||||||
if (json.error) {
|
|
||||||
throw json;
|
|
||||||
}
|
|
||||||
|
|
||||||
jQuery('#patchtester-progress-message').html(json.message);
|
/**
|
||||||
|
* Initialize the PatchFetcher object
|
||||||
|
*
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
var PatchFetcher = function () {
|
||||||
|
var offset = null,
|
||||||
|
progress = null,
|
||||||
|
path = 'index.php?option=com_patchtester&tmpl=component&format=json';
|
||||||
|
|
||||||
if (json.data.header) {
|
var initialize = function () {
|
||||||
jQuery('#patchtester-progress-header').html(json.data.header);
|
offset = 0;
|
||||||
}
|
progress = 0;
|
||||||
|
path = path + '&' + jQuery('#patchtester-token').attr('name') + '=1';
|
||||||
|
|
||||||
if (json.data.complete) {
|
getRequest('startfetch');
|
||||||
// Nothing to do
|
};
|
||||||
} else {
|
|
||||||
// Send another request
|
var getRequest = function (task) {
|
||||||
getRequest('fetch');
|
jQuery.ajax({
|
||||||
}
|
type: 'GET',
|
||||||
} catch (error) {
|
url: path,
|
||||||
try {
|
data: 'task=' + task,
|
||||||
if (json.error) {
|
dataType: 'json',
|
||||||
|
success: function (response, textStatus, xhr) {
|
||||||
|
try {
|
||||||
|
if (response === null) {
|
||||||
|
throw textStatus;
|
||||||
|
}
|
||||||
|
if (response.error) {
|
||||||
|
throw response;
|
||||||
|
}
|
||||||
|
|
||||||
|
jQuery('#patchtester-progress-message').html(response.message);
|
||||||
|
|
||||||
|
if (response.data.header) {
|
||||||
|
jQuery('#patchtester-progress-header').html(response.data.header);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!response.data.complete) {
|
||||||
|
// Send another request
|
||||||
|
getRequest('fetch');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
try {
|
||||||
|
if (response.error) {
|
||||||
|
jQuery('#patchtester-progress-header').text(Joomla.JText._('COM_PATCHTESTER_FETCH_AN_ERROR_HAS_OCCURRED'));
|
||||||
|
jQuery('#patchtester-progress-message').html(response.message);
|
||||||
|
}
|
||||||
|
} catch (ignore) {
|
||||||
|
if (error === '') {
|
||||||
|
error = Joomla.JText._('COM_PATCHTESTER_NO_ERROR_RETURNED');
|
||||||
|
}
|
||||||
|
|
||||||
|
jQuery('#patchtester-progress-header').text(Joomla.JText._('COM_PATCHTESTER_FETCH_AN_ERROR_HAS_OCCURRED'));
|
||||||
|
jQuery('#patchtester-progress-message').html(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
var json = (typeof jqXHR == 'object' && jqXHR.responseText) ? jqXHR.responseText : null;
|
||||||
jQuery('#patchtester-progress-header').text(Joomla.JText._('COM_PATCHTESTER_FETCH_AN_ERROR_HAS_OCCURRED'));
|
jQuery('#patchtester-progress-header').text(Joomla.JText._('COM_PATCHTESTER_FETCH_AN_ERROR_HAS_OCCURRED'));
|
||||||
jQuery('#patchtester-progress-message').html(json.message);
|
jQuery('#patchtester-progress-message').html(json);
|
||||||
}
|
}
|
||||||
} catch (ignore) {
|
});
|
||||||
if (error === '') {
|
|
||||||
error = Joomla.JText._('COM_PATCHTESTER_NO_ERROR_RETURNED');
|
|
||||||
}
|
|
||||||
jQuery('#patchtester-progress-header').text(Joomla.JText._('COM_PATCHTESTER_FETCH_AN_ERROR_HAS_OCCURRED'));
|
|
||||||
jQuery('#patchtester-progress-message').html(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
initialize();
|
||||||
};
|
};
|
||||||
|
|
||||||
function handleFailure(xhr) {
|
jQuery(function () {
|
||||||
json = (typeof xhr == 'object' && xhr.responseText) ? xhr.responseText : null;
|
new PatchFetcher();
|
||||||
jQuery('#patchtester-progress-header').text(Joomla.JText._('COM_PATCHTESTER_FETCH_AN_ERROR_HAS_OCCURRED'));
|
|
||||||
jQuery('#patchtester-progress-message').html(json);
|
|
||||||
};
|
|
||||||
|
|
||||||
initialize();
|
if (typeof window.parent.SqueezeBox == 'object') {
|
||||||
});
|
jQuery(window.parent.SqueezeBox).on('close', function () {
|
||||||
|
window.parent.location.reload(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}(jQuery, Joomla, window);
|
||||||
|
@ -1,23 +1,48 @@
|
|||||||
var PatchTester = {
|
/**
|
||||||
orderTable: function () {
|
* Patch testing component for the Joomla! CMS
|
||||||
var table = document.getElementById('sortTable'),
|
*
|
||||||
direction = document.getElementById('directionTable'),
|
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2016 Open Source Matters, Inc. All rights reserved.
|
||||||
order = table.options[table.selectedIndex].value,
|
* @license GNU General Public License version 2 or later
|
||||||
currentOrder = document.getElementById('adminForm').getAttribute('data-order').valueOf();
|
*/
|
||||||
|
|
||||||
if (order != currentOrder) {
|
if (typeof Joomla === 'undefined') {
|
||||||
var dirn = 'asc';
|
throw new Error('PatchTester JavaScript requires the Joomla core JavaScript API')
|
||||||
} else {
|
|
||||||
var dirn = direction.options[direction.selectedIndex].value;
|
|
||||||
}
|
|
||||||
|
|
||||||
Joomla.tableOrdering(order, dirn, '');
|
|
||||||
},
|
|
||||||
|
|
||||||
submitpatch: function (task, id) {
|
|
||||||
var idField = document.getElementById('pull_id');
|
|
||||||
idField.value = id;
|
|
||||||
|
|
||||||
return Joomla.submitbutton(task);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
!function (Joomla, window, document) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
window.PatchTester = {
|
||||||
|
/**
|
||||||
|
* Re-order the pull request list table
|
||||||
|
*/
|
||||||
|
orderTable: function () {
|
||||||
|
var table = document.getElementById('sortTable'),
|
||||||
|
direction = document.getElementById('directionTable'),
|
||||||
|
order = table.options[table.selectedIndex].value,
|
||||||
|
currentOrder = document.getElementById('adminForm').getAttribute('data-order').valueOf();
|
||||||
|
|
||||||
|
if (order != currentOrder) {
|
||||||
|
var dirn = 'asc';
|
||||||
|
} else {
|
||||||
|
var dirn = direction.options[direction.selectedIndex].value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Joomla.tableOrdering(order, dirn, '');
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process the patch action
|
||||||
|
*
|
||||||
|
* @param {String} task The task to perform
|
||||||
|
* @param {Number} id The item ID
|
||||||
|
*/
|
||||||
|
submitpatch: function (task, id) {
|
||||||
|
var idField = document.getElementById('pull_id');
|
||||||
|
idField.value = id;
|
||||||
|
|
||||||
|
Joomla.submitform(task);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}(Joomla, window, document);
|
||||||
|
Loading…
Reference in New Issue
Block a user