1664 lines
54 KiB
JavaScript
1664 lines
54 KiB
JavaScript
|
|
//#region Variables Globales
|
|
|
|
var server = WEB_APLICATION;
|
|
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 <= 11) {
|
|
|
|
//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 11 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 11 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
|
|
|
|
//#endregion
|
|
|
|
//#region CONTROLSETTINGS
|
|
|
|
this.GetControlsSettings = function (keyfiltro, keyformulario, form, DataModel, IsASync) {
|
|
|
|
|
|
if (IsASync == undefined) { IsASync = true };
|
|
|
|
FORM_VALIDATOR = $("#" + form).validate();
|
|
|
|
var uri = "api/GlobalAPI/GetControlsSettings?keyfiltro=" + keyfiltro + "&keyformulario=" + keyformulario;
|
|
|
|
$.ajax({
|
|
url: server + uri,
|
|
dataType: 'json',
|
|
data: null,
|
|
async: IsASync,
|
|
success: function (data) {
|
|
|
|
|
|
if (data != null && data.CodRespuesta != "ERROR") {
|
|
ControlsSettings = data;
|
|
|
|
if (data.Controls == null) {
|
|
toastr.warning("No se encontro configuracion para los controles", Message_Warning);
|
|
return;
|
|
}
|
|
|
|
$.each(data.Controls, function (key, item) {
|
|
try {
|
|
|
|
//#region DIV
|
|
if (typeof $("#div" + item.IdControl).val() !== 'undefined') {
|
|
|
|
if (item.Hidden == true)
|
|
$("#div" + item.IdControl).hide();
|
|
else
|
|
$("#div" + item.IdControl).show();
|
|
|
|
}
|
|
//#endregion
|
|
|
|
//#region CALENDAR
|
|
if (item.DescripcionTipoDato == "calendar") {
|
|
|
|
// $('#txt' + item.IdControl).attr("required", item.Requerido);
|
|
$('#txt' + item.IdControl).attr("disabled", item.Disabled);
|
|
$('#txt' + item.IdControl).attr("readonly", item.Readonly);
|
|
|
|
|
|
|
|
var param = {
|
|
dateFormat: IsNullOrEmpty(item.ValorAtributo1) ? "DD-MMMM-YYYY" : item.ValorAtributo1,
|
|
minimum: IsNullOrEmpty(item.ValorAtributo2) ? null : item.ValorAtributo2,
|
|
maximum: IsNullOrEmpty(item.ValorAtributo3) ? null : item.ValorAtributo3,
|
|
beforeShowDay: item.ValorAtributo4 == 1 ? true : false,
|
|
minDate: IsNullOrEmpty(item.ValorAtributo5) ? null : item.ValorAtributo6,
|
|
maxDate: IsNullOrEmpty(item.ValorAtributo6) ? null : item.ValorAtributo7,
|
|
yearRange: ((IsNullOrEmpty(this.minDate) ? '1945:' : this.minDate) + (IsNullOrEmpty(this.maxDate) ? ((new Date).getFullYear() + 15) : this.maxDate)),
|
|
|
|
}
|
|
|
|
if (!item.Readonly) {
|
|
|
|
$('#txt' + item.IdControl).Datepicker('#txt' + item.IdControl, param);
|
|
|
|
}
|
|
|
|
$('#txt' + item.IdControl).rules("add", {
|
|
required: item.Requerido,
|
|
dateFormatRequired: param,
|
|
minimumYearsRequired: param,
|
|
maximumYearsRequired: param,
|
|
messages: {
|
|
dateFormatRequired: jQuery.validator.format("SE REQUIERE EL FORMATO: " + param.dateFormat),
|
|
minimumYearsRequired: jQuery.validator.format("SE REQUIERE UN MINIMO DE " + param.minimum + " AÑOS"),
|
|
maximumYearsRequired: jQuery.validator.format("SOLO SE PERMITE UN MAXIMO DE " + param.maximum + " AÑOS")
|
|
}
|
|
});
|
|
if (item.Requerido == false) {
|
|
$('#txt' + item.IdControl).noRequired();
|
|
}
|
|
|
|
//if (param.dateFormat != null) {
|
|
// $('#txt' + item.IdControl).rules("add", {
|
|
// dateFormatRequired: param,
|
|
// messages: {
|
|
// dateFormatRequired: jQuery.validator.format("SE REQUIERE EL FORMATO: " + param.dateFormat)
|
|
// }
|
|
// });
|
|
//}
|
|
|
|
//if (param.minimum != null) {
|
|
// $('#txt' + item.IdControl).rules("add", {
|
|
// minimumYearsRequired: param,
|
|
// messages: {
|
|
// minimumYearsRequired: jQuery.validator.format("SE REQUIERE UN MINIMO DE " + param.minimum + " AÑOS")
|
|
// }
|
|
// });
|
|
//}
|
|
|
|
//if (param.maximum != null) {
|
|
// $('#txt' + item.IdControl).rules("add", {
|
|
// maximumYearsRequired: param,
|
|
// messages: {
|
|
// maximumYearsRequired: jQuery.validator.format("SOLO SE PERMITE UN MAXIMO DE " + param.maximum + " AÑOS")
|
|
// }
|
|
// });
|
|
//}
|
|
|
|
$('#txt' + item.IdControl).change(function () {
|
|
|
|
if (moment($('#txt' + item.IdControl).val(), 'DD-MMMM-YYYY', true).isValid())
|
|
$('#txt' + item.IdControl).val(moment($('#txt' + item.IdControl).val(), 'DD-MMMM-YYYY').format(param.dateFormat));
|
|
|
|
FORM_VALIDATOR.element('#' + this.id);
|
|
});
|
|
//#endregion
|
|
|
|
//#region NUMBER
|
|
} else if (item.DescripcionTipoDato == "percent" || item.DescripcionTipoDato == "currency"
|
|
|| item.DescripcionTipoDato == "whole" || item.DescripcionTipoDato == "decimal") {
|
|
|
|
$('#txt' + item.IdControl).attr("disabled", item.Disabled);
|
|
$('#txt' + item.IdControl).attr("readonly", item.Readonly);
|
|
|
|
switch (item.DescripcionTipoDato) {
|
|
case "currency":
|
|
$("#txt" + item.IdControl).autoNumeric('init', { aSign: item.ValorAtributo1, mDec: '2' });
|
|
break;
|
|
case "percent":
|
|
$("#txt" + item.IdControl).autoNumeric('init', { aSign: ' %', pSign: 's', mDec: '2' });
|
|
break;
|
|
case "whole":
|
|
$("#txt" + item.IdControl).autoNumeric('init', { mDec: '0' });
|
|
break;
|
|
case "decimal":
|
|
$("#txt" + item.IdControl).autoNumeric('init', { mDec: '2' });
|
|
break;
|
|
}
|
|
|
|
//Para los casos en los que el campo ya posee un valor cargado
|
|
try {
|
|
var _preValue = $('#txt' + item.IdControl).autoNumeric('get');
|
|
|
|
if(jQuery.isNumeric(_preValue))
|
|
$('#txt' + item.IdControl).autoNumeric('set', _preValue);
|
|
else
|
|
$('#txt' + item.IdControl).autoNumeric('set', '0');
|
|
|
|
} catch (e) {
|
|
$('#txt' + item.IdControl).autoNumeric('set', '0');
|
|
}
|
|
|
|
|
|
var param = {
|
|
minimum: item.ValorAtributo2,
|
|
maximum: item.ValorAtributo3
|
|
}
|
|
|
|
//NO FUNCIONA
|
|
//$('#txt' + item.IdControl).rules("add", {
|
|
// required: item.Requerido,
|
|
// minimumRequired: param,
|
|
// maximumRequired: param,
|
|
// messages: {
|
|
// minimumRequired: jQuery.validator.format("EL VALOR DEBE SER MAYOR QUE " + param.minimum),
|
|
// maximumRequired: jQuery.validator.format("EL VALOR DEBE SER MENOR QUE " + param.maximum)
|
|
// }
|
|
//});
|
|
|
|
$('#txt' + item.IdControl).change(function () {
|
|
|
|
FORM_VALIDATOR.element('#' + this.id);
|
|
});
|
|
|
|
//#endregion
|
|
|
|
//#region EMAIL
|
|
} else if (item.DescripcionTipoDato == "email") {
|
|
$('#txt' + item.IdControl).attr("required", item.Requerido);
|
|
$('#txt' + item.IdControl).attr("disabled", item.Disabled);
|
|
$('#txt' + item.IdControl).attr("readonly", item.Readonly);
|
|
$('#txt' + item.IdControl).attr("email", true);
|
|
$('#txt' + item.IdControl).removeAttr('style');
|
|
$('#txt' + item.IdControl).attr("style", 'text-transform: lowercase;');
|
|
|
|
if (item.Requerido == false) {
|
|
$('#txt' + item.IdControl).noRequired();
|
|
}
|
|
//#endregion
|
|
|
|
//#region CATALOGO
|
|
} else if (item.DescripcionTipoDato == "catalogo") {
|
|
|
|
$('#txt' + item.IdControl).attr("required", item.Requerido);
|
|
$('#txt' + item.IdControl).attr("disabled", item.Disabled);
|
|
$('#txt' + item.IdControl).attr("readonly", item.Readonly);
|
|
$('#btn' + item.IdControl).attr("disabled", item.Disabled);
|
|
|
|
$('#btn' + item.IdControl).attr("Direccion_API", $.trim(item.DireccionAPI));
|
|
|
|
|
|
if (item.Requerido == false) {
|
|
$('#txt' + item.IdControl).noRequired();
|
|
}
|
|
|
|
|
|
if ($.trim(item.DireccionAPI) != "") {
|
|
$('#btn' + item.IdControl).click(function () {
|
|
DireccionAPICatalogo = item.DireccionAPI
|
|
SelectedCatalog = item.IdControl;
|
|
CargarDataCatalogo(item.DireccionAPI, null, null);
|
|
});
|
|
}
|
|
|
|
$('#txt' + item.IdControl).change(function () {
|
|
FORM_VALIDATOR.element('#' + this.id);
|
|
});
|
|
|
|
//#endregion
|
|
|
|
//#region PHONE
|
|
} else if (item.DescripcionTipoDato == "phone") {
|
|
|
|
$('#txt' + item.IdControl).attr("required", item.Requerido);
|
|
$('#txt' + item.IdControl).attr("disabled", item.Disabled);
|
|
$('#txt' + item.IdControl).attr("readonly", item.Readonly);
|
|
|
|
if (item.Requerido == false) {
|
|
$('#txt' + item.IdControl).noRequired();
|
|
}
|
|
|
|
if (item.Hidden == true) {
|
|
$("#div" + item.IdControl).show()
|
|
$("#span" + item.IdControl).hide();
|
|
}
|
|
else if (item.Hidden == false)
|
|
$("#span" + item.IdControl).show();
|
|
|
|
$('#txt' + item.IdControl).blur(function () {
|
|
|
|
VerifyPhoneNumber('txt' + item.IdControl)
|
|
ENDREQUEST();
|
|
|
|
});
|
|
//#endregion
|
|
|
|
//#region TEXT
|
|
} else if (item.DescripcionTipoDato == "text") {
|
|
$('#txt' + item.IdControl).attr("required", item.Requerido);
|
|
$('#txt' + item.IdControl).attr("disabled", item.Disabled);
|
|
$('#txt' + item.IdControl).attr("readonly", item.Readonly);
|
|
|
|
if (item.Requerido == false) {
|
|
$('#txt' + item.IdControl).noRequired();
|
|
}
|
|
}
|
|
//#endregion
|
|
|
|
//#region Signature
|
|
else if (item.DescripcionTipoDato == "Signature") {
|
|
|
|
$('#psw' + item.IdControl).attr("required", item.Requerido);
|
|
$('#psw' + item.IdControl).attr("disabled", item.Disabled);
|
|
$('#psw' + item.IdControl).attr("readonly", item.Readonly);
|
|
|
|
|
|
GenerateSignatureControl(item.IdControl, FORM_VALIDATOR);
|
|
|
|
}
|
|
//#endregion
|
|
|
|
|
|
//#region CHECKBOX
|
|
else if (item.DescripcionTipoDato == "checkbox") {
|
|
$("#chk" + item.IdControl).attr("disabled", item.Disabled);
|
|
}
|
|
//#endregion
|
|
|
|
//#region PMAID
|
|
else if (item.DescripcionTipoDato == "pmaid") {
|
|
|
|
if (item.Pmaid == true) {
|
|
$("#radioCedula" + item.IdControl).attr('checked', true);
|
|
$("#divCedula" + item.IdControl).show();
|
|
$("#divPasaporte" + item.IdControl).hide();
|
|
$("#txtPasaporte" + item.IdControl).attr("required", false);
|
|
$("#txtCatalogo" + item.IdControl).attr("required", false);
|
|
$("#txtCatalogo" + item.IdControl).attr("readonly", true);
|
|
|
|
if (item.DireccionAPI.trim() != "") {
|
|
$('#btnCatalogo' + item.IdControl).click(function () {
|
|
DireccionAPICatalogo = item.DireccionAPI
|
|
SelectedCatalog = "Catalogo" + item.IdControl;
|
|
CargarDataCatalogo(item.DireccionAPI);
|
|
});
|
|
}
|
|
$("#divBuscar" + item.IdControl).show();
|
|
|
|
$("#radioCedula" + item.IdControl).change(function () {
|
|
$("#radioPasaporte" + item.IdControl).attr('checked', false);
|
|
$("#divCedula" + item.IdControl).show();
|
|
$("#divPasaporte" + item.IdControl).hide();
|
|
$("#txtPasaporte" + item.IdControl).attr("required", false);
|
|
$("#txtCatalogo" + item.IdControl).attr("required", false);
|
|
$("#txtCatalogo" + item.IdControl).attr("readonly", true);
|
|
});
|
|
|
|
|
|
$("#radioPasaporte" + item.IdControl).change(function () {
|
|
$("#radioCedula" + item.IdControl).attr('checked', false);
|
|
$("#divCedula" + item.IdControl).hide();
|
|
$("#divPasaporte" + item.IdControl).show();
|
|
$("#txtPasaporte" + item.IdControl).attr("required", true);
|
|
$("#txtCatalogo" + item.IdControl).attr("required", true);
|
|
$("#txtCatalogo" + item.IdControl).attr("readonly", true);
|
|
});
|
|
|
|
}
|
|
}
|
|
//#endregion
|
|
|
|
else if (item.DescripcionTipoDato == "radio") {
|
|
$("#radio" + item.IdControl).attr('checked', item.Checked);
|
|
}
|
|
|
|
//#region GRID
|
|
else if (item.DescripcionTipoDato == "Grid") {
|
|
BuildGrid(item);
|
|
|
|
}
|
|
//#endregion
|
|
}
|
|
catch(err){
|
|
alert("Error con el control " + item.IdControl + " " + err.message);
|
|
}
|
|
});
|
|
|
|
$("#" + form).valid();
|
|
Frmnombre = form;
|
|
}
|
|
else {
|
|
toastr.error("Ha ocurrido un error inesperado. Vuelva a intentarlo mas tarde", Message_Error);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
ENDREQUEST();
|
|
toastr.error("Ha ocurrido un error inesperado. Vuelva a intentarlo mas tarde", Message_Error);
|
|
}).then(function (value) {
|
|
|
|
if (typeof getDataModel !== 'undefined' && $.isFunction(getDataModel)) {
|
|
if (DataModel == true)
|
|
getDataModel();
|
|
else
|
|
ENDREQUEST();
|
|
}
|
|
else {
|
|
|
|
ENDREQUEST();
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
this.GetTypeNumeric = function (id, type) {
|
|
if (type == "currency") {
|
|
$("#txt" + id).autoNumeric('init', { aSign: '' });
|
|
|
|
if (item.Requerido == true)
|
|
$("#txt" + id).rules("add", {
|
|
currencyRequired: true
|
|
});
|
|
|
|
} else if (type == "percent") {
|
|
$("#txt" + id).autoNumeric('init', { aSign: ' %', pSign: 's' });
|
|
if (item.Requerido == true)
|
|
$("#txt" + id).rules("add", {
|
|
currencyRequired: true
|
|
});
|
|
|
|
} else if (type == "whole") {
|
|
$("#txt" + id).autoNumeric('init', { mDec: '0' });
|
|
} else if (type == "decimal") {
|
|
$("#txt" + id).autoNumeric('init');
|
|
if (item.Requerido == true)
|
|
$("#txt" + id).rules("add", {
|
|
currencyRequired: true
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.CargarDataCatalogo = function (Direccion, filtro) {
|
|
|
|
if ($.trim(Direccion) == "") {
|
|
toastr.warning("Debe definir la dirección del Web API para el catalogo.", Message_Warning);
|
|
return;
|
|
}
|
|
|
|
//var uri = Direccion.trim() + "?filtro=" + (filtro == null ? "" : filtro) + (id == null ? "" : "&id=" + id) + (id2 == null ? "" : "&id2=" + id2);
|
|
var uri = Direccion.trim() + "?filtro=" + (filtro == null ? "" : filtro);
|
|
var countId = 1;
|
|
for (var i = 2; i < arguments.length; i++) {
|
|
var id = arguments[i];
|
|
if (countId == 1)
|
|
uri += (id == null ? "" : "&id=" + id);
|
|
else
|
|
uri += (id == null ? "" : "&id" + countId + "=" + id);
|
|
countId++;
|
|
}
|
|
|
|
$.getJSON(server + uri).done(function (data) {
|
|
if (data != null) {
|
|
lista = data;
|
|
var Seleccionar = $("#ucBtnSeleccionar").html();
|
|
var columnDefinition = [
|
|
{ "data": null, className: "center", defaultContent: Seleccionar },
|
|
{ "data": "codigo" },
|
|
{ "data": "descripcion" }
|
|
];
|
|
|
|
$('#tableCatalogo').TableInit(0, false, true, false, false, columnDefinition, lista);
|
|
if ($.fn.DataTable.isDataTable('#tableCatalogo')) {
|
|
LoadMessage();
|
|
$('#tableCatalogo').DataTable().search('').draw();
|
|
$('#divmodalCatalogo').modal('show');
|
|
ENDREQUEST();
|
|
}
|
|
}
|
|
else {
|
|
toastr.error("Ha ocurrido un error inesperado. Vuelva a intentarlo mas tarde", Message_Error);
|
|
}
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
ENDREQUEST();
|
|
toastr.error("Ha ocurrido un error inesperado. Vuelva a intentarlo mas tarde", Message_Error);
|
|
}).then(function (value) {
|
|
ENDREQUEST();
|
|
});
|
|
}
|
|
|
|
$('#tableCatalogo').on('click', 'button', function () {
|
|
|
|
var data = $('#tableCatalogo').DataTable().row($(this).parents('tr')).data();
|
|
|
|
$("#hidden" + SelectedCatalog).val(data.codigo);
|
|
$("#txt" + SelectedCatalog).val(data.descripcion);
|
|
//$("#txt" + SelectedCatalog).trigger("change");//NO FUNCIONA
|
|
|
|
//FORM_VALIDATOR.element('#txt' + SelectedCatalog);//NO FUNCIONA
|
|
|
|
$('#divmodalCatalogo').modal('hide');
|
|
$("#" + Frmnombre).validateElement("#txt" + SelectedCatalog);
|
|
|
|
if (typeof DataCatalogo !== 'undefined' && $.isFunction(DataCatalogo)) {
|
|
DataCatalogo(SelectedCatalog, data);
|
|
}
|
|
|
|
//#region Implemnetacion para el proyecto de Prendario - Davivienda
|
|
if (typeof CargarDataCatalogoAdicional !== 'undefined' && $.isFunction(CargarDataCatalogoAdicional)) {
|
|
CargarDataCatalogoAdicional(SelectedCatalog);
|
|
}
|
|
//#endregion
|
|
|
|
});
|
|
|
|
$("#btnBuscar").click(function () {
|
|
CargarDataCatalogo(DireccionAPICatalogo, $("#txtDescripcion").val(), null);
|
|
});
|
|
|
|
this.GenerateSignatureControl = function (id, validator) {
|
|
|
|
|
|
$("#btn" + id).click(function () {
|
|
AutenticateUserSignature(id);
|
|
});
|
|
|
|
$("#btn" + id + "Remove").click(function () {
|
|
|
|
if (confirm("¿Desea remover la firma?")) {
|
|
|
|
$("#psw" + id).val("");
|
|
$("#lbl" + id + "User").text("");
|
|
$("#div" + id + "Container").show();
|
|
$("#div" + id + "Image").hide();
|
|
$("#psw" + id).required();
|
|
$("#" + Frmnombre).validateElement("#psw" + id);
|
|
validator.element('#psw' + id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
this.AutenticateUserSignature = function (id) {
|
|
|
|
var uri = 'api/GlobalAPI/UserAutenticate';
|
|
|
|
CredencialesUsuario = {
|
|
Usuario: $("#hiddenUserID").val(),
|
|
Contrasena: $("#psw" + id).val()
|
|
};
|
|
|
|
var DTO = JSON.stringify(CredencialesUsuario);
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: server + uri,
|
|
cache: false,
|
|
data: DTO,
|
|
contentType: 'application/json; charset=utf-8',
|
|
dataType: 'json',
|
|
success: function (data) {
|
|
if (data.ResultadoTransaccion.Resultado) {
|
|
|
|
|
|
if (data.Autenticado) {
|
|
|
|
$("#div" + id + "Container").hide();
|
|
|
|
$("#div" + id + "Image").show();
|
|
$("#img" + id).attr("src", data.RutaFirma);
|
|
$("#lbl" + id + "User").text($("#hiddenUserID").val());
|
|
$("#psw" + id).noRequired();
|
|
$("#" + Frmnombre).validateElement("#psw" + id);
|
|
|
|
}
|
|
else {
|
|
toastr.warning("La Contraseña es incorrecta", Message_Warning);
|
|
}
|
|
|
|
}
|
|
else
|
|
toastr.error("Ha ocurrido un error inesperado. Vuelva a intentarlo mas tarde", Message_Error);
|
|
}
|
|
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
|
|
toastr.error("Ha ocurrido un error inesperado. Vuelva a intentarlo mas tarde", Message_Error);
|
|
|
|
ENDREQUEST();
|
|
|
|
}).then(function (value) {
|
|
|
|
|
|
ENDREQUEST();
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
this.getUrlParameter = function (sParam) {
|
|
var sPageURL = window.location.search.substring(1);
|
|
var sURLVariables = sPageURL.split('&');
|
|
for (var i = 0; i < sURLVariables.length; i++) {
|
|
var sParameterName = sURLVariables[i].split('=');
|
|
if (sParameterName[0] == sParam) {
|
|
return sParameterName[1];
|
|
}
|
|
}
|
|
}
|
|
|
|
//#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) {
|
|
|
|
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();
|
|
}
|