Your IP : 3.23.102.99


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

function smazatOznacene(){
  let pocet = 0
      soubor = '';
  $('[id^="img-fotobar-"]:checked').each( function() {
    pocet++;
//    soubor = this.id.substr(12, 20) + '.jpg';
  })
  if (pocet == 0){
    $("#errFotoPruh").html("Nevybral jsi žádnou fotku.").removeClass("d-none");
  }
}

$('[id^="img-fotobar-"]').on("click", function (){
  $("#errFotoPruh").html("").addClass("d-none");
})

function oznacVsechny(){
  $("#errFotoPruh").html("").addClass("d-none");
  $('[id^="img-fotobar-"]').each( function(index, hodnota) {
    $(hodnota).prop('checked', 'checked');
  })
}

$("#galerieSeznam").on("change", function (){
  $("#errGalerie").addClass("d-none");
  let idgalerie = $("#galerieSeznam").val();
  $.ajax({
    url: "www/fotopruh/fotopruh-galerie-fotky.php",
    type: 'POST',
    dataType: 'HTML',
    data: {
      'idgalerie': idgalerie,
    },
    success: function (result) {
       $("#galerieFotky").html(result);
       }
  }); 
})

function spocitejGalerie(){
  let pocet = 0;
  $('[id^="img-galerie-"]:checked').each( function() {
    pocet++;
  })
  $("#oznaceno").html(pocet);
  $("#errGalerie").addClass("d-none");
}

class Fotka {
   nastav (id, idgalerie) {
    this.id = id;
    this.idgalerie = idgalerie;       
  }
}

let fotkyKopirovat = [];

function zkopirujVybrane(){
  let pocet = 0, 
      idgalerie = $("#galerieSeznam").val(),      
      fotka = new Fotka();
  $("#errGalerie").addClass("d-none");
  fotkyKopirovat = [];
  $('[id^="img-galerie-"]:checked').each( function(index, hodnota) {
    pocet++;
    fotka.nastav(hodnota.id.substr(12, 20), idgalerie);
    fotkyKopirovat.push(JSON.stringify(fotka));
  })
  if (pocet == 0){
      $("#errGalerie").removeClass("d-none alert-info").addClass('alert-danger').html("Nejsou vybrané žádné fotky pro zkopírování do fotopruhu.");
  } else {
    $("#progress").removeClass("d-none");    
    $("#bar").width('0%');
    kopirovani(0); 
  }
}

function kopirovani(kolikaty){
  let pocet = fotkyKopirovat.length - 1,
      fotka = new Fotka, 
      percentComplete = Math.floor(((kolikaty + 1)/ (pocet + 1)) * 100);
  $("#bar").width(percentComplete + '%');
  $("#bar").html(percentComplete + '%');
  fotka = JSON.parse(fotkyKopirovat[kolikaty]);    
  $("#img-galerie-"+fotka.id).prop('checked', false);
    
  $.ajax({
      url: "www/fotopruh/fotopruh-galerie-kopiruj.php",
      type: 'POST',
      dataType: 'HTML',
      data: {
        'fotka': fotkyKopirovat[kolikaty],
      },
      success: function (result) {
        kolikaty++;
        if (kolikaty <= pocet){
          kopirovani(kolikaty);
        } else {
          $("#progress").addClass("d-none");    
          $("#bar").width('0%');  
          $("#oznaceno").html(0);  
          $("#errGalerie").removeClass("d-none alert-danger").addClass('alert-info').html(`Počet zkopírovaných fotek: ${pocet+1}`);
          $("#errFotoPruh").html("").addClass("d-none");
          $.ajax({
              url: "www/fotopruh/fotopruh-fotky.php",
              type: 'POST',
              dataType: 'HTML',
              data: {
              },
              success: function (result) {
                $("#fotoPruh").html(result);
              }
          });
                    
        }
      }
  });    
}

function smazatOznacene(){
  let pocet = 0;
  $('[id^="img-fotobar-"]:checked').each( function() {
    pocet++;
  });
  if (pocet == 0){
    $("#errFotoPruh").html("Nevybral jsi žádnou fotku.").removeClass("d-none");
  } else {
    $("#errFotoPruh").html(`Chystáš se zmazat fotky (celkem: ${pocet}). 
      Chceš pokračovat? <button class="btn btn-info rounded-0 ml-5" onclick="nemazat()">Ne</botton>
      <button class="btn btn-danger ml-2 rounded-0" onclick="smazat()">Ano</botton>`).removeClass("d-none");
  }
}

function nemazat(){
  $("#errFotoPruh").html("").addClass("d-none");
}

function smazat(){
  let smazat = [];
  $("#errFotoPruh").html("").addClass("d-none");
  $('[id^="img-fotobar-"]:checked').each( function(index, hodnota) {
    smazat.push(hodnota.id.substr(12, 20));
  }) 
 $.ajax({
    url: "www/fotopruh/fotopruh-smazat.php",
    type: 'POST',
    dataType: 'HTML',
    data: {
      'smazat': JSON.stringify(smazat),
    },
    success: function (result) {
      $.ajax({
          url: "www/fotopruh/fotopruh-fotky.php",
          type: 'POST',
          dataType: 'HTML',
          data: {
          },
          success: function (result) {
            $("#fotoPruh").html(result);
          }
      });
    }
});
}