1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
$(function() {
var etape = 0;
var pourcent_progressbar=0;
$('#les_fomulaires').submit(function() {
$('#les_fomulaires').hide();
$("#text_result").html("Importation en cours : <span class='progression'>0/0</span>").show(10, function() {
$("#myprogressbar").progressbar({value:pourcent_progressbar});
$("#myprogressbar").show(10, function() {
if (jQuery.trim($("#id_src").val()).length!=0) {
// Récupèrer le nombre de photos à importer
$.ajax({
type : 'POST',
async : false,
url : '/nbphotos.php',
data : 'chem=$cheminimport',
success : function(nbphotos){
if (nbphotos>0){
$(".progression").html("0"+" / "+nbphotos);
var fini=false;
var nb_photos_imported=0;
var ajax_reussi = false;
var resultat_ajax="";
// Variables envoyées en Ajax
var datas = desvariables;
while (nb_photos_imported < nbphotos) {
ajax_reussi = false;
$.ajax({
type : 'GET',
async : false,
url : '/traitement.php',
data : datas,
success : function(resultat){
resultat_ajax=resultat;
ajax_reussi=true;
nb_photos_imported++;
}
});
if (ajax_reussi==true){
if (resultat_ajax=="ok") {
pourcent_progressbar = Math.floor(nb_photos_imported*100/nbphotos);
$("#myprogressbar").progressbar("option", "value", pourcent_progressbar);
console.info("Succès ajax (resultat : OK) : "+pourcent_progressbar);
$(".progression").html(nb_photos_imported+" / "+nbphotos);
} else {
fini=true;
$("#text_result").html(ajax_reussi);
return false;
}
} else {
// Erreur d'execution ajax => sortir du while
console.info("Erreur d'execution ajax "+nb_photos_imported);
return false;
}
} // While
if (fini==true) {
$("#myprogressbar").hide('slow');
$('#text_result').html("Importation de "+nb_photos_imported+" photos terminée avec succès.");
}
} else{
$("#text_result").html("Aucune photo à importer.");
$("#myprogressbar").hide(10);
$('#les_fomulaires').show("slow");
}
}
});
}
});
}); // callback #text_result.show()
return false;
});
}); |
Partager