1014 lines
28 KiB
JavaScript
1014 lines
28 KiB
JavaScript
//#region Variables Globales
|
|
var server = "http://" + location.host + "/ULA.Cathay.ModuloMantenimiento/";
|
|
var StarterTemplateVisible = true;
|
|
var ControlsSettings = {};
|
|
var SelectedCatalog = '';
|
|
var DireccionAPICatalogo = '';
|
|
var DataModel = false;
|
|
var Frmnombre = '';
|
|
var DateFormat = '';
|
|
var MinDate = '';
|
|
var MaxDate = '';
|
|
var RangoFecha = false;
|
|
var Finde = false;
|
|
var params = new Array();
|
|
|
|
var JsonCotizacionResponse = {};
|
|
|
|
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("currencyRequired", function (value, element) {
|
|
|
|
return ($("#" + element.id).autoNumeric('get') > 0);
|
|
|
|
}, "El MONTO DEBE SER MAYOR A CERO");
|
|
|
|
//#endregion
|
|
|
|
//#region Genericos
|
|
|
|
$("#btnDesarrollo").click(function () {
|
|
|
|
LoadMessage("REDIRECCIONANDO A LOCALHOST...");
|
|
|
|
var urlLocalhost = location.href;
|
|
|
|
urlLocalhost = urlLocalhost.replace("pasapr053", "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"
|
|
}
|
|
|
|
//ULT = new Ultimus.UI();
|
|
//ULT.DataTable_Spanish("#tableBitacora", 0, "asc", false, false, false);
|
|
//tableBitacora = $('#tableBitacora').DataTable();
|
|
|
|
$("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.ToMoney = function (value) {
|
|
|
|
return value.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
|
|
|
|
};
|
|
|
|
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=\"../../../../ULA.Cathay.PrestamoAutos/Images/ajax-loader.gif\" alt=\"loading\" height=\"50\" width=\"50\"></td>";
|
|
//stringHtml += "<td><i class=\"fa fa-spinner fa-spin fa-4x\"></i></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').attr('disabled', true);
|
|
|
|
$('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;
|
|
|
|
|
|
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"));
|
|
|
|
}
|
|
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"));
|
|
}
|
|
}
|
|
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"));
|
|
|
|
}
|
|
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').attr('disabled', true);
|
|
$('input,select').removeAttr('required', true);
|
|
};
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
$.fn.noRequired = function () {
|
|
|
|
this.attr('required', false);
|
|
this.removeClass('inputWarning');
|
|
|
|
};
|
|
|
|
$.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");
|
|
}
|
|
|
|
//if ($element.data("role") != undefined) {
|
|
// $("#" + $element.data("role")).tooltip("destroy").data("title", error.message).addClass("error").tooltip({ placement: 'right', trigger: 'hover', container: 'body' });
|
|
//} else {
|
|
$element.tooltip("destroy").data("title", error.message).addClass("error").tooltip({ placement: 'right', trigger: 'hover', container: 'body' });
|
|
//}
|
|
});
|
|
}
|
|
});
|
|
|
|
};
|
|
|
|
$.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);
|
|
|
|
if (RangoFecha == false && Finde == false)
|
|
this.datepicker({ yearRange: '1945:' + (new Date).getFullYear(), defaultDate: _dateObject, dateFormat: DateFormat }).datepicker('widget').wrap('<div class="ll-skin-cangas"/>');
|
|
|
|
if (Finde == true)
|
|
this.datepicker({
|
|
dateFormat: DateFormat,
|
|
beforeShowDay: noFinesDeSemanaNiFestivos
|
|
}).datepicker('widget').wrap('<div class="ll-skin-cangas"/>');
|
|
|
|
if (RangoFecha == true)
|
|
this.datepicker({
|
|
dateFormat: DateFormat,
|
|
minDate: MinDate,
|
|
maxDate: MaxDate
|
|
}).datepicker('widget').wrap('<div class="ll-skin-cangas"/>');
|
|
};
|
|
|
|
|
|
|
|
function noFinesDeSemanaNiFestivos(date) {
|
|
|
|
var noWeekend = $.datepicker.noWeekends(date);
|
|
|
|
if (noWeekend[0]) {
|
|
return nationalDays(date);
|
|
} else {
|
|
return noWeekend;
|
|
}
|
|
}
|
|
|
|
natDays = [
|
|
[11, 26]
|
|
];
|
|
|
|
function nationalDays(date) {
|
|
for (i = 0; i < natDays.length; i++) {
|
|
if (date.getMonth() == natDays[i][0] - 1
|
|
&& date.getDate() == natDays[i][1]) {
|
|
return [false, natDays[i][2] + '_day'];
|
|
}
|
|
}
|
|
return [true, ''];
|
|
}
|
|
//#endregion
|
|
|
|
//#endregion
|
|
|
|
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();
|
|
}
|
|
|
|
|
|
$.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"]],
|
|
|
|
});
|
|
};
|