PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.6.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.6.9
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / assets / js / dist / admin / pages / statistic.js

statistic.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.1.6.9, at assets/js/dist/admin/pages/statistic.js

309 lines 8.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (function() { // webpackBootstrap
2 var __webpack_exports__ = {};
3 /*!*****************************************************!*\
4 !*** ./assets/src/apps/js/admin/pages/statistic.js ***!
5 \*****************************************************/
6 (function ($) {
7 $.fn.LP_Chart_Line = function (data, config) {
8 return $.each(this, function () {
9 const $elem = $(this),
10 $canvas = $('<canvas />');
11 $elem.html('');
12 $canvas.appendTo($elem);
13 var lineChart = new Chart($canvas, {
14 type: 'line',
15 data: data,
16 options: config
17 });
18 }); //
19 };
20
21 $.fn.LP_Statistic_Users = function () {
22 if (parseInt($(this).length) === 0) {
23 return;
24 }
25
26 return $.each(this, function () {
27 const $buttons = $('.chart-buttons button').on('click', function () {
28 const $button = $(this),
29 type = $button.data('type');
30 let from = '',
31 to = '';
32 $buttons.not(this).not('[data-type="user-custom-time"]').prop('disabled', false);
33
34 if (type == 'user-custom-time') {
35 from = $('#user-custom-time input[name="from"]').val();
36 to = $('#user-custom-time input[name="to"]').val();
37
38 if (from == '' || to == '') {
39 return false;
40 }
41 } else {
42 $button.prop('disabled', true);
43 }
44
45 const $container = $('#learn-press-chart');
46 $container.addClass('loading');
47 $.ajax({
48 url: 'admin-ajax.php',
49 data: {
50 action: 'learnpress_load_chart',
51 type,
52 range: [from, to]
53 },
54 dataType: 'text',
55
56 success(response) {
57 response = LP.parseJSON(response);
58 $container.LP_Chart_Line(response, LP_Chart_Config);
59 $container.removeClass('loading');
60 }
61
62 });
63 return false;
64 }),
65 $inputs = $('.chart-buttons #user-custom-time input[type="text"]').on('change', function () {
66 const _valid_date = function () {
67 if (new Date($inputs[0].value) < new Date($inputs[1].value)) {
68 return true;
69 }
70 };
71
72 $buttons.filter('[data-type="user-custom-time"]').prop('disabled', $inputs.filter(function () {
73 return this.value == '';
74 }).get().length || !_valid_date());
75 });
76 });
77 };
78
79 $.fn.LP_Statistic_Courses = function () {
80 if (parseInt($(this).length) === 0) {
81 return;
82 }
83
84 return $.each(this, function () {
85 var $buttons = $('.chart-buttons button').on('click', function () {
86 let $button = $(this),
87 type = $button.data('type'),
88 from = '',
89 to = '',
90 $container = $('#learn-press-chart');
91 $buttons.not(this).not('[data-type="course-custom-time"]').prop('disabled', false);
92
93 if (type == 'course-custom-time') {
94 from = $('#course-custom-time input[name="from"]').val();
95 to = $('#course-custom-time input[name="to"]').val();
96
97 if (from == '' || to == '') {
98 return false;
99 }
100 } else {
101 $button.prop('disabled', true);
102 }
103
104 $container.addClass('loading');
105 $.ajax({
106 url: 'admin-ajax.php',
107 data: {
108 action: 'learnpress_load_chart',
109 type,
110 range: [from, to]
111 },
112 dataType: 'text',
113
114 success(response) {
115 response = LP.parseJSON(response);
116 $container.LP_Chart_Line(response, LP_Chart_Config);
117 $container.removeClass('loading');
118 }
119
120 });
121 return false;
122 }),
123 $inputs = $('.chart-buttons #course-custom-time input[type="text"]').on('change', function () {
124 const _valid_date = function () {
125 if (new Date($inputs[0].value) < new Date($inputs[1].value)) {
126 return true;
127 }
128 };
129
130 $buttons.filter('[data-type="course-custom-time"]').prop('disabled', $inputs.filter(function () {
131 return this.value == '';
132 }).get().length || !_valid_date());
133 });
134 });
135 };
136
137 $.fn.LP_Statistic_Orders = function () {
138 if (parseInt($(this).length) === 0) {
139 return;
140 }
141
142 $('.panel_report_option').hide();
143 $('#panel_report_sales_by_' + $('#report_sales_by').val()).show();
144 $('#report_sales_by').on('change', function () {
145 $('.panel_report_option').hide();
146 $('#panel_report_sales_by_' + $(this).val()).show();
147
148 if ('date' == $(this).val()) {
149 LP_Statistic_Orders_Upgrade_Chart();
150 }
151 });
152 /**
153 * Upgrade Chart for Order Statistics
154 *
155 * @return {boolean}
156 */
157
158 var LP_Statistic_Orders_Upgrade_Chart = function () {
159 let type = '',
160 from = '',
161 to = '',
162 report_sales_by = 'date',
163 cat_id = 0,
164 course_id = 0;
165 report_sales_by = $('#report_sales_by').val();
166 $container = $('#learn-press-chart');
167 $container.addClass('loading'); // get type
168
169 const $buttons = $('.chart-buttons button:disabled').not('[data-type="order-custom-time"]');
170
171 if (parseInt($buttons.length) > 0) {
172 type = $($buttons[0]).data('type');
173 } else {
174 type = 'order-custom-time';
175 from = $('#order-custom-time input[name="from"]').val();
176 to = $('#order-custom-time input[name="to"]').val();
177
178 if (from == '' || to == '') {
179 return false;
180 }
181 }
182
183 if ('course' === report_sales_by) {
184 course_id = $('#report-by-course-id').val();
185 } else if ('category' === report_sales_by) {
186 cat_id = $('#report-by-course-category-id').val();
187 }
188
189 $.ajax({
190 url: 'admin-ajax.php',
191 data: {
192 action: 'learnpress_load_chart',
193 type,
194 range: [from, to],
195 report_sales_by,
196 course_id,
197 cat_id
198 },
199 dataType: 'text',
200
201 success(response) {
202 response = LP.parseJSON(response);
203 $container.LP_Chart_Line(response, LP_Chart_Config);
204 $container.removeClass('loading');
205 }
206
207 });
208 };
209
210 $('#report-by-course-id').select2({
211 placeholder: 'Select a course',
212 minimumInputLength: 1,
213 ajax: {
214 url: ajaxurl + '?action=learnpress_search_course',
215 dataType: 'json',
216 quietMillis: 250,
217
218 data(term, page) {
219 return {
220 q: term // search term
221
222 };
223 },
224
225 results(data, page) {
226 return {
227 results: data.items
228 };
229 },
230
231 cache: true
232 }
233 });
234 $('#report-by-course-id').on('change', function () {
235 LP_Statistic_Orders_Upgrade_Chart();
236 });
237 $('#report-by-course-category-id').select2({
238 placeholder: 'Select a course',
239 minimumInputLength: 1,
240 ajax: {
241 url: ajaxurl + '?action=learnpress_search_course_category',
242 dataType: 'json',
243 quietMillis: 250,
244
245 data(term, page) {
246 return {
247 q: term // search term
248
249 };
250 },
251
252 results(data, page) {
253 return {
254 results: data.items
255 };
256 },
257
258 cache: true
259 }
260 });
261 $('#report-by-course-category-id').on('change', function () {
262 LP_Statistic_Orders_Upgrade_Chart();
263 });
264 var $buttons = $('.chart-buttons button').on('click', function () {
265 const $button = $(this),
266 type = $button.data('type'),
267 from = '',
268 to = '',
269 $container = $('#learn-press-chart');
270 $buttons.not(this).not('[data-type="order-custom-time"]').prop('disabled', false);
271
272 if (type !== 'order-custom-time') {
273 $button.prop('disabled', true);
274 $('#order-custom-time input[name="from"]').val('');
275 $('#order-custom-time input[name="to"]').val('');
276 }
277
278 LP_Statistic_Orders_Upgrade_Chart();
279 return false;
280 });
281 var $inputs = $('.chart-buttons #order-custom-time input[type="text"]').on('change', function () {
282 const _valid_date = function () {
283 if (new Date($inputs[0].value) < new Date($inputs[1].value)) {
284 return true;
285 }
286 };
287
288 $buttons.filter('[data-type="order-custom-time"]').prop('disabled', $inputs.filter(function () {
289 return this.value == '';
290 }).get().length || !_valid_date());
291 });
292 };
293
294 $(function () {
295 if (typeof $.fn.datepicker != 'undefined') {
296 $('.date-picker').datepicker({
297 dateFormat: 'yy/mm/dd'
298 });
299 }
300
301 $('.learn-press-statistic-users').LP_Statistic_Users();
302 $('.learn-press-statistic-courses').LP_Statistic_Courses();
303 $('.learn-press-statistic-orders').LP_Statistic_Orders();
304 });
305 return;
306 })(jQuery);
307 /******/ })()
308 ;
309 //# sourceMappingURL=statistic.js.map