var AjaxLib = (function () { return { Generic: function (srvcUrl, pageMethod, isSync, parameters, ajaxCallback) { if (isSync == true) { AjaxLib.Sync(srvcUrl, pageMethod, parameters, ajaxCallback); } else { AjaxLib.Async(srvcUrl, pageMethod, parameters, ajaxCallback); } }, Async: function (srvcUrl, pageMethod, parameters, ajaxCallback, headers) { var methodUrl = srvcUrl; if (typeof pageMethod !== undefined && pageMethod != "" && pageMethod != null) methodUrl = methodUrl + "/" + pageMethod; if (typeof headers === undefined || headers == "" || headers == null) headers = {}; $.ajax({ async: true, type: "POST", url: methodUrl, data: parameters, headers: headers, contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { ajaxCallback(data.d) }, error: function (response) { if (response.responseText != "undefined" && response.responseText != null && response.responseText != "") { //Tly.Helper.PopMsg(response.responseText); //Tly.Helper.LogError(response.responseText); } }, failure: function (response) { if (response.responseText != "undefined" && response.responseText != null && response.responseText != "") { //Tly.Helper.PopMsg(response.responseText); //Tly.Helper.LogError(response.responseText); } } }); }, Sync: function (srvcUrl, pageMethod, parameters, ajaxCallback) { var methodUrl = srvcUrl; if (typeof pageMethod !== undefined && pageMethod != "" && pageMethod != null) methodUrl = methodUrl + "/" + pageMethod; $.ajax({ async: false, type: "POST", url: methodUrl, data: parameters, contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { ajaxCallback(data.d) }, error: function (response) { if (response.responseText != "undefined" && response.responseText != null && response.responseText != "") { //Tly.Helper.PopMsg(response.responseText); //Tly.Helper.LogError(response.responseText); } }, failure: function (response) { if (response.responseText != "undefined" && response.responseText != null && response.responseText != "") { //Tly.Helper.PopMsg(response.responseText); //Tly.Helper.LogError(response.responseText); } } }); }, PrintMultipleWayBill: function (printRequst) { var request = new XMLHttpRequest; // //console.log("//"); //console.log("..."); request.open('POST', '/Handlers/FreightWeb/MultiplePrint.ashx'); request.responseType = 'arraybuffer'; request.setRequestHeader("content", JSON.stringify(printRequst)); request.send(); request.onload = function (e) { if (this.status == 200) { // Create a new Blob object using the response data of the onload object var blob = new Blob([this.response], { type: 'application/pdf' }); //Create a link element, hide it, direct it towards the blob, and then 'click' it programatically let a = document.createElement("a"); a.style = "display: none"; document.body.appendChild(a); //Create a DOMString representing the blob and point the link element towards it let url = window.URL.createObjectURL(blob); a.href = url; a.download = 'P&O Ferries_Print Waybills.pdf'; //programatically click the link to trigger the download $('body').removeClass("noScrollTwo"); a.click(); //release the reference to the file by revoking the Object URL window.URL.revokeObjectURL(url); } else { //deal with your error state here $('body').removeClass("noScrollTwo"); } }; }, PrintCreditWaybill: function (printRequestHeaders) { var request = new XMLHttpRequest; // //console.log("//"); request.open('POST', '/Handlers/FreightWeb/PrintPDF.ashx'); request.responseType = 'arraybuffer'; request.setRequestHeader('waybillNo', printRequestHeaders.waybillNo); request.setRequestHeader('fromPortName', printRequestHeaders.fromPortName); request.setRequestHeader('toPortName', printRequestHeaders.toPortName); request.setRequestHeader('description', printRequestHeaders.description); request.setRequestHeader('drivers', printRequestHeaders.drivers); request.setRequestHeader('unitType', printRequestHeaders.unitType); request.setRequestHeader('unitID', printRequestHeaders.unitID); request.setRequestHeader('jobReference', printRequestHeaders.jobReference); request.setRequestHeader('unitLength', printRequestHeaders.unitLength); request.setRequestHeader('bookedBy', printRequestHeaders.bookedBy); request.setRequestHeader('statusHistory', printRequestHeaders.statusHistory); request.setRequestHeader('statusTimeStamp', printRequestHeaders.statusTimeStamp); request.setRequestHeader('vesselName', printRequestHeaders.vesselName); request.setRequestHeader('temperatue', printRequestHeaders.temperatue); request.setRequestHeader('unitWeight', printRequestHeaders.unitWeight); request.setRequestHeader('travelDate', printRequestHeaders.travelDate); request.setRequestHeader('pageName', printRequestHeaders.pageName); if (printRequestHeaders.unitWidth) { request.setRequestHeader('unitWidth', printRequestHeaders.unitWidth); } else { request.setRequestHeader('unitWidth', ""); } request.send(); request.onload = function (e) { if (this.status == 200) { // Create a new Blob object using the response data of the onload object var blob = new Blob([this.response], { type: 'application/pdf' }); //Create a link element, hide it, direct it towards the blob, and then 'click' it programatically let a = document.createElement("a"); a.style = "display: none"; document.body.appendChild(a); //Create a DOMString representing the blob and point the link element towards it let url = window.URL.createObjectURL(blob); a.href = url; a.download = 'P&O Ferries_ Waybill_' + printRequestHeaders.waybillNo + '.pdf'; //programatically click the link to trigger the download $('body').removeClass("noScrollTwo"); a.click(); //release the reference to the file by revoking the Object URL window.URL.revokeObjectURL(url); } else { //deal with your error state here $('body').removeClass("noScrollTwo"); } }; }, ApiAsync: function (srvcUrl, pageMethod, parameters, ajaxCallback, headers) { var methodUrl = srvcUrl; if (typeof pageMethod !== undefined && pageMethod != "" && pageMethod != null) methodUrl = methodUrl + "/" + pageMethod; if (typeof headers === undefined || headers == "" || headers == null) headers = {}; $.ajax({ async: true, type: "POST", url: methodUrl, data: parameters, headers: headers, contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { ajaxCallback(data) }, error: function (response) { if (response.responseText != "undefined" && response.responseText != null && response.responseText != "") { //Tly.Helper.PopMsg(response.responseText); //Tly.Helper.LogError(response.responseText); } }, failure: function (response) { if (response.responseText != "undefined" && response.responseText != null && response.responseText != "") { //Tly.Helper.PopMsg(response.responseText); //Tly.Helper.LogError(response.responseText); } } }); }, ApiSync: function (srvcUrl, pageMethod, parameters, ajaxCallback, headers) { var methodUrl = srvcUrl; if (typeof pageMethod !== undefined && pageMethod != "" && pageMethod != null) methodUrl = methodUrl + "/" + pageMethod; if (typeof headers === undefined || headers == "" || headers == null) headers = {}; $.ajax({ async: false, type: "POST", url: methodUrl, data: parameters, headers: headers, contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { ajaxCallback(data) }, error: function (response) { if (response.responseText != "undefined" && response.responseText != null && response.responseText != "") { //Tly.Helper.PopMsg(response.responseText); //Tly.Helper.LogError(response.responseText); } }, failure: function (response) { if (response.responseText != "undefined" && response.responseText != null && response.responseText != "") { //Tly.Helper.PopMsg(response.responseText); //Tly.Helper.LogError(response.responseText); } } }); } }; // Public members 'return' ends })();