} */
const $clone = $copyTable.clone();
// Remove interactive elements & keep only text
$clone.find("input, textarea, select, button, svg").remove();
// Normalize text in each cell
$clone.find("th, td").each(function() {
const $text = $(this).text().trim().replace(/\s+/g, " ");
$(this).text($text);
});
// Basic inline styling so Word keeps visible borders
$clone.attr("border", "1");
$clone.css({
"border-collapse": "collapse",
"border": "1px solid #000"
});
$clone.find("th, td").css({
"border": "1px solid #000",
"padding": "4px",
"vertical-align": "top"
});
// Optional: keep header bold
$clone.find("th").css({"font-weight": "bold"});
// Final HTML document for clipboard (UTF-8)
const $htmlDoc =
'' +
'' +
$("").append($clone).html() +
"";
// 2) Plain-text TSV fallback (still great for Excel)
/** @type {string[]} */
const $lines = [];
$copyTable.find("tr").each(function() {
/** @type {string[]} */
const $cells = [];
$(this).find("th, td").each(function() {
const $t = $(this).text().trim().replace(/\s+/g, " ");
$cells.push($t);
});
$lines.push($cells.join("\t"));
});
const $tsv = $lines.join("\n");
// 3) Try modern Clipboard API with text/html + text/plain
try {
if(navigator.clipboard && window.isSecureContext && window.ClipboardItem) {
const $data = {
"text/html": new Blob([$htmlDoc], {type: "text/html"}),
"text/plain": new Blob([$tsv], {type: "text/plain"})
};
await navigator.clipboard.write([new ClipboardItem($data)]);
} else {
// Fallback: hidden contenteditable DIV + execCommand("copy") to copy HTML
const $div = document.createElement("div");
$div.setAttribute("contenteditable", "true");
$div.style.position = "fixed";
$div.style.left = "-9999px";
$div.innerHTML = $htmlDoc;
document.body.appendChild($div);
// Select the content of the DIV
const $range = document.createRange();
$range.selectNodeContents($div);
const $sel = window.getSelection();
$sel.removeAllRanges();
$sel.addRange($range);
// Copy selection as rich HTML
const $ok = document.execCommand("copy");
// Cleanup selection + node
$sel.removeAllRanges();
document.body.removeChild($div);
if(!$ok) {
// Last resort: copy TSV as plain text
const $ta = document.createElement("textarea");
$ta.value = $tsv;
$ta.style.position = "fixed";
$ta.style.top = "-1000px";
document.body.appendChild($ta);
$ta.focus();
$ta.select();
document.execCommand("copy");
document.body.removeChild($ta);
}
}
// UI feedback
$copyButton.find("span").text("Zkopírováno");
setTimeout(function() {$copyButton.find("span").text($copyButtonText);}, 1200);
} catch($err) {
alert("Zkopírování selhalo. Zkus tabulku označit a zkopírovat manuálně.");
console.error("Copy HTML error:", $err);
}
});
// FORM Client Save
// ************************************************************************************
if( $("#ClientSave").length ) {
const $prefixClientSave = 'ClientSave_';
const $formClientSave = $("#" + $prefixClientSave + "Form");
// ALL REQUIRED FIELDS
$formClientSave.find(".form-required").on("blur change", function() {
$(this).val( $.trim( $(this).val() ) );
$(this).removeClass("form-invalid").closest(".form-group").find("var.ra-alert").remove();
if( $(this).val() == '' ) $(this).addClass("form-invalid").closest(".form-group").append('' + LNG_FIELD_MANDATORY + '');
});
// MAIL REQUIRED check
$formClientSave.find(".mail-required").on("blur change", function() {
$(this).jCheckMail();
});
// INTERNATIONAL TELEPHONE INPUT
window.$iti = null;
window.$phoneInput = document.querySelector("#" + $prefixClientSave + "phone");
// INTERNATIONAL TELEPHONE INPUT
if(window.$phoneInput) {
window.$iti = window.intlTelInput(window.$phoneInput, {
initialCountry: "cz",
hiddenInput: "phone_full",
autoPlaceholder: "off",
autoHideDialCode: false,
separateDialCode: true,
nationalMode: true,
onlyCountries: ["al", "ad", "at", "by", "be", "ba", "bg", "hr", "cz", "dk",
"ee", "fo", "fi", "fr", "de", "gi", "gr", "va", "hu", "is", "ie", "it", "lv",
"li", "lt", "lu", "mk", "mt", "md", "mc", "me", "nl", "no", "pl", "pt", "ro",
"ru", "sm", "rs", "sk", "si", "es", "se", "ch", "ua", "gb"],
preferredCountries: ['cz', 'sk'],
utilsScript: PROJECTPATH + "jquery/intl-tel-input-" + $intlTelInput + "/js/utils.js", // just for formatting/placeholders/hiddenInput etc.
});
// alow autocomplete
window.$phoneInput.setAttribute("autocomplete", "tel");
}
// datetimepicker
$("#" + $prefixClientSave + "birth_date").datetimepicker({
lang: $lng,
dayOfWeekStart: 1,
timepicker: false,
format: "d.m.Y",
});
// save form
$formClientSave.on("submit", function(e) {
e.preventDefault();
let $saveERROR = 0;
$("." + $prefixClientSave + "ButtonSave").prop("disabled", true).closest(".form-group").find("var.ra-alert").remove();
// TRIM all fields
$.each($formClientSave.find(".form-control, .form-check-input"), function() {
$(this).val( $.trim( $(this).val() ) );
$(this).removeClass("form-invalid").closest(".form-group").find("var.ra-alert").remove();
});
// MAIL REQUIRED check
$formClientSave.find(".mail-required").jCheckMail();
// ALL REQUIRED FIELDS
$.each($formClientSave.find(".form-required"), function() {
if( $(this).val().trim() == '' || ($(this).is(':checkbox') && !$(this).is(':checked')) ) {
$(this).addClass("form-invalid").closest(".form-group").append('' + LNG_FIELD_MANDATORY + '');
$saveERROR += 1;
}
});
if($saveERROR > 0) {
$("." + $prefixClientSave + "ButtonSave").prop("disabled", false).closest(".form-group").append('Formulář obsahuje chyby. Ověřte znovu správnost vyplnění.');
return;
}
// submit
HTMLFormElement.prototype.submit.call(this);
});
// after save
if( $("#" + $prefixClientSave + "Submited").val() == 1 ) {
if( $("#" + $prefixClientSave + "SuccessSave").val() == 1 ) {
$("#" + $prefixClientSave + "Form").find(".alert-success").css({ "display" : "inline-block" });
setTimeout(function() {
$("#" + $prefixClientSave + "Form").find(".alert-success").css({ "display" : "none" });
}, 4000);
} else {
$("#" + $prefixClientSave + "Form").find(".alert-danger").css({ "display" : "inline-block" });
setTimeout(function() {
$("#" + $prefixClientSave + "Form").find(".alert-success").css({ "display" : "none" });
$("#" + $prefixClientSave + "Form").find(".alert-danger").css({ "display" : "none" });
}, 6000);
}
}
// EDIT ATTENDANCE
$(".EditClientSave").on("click dblclick", function() {
$editId = $(this).closest("tr").data("id");
sendPostData($FULLREQUESTURI, { editId: $editId, });
return false;
});
// KILL ATTENDANCE (DELETE for ever)
$(".KillClientSave").on("click dblclick", function() {
$thisId = $(this).closest("tr").data("id");
if(window.confirm ("Chceš smazat tohoto účastníka?\n" + LNG_FOREVER)) {
sendPostData($FULLREQUESTURI, { actio: 'KillClientSave', thisId: $thisId, });
}
return false;
});
}
// FORM Certificate
// ************************************************************************************
if( $("#TrainingEventCertificate").length ) {
const $formCertificate = $("#TrainingEventForm");
const $prefixCertificateForm = "Certificate_";
// ALL REQUIRED FIELDS
$formCertificate.find(".form-required").on("blur change", function() {
$(this).val( $.trim( $(this).val() ) );
$(this).removeClass("form-invalid").closest(".form-group").find("var.ra-alert").remove();
if( $(this).val() == '' ) $(this).addClass("form-invalid").closest(".form-group").append('' + LNG_FIELD_MANDATORY + '');
});
// datetimepicker
$("#" + $prefixCertificateForm + "certificate_date_issue").datetimepicker({
lang: $lng,
dayOfWeekStart: 1,
timepicker: false,
format: "d.m.Y",
});
// save form
$formCertificate.on("submit", function(e) {
e.preventDefault();
let $saveERROR = 0;
$(".TrainingButtonSave").prop("disabled", true).closest(".form-group").find("var.ra-alert").remove();
// TRIM all fields
$.each($formCertificate.find(".form-control, .form-check-input"), function() {
$(this).val( $.trim( $(this).val() ) );
$(this).removeClass("form-invalid").closest(".form-group").find("var.ra-alert").remove();
});
// ALL REQUIRED FIELDS
$.each($formCertificate.find(".form-required"), function() {
if( $(this).val().trim() == '' || ($(this).is(':checkbox') && !$(this).is(':checked')) ) {
$(this).addClass("form-invalid").closest(".form-group").append('' + LNG_FIELD_MANDATORY + '');
$saveERROR += 1;
}
});
if($saveERROR > 0) {
$(".TrainingButtonSave").prop("disabled", false).closest(".form-group").append('Formulář obsahuje chyby. Ověřte znovu správnost vyplnění.');
return;
}
// submit
HTMLFormElement.prototype.submit.call(this);
});
// after save
if( $("#TrainingSubmited").val() == 1 ) {
if( $("#TrainingSuccessSave").val() == 1 ) {
$("#TrainingEventForm").find(".alert-success").css({ "display" : "inline-block" });
setTimeout(function() {
$("#TrainingEventForm").find(".alert-success").css({ "display" : "none" });
}, 4000);
} else {
$("#TrainingEventForm").find(".alert-danger").css({ "display" : "inline-block" });
setTimeout(function() {
$("#TrainingEventForm").find(".alert-success").css({ "display" : "none" });
$("#TrainingEventForm").find(".alert-danger").css({ "display" : "none" });
}, 6000);
}
}
// SET ATTENDANCE ORDER
$("#SetAttendanceOrder").on("click dblclick", function() {
sendPostData($FULLREQUESTURI, { actio: 'SetAttendanceOrder' });
return false;
});
}
// FORM Attendance IMPORT
// ************************************************************************************
if( $("#TrainingAttendanceImportForm").length ) {
const $formImport = $("#TrainingAttendanceImportForm");
const $prefixImportFrom = "Import_";
// ALL REQUIRED FIELDS
$formImport.find(".form-required").on("blur change", function() {
$(this).val( $.trim( $(this).val() ) );
$(this).removeClass("form-invalid").closest(".form-group").find("var.ra-alert").remove();
if( $(this).val() == '' ) $(this).addClass("form-invalid").closest(".form-group").append('' + LNG_FIELD_MANDATORY + '');
});
// save form
$formImport.on("submit", function(e) {
e.preventDefault();
let $saveERROR = 0;
$(".TrainingAttendanceImportButtonSave").prop("disabled", true).closest(".form-group").find("var.ra-alert").remove();
// TRIM all fields
$.each($formImport.find(".form-control, .form-check-input"), function() {
$(this).val( $.trim( $(this).val() ) );
$(this).removeClass("form-invalid").closest(".form-group").find("var.ra-alert").remove();
});
// ALL REQUIRED FIELDS
$.each($formImport.find(".form-required"), function() {
if( $(this).val().trim() == '' || ($(this).is(':checkbox') && !$(this).is(':checked')) ) {
$(this).addClass("form-invalid").closest(".form-group").append('' + LNG_FIELD_MANDATORY + '');
$saveERROR += 1;
}
});
if($saveERROR > 0) {
$(".TrainingAttendanceImportButtonSave").prop("disabled", false).closest(".form-group").append('Formulář obsahuje chyby. Ověřte znovu správnost vyplnění.');
return;
}
// submit
HTMLFormElement.prototype.submit.call(this);
});
// after save
if( $("#TrainingAttendanceImportSubmited").val() == 1 ) {
if( $("#TrainingAttendanceImportSuccessSave").val() == 1 ) {
$("#TrainingAttendanceImportForm").find(".alert-success").css({ "display" : "inline-block" });
setTimeout(function() {
$("#TrainingAttendanceImportForm").find(".alert-success").css({ "display" : "none" });
}, 4000);
} else {
$("#TrainingAttendanceImportForm").find(".alert-danger").css({ "display" : "inline-block" });
setTimeout(function() {
$("#TrainingAttendanceImportForm").find(".alert-success").css({ "display" : "none" });
$("#TrainingAttendanceImportForm").find(".alert-danger").css({ "display" : "none" });
}, 6000);
}
}
}
// TOGGLE COLUMNS into table (not in use)
// ************************************************************************************
$(function() {
/*
// jQuery: toggle hidden columns on click/dblclick
$(function() {
const $btn = $(".SwitchAttendanceTable");
const $table = $(".tableAttendance");
$(document).on("click dblclick", ".SwitchAttendanceTable", function(e) {
e.preventDefault();
const $show = $(this).data("show") === "full" ? "short" : "full";
$(this).data("show", $show);
if($show === "short") {
$table.find(".display-cell-no").addClass("d-none");
$(this).text("Zobrazit úplné údaje");
} else {
$table.find(".display-cell-no").removeClass("d-none");
$(this).text("Zobrazit zkrácené údaje (jen pro prezenční listinu a certifikát)");
}
});
});
*/
const $btn = $(".SwitchAttendanceTable");
const $table = $(".tableAttendance");
// Collect column indexes from
.display-cell-no
const $hideIndexes = [];
$table.find("thead th").each(function($i) {
if($(this).hasClass("display-cell-no")) { $hideIndexes.push($i); }
});
$(document).on("click dblclick", ".SwitchAttendanceTable", function($e) {
$e.preventDefault();
const $new = $(this).data("show") === "full" ? "short" : "full";
$(this).data("show", $new).attr("data-show", $new);
$table.find("tr").each(function() {
$(this).children().each(function($i) {
if($hideIndexes.includes($i)) {
$new === "short" ? $(this).addClass("d-none") : $(this).removeClass("d-none");
}
});
});
$(this).text($new === "short" ? "Zobrazit úplné údaje" : "Zobrazit zkrácené údaje (jen pro prezenční listinu a certifikát)");
});
});
// CREATE TRAINING LIST
// ************************************************************************************
$( "#CreateTrainingList" ).on( "click dblclick", function() {
const $eventId = $( "#CreateTrainingList" ).data( "event-id" );
const $more = $( "#CreateTrainingList" ).data( "more" );
// Disable button during processing
$( "#CreateTrainingList" ).prop( "disabled", true );
const $url = PROJECTPATH + "templates/202509_atta_attendance_sheet_create.php";
const $dataString = {
eventId: $eventId,
more: $more,
};
if($userAccessLevel >= 100) $("#showAjax").append( " L:" + (new Error).lineNumber + "#url+dataString=<"+"a href=\"" + $url + '?' + decodeURIComponent($.param($dataString)) + "\" target=\"_blank\" style=\"color:red;\">" + $url + '?' + decodeURIComponent($.param($dataString)) + "<"+"/a> \n" ); // TEST
$.ajax({
url: $url,
data: $dataString,
method: "GET",
dataType: "json",
success: function($res) {
// Show download button only on success
if($res && $res.success === true) {
$( "#DownloadTrainingList" ).removeClass( "d-none" );
} else {
alert( "Nepodařilo se vygenerovat PDF." );
}
},
error: function() {
alert( "Chyba při generování PDF." );
},
complete: function() {
$( "#CreateTrainingList" ).prop( "disabled", false );
},
});
});
// DOWNLOAD TRAINING LIST
// ************************************************************************************
$( "#DownloadTrainingList" ).on( "click dblclick", function() {
const $eventId = $(this).data( "event-id" );
const $url = PROJECTPATH + "templates/202509_atta_attendance_sheet_download.php?eventId=" + $eventId;
// Open download in new tab
window.open( $url, "_blank" );
});
// CREATE CERTIFICATE
// ************************************************************************************
$( "#CreateTrainingCertificate" ).on( "click dblclick", function() {
const $eventId = $( this ).data( "event-id" );
const $more = $( this ).data( "more" );
// Disable button during processing
$( this ).prop( "disabled", true );
const $url = PROJECTPATH + "templates/202509_atta_certificate_create.php";
const $dataString = {
eventId: $eventId,
more: $more,
};
if($userAccessLevel >= 100) $("#showAjax").append( " L:" + (new Error).lineNumber + "#url+dataString=<"+"a href=\"" + $url + '?' + decodeURIComponent($.param($dataString)) + "\" target=\"_blank\" style=\"color:red;\">" + $url + '?' + decodeURIComponent($.param($dataString)) + "<"+"/a> \n" ); // TEST
$.ajax({
url: $url,
data: $dataString,
method: "GET",
dataType: "json",
success: function($res) {
// Show download button only on success
if($res && $res.success === true) {
$( "#DownloadTrainingCertificate" ).removeClass( "d-none" );
} else {
alert( "Nepodařilo se vygenerovat PDF." );
}
},
error: function() {
alert( "Chyba při generování PDF." );
},
complete: function() {
$( "#CreateTrainingCertificate" ).prop( "disabled", false );
},
});
});
// DOWNLOAD CERTIFICATE
// ************************************************************************************
$( "#DownloadTrainingCertificate" ).on( "click dblclick", function() {
const $eventId = $(this).data( "event-id" );
const $url = PROJECTPATH + "templates/202509_atta_certificate_download.php?eventId=" + $eventId;
// Open download in new tab
window.open( $url, "_blank" );
});
|