diff --git a/ui/site/site.js b/ui/site/site.js index 250591b..71f1c8b 100644 --- a/ui/site/site.js +++ b/ui/site/site.js @@ -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); +} diff --git a/ui/site/user-agreements.html b/ui/site/user-agreements.html index 16e9ed8..49446cf 100644 --- a/ui/site/user-agreements.html +++ b/ui/site/user-agreements.html @@ -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) {