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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| // plugin JQuery
(function($){
/********************************************************************/
// options.infoWindow : fenetre modale qui est affichée pendant le chargement
// options.jsonFile : addresse du fichier .json a charger
// options.timeout : temps entre envoie de deux requetes pour trouvé le produit
// options.success : function(data), fonction executée lors de la réception des données
// options.errorJSON : function(jsonVar), fonction executée lors de la réception du fichier .json et qu'il y a une erreur detectée
// options.error : function(jqXHR, textStatus, errorThrown) fonction executée lorsqu'une erreur au niveau du XHR est détectée
// options.endPost : function(), fonction executée lorsque le process est terminé
// options.msg : message d'attente affiché
// options.initMode : "hide" ou "show". indique si on affiche infoWindow lors du lancement de la requete
//*
$.customLoadJSON = function(options){
var defauts = {
"infoWindow": "#infoWindow",
"jsonFile": "",
"success": null,
"error": null,
"errorJSON": null,
"timeout": 3000,
"msg": "Connexion au produit en cours...",
initMode: "hide"
};
var myOptions = $.extend(defauts, options);
var $infoWindow;
$infoWindow = $(myOptions.infoWindow);
var $div = $infoWindow.find(".modal-body");
$infoWindow.find(".modal-header h3").text("Informations");
var $msg = $('<div/>').addClass("alert").text(myOptions.msg);
$div.empty().append($msg);
$infoWindow.find(".modal-footer button").addClass("hide");
if(myOptions.initMode === "show"){
$infoWindow.modal("show");
}
function sendRequest($infoWindow, myOptions){
$.ajax({
url: myOptions.jsonFile,
dataType: "json",
type: "GET",
cache: false,
timeout: myOptions.timeout,
error: function(jqXHR, textStatus, errorThrown){
if(textStatus === "timeout"){
$infoWindow.modal("show");
sendRequest($infoWindow, myOptions);
// => on relance la requete car produit non detecté
} else if(textStatus === "abort"){
// on a executé une demande d'arret : $ajax.abort();
$infoWindow.modal("hide");
} else {
if(myOptions.error !== null){
myOptions.error(jqXHR, textStatus, errorThrown);
}
$infoWindow.find(".alert").addClass(".alert-error").text("Erreur : " + textStatus);
$infoWindow.find('.modal-footer button[data-dismiss="modal"]').removeClass("hide");
$infoWindow.modal("show");
}
},
//data: postStr,
success: function(data){
// **********************************************
// Gestion des flag de sauvegarde
var $save = $("#mustSave");
var $reboot = $("#mustReboot");
$save.removeClass("active disabled");
$reboot.removeClass("active disabled");
if(data.CmdProcess_Status.cfgIsSaved === "0"){
$save.removeClass("hide");
$reboot.addClass("hide");
} else if(data.CmdProcess_Status.mustReboot === "1"){
$save.addClass("hide");
$reboot.removeClass("hide");
} else {
$save.addClass("hide");
$reboot.addClass("hide");
}
if(data.CmdProcess_Status.status === "[OK]"){
if(myOptions.success !== null){
myOptions.success(data);
}
} else {
if(myOptions.errorJSON !== null){
myOptions.errorJSON(data);
}
}
$("body > .container").removeClass("hide");
$infoWindow.modal("hide");
}
});
}
sendRequest($infoWindow, myOptions);
};
})(jQuery); |
Partager