79 lines
2.4 KiB
JavaScript
79 lines
2.4 KiB
JavaScript
var urlBase = config.urlBase;
|
|
|
|
function confirmReset() {
|
|
$(".confirm").removeClass('confirmKO');
|
|
$(".txtConfirm").empty();
|
|
}
|
|
|
|
function printError(msg){
|
|
confirmReset();
|
|
$(".txtConfirm").append(msg);
|
|
$(".confirm").addClass('confirmKO');
|
|
$(".confirm").fadeIn(200);
|
|
setTimeout(function() {
|
|
$(".confirm").fadeOut(200);
|
|
setTimeout(confirmReset, 200);
|
|
}, 1500);
|
|
}
|
|
|
|
$.ajaxPrefilter(function(xhr) {
|
|
var orgErrorHandler = xhr.error;
|
|
|
|
var key = localStorage.getItem('vnKey');
|
|
if (key) {
|
|
xhr.jsonData.push(key)
|
|
}
|
|
|
|
Object.assign(xhr, {
|
|
url: `${urlBase}/workerTimeControl/${xhr.urlPath}`,
|
|
headers: {
|
|
'version': '1',
|
|
'aplicacion': 'workerTimeControl'
|
|
},
|
|
timeout: 1000,
|
|
contentType: 'application/json; charset=utf-8',
|
|
dataType: 'json',
|
|
processData: false,
|
|
data: JSON.stringify(xhr.jsonData),
|
|
error: function(xhr, textStatus, err) {
|
|
if (orgErrorHandler) {
|
|
try {
|
|
orgErrorHandler(xhr, textStatus, err);
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
}
|
|
|
|
switch (textStatus){
|
|
case 'parsererror':
|
|
mensaje = 'Requested JSON parse failed';
|
|
break;
|
|
case 'timeout':
|
|
mensaje = 'Time out error';
|
|
break;
|
|
case 'abort':
|
|
mensaje = 'Ajax request aborted';
|
|
break;
|
|
case 'error':
|
|
switch (xhr.status){
|
|
case 0:
|
|
mensaje = 'Not connect: Verify Network';
|
|
break;
|
|
case 555:
|
|
mensaje = JSON.parse(xhr.statusText).Message;
|
|
break;
|
|
default:
|
|
if (xhr.status >= 400 && xhr.status < 500)
|
|
mensaje = xhr.statusText;
|
|
else
|
|
mensaje = 'Ha ocurrido un error, consulta con informática';
|
|
}
|
|
break;
|
|
default:
|
|
mensaje = 'Ha ocurrido un error, consulta con informática';
|
|
}
|
|
printError(mensaje);
|
|
}
|
|
});
|
|
});
|