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';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2020-11-20 19:32:32 -05:00
|
|
|
document.querySelector('#user_perm_form').addEventListener('submit', submit_user_perms);
|
2019-09-25 12:51:36 -04:00
|
|
|
}
|
|
|
|
|
2020-11-20 19:32:32 -05:00
|
|
|
function submit_user_perms(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
let perms_diff = {};
|
|
|
|
for (let input of event.target.querySelectorAll('input[type=checkbox]')) {
|
|
|
|
let user_id = input.dataset['userId'];
|
|
|
|
let app_id = input.dataset['appId'];
|
|
|
|
if (input.checked != user_perms[user_id][app_id]) {
|
|
|
|
let perms = perms_diff[user_id] || {};
|
|
|
|
perms[app_id] = input.checked;
|
|
|
|
perms_diff[user_id] = perms;
|
2019-09-20 19:24:12 -04:00
|
|
|
}
|
|
|
|
}
|
2020-11-20 19:32:32 -05:00
|
|
|
|
|
|
|
let form_body = {
|
|
|
|
'form_name': 'change_user_perms',
|
|
|
|
'perms': JSON.stringify(perms_diff),
|
2019-09-20 19:24:12 -04:00
|
|
|
}
|
2020-11-20 19:32:32 -05:00
|
|
|
let payload = [];
|
|
|
|
for (let property in form_body) {
|
|
|
|
let encoded_key = encodeURIComponent(property);
|
|
|
|
let encoded_value = encodeURIComponent(form_body[property]);
|
|
|
|
payload.push(encoded_key + '=' + encoded_value);
|
2019-10-17 13:38:40 -04:00
|
|
|
}
|
2020-11-20 19:32:32 -05:00
|
|
|
payload = payload.join('&');
|
|
|
|
|
2019-10-17 13:38:40 -04:00
|
|
|
fetch(window.location.pathname, {
|
|
|
|
method: 'POST',
|
2020-11-20 19:32:32 -05:00
|
|
|
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
|
|
|
body: payload,
|
|
|
|
}).then(function(response) {
|
|
|
|
window.location.reload();
|
2019-10-17 13:38:40 -04:00
|
|
|
});
|
|
|
|
}
|