Rev 26167 | Rev 30599 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
$(document).on('click', 'a.list-group-item', function() {startDate=undefined;endDate=undefined;reportTitle = $(this).find('h4').html();reportUrl = this.href;$reportModal = $('#report-modal');$reportModal.find('h4.modal-title').html(reportTitle);if($(this).data("paramslist") == undefined) {return true;} else {var paramsList = $(this).data("paramslist");paramsMap = {};renderInputDialog(paramsList);$reportModal.modal('show');return false;}});$(document).on('click', 'button.download-report', function(){var reportParams = {};var validated = true;$inputContainer.find("input.param,select.param").each(function(idx, inputElement) {var inputName = $(inputElement).attr("name");if(typeof inputName === "undefined" || !(inputName in paramsMap)) {console.log(inputName);return;}param = paramsMap[inputName];if($(inputElement).val()=="") {bootbox.alert(`${param.displayName} is required`);validated = false;return false;}if(param.type=='DATE') {reportParams[`MANUAL_${inputName}`] = startDate;} else if(param.type=='DATE_RANGE') {reportParams[`MANUAL_${inputName}_FROMDATE`] = startDate;reportParams[`MANUAL_${inputName}_TODATE`] = endDate;} else {if(['code', 'warehouseId'].indexOf(param.name) >= 0) {if(typeof $(inputElement).val() == "string") {reportParams[`${inputName}`] = $(inputElement).val();} else {reportParams[`${inputName}`] = $(inputElement).val().join(",");}} else {reportParams[`MANUAL_${inputName}`] = $(inputElement).val();}}});if(validated) {var jsonParams = JSON.stringify(reportParams);doAjaxPostDownload(reportUrl, jsonParams, `${reportTitle}.csv`);}});function renderInputDialog(paramsList) {$reportModal = $('div#report-modal');$inputContainer = $reportModal.find('div.modal-body');//Clear container first$inputContainer.html('');paramsList.forEach(function(value) {paramsMap[value.name] = value;renderInput($inputContainer, value);});}function renderInput($inputContainer, param) {console.log(param.type);switch (param.type) {case "DATE": {$inputContainer.append(`<div class="form-group"><label>${param.displayText}</label><input name="${param.name}" type="text" value="" class="param form-control input-sm"></div>`);$inputContainer.find(`input[name="${param.name}"]`).daterangepicker(getSingleDatePicker(),reporticoDRCallback);reporticoDRCallback(moment(), moment());return;}case "DATE_RANGE" : {$inputContainer.append(`<div class="form-group"><label>${param.displayText}</label><input name="${param.name}" type="text" value="" class="param form-control input-sm"></div>`);$inputContainer.find(`input[name="${param.name}"]`).daterangepicker(getRangedDatePicker(true),reporticoDRCallback);reporticoDRCallback(moment(), moment());return;}case "STRING": {if(param.name=="authId") {$inputContainer.append(`<input type="hidden" name="${param.name}" type="text" value="${authId}" class="param form-control input-sm">`);} else {$inputContainer.append(`<div class="form-group"><label>${param.displayText}</label><input name="${param.name}" type="text" value="" class="param form-control input-sm"></div>`);}return;}case "LIST" : {if(param.name == "code"){var arr = [];if(retailers.length==1) {$inputContainer.append(`<input type="hidden" name="${param.name}" type="text" value="${authId}" class="param form-control input-sm">`)} else {for(var i in retailers) {arr.push(`<option value="${retailers[i].code}">${retailers[i].displayName}-${retailers[i].code}</option>`);}var options = arr.join("");$inputContainer.append(`<div class="col-lg-2 form-group"><label>${param.displayText}</label><select class="param form-control input-sm" id="code" multiple="multiple" name="${param.name}"><option value="" disabled selected>Select Franchisee</option>${options}</select></div>`);$('#code').multiselect({includeSelectAllOption: true,multiple:true,maxHeight: 200,buttonWidth: '180px',numberDisplayed: 1,nonSelectedText: 'Franchisee',nSelectedText: ' - Franchisees Selected',allSelectedText: 'All Franchisees',enableFiltering: true,enableCaseInsensitiveFiltering : true});}} else if(param.name == "warehouseId"){var arr = [];for(var i in warehouses) {arr.push(`<option value="${i}">${warehouses[i]}</option>`);}var options = arr.join("");$inputContainer.append(`<div class="col-lg-2 form-group"><label>${param.displayText}</label><select class="param form-control input-sm" id="code" multiple="multiple" name="${param.name}"><option value="" disabled selected>Select Warehouses</option>${options}</select></div>`);$('#code').multiselect({includeSelectAllOption: true,multiple:true,maxHeight: 200,buttonWidth: '180px',numberDisplayed: 1,nonSelectedText: 'Warehouses',nSelectedText: ' - Warehouse Selected',allSelectedText: 'All Warehouses',enableFiltering: true,enableCaseInsensitiveFiltering : true});} else {$inputContainer.append(`<div class="form-group"><label>${param.displayText}(Comma Separated)</label><input name="${param.name}" type="text" value="" class="param form-control input-sm"></div>`);}return;}}}