|
1 |
| -(function() { |
2 |
| - "use strict"; |
3 |
| - jQuery(document).ready(function() { |
4 |
| - |
5 |
| - // expand the current selected menu |
6 |
| - jQuery('#metrics-sidemenu').foundation('down', jQuery(`#${window.wp_js_object.base_slug}-menu`)); |
7 |
| - |
8 |
| - |
9 |
| - show_template_overview() |
10 |
| - |
11 |
| - }) |
12 |
| - |
13 |
| - function show_template_overview(){ |
14 |
| - |
15 |
| - let localizedObject = window.wp_js_object // change this object to the one named in ui-menu-and-enqueue.php |
16 |
| - let translations = localizedObject.translations |
17 |
| - |
18 |
| - let chartDiv = jQuery('#chart') // retrieves the chart div in the metrics page |
19 |
| - |
20 |
| - chartDiv.empty().html(` |
21 |
| - <span class="section-header">${localizedObject.translations.title}</span> |
22 |
| -
|
23 |
| - <hr style="max-width:100%;"> |
24 |
| - |
25 |
| - <div id="chartdiv"></div> |
26 |
| - |
27 |
| - <hr style="max-width:100%;"> |
28 |
| -
|
29 |
| - <button type="button" onclick="sample_api_call('Yeh successful response from API!')" class="button" id="sample_button">${translations["Sample API Call"]}</button> |
30 |
| - <div id="sample_spinner" style="display: inline-block" class="loading-spinner"></div> |
31 |
| - `) |
32 |
| - |
33 |
| - // Create chart instance |
34 |
| - var chart = am4core.create("chartdiv", am4charts.PieChart); |
35 |
| - |
36 |
| - // Add data |
37 |
| - chart.data = [{ |
38 |
| - "country": "Lithuania", |
39 |
| - "litres": 501.9 |
40 |
| - }, { |
41 |
| - "country": "Czech Republic", |
42 |
| - "litres": 301.9 |
43 |
| - }, { |
44 |
| - "country": "Ireland", |
45 |
| - "litres": 201.1 |
46 |
| - }, { |
47 |
| - "country": "Germany", |
48 |
| - "litres": 165.8 |
49 |
| - }, { |
50 |
| - "country": "Australia", |
51 |
| - "litres": 139.9 |
52 |
| - }, { |
53 |
| - "country": "Austria", |
54 |
| - "litres": 128.3 |
55 |
| - }, { |
56 |
| - "country": "UK", |
57 |
| - "litres": 99 |
58 |
| - }, { |
59 |
| - "country": "Belgium", |
60 |
| - "litres": 60 |
61 |
| - }, { |
62 |
| - "country": "The Netherlands", |
63 |
| - "litres": 50 |
64 |
| - }]; |
65 |
| - |
66 |
| - // Add and configure Series |
67 |
| - var pieSeries = chart.series.push(new am4charts.PieSeries()); |
68 |
| - pieSeries.dataFields.value = "litres"; |
69 |
| - pieSeries.dataFields.category = "country"; |
70 |
| - } |
71 |
| - |
72 |
| - window.sample_api_call = function sample_api_call( button_data ) { |
73 |
| - |
74 |
| - |
75 |
| - let localizedObject = window.wp_js_object // change this object to the one named in ui-menu-and-enqueue.php |
76 |
| - |
77 |
| - let button = jQuery('#sample_button') |
78 |
| - |
79 |
| - $('#sample_spinner').addClass("active") |
80 |
| - |
81 |
| - let data = { "button_data": button_data }; |
82 |
| - return jQuery.ajax({ |
83 |
| - type: "POST", |
84 |
| - data: JSON.stringify(data), |
85 |
| - contentType: "application/json; charset=utf-8", |
86 |
| - dataType: "json", |
87 |
| - url: `${localizedObject.rest_endpoints_base}/sample`, |
88 |
| - beforeSend: function(xhr) { |
89 |
| - xhr.setRequestHeader('X-WP-Nonce', localizedObject.nonce); |
90 |
| - }, |
91 |
| - }) |
92 |
| - .done(function (data) { |
93 |
| - $('#sample_spinner').removeClass("active") |
94 |
| - button.empty().append(data) |
95 |
| - console.log( 'success' ) |
96 |
| - console.log( data ) |
97 |
| - }) |
98 |
| - .fail(function (err) { |
99 |
| - $('#sample_spinner').removeClass("active") |
100 |
| - button.empty().append("error. Something went wrong") |
101 |
| - console.log("error"); |
102 |
| - console.log(err); |
103 |
| - }) |
104 |
| - } |
105 |
| -})(); |
| 1 | +'use strict'; |
| 2 | + |
| 3 | +jQuery(document).ready(function () { |
| 4 | + jQuery('#metrics-sidemenu').foundation( |
| 5 | + 'down', |
| 6 | + jQuery(`#${window.wp_js_object.base_slug}-menu`), |
| 7 | + ); |
| 8 | + |
| 9 | + let chartDiv = jQuery('#chart'); |
| 10 | + chartDiv.empty().html(` |
| 11 | + <span class="section-header" title="Showing all contacts from all time with any status">${window.wp_js_object.translations.title}</span> |
| 12 | + <div id="mapping_chart"></div> |
| 13 | + `); |
| 14 | + |
| 15 | + window.page_mapping_view(window.wp_js_object.rest_endpoints_base); |
| 16 | +}); |
0 commit comments