1 line
No EOL
4 KiB
JavaScript
1 line
No EOL
4 KiB
JavaScript
var response_content,isjQueryReady=!1,isGoogleChartsReady=!1,isInitialized=!1;function googleChartsLoadCallback(){isGoogleChartsReady=!0,init()}function init(){isjQueryReady&&isGoogleChartsReady&&!isInitialized&&(isInitialized=!0,jQuery(".chart-period").change(function(){var t=jQuery(this).val(),a=jQuery(this).closest("form").find(".chart-period-start"),e=jQuery(this).closest("form").find(".chart-period-end"),o=new Date;if("this_week"===t)o.setDate(o.getDate()-o.getDay()+1),a.val(format_date(o)),o.setDate(o.getDate()+6),e.val(format_date(o));else if("this_month"===t){var n=new Date(o.getFullYear(),o.getMonth(),1);a.val(format_date(n));var i=new Date(o.getFullYear(),o.getMonth()+1,0);e.val(format_date(i))}}),jQuery(".chart-period-start, .chart-period-end").change(function(){jQuery(this).closest("form").find(".chart-period").val("custom")}),jQuery(".chart-options").submit(function(t){return t.preventDefault(),showChart(jQuery(this).serialize()),!1}),jQuery(".coupon-options").submit(function(t){return t.preventDefault(),loadCouponDetails(jQuery(this).serialize()),!1}),jQuery("#wdr-statistics-tabs li a").click(function(){jQuery(this).hasClass("active")||(jQuery("#wdr-statistics-tabs li a").removeClass("active"),jQuery(this).addClass("active"),jQuery(".wdr-statistics-container").hide(),jQuery(jQuery(this).data("target")).fadeIn("slow"))}),jQuery(window).resize(function(){response_content&&response_content.data.chart.columns.length>1&&renderChart(response_content.data.chart)}),jQuery(".chart-period").change(),jQuery(".chart-options").submit(),jQuery(".coupon-options").submit())}function renderChart(t){var a=new google.visualization.DataTable;t.columns&&t.columns.forEach(function(t,e){a.addColumn(0===e?"string":"number",t)}),t.rows&&(a.addRows(Object.values(t.rows)),new google.visualization.NumberFormat({fractionDigits:2}).format(a,1));var e=jQuery("#chart-container").width(),o=jQuery(window).height()-jQuery("#chart-container").offset().top;200>o&&(o=200);var n={chart:{title:t.title?t.title:"",subtitle:t.subtitle?t.subtitle:""},width:e,height:o};new google.charts.Line(document.getElementById("chart-container")).draw(a,n)}function showChart(t){let a=jQuery(".woo_discount_loader");a.show(),jQuery("#info-container").find("#total-orders, #total-revenue, #discounted-amount, #total-free-shipping").html("-"),jQuery.post(ajaxurl,{action:"wdr_admin_statistics",method:"get_chart_data",params:t},function(t){a.hide(),t.success&&t.data.chart.columns&&t.data.chart.columns.length>1?(response_content=t,renderChart(t.data.chart),jQuery("#info-container").show(),t.data.other&&(jQuery("#info-container #total-orders").html(t.data.other.total_orders),jQuery("#info-container #total-revenue").html(t.data.other.revenue),jQuery("#info-container #discounted-amount").html(t.data.other.discounted_amount),jQuery("#info-container #total-free-shipping").html(t.data.other.total_free_shipping))):(jQuery("#chart-container").html(wdr_data.localization_data.chart_data),jQuery("#info-container").hide())},"json")}function loadCouponDetails(t){let a=jQuery(".woo_discount_loader");a.show(),jQuery.post(ajaxurl,{action:"wdr_admin_statistics",method:"get_coupon_data",params:t},function(t){a.hide(),t.success&&t.data&&t.data.length?(jQuery("#coupon-container .no-data").hide(),jQuery("#coupon-container .list-coupons").show(),jQuery("#coupon-container table tbody").html(""),t.data.forEach(function(t){jQuery("#coupon-container table tbody").append("<tr><td>"+t.name+"</td><td>"+t.orders+"</td><td>"+t.amount+"</td></tr>")})):(jQuery("#coupon-container .list-coupons").hide(),jQuery("#coupon-container .no-data").html(wdr_data.localization_data.chart_data).show())},"json")}function to2Digits(t){return t<10?"0"+t:t}function format_date(t){return[to2Digits(t.getFullYear()),to2Digits(t.getMonth()+1),to2Digits(t.getDate())].join("-")}google.charts.load("current",{packages:["line"]}),google.charts.setOnLoadCallback(googleChartsLoadCallback),jQuery(document).ready(function(){isjQueryReady=!0,jQuery(".chart-type").select2({width:"260px"}),init()}); |