Your IP : 52.15.110.218


Current Path : /data/web/virtuals/51568/virtual/www/www/plany/
Upload File :
Current File : /data/web/virtuals/51568/virtual/www/www/plany/textyAttach.js

function zvolSouborAttach() {
    $('#fileInputAttach').click();
}

function formatBytes(bytes, decimals = 2) {
    if (bytes === 0) return '0 Bytes';
    const k = 1024;
    const dm = decimals < 0 ? 0 : decimals;
    const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
    const i = Math.floor(Math.log(bytes) / Math.log(k));
    return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + '&nbsp;' + sizes[i];
}

function dialogNacteniAttach() {
    let vstup = document.getElementById("fileInputAttach"),
        soubor = vstup.files[0],
        velikost = formatBytes(soubor.size);
    $.ajax({
        url: "www/plany/textyAttach.php",
        type: 'POST',
        data: {
            'data': JSON.stringify({
                command: 'dialogNacteniAttach',
                jmenoSouboru: soubor.name,
                velikostSouboru: velikost,

            })
        },
        success: function(result) {
            $("#attach-div-nacteni").html(result).removeClass("d-none");
        }
    });
}

function saveAttach() {
    $("#progress").removeClass("d-none");
    let fd = new FormData(),
        vstup = document.getElementById("fileInputAttach"),
        soubor = vstup.files[0],
        velikost = formatBytes(soubor.size),
        idTyden = $("#attach-top").data("idtyden"),
        popis = $('#attach-komentar').val().trim();
    fd.append('idTyden', idTyden);
    fd.append('velikost', velikost);
    fd.append('popis', popis);
    fd.append("filesToUpload[]", soubor);
    $.ajax({
        xhr: function() {
            let xhr = new window.XMLHttpRequest();
            xhr.upload.addEventListener("progress", function(evt) {
                if (evt.lengthComputable) {
                    let percentComplete = Math.floor((evt.loaded / evt.total) * 100);
                    $("#bar").width(percentComplete + '%');
                    $("#bar").html(percentComplete + '%');
                }
            }, false);
            return xhr;
        },

        type: 'POST',
        url: 'www/plany/textyAttachUpload.php',
        cache: false,
        contentType: false,
        processData: false,
        data: fd,
        success: function(result) {

            $.ajax({
                url: 'www/plany/textyAttach.php',
                type: 'POST',
                dataType: 'HTML',
                data: {
                    'data': JSON.stringify({
                        command: 'tabulkaAttach',
                        idTyden: idTyden,
                    })
                },
                success: function(result) {
                    $('#attach-div-nacteni').addClass('d-none');
                    $('#attach-main').html(result);
                }
            });
        },
    });
}

function smazatAtach(id) {
    idTyden = $("#attach-top").data("idtyden");
    $.ajax({
        url: "www/plany/textyAttach.php",
        type: 'POST',
        data: {
            'data': JSON.stringify({
                command: 'smazatAtach',
                id: id,
                idTyden: idTyden,

            })
        },
        success: function(result) {
            $('#attach-main').html(result);
        }
    });
}