working on javascript compatibility for old browsers
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -2,16 +2,6 @@ var params = new URLSearchParams(window.location.search)
|
|||||||
var json = paramsToObject(params);
|
var json = paramsToObject(params);
|
||||||
var scopes = {};
|
var scopes = {};
|
||||||
|
|
||||||
// Replacement for Object.toEntries(…)
|
|
||||||
function paramsToObject(entries) {
|
|
||||||
const result = {};
|
|
||||||
for(var key of entries) { // each 'entry' is a [key, value] tupple
|
|
||||||
result[key[0]] = key[1];
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function showConfirmationDialog(name){
|
function showConfirmationDialog(name){
|
||||||
get('name').innerHTML = name;
|
get('name').innerHTML = name;
|
||||||
show('content');
|
show('content');
|
||||||
|
|||||||
@@ -2,25 +2,26 @@ function edit(clientId){
|
|||||||
redirect("edit_client.html?id="+clientId);
|
redirect("edit_client.html?id="+clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleClients(response){
|
function handleClients(response){
|
||||||
if (response.status == UNAUTHORIZED) {
|
if (response.status == UNAUTHORIZED) {
|
||||||
redirect('login.html?return_to='+encodeURI(window.location.href))
|
redirect('login.html?return_to='+encodeURI(window.location.href))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var clients = await response.json();
|
var clients = response.json().then(clients => {
|
||||||
var bottom = document.getElementById('bottom');
|
var bottom = document.getElementById('bottom');
|
||||||
for (let id in clients){
|
for (let id in clients){
|
||||||
var row = document.createElement("tr");
|
var row = document.createElement("tr");
|
||||||
var client = clients[id];
|
var client = clients[id];
|
||||||
row.innerHTML = `<td>${client.name}</td>
|
row.innerHTML = `<td>${client.name}</td>
|
||||||
<td>${id}</td>
|
<td>${id}</td>
|
||||||
<td>${client.redirect_uris.join("<br/>")}</td>
|
<td>${client.redirect_uris.join("<br/>")}</td>
|
||||||
<td>
|
<td>
|
||||||
<button type="button" onclick="edit('${id}')">Edit</button>
|
<button type="button" onclick="edit('${id}')">Edit</button>
|
||||||
<button class="danger" onclick="remove('${id}')" type="button">Remove</button>
|
<button class="danger" onclick="remove('${id}')" type="button">Remove</button>
|
||||||
</td>`;
|
</td>`;
|
||||||
bottom.parentNode.insertBefore(row,bottom);
|
bottom.parentNode.insertBefore(row,bottom);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleRemove(response){
|
function handleRemove(response){
|
||||||
@@ -32,11 +33,10 @@ function remove(clientId){
|
|||||||
if (confirm(message.replace("{}",clientId))) {
|
if (confirm(message.replace("{}",clientId))) {
|
||||||
fetch(client_controller+"/delete",{
|
fetch(client_controller+"/delete",{
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
body : JSON.stringify({ client_id : clientId })
|
body : JSON.stringify({ client_id : clientId }),
|
||||||
|
credentials:'include'
|
||||||
}).then(handleRemove);
|
}).then(handleRemove);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fetch(client_controller+"/list",{method:'POST',credentials:'include'}).then(handleClients);
|
||||||
|
|
||||||
fetch(client_controller+"/list",{method:'POST'}).then(handleClients);
|
|
||||||
@@ -41,6 +41,15 @@ function login(){
|
|||||||
redirect('login.html?return_to='+encodeURIComponent(window.location.href));
|
redirect('login.html?return_to='+encodeURIComponent(window.location.href));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replacement for Object.toEntries(…)
|
||||||
|
function paramsToObject(entries) {
|
||||||
|
const result = {};
|
||||||
|
for(var key of entries) { // each 'entry' is a [key, value] tupple
|
||||||
|
result[key[0]] = key[1];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
function redirect(page){
|
function redirect(page){
|
||||||
window.location.href = page;
|
window.location.href = page;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,18 @@ var params = new URLSearchParams(window.location.search);
|
|||||||
var id = params.get('id');
|
var id = params.get('id');
|
||||||
|
|
||||||
|
|
||||||
async function handleLoadResponse(response){
|
function handleLoadResponse(response){
|
||||||
if (response.ok){
|
if (response.ok){
|
||||||
var json = await response.json();
|
response.json().then(json => {
|
||||||
get('client-id').value = json.client_id;
|
get('client-id').value = json.client_id;
|
||||||
get('client-name').value = json.name;
|
get('client-name').value = json.name;
|
||||||
get('client-secret').value = json.secret;
|
get('client-secret').value = json.secret;
|
||||||
get('redirect-urls').value = json.redirect_uris.join("\n");
|
get('redirect-urls').value = json.redirect_uris.join("\n");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleUpdateResponse(response){
|
function handleUpdateResponse(response){
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
enable('button');
|
enable('button');
|
||||||
setText('button','saved.');
|
setText('button','saved.');
|
||||||
@@ -38,7 +39,8 @@ function updateClient(){
|
|||||||
headers : {
|
headers : {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body : JSON.stringify(data)
|
body : JSON.stringify(data),
|
||||||
|
credentials:'include'
|
||||||
}).then(handleUpdateResponse);
|
}).then(handleUpdateResponse);
|
||||||
setTimeout(resetButton,4000);
|
setTimeout(resetButton,4000);
|
||||||
}
|
}
|
||||||
@@ -48,5 +50,6 @@ fetch(api+'/client',
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
client_id : id
|
client_id : id
|
||||||
})
|
}),
|
||||||
|
credentials:'include'
|
||||||
}).then(handleLoadResponse);
|
}).then(handleLoadResponse);
|
||||||
@@ -11,7 +11,8 @@ function addClient(){
|
|||||||
headers : {
|
headers : {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body : JSON.stringify(newData)
|
body : JSON.stringify(newData),
|
||||||
|
credentials:'include'
|
||||||
}).then(handleClientdResponse);
|
}).then(handleClientdResponse);
|
||||||
|
|
||||||
setText('button','sent…');
|
setText('button','sent…');
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ function handleNavigation(response){
|
|||||||
var nav = document.getElementsByTagName('nav')[0];
|
var nav = document.getElementsByTagName('nav')[0];
|
||||||
nav.innerHTML = content;
|
nav.innerHTML = content;
|
||||||
var links = nav.getElementsByTagName('a');
|
var links = nav.getElementsByTagName('a');
|
||||||
|
|
||||||
for (var index = links.length; index > 0; index--){
|
for (var index = links.length; index > 0; index--){
|
||||||
var link = links[index-1];
|
var link = links[index-1];
|
||||||
var clazz = link.hasAttribute('class') ? link.getAttribute("class") : null;
|
var clazz = link.hasAttribute('class') ? link.getAttribute("class") : null;
|
||||||
@@ -28,7 +29,9 @@ function handleNavigation(response){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(user_controller+"/",{
|
document.addEventListener("DOMContentLoaded", function(event) { // wait until page loaded
|
||||||
method:'POST',
|
fetch(user_controller+"/",{
|
||||||
credentials:'include'
|
method:'POST',
|
||||||
}).then(handleUser);
|
credentials:'include'
|
||||||
|
}).then(handleUser);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user