Rev 24380 | Rev 24410 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
function badRequestAlert(response){console.log(response.responseText);var errorObject = JSON.parse(response.responseText);errorObject = errorObject.response;bootbox.alert('Bad Request\n'+'rejectedType : '+errorObject.rejectedType+'\n'+'rejectedValue : '+errorObject.rejectedValue+'\n'+'message : '+errorObject.message);}function internalServerErrorAlert(response){console.log(response.responseText);var errorObject = JSON.parse(response.responseText);errorObject = errorObject.response;bootbox.alert('Internal Server Error\n'+'rejectedType : '+errorObject.rejectedType+'\n'+'rejectedValue : '+errorObject.rejectedValue+'\n'+'message : '+errorObject.message);}$( document ).ajaxError(function(event, jqxhr, settings, thrownError) {if(typeof loaderDialogObj!="undefined")loaderDialogObj.modal('hide');if(jqxhr.status == 400){// $('#error-prompt-model').modal();badRequestAlert(jqxhr);}else{internalServerErrorAlert(jqxhr);}});$(document).ajaxComplete(function(){if(typeof loaderDialogObj!="undefined")loaderDialogObj.modal('hide');});$( document ).ajaxStart(function() {if(typeof loaderDialogObj!="undefined")loaderDialogObj.modal('show');if(typeof isInvestmentOk != "undefined" && !isInvestmentOk && $('#order-details').length == 0) {var investmentDialog = bootbox.dialog({title: '<h3 class="text-danger">ATTENTION!! ORDERING THROUGH APP MAY BE BLOCKED DUE TO LOW INVESTMENTS!</h3>',message : "<h3>Dear Partner, your investments are low by " + shortPercentage + "%</h3>"+ "<dl>"+ "<dt>Investment Should be</dt><dd>- " + minimumInvestmentAmount +"</dd>"+ "<dt>Total Invested Amount</dt><dd>-" + totalInvestedAmount +"</dd>"+ '<dt>Investment Amount Short By</dt><dd class="text-danger lead">- ' + shortAmount+'</dd></dl>'+ '<pre class="text-danger" style="font-size:18px;"><strong>To unblock your Billing, please \nadd Rs.'+ minAmountToBeAdded + ' to wallet immediately.</strong></pre>',buttons:{cancel: {label: "OK",className: 'btn-primary'}},});investmentDialog.on('shown.bs.modal', function(){var dialogEl = investmentDialog.find('.modal-content')[0];var dialogRect = dialogEl.getBoundingClientRect();var height = window.innerHeight - dialogRect.height;var width = window.innerWidth - dialogRect.width;var left = Math.floor(Math.random()*width) - dialogRect.leftvar top = Math.floor(Math.random()*height) - dialogRect.top$(dialogEl).css("left",left).css("top",top);});}});function doAjaxRequestWithParamsHandler(urlString, httpType, params, callback_function){$.ajax({url: urlString,async: true,cache: false,data: params,// dataType:'json',type: httpType,success: function(response) {callback_function(response);$('.currency').each(function(index,ele){if(!isNaN(parseInt($(ele).html()))) {$(ele).html(numberToComma($(ele).html()));}});}});}function doGetAjaxRequestWithParamsHandler(urlString, params, callback_function){doAjaxRequestWithParamsHandler(urlString, "GET", params, callback_function);}function doPostAjaxRequestWithParamsHandler(urlString, params, callback_function){doAjaxRequestWithParamsHandler(urlString, "POST", params, callback_function);}function doAjaxRequestWithJsonHandler(urlString, httpType, json, callback_function){$.ajax({url: urlString,async: true,cache: false,processData: false,data: json,contentType:'application/json',type: httpType,success: function(response) {// console.log("response"+JSON.stringify(data));callback_function(response);$('.currency').each(function(index,ele){if(!isNaN(parseInt($(ele).html()))) {$(ele).html(numberToComma($(ele).html()));}});}});}function doPostAjaxRequestWithJsonHandler(urlString, json, callback_function){doAjaxRequestWithJsonHandler(urlString, "POST", json, callback_function);}function doPutAjaxRequestWithJsonHandler(urlString, json, callback_function){doAjaxRequestWithJsonHandler(urlString, "PUT", json, callback_function);}function doAjaxRequestHandler(urlString, httpType, callback_function){$.ajax({url: urlString,async: true,cache: false,type: httpType,success: function(response) {callback_function(response);$('.currency').each(function(index,ele){if(!isNaN(parseInt($(ele).html()))) {$(ele).html(numberToComma($(ele).html()));}});}});}function doGetAjaxRequestHandler(urlString, callback_function){doAjaxRequestHandler(urlString, "GET", callback_function);}function doPutAjaxRequestHandler(urlString, callback_function){doAjaxRequestHandler(urlString, "PUT", callback_function);}function doPostAjaxRequestHandler(urlString, callback_function){doAjaxRequestHandler(urlString, "POST", callback_function);}function doDeleteAjaxRequestHandler(urlString, callback_function){doAjaxRequestHandler(urlString, "DELETE", callback_function);}function doAjaxUploadRequest(urlString, httpType, file){var response;doAjaxUploadRequestHandler(urlString, httpType, file, function(ajaxResponse){response = ajaxResponse;});return response;}function doAjaxUploadRequestHandler(urlString, httpType, file, callback_function){var formData = new FormData();formData.append("file", file);$.ajax({url: urlString,type: httpType,data: formData,dataType: 'json',async: true,cache: false,contentType: false,enctype: 'multipart/form-data',processData: false,success: function(response) {// console.log("response"+JSON.stringify(data));callback_function(response);}});}function doAjaxUploadRequestJsonHandler(urlString, httpType, file,json,callback_function){var formData = new FormData();formData.append("file", file);formData.append('json',new Blob([json]));$.ajax({url: urlString,type: httpType,data: formData,enctype: 'multipart/form-data',contentType: false,processData: false,success: function(response) {// console.log("response"+JSON.stringify(data));callback_function(response);}});}function uploadDocument(file){var url = webApiScheme + '://'+ webApiHost + ':' + webApiPort + webApiRoot + '/document-upload';doAjaxUploadRequestHandler(url, 'POST', file, function(response){var documentId = response.response.document_id;console.log("documentId : "+documentId);return documentId;});}function doAjaxGetDownload(urlString, fileName){console.log("fileName : "+fileName);doAjaxDownload(urlString, "GET", null, fileName);}function doAjaxPostDownload(urlString, data, fileName){doAjaxDownload(urlString, "POST", data, fileName);}function doAjaxDownload(urlString, httpType, data, fileName){xhttp = new XMLHttpRequest();xhttp.onreadystatechange = function() {var a;if(xhttp.readyState === 2){if(xhttp.status == 200){xhttp.responseType = "blob";} else {xhttp.responseType = "text";}}else if (xhttp.readyState === 4 && xhttp.status === 200) {// Trick for making downloadable linka = document.createElement('a');a.href = window.URL.createObjectURL(xhttp.response);// Give filename you wish to downloada.download = fileName;a.style.display = 'none';document.body.appendChild(a);a.click();}else if(xhttp.readyState == 4 && xhttp.status === 400){badRequestAlert(xhttp);}else if(xhttp.readyState == 4 && xhttp.status === 500){internalServerErrorAlert(xhttp);}};// Post data to URL which handles post requestxhttp.open(httpType, urlString);if(httpType == "POST"){xhttp.setRequestHeader("Content-Type", "application/json");}// You should set responseType as blob for binary responses// xhttp.responseType = 'blob';xhttp.send(data);}function loadPaginatedNextItems(url, params, paginatedIdentifier, tableIdentifier, detailsContainerIdentifier){var start = $("#"+paginatedIdentifier+" .start").text();var end = $("#"+paginatedIdentifier+" .end").text();url = context + url + "?offset=" + end;if(params != null){for (var key in params) {if (params.hasOwnProperty(key)) {// console.log(key + " -> " + p[key]);url = url +"&" + key + "=" + params[key];}}}doGetAjaxRequestHandler(url, function(response){var size = $("#"+paginatedIdentifier+" .size").text();if((parseInt(end) + 10) > parseInt(size)){console.log("(end + 10) > size == true");$("#"+paginatedIdentifier+" .end").text(size);}else{console.log("(end + 10) > size == false");$("#"+paginatedIdentifier+" .end").text(+end + +10);}$("#"+paginatedIdentifier+" .start").text(+start + +10);var last = $("#"+paginatedIdentifier+" .end").text();var temp = $("#"+paginatedIdentifier+" .size").text();if (parseInt(last) >= parseInt(temp)){$("#"+paginatedIdentifier+" .next").prop('disabled', true);// $( "#good-inventory-paginated .end" ).text(temp);}$('#'+tableIdentifier).html(response);if(detailsContainerIdentifier != null){$('#'+detailsContainerIdentifier).html('');}$("#"+paginatedIdentifier+" .previous").prop('disabled', false);});}function loadPaginatedPreviousItems(url, params, paginatedIdentifier, tableIdentifier, detailsContainerIdentifier){var start = $("#"+paginatedIdentifier+" .start").text();var end = $("#"+paginatedIdentifier+" .end").text();var size = $("#"+paginatedIdentifier+" .size").text();if(parseInt(end) == parseInt(size) && parseInt(end)%10 !=0){var mod = parseInt(end) % 10;end = parseInt(end) + (10 - mod);}var pre = end - 20;url = context + url + "?offset=" + pre;if(params != null){for (var key in params) {if (params.hasOwnProperty(key)) {url = url +"&" + key + "=" + params[key];}}}doGetAjaxRequestHandler(url, function(response){$("#"+paginatedIdentifier+" .end").text(+end - +10);$("#"+paginatedIdentifier+" .start").text(+start - +10);$('#'+tableIdentifier).html(response);if(detailsContainerIdentifier != null){$('#'+detailsContainerIdentifier).html('');}$("#"+paginatedIdentifier+" .next").prop('disabled', false);if (parseInt(pre)==0){$("#"+paginatedIdentifier+" .previous").prop('disabled', true);}});}function numberToComma(x) {x=parseInt(x);x=x.toString();var lastThree = x.substring(x.length-3);var otherNumbers = x.substring(0,x.length-3);if(otherNumbers != '')lastThree = ',' + lastThree;return otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree;}function dateRangeCallback(start, end) {startMoment = start;endMoment = end;startDate = start.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);endDate = end.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);}function getSingleDatePicker(){var singleDatePicker ={"todayHighlight": true,"startDate": startMoment || moment(),"autoclose": true,"autoUpdateInput": true,"singleDatePicker": true,"locale": {'format': 'DD/MM/YYYY'}};return singleDatePicker;}function getRangedDatePicker(showRanges){if(typeof showRanges=="undefined") {showRanges = false;}var rangedDatePicker ={"todayHighlight": true,"opens": "right","startDate": startMoment || moment(),"endDate": endMoment || moment(),"autoclose": true,"alwaysShowCalendars": false,"autoUpdateInput": true,"locale": {'format': 'DD/MM/YYYY'}};if(showRanges) {rangedDatePicker['ranges'] ={'Today': [moment(), moment()],'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],'Last 7 Days': [moment().subtract(6, 'days'), moment()],'Last 30 Days': [moment().subtract(29, 'days'), moment()],'This Month': [moment().startOf('month'), moment().endOf('month')],'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]}}return rangedDatePicker;}function showPosition(position) {if(typeof latitude == "undefined") {var coords = {latitude:position.coords.latitude, longitude:position.coords.longitude}doAjaxRequestWithJsonHandler('partner/location', 'PUT', JSON.stringify(coords), function(){latitude = position.coords.latitude;longitude = position.coords.longitude;});}// distance = getDistance(latitude, longitude, position.coords.latitude,// position.coords.longitude);}function getAuthorisedWarehouses(callback){bootBoxObj = {size: "small",title: "Choose Warehouse",callback: callback,inputType:'select',inputOptions : typeof inputOptions == "undefined" ? undefined : inputOptions}if(typeof inputOptions=="undefined") {doGetAjaxRequestHandler(context+"/authorisedWarehouses", function(response){response = JSON.parse(response);inputOptions = [];response.forEach(function(warehouse){inputOptions.push({text:warehouse.name,value:warehouse.id,});});bootBoxObj['inputOptions'] = inputOptions;bootbox.prompt(bootBoxObj);});} else if(inputOptions.length==1) {callback(inputOptions[0].warehouse.id);}else {bootbox.prompt(bootBoxObj);}}function getColorsForItems(catalogId, description, callback) {bootBoxObj = {size: "small",className:"item-wrapper",title: "Active/Inactive - " + description,callback: callback,inputType:'checkbox',}doGetAjaxRequestHandler(context+"/itemsByCatalogId?catalogId="+catalogId, function(response){coloredItems = JSON.parse(response);inputOptions = [{text:"All", value:"0", onclick:"toggleAll('itemIds')"}];coloredItems.forEach(function(item){inputOptions.push({text:item.color,value:item.id,selected:item.active});});bootBoxObj['inputOptions'] = inputOptions;bootbox.prompt(bootBoxObj);$('.item-wrapper').find('input[type="checkbox"]').slice(1).each(function(index,checkbox){checkbox.checked=coloredItems[index].active;});});}$(".item-wrapper").find("input[type='checkbox']:first").live('change', function(){if(this.value=="0") {$(this).closest('.item-wrapper').find("input[type='checkbox']").slice(1).prop('checked', $(this).prop('checked'));}});function getItemAheadOptions(jqElement, callback) {jqElement.typeahead('destroy').typeahead({source: function(q, process) {if (q.length >= 3){return $.ajax(context+"/item", {global:false,data: {query : q},success: function(data){queryData = JSON.parse(data);process(queryData);},});}},delay: 400,items: 20,displayText: function(item){return item.itemDescription;},autoSelect: true,afterSelect: callback});}function getPartnerAheadOptions(jqElement, callback) {jqElement.typeahead('destroy').typeahead({source: function(q, process) {if (q.length >= 3){return $.ajax(context+"/partners", {global:false,data: {query : q},success: function(data){queryData = JSON.parse(data);process(queryData);},});}},delay: 300,items: 20,displayText: function(partner){return partner.displayName;},autoSelect: true,afterSelect: callback});}function loadPriceDrop(domId){doGetAjaxRequestHandler(context+"/getItemDescription", function(response){$('#' + domId).html(response);});}$(".price_drop").live('click', function() {loadPriceDrop("main-content");});