1087 lines
31 KiB
JavaScript
1087 lines
31 KiB
JavaScript
|
|
//#region Variables Globales
|
|
|
|
var server = "http://" + location.host + "/ULA.Cathay.Credito/";
|
|
var StarterTemplateVisible = true;
|
|
var ControlsSettings = {};
|
|
var SelectedCatalog = '';
|
|
var DireccionAPICatalogo = '';
|
|
var DataModel = false;
|
|
var Frmnombre = '';
|
|
var DataCatalogo;
|
|
|
|
var FORM_VALIDATOR = {};
|
|
|
|
|
|
|
|
|
|
var isMobile = {
|
|
Android: function () {
|
|
return navigator.userAgent.match(/Android/i);
|
|
},
|
|
BlackBerry: function () {
|
|
return navigator.userAgent.match(/BlackBerry/i);
|
|
},
|
|
iOS: function () {
|
|
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
|
|
},
|
|
Opera: function () {
|
|
return navigator.userAgent.match(/Opera Mini/i);
|
|
},
|
|
Windows: function () {
|
|
return navigator.userAgent.match(/IEMobile/i);
|
|
},
|
|
any: function () {
|
|
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
|
|
}
|
|
};
|
|
|
|
//#endregion
|
|
|
|
//#region MOMENT CONFIGURATION (DATE AND TIME CONFIGURATION)
|
|
|
|
moment.lang('es-PA', {
|
|
months: [
|
|
"Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio",
|
|
"Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"
|
|
]
|
|
});
|
|
|
|
moment.lang('es-PA');
|
|
|
|
//#endregion
|
|
|
|
//#region ULTIMUS DATEPIKER CONFIGURATION
|
|
|
|
jQuery(function ($) {
|
|
$.datepicker.regional['es'] = {
|
|
closeText: 'Cerrar',
|
|
prevText: '<Ant',
|
|
nextText: 'Sig>',
|
|
currentText: 'Hoy',
|
|
monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio',
|
|
'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
|
|
monthNamesShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun',
|
|
'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
|
|
dayNames: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
|
|
dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mié', 'Juv', 'Vie', 'Sáb'],
|
|
dayNamesMin: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sá'],
|
|
weekHeader: 'Sm',
|
|
dateFormat: 'dd-MM-yy',
|
|
firstDay: 1,
|
|
isRTL: false,
|
|
showMonthAfterYear: false,
|
|
yearSuffix: '',
|
|
yearRange: '1945:' + (new Date).getFullYear(),
|
|
changeMonth: true,
|
|
changeYear: true
|
|
};
|
|
$.datepicker.setDefaults($.datepicker.regional['es']);
|
|
|
|
});
|
|
|
|
|
|
|
|
//#endregion
|
|
|
|
//#region GENERIC MESSAGE
|
|
|
|
var Message_Success = "PROCESO COMPLETADO";
|
|
var Message_Warning = "ADVERTENCIA DEL SISTEMA";
|
|
var Message_Info = "INFORMACIÓN DEL SISTEMA";
|
|
var Message_Error = "ERROR INESPERADO";
|
|
|
|
var MessageFull_Error = "Ha ocurrido un error inesperado. Vuelva a intentarlo mas tarde";
|
|
|
|
//#endregion
|
|
|
|
//#region JQUERY.VALIDATE CONFIGURATION
|
|
|
|
jQuery.extend(jQuery.validator.messages, {
|
|
required: "CAMPO REQUERIDO",
|
|
email: "CORREO INCORRECTO: Por favor introducir un correo electrónico valido. Asegúrese de no tener espacios en blanco ni caracteres especiales",
|
|
number: "NUMERO INCORRECTO: Por favor introducir un numero valido. Asegúrese de no tener espacios en blanco ni caracteres especiales"
|
|
});
|
|
|
|
jQuery.validator.addMethod("lettersonly", function (value, element) {
|
|
return this.optional(element) || /^[a-zñ\s]+$/i.test(value);
|
|
}, "SOLO LETRAS");
|
|
|
|
jQuery.validator.addMethod("minimumRequired", function (value, element, params) {
|
|
|
|
return ($.trim(params.minimum) == "" ? true : ($("#" + element.id).autoNumeric('get') > parseFloat(params.minimum)));
|
|
|
|
}, "El VALOR DEBE SER MAYOR");
|
|
|
|
jQuery.validator.addMethod("maximumRequired", function (value, element, params) {
|
|
|
|
return ($.trim(params.maximum) == "" ? true : ($("#" + element.id).autoNumeric('get') <= parseFloat(params.maximum)));
|
|
|
|
}, "El VALOR DEBE SER MENOR");
|
|
|
|
|
|
jQuery.validator.addMethod("dateFormatRequired", function (value, element, params) {
|
|
|
|
return value == "" || moment(value, params.dateFormat, true).isValid();
|
|
|
|
}, "EL FORMATO INGRESADO NO ES CORRECTO");
|
|
|
|
jQuery.validator.addMethod("minimumYearsRequired", function (value, element, params) {
|
|
|
|
if (params.minimum == null || params.minimum == "" || params.minimum == 0 || !moment(value, params.dateFormat, true).isValid()) return true;
|
|
var now = new Date();
|
|
var fecha = moment(value, params.dateFormat);
|
|
|
|
// moment(fecha.toUTCString()).utc().format("DD-MMMM-YYYY");
|
|
var age = now.getFullYear() - fecha.year();
|
|
|
|
return (age < params.minimum ? false : true);
|
|
|
|
}, "LA FECHA DEBE SER MENOR");
|
|
|
|
jQuery.validator.addMethod("maximumYearsRequired", function (value, element, params) {
|
|
|
|
if (params.maximum == null || params.maximum == "" || params.maximum == 0 || !moment(value, params.dateFormat, true).isValid()) return true;
|
|
|
|
var now = new Date();
|
|
var fecha = moment(value, params.dateFormat);
|
|
|
|
// moment(fecha.toUTCString()).utc().format("DD-MMMM-YYYY");
|
|
var age = now.getFullYear() - fecha.year();
|
|
|
|
return (age <= params.maximum ? true : false);
|
|
|
|
}, "LA FECHA DEBE SER MENOR");
|
|
|
|
//#endregion
|
|
|
|
//#region Genericos
|
|
|
|
$("#btnDesarrollo").click(function () {
|
|
|
|
LoadMessage("REDIRECCIONANDO A LOCALHOST...");
|
|
|
|
var urlLocalhost = location.href;
|
|
|
|
urlLocalhost = urlLocalhost.replace(window.location.hostname, "LOCALHOST");
|
|
|
|
location.href = urlLocalhost;
|
|
|
|
});
|
|
|
|
$("#btnHeaderToggle").click(function () {
|
|
|
|
|
|
HeaderToggle();
|
|
|
|
});
|
|
|
|
this.HeaderToggle = function () {
|
|
|
|
if (isMobile.any()) {
|
|
|
|
$("#btnHeaderToggle").find('i').toggleClass('fa-chevron-circle-down fa-chevron-circle-up');
|
|
|
|
if (StarterTemplateVisible) {
|
|
|
|
$("#divStarterTemplate").css({ "padding": "20px 0 0 0" });
|
|
|
|
|
|
$('#divHeader').hide();
|
|
$('#divMenuBar').hide();
|
|
|
|
StarterTemplateVisible = false;
|
|
|
|
}
|
|
else {
|
|
|
|
$("#divStarterTemplate").css({ "padding": "120px 0 0 0" });
|
|
|
|
$('#divHeader').show();
|
|
$('#divMenuBar').show();
|
|
|
|
StarterTemplateVisible = true;
|
|
}
|
|
|
|
}
|
|
else {
|
|
|
|
$('#divHeader').slideToggle("fast");
|
|
$('#divMenuBar').slideToggle("fast");
|
|
|
|
$("#btnHeaderToggle").find('i').toggleClass('fa-chevron-circle-down fa-chevron-circle-up');
|
|
|
|
if (StarterTemplateVisible) {
|
|
|
|
$("#divStarterTemplate").animate({ paddingTop: "-=100px" });
|
|
|
|
StarterTemplateVisible = false;
|
|
|
|
}
|
|
else {
|
|
|
|
$("#divStarterTemplate").animate({ paddingTop: "+=100px" });
|
|
|
|
StarterTemplateVisible = true;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
$(document).ajaxStart(function () {
|
|
|
|
|
|
LoadMessage();
|
|
|
|
});
|
|
|
|
jQuery(document).ready(function () {
|
|
|
|
if (isMobile.any()) {
|
|
|
|
HeaderToggle();
|
|
}
|
|
|
|
|
|
//$(function () {
|
|
// FastClick.attach(document.body);
|
|
//});
|
|
|
|
|
|
if (navigator.appName.indexOf("Internet Explorer") == -1) { //yeah, he's using IE
|
|
|
|
if (window.matchMedia("(orientation: portrait)").matches) {
|
|
$('#modalMensajeMobile').modal('show');
|
|
}
|
|
|
|
if (window.matchMedia("(orientation: landscape)").matches) {
|
|
// you're in LANDSCAPE mode
|
|
$('#modalMensajeMobile').modal('hide');
|
|
}
|
|
|
|
}
|
|
|
|
|
|
toastr.options = {
|
|
"closeButton": true,
|
|
"debug": false,
|
|
"positionClass": "toast-top-right",
|
|
"onclick": null,
|
|
"showDuration": "300",
|
|
"hideDuration": "1000",
|
|
"timeOut": "10000",
|
|
"extendedTimeOut": "1000",
|
|
"showEasing": "swing",
|
|
"hideEasing": "swing",
|
|
"showMethod": "slideDown",
|
|
"hideMethod": "slideUp"
|
|
}
|
|
|
|
$("form").submit(function () {
|
|
if (!$(this).valid()) {
|
|
return false;
|
|
}
|
|
else {
|
|
|
|
LoadMessage();
|
|
|
|
return true;
|
|
}
|
|
});
|
|
|
|
$("[data-toggle=tooltip]").tooltip({ placement: 'right' });
|
|
|
|
$('[data-toggle="popover"]').popover({ trigger: 'hover', 'placement': 'top' });
|
|
|
|
jQuery('[data-confirm]').click(function (e) {
|
|
if (!confirm(jQuery(this).attr("data-confirm"))) {
|
|
e.preventDefault();
|
|
}
|
|
else {
|
|
|
|
LoadMessage();
|
|
|
|
}
|
|
});
|
|
|
|
jQuery('[data-toggle="tab"]').click(function (e) {
|
|
|
|
jQuery('[class="nav-active"]').attr("class", "");
|
|
jQuery(this).attr("class", "nav-active");
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.LoadToastContainer = function (form) {
|
|
|
|
if ($("#toast-container").length > 0) {
|
|
var $div = $('<div />').appendTo('body');
|
|
$div.attr('id', 'toast-container');
|
|
$div.attr('class', 'toast-top-right');
|
|
}
|
|
|
|
};
|
|
|
|
this.LoadMessage = function (Message) {
|
|
|
|
if (Message == null) {
|
|
|
|
Message = "Cargando Datos, Espere por favor!";
|
|
}
|
|
|
|
if ($("#toast-container").length > 0) {
|
|
var $div = $('<div />').appendTo('body');
|
|
$div.attr('id', 'toast-container');
|
|
$div.attr('class', 'toast-top-right');
|
|
}
|
|
|
|
$("#toast-container").empty();
|
|
|
|
var stringHtml = "";
|
|
|
|
stringHtml += "<div id=\"loadingGif\" class=\"toast toast-default\" style=\"font-size:14px;\">";
|
|
stringHtml += "<table>";
|
|
stringHtml += "<tr>";
|
|
stringHtml += "<td><img src=\"" + server + "Images/ajax-loader.gif\" alt=\"loading\" height=\"50\" width=\"50\"></td>";
|
|
stringHtml += "<td> </td>";
|
|
stringHtml += "<td>";
|
|
stringHtml += "<div class=\"toast-title\">" + Message + "</div>";
|
|
stringHtml += "</td>";
|
|
stringHtml += "</tr>";
|
|
stringHtml += "</table>";
|
|
stringHtml += "</div>";
|
|
|
|
$("#toast-container").append(stringHtml);
|
|
|
|
};
|
|
|
|
this.ENDREQUEST = function (text) {
|
|
$("#loadingGif").hide();
|
|
};
|
|
|
|
this.IsNullOrEmpty = function (value) {
|
|
|
|
if (value == null || $.trim(value) == "") return true;
|
|
return false;
|
|
}
|
|
|
|
|
|
this.lockViewContent = function () {
|
|
var status = $("#hiddenTaskStatus").val();
|
|
|
|
if (status != 1) {
|
|
|
|
FormReadOnly();
|
|
$('button').attr('disabled', true);
|
|
$('button').each(
|
|
function () {
|
|
if ($(this).attr('id') != null) {
|
|
if ($(this).attr('id').toLowerCase().indexOf("imprim") != -1) {
|
|
$(this).attr('disabled', false);
|
|
}
|
|
|
|
if ($(this).attr('id').toLowerCase().indexOf("envia") != -1 || $(this).attr('id').toLowerCase().indexOf("send") != -1) {
|
|
$(this).hide();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
this.FormDisable = function () {
|
|
|
|
$('input,select').removeAttr('disabled');
|
|
|
|
$('input,select').addClass("is-disabled");
|
|
|
|
$('input,select').focus(function () {
|
|
this.blur();
|
|
});
|
|
|
|
$('select').dblclick(function (e) {
|
|
alert('No puede seleccionar esto.');
|
|
});
|
|
|
|
$('input').datepicker("destroy");
|
|
|
|
$('input:radio').attr('disabled', true);
|
|
$('input:checkbox').attr('disabled', true);
|
|
|
|
$('input,select').removeAttr('required', true);
|
|
};
|
|
|
|
// Permitir Letras y numeros
|
|
this.LettersNumbersOnly = function (evt) {
|
|
evt = (evt) ? evt : event;
|
|
|
|
var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
|
|
((evt.which) ? evt.which : 0));
|
|
|
|
if ((charCode >= 48 && charCode <= 57) ||
|
|
(charCode >= 65 && charCode <= 90) ||
|
|
(charCode >= 97 && charCode <= 122) ||
|
|
(charCode >= 192 && charCode <= 255) ||
|
|
charCode == 8 || charCode == 32 || charCode == 180 || // 8 = backspace, 32 = space, 180 = apostrofe
|
|
charCode == 46 || charCode == 44 || charCode == 45 || charCode == 59) { // 188 = dot, 189 = colon, 190 = guion ,semi colon
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
|
|
// Permitir Letras, numeros y punto
|
|
this.LettersNumbersAndGuionOnly = function (evt) {
|
|
evt = (evt) ? evt : event;
|
|
|
|
var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
|
|
((evt.which) ? evt.which : 0));
|
|
|
|
if ((charCode >= 48 && charCode <= 57) ||
|
|
(charCode >= 65 && charCode <= 90) ||
|
|
(charCode >= 97 && charCode <= 122) ||
|
|
charCode == 8 || charCode == 32 || charCode == 45) // 8 = backspace, 32 = space,45 = guion
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
|
|
// Permitir Letras, numeros y punto
|
|
this.LettersNumbersAndDotOnly = function (evt) {
|
|
evt = (evt) ? evt : event;
|
|
|
|
var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
|
|
((evt.which) ? evt.which : 0));
|
|
|
|
if ((charCode >= 48 && charCode <= 57) ||
|
|
(charCode >= 65 && charCode <= 90) ||
|
|
(charCode >= 97 && charCode <= 122) ||
|
|
charCode == 8 || charCode == 32 || charCode == 46) // 8 = backspace, 32 = space, 44 = dot
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
// Permitir solo Letras
|
|
this.LettersOnly = function (evt) {
|
|
evt = (evt) ? evt : event;
|
|
var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
|
|
((evt.which) ? evt.which : 0));
|
|
if (charCode > 32 && (charCode < 65 || charCode > 90) &&
|
|
(charCode < 97 || charCode > 122)) {
|
|
return false;
|
|
}
|
|
else
|
|
return true;
|
|
};
|
|
|
|
// formato numero telefonico residencial
|
|
this.VerifyPhoneNumber = function (id) {
|
|
|
|
if ($("#" + id).val() != "") {
|
|
|
|
var formatoCorrectoNumeroTelefono = ($("#" + id).val().match(/\b\d{3}[-]\d{4}\b/)) ? true : false;
|
|
//alert(formatoCorrecto);
|
|
|
|
if (formatoCorrectoNumeroTelefono == false) {
|
|
var numeroTelefono = $("#" + id).val();
|
|
|
|
if (numeroTelefono.indexOf("-") != -1) {
|
|
numeroTelefono = numeroTelefono.replace("-", "");
|
|
}
|
|
|
|
if ($("#hiddenResidente").val() == "false") {
|
|
if (numeroTelefono.length <= 8) {
|
|
|
|
//reformat phone number
|
|
// $("#" + id).val(numeroTelefono.replace(/(\d{3})(\d{4})/, "$1-$2")); validar, por ahora Fernando solicito no usar guiones
|
|
|
|
}
|
|
else {
|
|
toastr.warning("Verifique haya introducido hasta 8 números", "Ingresar Datos Requeridos");
|
|
//$("#" + id).val("");
|
|
$("#" + id).focus();
|
|
}
|
|
}
|
|
else {
|
|
if (numeroTelefono.length == 8) {
|
|
var validanumero = $("#" + id).val().split("");
|
|
|
|
if (validanumero[0] == 0 || $("#" + id).val() == "1111111") {
|
|
|
|
toastr.warning("Ingresar un número valido", "Ingresar Datos Requeridos");
|
|
//$("#" + id).val("");
|
|
$("#" + id).focus();
|
|
|
|
} else {
|
|
//reformat phone number
|
|
//$("#" + id).val(numeroTelefono.replace(/(\d{3})(\d{4})/, "$1-$2")); validar, por ahora Fernando solicito no usar guiones
|
|
}
|
|
}
|
|
else {
|
|
toastr.warning("Verifique haya introducido 8 números", "Ingresar Datos Requeridos");
|
|
//$("#" + id).val("");
|
|
$("#" + id).focus();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// formato numero de celular
|
|
this.VerifyMobileNumber = function (id) {
|
|
|
|
if ($("#" + id).val() != "") {
|
|
|
|
var formatoCorrectoNumeroCelular = ($("#" + id).val().match(/\b\d{4}[-]\d{4}\b/)) ? true : false;
|
|
//alert(formatoCorrecto);
|
|
|
|
if (formatoCorrectoNumeroCelular == false) {
|
|
var numeroCelular = $("#" + id).val();
|
|
|
|
if (numeroCelular.indexOf("-") != -1) {
|
|
numeroCelular = numeroCelular.replace("-", "");
|
|
}
|
|
|
|
if ($("#hiddenResidente").val() == "false") {
|
|
if (numeroCelular.length <= 11) {
|
|
|
|
//reformat phone number
|
|
// $("#" + id).val(numeroCelular.replace(/(\d{4})(\d{4})/, "$1-$2")); validar, por ahora Fernando solicito no usar guiones
|
|
|
|
}
|
|
else {
|
|
|
|
toastr.warning("Verifique haya introducido hasta 8 números", "Ingresar Datos Requeridos");
|
|
$("#" + id).val("");
|
|
$("#" + id).focus();
|
|
}
|
|
}
|
|
else {
|
|
if (numeroCelular.length == 8) {
|
|
//var validanumero = $("#" + id).val().split("");
|
|
//if (validanumero[0] != 6) {
|
|
// toastr.warning("El número debe iniciar con 6", "Ingresar Datos Requeridos");
|
|
// $("#" + id).val("");
|
|
// $("#" + id).focus();
|
|
//}
|
|
//} else {
|
|
// $("#" + id).val(numeroCelular.replace(/(\d{4})(\d{4})/, "$1-$2"));
|
|
//}
|
|
//reformat phone number
|
|
|
|
|
|
|
|
}
|
|
else {
|
|
|
|
toastr.warning("Verifique haya introducido 8 números", "Ingresar Datos Requeridos");
|
|
$("#" + id).val("");
|
|
$("#" + id).focus();
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
// Solo permite numeros -- Segun Caracteres
|
|
this.OnlyNumbers = function (event) {
|
|
var charCode = (event.which) ? event.which : event.keyCode
|
|
|
|
if (charCode > 31 && (charCode < 48 || charCode > 57))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
this.OnlyNumerosyGuiones = function (event) {
|
|
var charCode = (event.which) ? event.which : event.keyCode
|
|
if (charCode == 45)
|
|
return true;
|
|
if (charCode > 31 && (charCode < 48 || charCode > 57))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
// Solo permite numeros -- Segun Caracteres
|
|
this.OnlyNumbersAndDot = function (event, id) {
|
|
var charCode = (event.which) ? event.which : event.keyCode
|
|
|
|
if (charCode == 46) {
|
|
|
|
var valor = $("#" + id).val();
|
|
|
|
var permitirPunto = (valor.indexOf('.') != -1) ? false : true;
|
|
|
|
return permitirPunto;
|
|
|
|
}
|
|
|
|
if (charCode > 31 && (charCode < 48 || charCode > 57))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
this.replaceAll = function (find, replace, str) {
|
|
return str.replace(new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), replace);
|
|
};
|
|
|
|
this.FormReadOnly = function () {
|
|
$('input,select,textarea').attr('disabled', true);
|
|
$('input,select,textarea').removeAttr('required');
|
|
};
|
|
|
|
|
|
this.Today = function () {
|
|
|
|
return moment(new Date());
|
|
};
|
|
|
|
//#endregion
|
|
|
|
//#region ULTIMUS PROPERTIES AND EXTENTION
|
|
|
|
//#region General Control extentions
|
|
|
|
$.fn.disable = function () {
|
|
|
|
this.attr('disabled', true);
|
|
|
|
};
|
|
|
|
$.fn.enable = function () {
|
|
|
|
this.attr('disabled', false);
|
|
|
|
};
|
|
|
|
$.fn.required = function () {
|
|
|
|
this.attr('required', true);
|
|
FORM_VALIDATOR.element(this);
|
|
};
|
|
|
|
$.fn.noRequired = function () {
|
|
|
|
var validator = this.closest('form').validate();
|
|
this.attr('required', false);
|
|
this.removeClass('inputWarning');
|
|
validator.element(this);
|
|
};
|
|
|
|
$.fn.EnableValidationToolTip = function () {
|
|
|
|
this.validate({
|
|
|
|
ignore: "not:hidden",
|
|
|
|
showErrors: function (errorMap, errorList) {
|
|
|
|
|
|
$.each(this.validElements(), function (index, element) {
|
|
var $element = $(element);
|
|
|
|
if ($element.prop("type") == "select-one") {
|
|
if ($element.attr('required')) {
|
|
$element.removeClass("selectWarning").addClass("inputSuccess");
|
|
}
|
|
else {
|
|
$element.removeClass("selectWarning");
|
|
}
|
|
}
|
|
else {
|
|
|
|
if ($element.attr('required')) {
|
|
$element.removeClass("inputWarning").addClass("inputSuccess");
|
|
}
|
|
else {
|
|
$element.removeClass("inputWarning");
|
|
}
|
|
}
|
|
|
|
|
|
$element.data("title", "").removeClass("error").tooltip("destroy");
|
|
|
|
});
|
|
|
|
$.each(errorList, function (index, error) {
|
|
var $element = $(error.element);
|
|
|
|
if ($element.prop("type") == "select-one") {
|
|
$element.removeClass("inputSuccess").addClass("selectWarning");
|
|
}
|
|
else {
|
|
$element.removeClass("inputSuccess").addClass("inputWarning");
|
|
}
|
|
|
|
$element.tooltip("destroy").data("title", error.message).addClass("error").tooltip({ placement: 'right', trigger: 'hover', container: 'body' });
|
|
|
|
});
|
|
}
|
|
});
|
|
|
|
};
|
|
|
|
//$.fn.TableInit = function (columnOrder, order, bPaginate, bFilter, bInfo, columnDefinition, data) {
|
|
|
|
// var ES = {
|
|
// "sProcessing": "Procesando...",
|
|
// "sLengthMenu": "Mostrar _MENU_ registros",
|
|
// "sZeroRecords": "No se encontraron resultados",
|
|
// "sEmptyTable": "Ningún dato disponible",
|
|
// "sInfo": "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
|
|
// "sInfoEmpty": "Mostrando registros del 0 al 0 de un total de 0 registros",
|
|
// "sInfoFiltered": "(filtrado de un total de _MAX_ registros)",
|
|
// "sInfoPostFix": "",
|
|
// "sSearch": "Buscar:",
|
|
// "sUrl": "",
|
|
// "sInfoThousands": ",",
|
|
// "sLoadingRecords": "Cargando...",
|
|
// "oPaginate": {
|
|
// "sFirst": "Primero",
|
|
// "sLast": "Último",
|
|
// "sNext": "Siguiente",
|
|
// "sPrevious": "Anterior"
|
|
// },
|
|
// "oAria": {
|
|
// "sSortAscending": ": Activar para ordenar la columna de manera ascendente",
|
|
// "sSortDescending": ": Activar para ordenar la columna de manera descendente"
|
|
// }
|
|
// };
|
|
|
|
// var EN = {
|
|
// "sProcessing": "Processing...",
|
|
// "sLengthMenu": "Show _MENU_ registers",
|
|
// "sZeroRecords": "No results found",
|
|
// "sEmptyTable": "No data available",
|
|
// "sInfo": "Showing registers from _START_ to _END_ of a total of _TOTAL_ registers",
|
|
// "sInfoEmpty": "Showing registers from 0 to 0 of a total of 0 registers",
|
|
// "sInfoFiltered": "(filtering of a total of _MAX_ registers)",
|
|
// "sInfoPostFix": "",
|
|
// "sSearch": "Find:",
|
|
// "sUrl": "",
|
|
// "sInfoThousands": ",",
|
|
// "sLoadingRecords": "Loading...",
|
|
// "oPaginate": {
|
|
// "sFirst": "First",
|
|
// "sLast": "Last",
|
|
// "sNext": "Next",
|
|
// "sPrevious": "Previous"
|
|
// },
|
|
// "oAria": {
|
|
// "sSortAscending": ": Activate to sort the column in ascending order",
|
|
// "sSortDescending": ": Activate to sort the column in descending order"
|
|
// }
|
|
// };
|
|
|
|
// this.dataTable({
|
|
// "language": EN,
|
|
// "order": [[columnOrder, order]],
|
|
// "destroy": true,
|
|
// "bPaginate": bPaginate,
|
|
// "bFilter": bFilter,
|
|
// "bInfo": bInfo,
|
|
// "data": data,
|
|
// "columns": columnDefinition,
|
|
// "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
|
|
// });
|
|
//};
|
|
|
|
$.fn.validateElement = function (controlId) {
|
|
|
|
var validator = this.validate();
|
|
validator.element(controlId);
|
|
|
|
};
|
|
|
|
$.fn.reset = function () {
|
|
$(this).each(function () { this.reset(); });
|
|
}
|
|
|
|
$.fn.setByText = function (value) {
|
|
|
|
if (value != '')
|
|
$(this.selector + " option:contains(" + value + ")").attr('selected', 'selected');
|
|
|
|
};
|
|
|
|
|
|
|
|
//#endregion
|
|
|
|
//#region Date time extentions
|
|
|
|
$.fn.dateFormatNoTime = function (value) {
|
|
|
|
|
|
|
|
if (value != null && value != '' && value != '0001-01-01T00:00:00') {
|
|
|
|
try { value = value.substring(0, 19); }
|
|
catch (ex) { }
|
|
|
|
var fecha = new Date(value);
|
|
this.val(moment(fecha.toUTCString()).utc().format("DD-MMMM-YYYY"));
|
|
}
|
|
else
|
|
return '';
|
|
};
|
|
|
|
$.fn.CalculateAge = function (controlYear, controlMonth) {
|
|
|
|
var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
|
|
var mayoriaEdad = 18;
|
|
|
|
var fechaActual = new Date();
|
|
var mesActual = fechaActual.getUTCMonth() + 1;
|
|
var diaActual = fechaActual.getDate();
|
|
var añoActual = fechaActual.getUTCFullYear();
|
|
|
|
var momentfecha = moment(this.val(), "DD-MMMM-YYYY");
|
|
var DayOfBirthString = monthNames[momentfecha._a[1]] + " " + momentfecha._a[2] + ", " + momentfecha._a[0];
|
|
|
|
var fecha = new Date(DayOfBirthString);
|
|
var mesFechaNacimiento = fecha.getUTCMonth() + 1;
|
|
var diaFechaNacimiento = fecha.getDate();
|
|
var añoFechaNacimiento = fecha.getUTCFullYear();
|
|
|
|
var edad = añoActual - añoFechaNacimiento;
|
|
|
|
if (edad >= mayoriaEdad) {
|
|
|
|
var mesesCumplidos = 0;
|
|
var mesVerificar;
|
|
|
|
var verificarAñoSiguiente = (mesFechaNacimiento >= mesActual) ? true : false;
|
|
|
|
if (verificarAñoSiguiente) {
|
|
mesActual = 12; // refleja un año entero a verificar
|
|
}
|
|
|
|
mesVerificar = mesFechaNacimiento + 1;
|
|
|
|
while (mesVerificar <= mesActual) {
|
|
|
|
if (mesVerificar == mesActual) {
|
|
if ((diaActual >= diaFechaNacimiento) ? true : false) {
|
|
|
|
if (verificarAñoSiguiente) {
|
|
mesActual = fechaActual.getUTCMonth() + 1;
|
|
mesVerificar = 1;
|
|
verificarAñoSiguiente = false;
|
|
mesesCumplidos++;
|
|
if (mesesCumplidos != 12) // Año cumplido
|
|
edad--;
|
|
else if (mesesCumplidos == 12)
|
|
mesesCumplidos = 0;
|
|
}
|
|
else {
|
|
mesVerificar++;
|
|
mesesCumplidos++;
|
|
}
|
|
}
|
|
else {
|
|
|
|
if (verificarAñoSiguiente) {
|
|
mesActual = fechaActual.getUTCMonth() + 1;
|
|
mesVerificar = 1;
|
|
|
|
verificarAñoSiguiente = false;
|
|
mesesCumplidos++;
|
|
if (mesesCumplidos != 12) // Año cumplido
|
|
edad--;
|
|
else if (mesesCumplidos == 12)
|
|
mesesCumplidos = 0;
|
|
}
|
|
else {
|
|
mesVerificar++;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
mesesCumplidos++;
|
|
mesVerificar++;
|
|
}
|
|
}
|
|
|
|
$(controlYear).val(edad);
|
|
$(controlMonth).val(mesesCumplidos);
|
|
}
|
|
else {
|
|
$(controlYear).val('');
|
|
$(controlMonth).val('');
|
|
}
|
|
}
|
|
|
|
$.fn.CalculateLaboralAgeActual = function (controlYear, controlMonth) {
|
|
|
|
var txtFechaInicioEmpleo = moment(this.val(), "DD-MMMM-YYYY");
|
|
|
|
var years = moment().diff(txtFechaInicioEmpleo, 'years');
|
|
var months = moment().diff(txtFechaInicioEmpleo, 'months');
|
|
|
|
months = months - (years * 12);
|
|
|
|
$(controlYear).val(years);
|
|
$(controlMonth).val(months);
|
|
}
|
|
|
|
$.fn.dotNetFormat = function () {
|
|
|
|
if (this.val() != null && this.val() != '') {
|
|
|
|
var momentDate = moment(this.val(), "DD-MMMM-YYYY");
|
|
var dotNetFormatDate = momentDate.format("MM-DD-YYYY");
|
|
|
|
return dotNetFormatDate;
|
|
}
|
|
else
|
|
return '';
|
|
};
|
|
|
|
$.fn.CalculateLaboralAge = function (controlYear, controlMonth, controlEndDate) {
|
|
|
|
var txtFechaInicioEmpleo = moment(this.val(), "DD-MMMM-YYYY");
|
|
var txtFechaFinEmpleo = moment($(controlEndDate).val(), "DD-MMMM-YYYY");
|
|
|
|
var years = txtFechaFinEmpleo.diff(txtFechaInicioEmpleo, 'years');
|
|
var months = txtFechaFinEmpleo.diff(txtFechaInicioEmpleo, 'months');
|
|
|
|
months = months - (years * 12);
|
|
|
|
$(controlYear).val(years);
|
|
$(controlMonth).val(months);
|
|
}
|
|
|
|
$.fn.DatepickerPast = function (ControlId) {
|
|
|
|
/// <summary>Method for asing Datepciker that start from 18 year ago to a text input html control.</summary>
|
|
/// <param name="ControlId" type="text">Control ID of text input control</param>
|
|
|
|
var _dateObject = new Date();
|
|
var _yearInit = _dateObject.getFullYear();
|
|
|
|
_dateObject.setFullYear(_yearInit);
|
|
|
|
|
|
this.datepicker({ yearRange: '1945:' + ((new Date).getFullYear() + 15), defaultDate: _dateObject }).datepicker('widget').wrap('<div class="ll-skin-cangas"/>');
|
|
|
|
};
|
|
|
|
$.fn.Datepicker = function (ControlId, params) {
|
|
|
|
/// <summary>Method for asing Datepciker that star-t from 18 year ago to a text input html control.</summary>
|
|
/// <param name="ControlId" type="text">Control ID of text input control</param>
|
|
|
|
var _dateObject = new Date();
|
|
var _yearInit = _dateObject.getFullYear();
|
|
|
|
_dateObject.setFullYear(_yearInit);
|
|
|
|
|
|
if (params == null) {
|
|
this.datepicker({
|
|
dateFormat: 'dd-MM-yy',
|
|
yearRange: '1945:' + ((new Date).getFullYear() + 15),
|
|
defaultDate: _dateObject
|
|
}).datepicker('widget').wrap('<div class="ll-skin-cangas"/>');
|
|
}
|
|
else {
|
|
|
|
this.datepicker({
|
|
defaultDate: _dateObject,
|
|
dateFormat: 'dd-MM-yy',
|
|
yearRange: params.yearRange,
|
|
beforeShowDay: params.beforeShowDay
|
|
}).datepicker('widget').wrap('<div class="ll-skin-cangas"/>');
|
|
}
|
|
|
|
};
|
|
|
|
//#endregion
|
|
|
|
|
|
this.BuildGrid = function (ModelTabla) {
|
|
|
|
if (ModelTabla.GridSettings == null) return;
|
|
|
|
var settings = $.parseJSON(ModelTabla.GridSettings);
|
|
|
|
var url = (settings.WebAPILocal ? server + ModelTabla.DireccionAPI : settings.UrlSiteAPI + ModelTabla.DireccionAPI)
|
|
|
|
$('#' + ModelTabla.IdControl).TableInit(settings.ColumnOrder, settings.Orden, settings.Paginacion, settings.Filtro, settings.Leyenda, settings.ColumnDefinition, null);
|
|
|
|
if ($.trim(ModelTabla.DireccionAPI) == "") return;
|
|
|
|
var model = {};
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: url,
|
|
cache: false,
|
|
data: JSON.stringify(model),
|
|
contentType: "application/json",
|
|
dataType: "json",
|
|
success: function (resp) {
|
|
|
|
if (resp != null) {
|
|
|
|
settings.data = $.parseJSON(resp.JSONData);
|
|
|
|
if (typeof setCustomSettingssDataGrid !== 'undefined' && $.isFunction(setCustomSettingssDataGrid)) {
|
|
var newSettings = setCustomSettingssDataGrid(ModelTabla.IdControl, settings);
|
|
settings = newSettings;
|
|
}
|
|
|
|
$('#' + ModelTabla.IdControl).TableInit(settings.ColumnOrder, settings.Orden, settings.Paginacion, settings.Filtro, settings.Leyenda, settings.ColumnDefinition, settings.data);
|
|
|
|
$('#' + ModelTabla.IdControl + ' tbody td').live('click', 'td', function (event) {
|
|
|
|
var data = $('#' + ModelTabla.IdControl).DataTable().row($(this).parents('tr')).data();
|
|
|
|
if (typeof GridRowEvent !== 'undefined' && $.isFunction(GridRowEvent))
|
|
GridRowEvent(ModelTabla.IdControl, event.target.id, data);
|
|
|
|
});
|
|
}
|
|
|
|
else {
|
|
|
|
toastr.error(MessageFull_Error, Message_Error);
|
|
}
|
|
}
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
if (typeof AjaxFailEvent !== 'undefined' && $.isFunction(AjaxFailEvent) && !AjaxFailEvent(jqxhr, textStatus, error))
|
|
return;
|
|
ENDREQUEST();
|
|
|
|
toastr.error(MessageFull_Error, Message_Error);
|
|
|
|
}).then(function (value) {
|
|
|
|
ENDREQUEST();
|
|
});
|
|
|
|
}
|
|
|
|
function swapDataTableRows(selector, row1Index, row2Index) {
|
|
var datatable = selector.DataTable();
|
|
//var rows = datatable.rows().data();
|
|
var row1Data = datatable.row(row1Index).data();
|
|
var row2Data = datatable.row(row2Index).data();
|
|
|
|
datatable.row(row1Index).data(row2Data).draw();
|
|
datatable.row(row2Index).data(row1Data).draw();
|
|
// datatable.drow();
|
|
}
|