{"version":3,"sources":["../../Contents/js/FE/ajaxHelper.js"],"names":["$","document","ready","toastr","options","closeButton","progressBar","showMethod","timeOut","window","NotiError","title","message","error","NotiSuccess","success","NotiWarning","warning","handleErrorStatus","errorThrown","status","location","assign","console","log","xhrPool","abortAll","each","idx","jqXHR","abort","length","ajaxSetup","beforeSend","push","complete","index","indexOf","splice","textStatus","responseJSON","undefined","Code","ErrorMessage","headers","Authorization","languages","PerformAjax","type","url","data","processData","contentType","dataType","async","moreOptions","ajax","JSON","stringify","PerformAjaxGet","_","partial","PerformAjaxGetSync","PerformAjaxPost","PerformAjaxPostSync","PerformAjaxPut","PerformAjaxDelete"],"mappings":";;;;AAAAA,EAAEC,QAAF,EAAYC,KAAZ,CAAkB,YAAY;AAC1B;AACAC,WAAOC,OAAP,GAAiB;AACbC,qBAAa,IADA;AAEbC,qBAAa,IAFA;AAGbC,oBAAY,WAHC;AAIbC,iBAAS;AAJI,KAAjB;;AAOAC,WAAOC,SAAP,GAAmB,UAACC,KAAD,EAAQC,OAAR;AAAA,eAAoBT,OAAOU,KAAP,CAAaD,OAAb,EAAsBD,KAAtB,CAApB;AAAA,KAAnB;AACAF,WAAOK,WAAP,GAAqB,UAACH,KAAD,EAAQC,OAAR;AAAA,eAAoBT,OAAOY,OAAP,CAAeH,OAAf,EAAwBD,KAAxB,CAApB;AAAA,KAArB;AACAF,WAAOO,WAAP,GAAqB,UAACL,KAAD,EAAQC,OAAR;AAAA,eAAoBT,OAAOc,OAAP,CAAeL,OAAf,EAAwBD,KAAxB,CAApB;AAAA,KAArB;AAEH,CAbD;;AAeC,aAAY;AACT,QAAIO,oBAAoB,SAApBA,iBAAoB,CAAUC,WAAV,EAAuBC,MAAvB,EAA+B;AACnD,gBAAQA,MAAR;AACI,iBAAK,GAAL;AACIC,yBAASC,MAAT,CAAgB,gBAAhB;AACA;;AAEJ,iBAAK,GAAL;AACID,yBAASC,MAAT,CAAgB,qBAAhB;AACA;;AAEJ,iBAAK,GAAL;AACID,yB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AAwBL,EAAEC,OAAF,CAAUd,WAAV,EAAuB,KAAvB,CAAxB;AACAtC,WAAOyD,iBAAP,GAA2BN,EAAEC,OAAF,CAAUd,WAAV,EAAuB,QAAvB,EAAiCa,CAAjC,EAAoCA,CAApC,EAAuC,KAAvC,CAA3B;AACAnD,WAAOS,iBAAP,GAA2BA,iBAA3B;AACH,CA3FA,GAAD","file":"ajaxHelper.js","sourcesContent":["$(document).ready(function () {\r\n // Config toastr\r\n toastr.options = {\r\n closeButton: true,\r\n progressBar: true,\r\n showMethod: 'slideDown',\r\n timeOut: 4000\r\n };\r\n\r\n window.NotiError = (title, message) => toastr.error(message, title);\r\n window.NotiSuccess = (title, message) => toastr.success(message, title);\r\n window.NotiWarning = (title, message) => toastr.warning(message, title);\r\n\r\n});\r\n\r\n(function () {\r\n var handleErrorStatus = function (errorThrown, status) {\r\n switch (status) {\r\n case 401:\r\n location.assign('/Account/Login');\r\n break;\r\n\r\n case 403:\r\n location.assign('/Error/Unauthorized');\r\n break;\r\n\r\n case 404:\r\n location.assign('/Error/404');\r\n break;\r\n\r\n case 0:\r\n console.log('errorThrown : ' + errorThrown);\r\n break;\r\n\r\n default:\r\n NotiError(errorThrown, status);\r\n break;\r\n }\r\n };\r\n\r\n //User xhrPool to handle abort ajax calls\r\n $.xhrPool = []; // array of uncompleted requests\r\n\r\n $.xhrPool.abortAll = function () { // our abort function\r\n $(this).each((idx, jqXHR) => jqXHR.abort());\r\n $.xhrPool.length = 0;\r\n };\r\n\r\n $.ajaxSetup({\r\n beforeSend: jqXHR => $.xhrPool.push(jqXHR), // before jQuery send the request we will push it to our array\r\n complete(jqXHR) { // when some of the requests completed it will splice from the array\r\n var index = $.xhrPool.indexOf(jqXHR);\r\n \r\n if (index > -1) {\r\n $.xhrPool.splice(index, 1);\r\n }\r\n },\r\n error({ responseJSON, status }, textStatus, errorThrown) {\r\n if (textStatus === 'parsererror') {\r\n return undefined;\r\n }\r\n \r\n if (!responseJSON) {\r\n handleErrorStatus(errorThrown, status);\r\n return undefined;\r\n }\r\n\r\n var { Code, ErrorMessage } = responseJSON;\r\n\r\n handleErrorStatus(ErrorMessage, Code);\r\n },\r\n headers: {\r\n Authorization: `Bearer VSIP`,\r\n 'languages': '_' + document.languages\r\n }\r\n });\r\n\r\n // Assign new token from cookie in case old token in be expired\r\n //$.ajaxPrefilter(options => {\r\n // var tokenInHeaders = options.headers.Authorization.substring(7),\r\n // tokenInCookie = $.cookie('accessToken');\r\n\r\n // if (tokenInHeaders !== tokenInCookie) {\r\n // Object.assign(options.headers, { Authorization: `Bearer ${tokenInCookie}` });\r\n // }\r\n //});\r\n\r\n var PerformAjax = function (type, url, data = [], processData = true, contentType = 'application/json; charset=utf-8', dataType = 'json', async = true, moreOptions = {}) {\r\n return $.ajax({\r\n async,\r\n contentType,\r\n data: processData ? JSON.stringify(data) : data,\r\n dataType,\r\n type,\r\n url,\r\n ...moreOptions\r\n });\r\n };\r\n\r\n window.PerformAjaxGet = _.partial(PerformAjax, 'GET', _, _, false);\r\n window.PerformAjaxGetSync = _.partial(PerformAjax, 'GET', _, _, false, _, _, false)\r\n window.PerformAjaxPost = _.partial(PerformAjax, 'POST');\r\n window.PerformAjaxPostSync = _.partial(PerformAjax, 'POST', _, _, true, _, _, false);\r\n window.PerformAjaxPut = _.partial(PerformAjax, 'PUT');\r\n window.PerformAjaxDelete = _.partial(PerformAjax, 'DELETE', _, _, false);\r\n window.handleErrorStatus = handleErrorStatus;\r\n}());"]}