diff --git a/AYA.SlnSynor/AYA.SlnSynor/Sinort-Scripts/Global.js b/AYA.SlnSynor/AYA.SlnSynor/Sinort-Scripts/Global.js index 8d5820fe6..c9fad9c99 100644 --- a/AYA.SlnSynor/AYA.SlnSynor/Sinort-Scripts/Global.js +++ b/AYA.SlnSynor/AYA.SlnSynor/Sinort-Scripts/Global.js @@ -1,6 +1,8 @@ var CatalogosWCF = $("#hiddenSinortCatalogosWCF").val(); var SinortWCF = $("#hiddenSinortWCF").val(); var server = "http://" + location.host + "/AYA.SlnSynor.WCF/"; +var TipoRespuesta = { EXITOSO: "1", FALLIDO: "0" }; +var LoadMessageThreadCounter = 0; function Mensajes(mensaje) { if (mensaje.CodigoRespuesta === "1") { @@ -25,7 +27,7 @@ function Mensajes(mensaje) { toastr["success"]("Operación procesada exitosamente", "SINORT"); } - if(mensaje.CodigoRespuesta === "0") { + if (mensaje.CodigoRespuesta === "0") { toastr.options = { "closeButton": true, "debug": false, @@ -46,61 +48,30 @@ function Mensajes(mensaje) { toastr["warning"]("Error al procesar la operación", "SINORT"); } - toastr.options = { - "closeButton": true, - "debug": false, - "newestOnTop": false, - "progressBar": false, - "positionClass": "toast-bottom-full-width", - "preventDuplicates": true, - "onclick": null, - "showDuration": "300", - "hideDuration": "1000", - "timeOut": "5000", - "extendedTimeOut": "1000", - "showEasing": "swing", - "hideEasing": "linear", - "showMethod": "fadeIn", - "hideMethod": "fadeOut" - }; + toastr.options = { + "closeButton": true, + "debug": false, + "newestOnTop": false, + "progressBar": false, + "positionClass": "toast-bottom-full-width", + "preventDuplicates": true, + "onclick": null, + "showDuration": "300", + "hideDuration": "1000", + "timeOut": "5000", + "extendedTimeOut": "1000", + "showEasing": "swing", + "hideEasing": "linear", + "showMethod": "fadeIn", + "hideMethod": "fadeOut" + }; - toastr["error"](mensaje.DescripcionRespuesta, "SINORT"); + toastr["error"](mensaje.DescripcionRespuesta, "SINORT"); } -function pagerFilter(data) { - if (typeof data.length === 'number' && typeof data.splice === 'function') { // is array - data = { - total: data.length, - rows: data - }; - } - var dg = $(this); - var opts = dg.datagrid('options'); - var pager = dg.datagrid('getPager'); - pager.pagination({ - onSelectPage: function (pageNum, pageSize) { - opts.pageNumber = pageNum; - opts.pageSize = pageSize; - pager.pagination('refresh', { - pageNumber: pageNum, - pageSize: pageSize - }); - dg.datagrid('loadData', data); - } - }); - if (!data.originalRows) { - data.originalRows = data.rows; - } - var start = (opts.pageNumber - 1) * parseInt(opts.pageSize); - var end = start + parseInt(opts.pageSize); - data.rows = data.originalRows.slice(start, end); - return data; -} - -function STARTREQUEST (Message) { - - if (Message == null) { +function STARTREQUEST(Message) { + if (IsNullOrEmpty(Message)) { Message = "Cargando Datos, Espere por favor!"; } @@ -225,7 +196,6 @@ $.fn.TableInit = function (columnOrder, order, bPaginate, bFilter, bInfo, column }); }; - $.fn.EnableValidationToolTip = function () { this.validate({ @@ -280,4 +250,67 @@ $.fn.EnableValidationToolTip = function () { } }); +}; + +IsNullOrEmpty = function (value) { + + if (value == null || $.trim(value) == "") return true; + + return false; +} + +this.AjaxPostData = function (n, t, i, r, u, f, e) { + var o = null; + return LoadMessage(), + LoadMessageThreadCounter++, + $.ajax({ + url: n, + async: i, + type: 'POST', + data: JSON.stringify(t), + cache: !1, + contentType: 'application/json; charset=utf-8', + dataType: 'json', + success: function (n) { + o = AjaxResponse(n, r, u, f, e) + } + }).fail(function (t, i, r) { + (LoadMessageThreadCounter--, typeof AjaxFailEvent == 'undefined' || !$.isFunction(AjaxFailEvent) || AjaxFailEvent(t, i, r)) && (ENDREQUEST(), f != 'ERROR' && toastr.error('Error al ejecutar la petición al WebAPI\n' + r + '\n Url:' + n, Message_Error)) + }).then(function () { + u == null && ENDREQUEST() + }), + o +}; + +this.AjaxResponse = function (n, t, i, r, u) { + LoadMessageThreadCounter--; + u = IsNullOrEmpty(u) ? 'Acción completada con exito.' : u; + t == !0 && (n != null && n.CodigoRespuesta == 'EXITOSO' ? toastr.success(u, Message_Success) : n != null && n.CodigoRespuesta == 'ADVERTENCIA' ? toastr.warning(n.DescripcionRespuesta, Message_Warning) : toastr.error('Error verifique los Logs del WebAPI', Message_Error)); + var f = r == 'ERROR' || n != null && IsNullOrEmpty(n.CodigoRespuesta) ? !0 : n != null && $.inArray(n.CodigoRespuesta, [ + 'EXITOSO', + 'ADVERTENCIA' + ]) != -1 && r == 'ADVERTENCIA' ? !0 : n != null && n.CodigoRespuesta == 'EXITOSO' ? !0 : !1; + return i != null && f ? i(n) : ENDREQUEST(), + n +}; + +this.AjaxGetData = function (n, t, i, r, u, f) { + var e = null; + return LoadMessage(), + LoadMessageThreadCounter++, + $.ajax({ + url: n, + dataType: 'json', + data: null, + cache: !1, + async: t, + success: function (n) { + e = AjaxResponse(n, i, r, u, f) + } + }).fail(function (t, i, r) { + (LoadMessageThreadCounter--, typeof AjaxFailEvent == 'undefined' || !$.isFunction(AjaxFailEvent) || AjaxFailEvent(t, i, r)) && (ENDREQUEST(), u != 'ERROR' && toastr.error('Error al ejecutar la petición al WebAPI\n' + r + '\n Url:' + n, Message_Error)) + }).then(function () { + r == null && ENDREQUEST() + }), + e }; \ No newline at end of file