First version, for githup; UNSTABLE, DO NOT USE!
This commit is contained in:
192
www/intern/scripts/kampfrichter/js/js-kampfrichter-admin.js
Normal file
192
www/intern/scripts/kampfrichter/js/js-kampfrichter-admin.js
Normal file
@@ -0,0 +1,192 @@
|
||||
jQuery(document).ready(function($) {
|
||||
$('.ranglisteExport').on('click', function() {
|
||||
const $button = $(this);
|
||||
const progId = $button.data('id');
|
||||
const fieldType = $button.data('field_type');
|
||||
|
||||
// Visual feedback (optional but recommended)
|
||||
$button.prop('disabled', true).text('Generating...');
|
||||
|
||||
const url = '/intern/scripts/kampfrichter/ajax/ajax-neu_rangliste.php';
|
||||
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
||||
body: new URLSearchParams({
|
||||
prog: progId,
|
||||
type: fieldType
|
||||
})
|
||||
})
|
||||
.then(response => {
|
||||
// CRITICAL: Check if the server actually returned a success code
|
||||
if (!response.ok) {
|
||||
throw new Error('Server returned an error (Status ' + response.status + ')');
|
||||
}
|
||||
return response.blob();
|
||||
})
|
||||
.then(blob => {
|
||||
if (fieldType !== 'upload_programm') {
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `Ergebnisse_${progId}.pdf`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
window.URL.revokeObjectURL(url);
|
||||
} else {
|
||||
alert('PDF auf Webseite geladen!');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Export Error:', error);
|
||||
alert('Fehler beim Exportieren der Rangliste.');
|
||||
})
|
||||
.finally(() => {
|
||||
// Restore button state
|
||||
$button.prop('disabled', false).text('Export PDF');
|
||||
});
|
||||
});
|
||||
|
||||
$('.protokollExport').on('click', function() {
|
||||
console.log('ok');
|
||||
const $input = $(this);
|
||||
|
||||
// Build the data to send
|
||||
const data = new URLSearchParams();
|
||||
data.append('abteilung', $input.data('abteilung'));
|
||||
|
||||
// Record start time
|
||||
const start = performance.now();
|
||||
|
||||
const url = '/intern/scripts/kampfrichter/ajax/ajax-neu_protokoll.php';
|
||||
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
||||
body: new URLSearchParams({
|
||||
abteilung: $input.data('abteilung')
|
||||
})
|
||||
})
|
||||
.then(res => res.blob())
|
||||
.then(blob => {
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = "KTBB_Protokoll.pdf"; // optional
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
window.URL.revokeObjectURL(url);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
let activeEdit = null;
|
||||
|
||||
console.log('pre');
|
||||
|
||||
$(document).on('click', '.editableValue', function () {
|
||||
console.log('ok');
|
||||
const input = $(this);
|
||||
|
||||
// Already editing
|
||||
if (!input.prop('readonly')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Close another active edit
|
||||
if (activeEdit && activeEdit.get(0) !== input.get(0)) {
|
||||
cancelEdit(activeEdit);
|
||||
}
|
||||
|
||||
input.data('original', input.val());
|
||||
input.prop('readonly', false).focus().select();
|
||||
|
||||
activeEdit = input;
|
||||
|
||||
input.on('keydown.edit', function (e) {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
saveEdit(input);
|
||||
}
|
||||
|
||||
if (e.key === 'Escape') {
|
||||
e.preventDefault();
|
||||
cancelEdit(input);
|
||||
}
|
||||
});
|
||||
|
||||
input.on('blur.edit', function () {
|
||||
saveEdit(input);
|
||||
});
|
||||
});
|
||||
|
||||
function saveEdit(input) {
|
||||
const originalValue = input.data('original');
|
||||
const newValue = input.val();
|
||||
const type = input.data('type');
|
||||
const discipline = input.data('discipline');
|
||||
const dataId = input.data('id');
|
||||
|
||||
if (newValue === originalValue) {
|
||||
input.prop('readonly', true);
|
||||
cleanup(input);
|
||||
return;
|
||||
}
|
||||
|
||||
input.addClass('is-saving');
|
||||
|
||||
$.ajax({
|
||||
url: '/intern/scripts/kampfrichter/ajax/ajax-update_value_kampfrichter_admin.php',
|
||||
method: 'POST',
|
||||
data: {
|
||||
id: dataId,
|
||||
field_type: type,
|
||||
discipline: discipline,
|
||||
value: newValue
|
||||
},
|
||||
success: function () {
|
||||
input.prop('readonly', true);
|
||||
|
||||
const row = input.closest('td');
|
||||
if (row.length) {
|
||||
row.css(
|
||||
'background',
|
||||
'radial-gradient(circle at bottom right, #22c55e, transparent 55%)'
|
||||
);
|
||||
|
||||
setTimeout(() => row.css('background', ''), 2000);
|
||||
}
|
||||
|
||||
ws.send(JSON.stringify({
|
||||
type: "KAMPFRICHTER_UPDATE",
|
||||
payload: {
|
||||
discipline: discipline,
|
||||
id: dataId,
|
||||
val: newValue
|
||||
}
|
||||
}));
|
||||
},
|
||||
error: function () {
|
||||
input.val(originalValue).prop('readonly', true);
|
||||
alert('Speichern fehlgeschlagen');
|
||||
},
|
||||
complete: function () {
|
||||
input.removeClass('is-saving');
|
||||
cleanup(input);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function cancelEdit(input) {
|
||||
input.val(input.data('original')).prop('readonly', true);
|
||||
cleanup(input);
|
||||
}
|
||||
|
||||
function cleanup(input) {
|
||||
input.off('.edit');
|
||||
activeEdit = null;
|
||||
}
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user