100 lines
2.6 KiB
JavaScript
100 lines
2.6 KiB
JavaScript
const swalClasses = {
|
|
container: 'text-center',
|
|
confirmButton: 'btn btn-lg btn-primary',
|
|
cancelButton: 'btn btn-lg btn-secondary ms-3',
|
|
popup: 'border p-5',
|
|
title: 'fs-2',
|
|
inputLabel: 'fs-5',
|
|
htmlContainer: 'fs-5'
|
|
};
|
|
|
|
function showSingleCalcDialog(btn) {
|
|
Swal.fire({
|
|
title: 'Einzel-Abfrage',
|
|
input: 'text',
|
|
inputLabel: 'Welcher Spieler soll abgefragt werden?\nDie Abfrage kann ein paar Sekunden dauern.',
|
|
inputPlaceholder: 'Spieler-Name eingeben...',
|
|
confirmButtonText: 'Berechnen',
|
|
showCancelButton: true,
|
|
cancelButtonText: 'Abbrechen',
|
|
customClass: swalClasses,
|
|
buttonsStyling: false
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
htmx.ajax('POST', '/score/' + result.value, {target: '#' + btn.id, swap: 'none'})
|
|
}
|
|
});
|
|
}
|
|
|
|
function showSingleCalcResultDialog(xhr, reqPath) {
|
|
let icon;
|
|
switch (xhr.status) {
|
|
case 200:
|
|
icon = 'success';
|
|
break;
|
|
case 404:
|
|
icon = 'warning';
|
|
break;
|
|
default:
|
|
icon = 'error';
|
|
}
|
|
|
|
Swal.fire({
|
|
title: 'Abfrage für ' + reqPath.replace("/score/", ''),
|
|
text: "Score: " + xhr.response,
|
|
icon: icon,
|
|
customClass: swalClasses
|
|
});
|
|
}
|
|
|
|
function showAdminActionExecutedDialog(xhr, method) {
|
|
Swal.fire({
|
|
title: 'Action executed',
|
|
text: xhr.response,
|
|
icon: xhr.status === 200 ? 'success' : 'error'
|
|
}).then(() => {
|
|
if (method === "delete") {
|
|
location.reload();
|
|
}
|
|
});
|
|
}
|
|
|
|
function confirmAndTrigger(btn) {
|
|
Swal.fire({
|
|
title: btn.innerText,
|
|
text: 'Do you want to continue?',
|
|
confirmButtonText: 'Yes',
|
|
confirmButtonColor: '#dd6b55',
|
|
denyButtonColor: '#3085d6',
|
|
icon: 'warning',
|
|
showDenyButton: true,
|
|
customClass: swalClasses,
|
|
buttonsStyling: false
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
htmx.trigger(btn, 'confirmed');
|
|
}
|
|
});
|
|
}
|
|
|
|
function createCodeDialog(btn) {
|
|
Swal.fire({
|
|
title: btn.innerText,
|
|
input: 'select',
|
|
inputOptions: {
|
|
'READER': 'Reader',
|
|
'AUTHOR': 'Author',
|
|
'ADMIN': 'Admin'
|
|
},
|
|
inputPlaceholder: 'Select a role',
|
|
confirmButtonText: 'Generate',
|
|
showCancelButton: true,
|
|
customClass: swalClasses,
|
|
buttonsStyling: false
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
btn.setAttribute('hx-vals', '{"user_role": "' + result.value + '"}');
|
|
htmx.trigger(btn, 'confirmed');
|
|
}
|
|
});
|
|
} |