Skip to content

Commit

Permalink
fix(UI): fix usage of $.ajax by going VanillaJS
Browse files Browse the repository at this point in the history
chaining .success() and .fail() was not working anymore, and jQuery is to
be deprecated anyway. A step thereto! Also clears metadata step after
an unsuccessful save to not be misleading.

Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed Dec 3, 2024
1 parent 2fd7031 commit 474c65f
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,26 +120,32 @@
},

testMetaData: function() {
var type = $('#user-saml').data('type');

// Checks on each request whether the settings make sense or not
const type = document.getElementById('user-saml').dataset.type;
if (type === 'environment-variable') {
return
}

// Checks on each request whether the settings make sense or not
$.ajax({
url: OC.generateUrl('/apps/user_saml/saml/metadata'),
data: { idp: this.currentConfig },
type: 'GET'
}).fail(function (e) {
if (e.status === 500) {
$('#user-saml-settings-complete').addClass('hidden');
$('#user-saml-settings-incomplete').removeClass('hidden');
let xhr = new XMLHttpRequest();
xhr.open('GET', OC.generateUrl('/apps/user_saml/saml/metadata?idp=' + this.currentConfig));
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('requesttoken', OC.requestToken);

xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 300) {
document.getElementById('user-saml-settings-complete').classList.remove('hidden');
document.getElementById('user-saml-settings-incomplete').classList.add('hidden');
} else {
document.getElementById('user-saml-settings-complete').classList.add('hidden');
document.getElementById('user-saml-settings-incomplete').classList.remove('hidden');
}
}).success(function () {
$('#user-saml-settings-complete').removeClass('hidden');
$('#user-saml-settings-incomplete').addClass('hidden');
});
};
xhr.onerror = function () {
document.getElementById('user-saml-settings-complete').classList.add('hidden');
document.getElementById('user-saml-settings-incomplete').classList.remove('hidden');
};

xhr.send();
},

setSamlConfigValue: function(category, setting, value, global) {
Expand All @@ -156,6 +162,9 @@
},
error: function() {
OC.msg.finishedSaving('#user-saml-save-indicator', {status: 'error', data: {message: t('user_saml', 'Could not save')}});
// reset any meta data indicator as the test would not be called now, old state might be misleading
document.getElementById('user-saml-settings-complete').classList.add('hidden');
document.getElementById('user-saml-settings-incomplete').classList.add('hidden');
}
};

Expand Down

0 comments on commit 474c65f

Please sign in to comment.