Convert admin.js to ES5 syntax to support legacy gulp uglify
This commit is contained in:
@@ -2,7 +2,6 @@ $(document).ready(function() {
|
||||
// Check if admin
|
||||
$.get('/api/auth/me')
|
||||
.done(function(user) {
|
||||
console.log("Logged in:", user);
|
||||
if(user.role !== 'admin') {
|
||||
alert("Kein Zugriff!");
|
||||
window.location.href = '/';
|
||||
@@ -25,23 +24,23 @@ $(document).ready(function() {
|
||||
$.get('/api/admin/users').done(function(users) {
|
||||
$('#users-tbody').empty();
|
||||
$('#user-select').html('<option value="">Nutzer wählen...</option>');
|
||||
users.forEach(u => {
|
||||
$('#users-tbody').append(`
|
||||
<tr>
|
||||
<td>${u.id}</td>
|
||||
<td>${u.username} ${u.role==='admin'?'(Admin)':''}</td>
|
||||
<td>${u.id !== 1 ? `<button onclick="deleteUser(${u.id})">Löschen</button>` : ''}</td>
|
||||
</tr>
|
||||
`);
|
||||
users.forEach(function(u) {
|
||||
$('#users-tbody').append(
|
||||
'<tr>' +
|
||||
'<td>' + u.id + '</td>' +
|
||||
'<td>' + u.username + ' ' + (u.role === 'admin' ? '(Admin)' : '') + '</td>' +
|
||||
'<td>' + (u.id !== 1 ? '<button onclick="deleteUser(' + u.id + ')">Löschen</button>' : '') + '</td>' +
|
||||
'</tr>'
|
||||
);
|
||||
if(u.role !== 'admin') {
|
||||
$('#user-select').append(`<option value="${u.id}">${u.username}</option>`);
|
||||
$('#user-select').append('<option value="' + u.id + '">' + u.username + '</option>');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
window.deleteUser = function(id) {
|
||||
if(confirm("Nutzer löschen?")) {
|
||||
if(confirm("Nutzer loeschen?")) {
|
||||
$.ajax({url: '/api/admin/users/'+id, type: 'DELETE'}).done(loadUsers);
|
||||
}
|
||||
};
|
||||
@@ -56,37 +55,35 @@ $(document).ready(function() {
|
||||
}).fail(function(err) { alert("Fehler: " + err.responseJSON.error); });
|
||||
});
|
||||
|
||||
let allImages = [];
|
||||
function loadAssignmentImages() {
|
||||
$.get('/images/fulls/').done(function(files) {
|
||||
allImages = files;
|
||||
$('#image-checkboxes').empty();
|
||||
files.forEach(f => {
|
||||
$('#image-checkboxes').append(`
|
||||
<label class="img-check">
|
||||
<img src="/images/thumbs/${encodeURIComponent(f.name)}" />
|
||||
<br/><input type="checkbox" value="${f.name}" class="img-cb"/>
|
||||
</label>
|
||||
`);
|
||||
files.forEach(function(f) {
|
||||
$('#image-checkboxes').append(
|
||||
'<label class="img-check">' +
|
||||
'<img src="/images/thumbs/' + encodeURIComponent(f.name) + '" />' +
|
||||
'<br/><input type="checkbox" value="' + f.name + '" class="img-cb"/>' +
|
||||
'</label>'
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$('#user-select').change(function() {
|
||||
const uid = $(this).val();
|
||||
var uid = $(this).val();
|
||||
$('.img-cb').prop('checked', false);
|
||||
if(!uid) return;
|
||||
$.get('/api/admin/assign').done(function(assignments) {
|
||||
assignments.filter(a => a.user_id == uid).forEach(a => {
|
||||
$(`.img-cb[value="${a.image_name}"]`).prop('checked', true);
|
||||
assignments.filter(function(a) { return a.user_id == uid; }).forEach(function(a) {
|
||||
$('.img-cb[value="' + a.image_name + '"]').prop('checked', true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('#save-assignments').click(function() {
|
||||
const uid = $('#user-select').val();
|
||||
if(!uid) return alert('Bitte Nutzer wählen');
|
||||
const selected = [];
|
||||
var uid = $('#user-select').val();
|
||||
if(!uid) return alert('Bitte Nutzer waehlen');
|
||||
var selected = [];
|
||||
$('.img-cb:checked').each(function() { selected.push($(this).val()); });
|
||||
|
||||
$.post('/api/admin/assign', { user_id: uid, image_names: selected })
|
||||
@@ -94,11 +91,11 @@ $(document).ready(function() {
|
||||
});
|
||||
|
||||
$('#update-btn').click(function() {
|
||||
if(!confirm("Achtung: Dies startet den Server neu. Fortfahren?")) return;
|
||||
$('#update-status').text('Update läuft...');
|
||||
if(!confirm("Achtung: Dies startet den Server auf dem NAS neu. Fortfahren?")) return;
|
||||
$('#update-status').text('Update laeuft...');
|
||||
$.post('/api/admin/update').done(function(res) {
|
||||
$('#update-status').text(res.message);
|
||||
setTimeout(() => { window.location.reload(); }, 5000);
|
||||
setTimeout(function() { window.location.reload(); }, 5000);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user