Skip to content

Commit

Permalink
Last tweak to fix
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Lodder committed Jan 4, 2018
1 parent be826b8 commit a545db9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 43 deletions.
79 changes: 37 additions & 42 deletions media/system/js/fields/permissions.js
@@ -1,6 +1,6 @@
/**
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

Joomla = window.Joomla || {};
Expand Down Expand Up @@ -72,56 +72,51 @@ Joomla = window.Joomla || {};
Joomla.removeMessages();

// Ajax request
Joomla.request(
{
url: document.getElementById('permissions-sliders').getAttribute('data-ajaxuri'),
method: 'POST',
data: JSON.stringify(permissionData),
perform: true,
headers: {'Content-Type': 'application/json'},
onSuccess: function(response, xhr)
{
// @todo this needs a try/catch
Joomla.request({
url: document.getElementById('permissions-sliders').getAttribute('data-ajaxuri'),
method: 'POST',
data: JSON.stringify(permissionData),
perform: true,
headers: {'Content-Type': 'application/json'},
onSuccess: function(response, xhr) {
try {
response = JSON.parse(response);
} catch(e) {
console.log(e)
}

icon.removeAttribute('class');
icon.removeAttribute('class');

if (response.data) {
// Check if everything is OK
if (response.data.result === 'true') {
icon.setAttribute('class', 'fa fa-check');
// Check if everything is OK
if (response.data && response.data.result === true) {
icon.setAttribute('class', 'fa fa-check');

var badgeSpan = target.parentNode.parentNode.querySelector('span');
alert(badgeSpan)
badgeSpan.removeAttribute('class');
badgeSpan.setAttribute('class', response.data['class']);
badgeSpan.innerHTML = response.data.text;
}
}
var badgeSpan = target.parentNode.parentNode.nextElementSibling.querySelector('span');
badgeSpan.removeAttribute('class');
badgeSpan.setAttribute('class', response.data['class']);
badgeSpan.innerHTML = response.data.text;
}

// Render messages, if any. There are only message in case of errors.
if (typeof response.messages === 'object' && response.messages !== null) {
Joomla.renderMessages(response.messages);
// Render messages, if any. There are only message in case of errors.
if (typeof response.messages === 'object' && response.messages !== null) {
Joomla.renderMessages(response.messages);

if (response.data && response.data.result === true)
{
icon.setAttribute('class', 'fa fa-check');
} else {
icon.setAttribute('class', 'fa fa-times');
}
if (response.data && response.data.result === true) {
icon.setAttribute('class', 'fa fa-check');
} else {
icon.setAttribute('class', 'fa fa-times');
}
},
onError: function(xhr)
{
// Remove the spinning icon.
icon.removeAttribute('style');
}
},
onError: function(xhr) {
// Remove the spinning icon.
icon.removeAttribute('style');

Joomla.renderMessages(Joomla.ajaxErrorsMessages(jqXHR, textStatus, error));
Joomla.renderMessages(Joomla.ajaxErrorsMessages(jqXHR, textStatus, error));

icon.setAttribute('class', 'fa fa-times');
}
icon.setAttribute('class', 'fa fa-times');
}
);
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion media/system/js/fields/permissions.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a545db9

Please sign in to comment.