Refactor accept agreement

This commit is contained in:
root
2021-05-14 12:48:48 +00:00
parent 341f3dbe12
commit f6faacaf4f
2 changed files with 25 additions and 12 deletions

View File

@@ -174,3 +174,25 @@ function loadAgreements(method, address, cb) {
}
xhr1.send();
}
function acceptAgreement(method, address, brief, options, cb) {
var xhr1 = new XMLHttpRequest();
var params = '';
if (options) {
params = JSON.stringify(options);
}
xhr1.open('POST', "/v1/agreement/" + brief + "/" + method + "/" + address);
xhr1.setRequestHeader("X-Bunker-Token", xtoken)
xhr1.setRequestHeader('Content-type', 'application/json');
xhr1.onload = function() {
if (xhr1.status === 200) {
var data = JSON.parse(xhr1.responseText);
if (cb) {
cb(data);
}
} else if (xhr1.status > 400 && xhr1.status < 500) {
document.location = "/";
}
}
xhr1.send(params);
}

View File

@@ -85,18 +85,9 @@ function withdrawConsent(brief) {
}
function acceptConsent(brief) {
var xhr = new XMLHttpRequest();
xhr.open('POST', "/v1/agreement/" + brief + "/token/" + token);
xhr.setRequestHeader("X-Bunker-Token", xtoken)
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
if (xhr.status === 200) {
document.location.reload();
} else if (xhr.status > 400 && xhr.status < 500) {
document.location = "/";
}
}
xhr.send();
acceptAgreement('token', token, brief, '', function(data) {
document.location.reload();
});
}
function prepareRow(row) {