Buckler/static/buckler.js

59 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-09-25 12:51:36 -04:00
function load() {
let headers = document.querySelectorAll('h2');
2019-09-27 13:57:00 -04:00
headers = Array.prototype.slice.call(headers);
let headers3 = document.querySelectorAll('h3');
headers3 = Array.prototype.slice.call(headers3);
headers = headers.concat(headers3);
2019-09-25 12:51:36 -04:00
headers.forEach(function(header) {
header.addEventListener('click', function() {
let article = this.nextElementSibling;
if (article.style.display === 'none') {
article.style.display = '';
} else {
article.style.display = 'none';
}
});
});
}
2019-09-20 19:24:12 -04:00
function perm_change(row) {
let user_perms = users_perms[row.children[0].textContent];
2019-09-26 14:39:48 -04:00
let row_perms = {};
2019-09-20 19:24:12 -04:00
for (let child of row.children) {
if (child.firstChild.type == "checkbox") {
if (child.firstChild.checked) {
2019-09-26 14:39:48 -04:00
row_perms[child.firstChild.dataset.appName] = true;
2019-09-20 19:24:12 -04:00
} else {
2019-09-26 14:39:48 -04:00
row_perms[child.firstChild.dataset.appName] = false;
2019-09-20 19:24:12 -04:00
}
}
}
let perms_changed = false;
2019-09-26 14:39:48 -04:00
for (let app_name of Object.keys(user_perms)) {
if (user_perms[app_name] != row_perms[app_name]) {
2019-09-20 19:24:12 -04:00
perms_changed = true;
}
}
console.log("perms_changed = " + perms_changed);
}
2019-10-17 13:38:40 -04:00
function submit_user_perms(row) {
let row_perms = {};
for (let child of row.children) {
if (child.firstChild.type == "checkbox") {
if (child.firstChild.checked) {
row_perms[child.firstChild.dataset.appName] = true;
} else {
row_perms[child.firstChild.dataset.appName] = false;
}
}
}
console.log(row_perms);
fetch(window.location.pathname, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: row_perms
});
}