Your IP : 3.129.26.177


Current Path : /data/web/virtuals/51568/virtual/www/subdom/agenda.old/js.x/
Upload File :
Current File : /data/web/virtuals/51568/virtual/www/subdom/agenda.old/js.x/Editors.js

function editorPrepniEnabled(id) {
    let url = document.location.pathname,
        path = url.substring(0, url.lastIndexOf('/') + 1);
    $.ajax({
        url: path + '../../app/php/ajaxEditors.php',
        type: 'POST',
        dataType: 'HTML',
        data: {
            'data': JSON.stringify({
                command: 'editorPrepniEnabled',
                id: id,
            })
        },
        success: function(result) {
            enabled = (result == '1') ? '<i class="fas fa-user"></i>' : '<i class="fas fa-user-slash"></i>';
            $("#editor-enabled" + id).html(enabled);
        }
    });
}

function editorEdituj(id) {
    let url = document.location.pathname,
        path = url.substring(0, url.lastIndexOf('/') + 1);
    $.ajax({
        url: path + '../../app/php/ajaxEditors.php',
        type: 'POST',
        dataType: 'HTML',
        data: {
            'data': JSON.stringify({
                command: 'editorEdituj',
                id: id
            })
        },
        success: function(result) {
            $("#div-dialogy").html(result);
        }
    });
}

// elozEditora: id == 0 => je novy -- odesle se mu email na zalozeni hesla
function ulozEditora(id) {
    let errors = [],
        email = $("#email").val(),
        jeNovy = (id > 0);
    $("#editor-err-alert").addClass("d-none");
    if (!(/^\w+([\.-]?\w+)*@gymzn.cz/.test(email))) {
        errors.push('přípustný je pouze validní email z domény gymzn.cz');
    }
    if (errors.length > 0) {
        message = '<ul class="mb-0">';
        errors.forEach(element => {
            message += `<li>${element}</li>`;
        });
        message += '</ul>';
        $("#editor-err-alert").html(message).removeClass('d-none');
    } else {
        let url = document.location.pathname,
            path = url.substring(0, url.lastIndexOf('/') + 1),
            spravce = '0';    
        if (id > 0){
          spravce = ($('#editor-spravce').prop('checked')) ? '1' : '0';
        }
        
        $.ajax({
            url: path + '../../app/php/ajaxEditors.php',
            type: 'POST',
            dataType: 'HTML',
            data: {
                'data': JSON.stringify({
                    command: 'editorUloz',
                    login: email,
                    id: id,
                    spravce: spravce
                })
            },
            success: function(result) {
            
                let data = JSON.parse(result);
                if (data.error){
                    $("#editor-err-alert").html('tento email je již použit').removeClass('d-none');
                } else {
                    if (data.novy) {
                      editorEdituj(data.id);
                      $.ajax({
                          url: path + '../../app/php/ajaxEditors.php',
                          type: 'POST',
                          dataType: 'HTML',
                          data: {
                              'data': JSON.stringify({
                                  command: 'posliEmailHeslo',
                                  id: data.id
                              })
                          },
                          success: function(result) {
                            $("#div-supliky-table").html(result);
                          }
                      });                      
                      
                      
                    }
                } 
            }
        });
    }
}