PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / layouts / statistics / widgets / dashboard / packages / table.php
vikappointments / admin / layouts / statistics / widgets / dashboard / packages Last commit date
table 6 days ago index.html 6 days ago table.php 6 days ago
table.php
252 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Layout variables
16 * -----------------
17 * @var VAPStatisticsWidget $widget The instance of the widget to be displayed.
18 * @var mixed $data The table rows data.
19 */
20 extract($displayData);
21
22 // get active tab
23 $active = JFactory::getApplication()->input->cookie->get('vap_widget_' . $widget->getName() . '_active_' . $widget->getID(), 'purchased');
24
25 ?>
26
27 <div class="canvas-align-top">
28
29 <!-- widget container -->
30
31 <div class="vapdash-container">
32
33 <!-- widget tabs -->
34
35 <div class="vapdash-tab-head">
36 <div class="vapdash-tab-button">
37 <a href="javascript:void(0)" data-pane="purchased" class="<?php echo ($active == 'purchased' ? 'active' : ''); ?>">
38 <?php echo JText::translate('VAP_STATS_WIDGET_DASHBOARD_PACKAGES_TABLE_PURCHASED_FIELD'); ?>
39 </a>
40 </div>
41
42 <div class="vapdash-tab-button">
43 <a href="javascript:void(0)" data-pane="redeemed" class="<?php echo ($active == 'redeemed' ? 'active' : ''); ?>">
44 <?php echo JText::translate('VAP_STATS_WIDGET_DASHBOARD_PACKAGES_TABLE_REDEEMED_FIELD'); ?>
45 </a>
46 </div>
47 </div>
48
49 <!-- widget latest purchased pane -->
50
51 <div class="vapdash-tab-pane" data-pane="purchased" style="<?php echo $active == 'purchased' ? '' : 'display:none'; ?>">
52
53 </div>
54
55 <!-- widget latest redeemed pane -->
56
57 <div class="vapdash-tab-pane" data-pane="redeemed" style="<?php echo $active == 'redeemed' ? '' : 'display:none'; ?>">
58
59 </div>
60
61 </div>
62
63 </div>
64
65 <script>
66
67 (function($) {
68 'use strict';
69
70 /**
71 * Flag used to track the ID of the latest order
72 * fetched. In this way, we can play a sound every
73 * time a new order is higher the the latest one.
74 *
75 * USE the same variable for each widget in order
76 * to avoid playing the sound more than once.
77 *
78 * @var integer
79 */
80 let LATEST_ORDER_FETCHED = 0;
81
82 /**
83 * Register callback to be executed before
84 * launching the update request.
85 *
86 * @param mixed widget The widget selector.
87 * @param object config The widget configuration.
88 *
89 * @return void
90 */
91 WIDGET_PREFLIGHTS[<?php echo $widget->getID(); ?>] = (widget, config) => {
92 // count disabled panes
93 var disabled = 0;
94 // reference to first enabled tab
95 var firstEnabled = null;
96 // flag to check if the current active pane is disabled
97 var activeDisabled = false;
98
99 var id = $(widget).attr('id');
100
101 // iterate panes and toggle them according to the widget config
102 $(widget).find('.vapdash-tab-head a').each(function() {
103 var pane = $(this).data('pane');
104
105 if (config[pane]) {
106 $(this).show()
107 .parent()
108 .show();
109
110 // register tab as first available, only
111 // if the flag is still empty
112 if (!firstEnabled) {
113 firstEnabled = this;
114 }
115 } else {
116 $(this).hide()
117 .parent()
118 .hide();
119
120 // increase disabled counter
121 disabled++;
122 // inform the caller that the active pane is disabled
123 activeDisabled = activeDisabled || $(this).hasClass('active');
124 }
125 });
126
127 // hide all tabs in case only one is enabled
128 if (disabled < 1) {
129 $(widget).find('.vapdash-tab-head').show();
130 } else {
131 $(widget).find('.vapdash-tab-head').hide();
132 }
133
134 // in case the active pane was disabled, we should display the first one available
135 if (activeDisabled && firstEnabled) {
136 $(firstEnabled).trigger('click');
137 }
138 }
139
140 /**
141 * Register callback to be executed after
142 * completing the update request.
143 *
144 * @param mixed widget The widget selector.
145 * @param string data The JSON response.
146 * @param object config The widget configuration.
147 *
148 * @return void
149 */
150 WIDGET_CALLBACKS[<?php echo $widget->getID(); ?>] = (widget, data, config) => {
151 var id = $(widget).attr('id');
152
153 $(widget).find('.vapdash-tab-pane').each(function() {
154 // get pane id
155 var pane = $(this).data('pane');
156
157 if (data[pane] !== undefined) {
158 // fill body with returned HTML
159 $(this).html(data[pane]);
160 } else {
161 // set empty string
162 $(this).html('');
163 }
164 });
165
166 var tmp_latest_id = LATEST_ORDER_FETCHED;
167 var firstDownload = LATEST_ORDER_FETCHED == 0;
168 var shouldPlaySound = false;
169
170 // iterate all order IDs to look for a newer one
171 $(widget).find('tr[data-order-id]').each(function() {
172 // extract order ID
173 var id_order = parseInt($(this).data('order-id'));
174
175 // the order is higher than the current one
176 if (id_order > LATEST_ORDER_FETCHED) {
177 // update flag
178 LATEST_ORDER_FETCHED = id_order;
179 }
180
181 // Make sure we are not doing the first download of the session.
182 // Compare order ID with previous one in order to mark all the
183 // new records instead of the latest one.
184 if (!firstDownload && id_order > tmp_latest_id) {
185 shouldPlaySound = true;
186 }
187 });
188
189 // play notification sound in case of new orders
190 // and in case we are not doing the first download
191 if (shouldPlaySound) {
192 $.vapDashboard('play');
193 }
194 }
195
196 $(function() {
197 // get widget element
198 const widget = $('#widget-<?php echo $widget->getID(); ?>');
199
200 // register click event for tab buttons
201 $(widget).find('.vapdash-tab-head a').on('click', function() {
202 // get button pane
203 var pane = $(this).data('pane');
204
205 // deactivate all buttons
206 $(widget).find('.vapdash-tab-head a').removeClass('active');
207 // active clicked button
208 $(this).addClass('active');
209
210 // hide all panes
211 $(widget).find('.vapdash-tab-pane').hide();
212 // show selected pane
213 $(widget).find('.vapdash-tab-pane[data-pane="' + pane + '"]').show();
214
215 // register selected button in cookie
216 document.cookie = 'vap.widget.<?php echo $widget->getName(); ?>.active.<?php echo $widget->getID(); ?>=' + pane + '; path=/';
217 });
218
219 // display order details in a modal box
220 $(document).on('click', '#widget-<?php echo $widget->getID(); ?> a[data-package-id]', function() {
221 // get order ID
222 const order_id = $(this).data('package-id');
223
224 // update href to access the management page of the order
225 let href = $('#packinfo-edit-btn').attr('href');
226 $('#packinfo-edit-btn').attr('href', href.replace(/cid\[\]=[\d]*$/, 'cid[]=' + order_id));
227
228 // create URL
229 const url = 'index.php?option=com_vikappointments&view=packorderinfo&tmpl=component&cid[]=' + order_id;
230 // open modal
231 $('#jmodal-packinfo').vapJModal('open', url);
232 });
233
234 // display customer details in a modal box
235 $(document).on('click', '#widget-<?php echo $widget->getID(); ?> a[data-customer-id]', function() {
236 // get customer ID
237 const user_id = $(this).data('customer-id');
238
239 // update href to access the management page of the customer
240 let href = $('#custinfo-edit-btn').attr('href');
241 $('#custinfo-edit-btn').attr('href', href.replace(/cid\[\]=[\d]*$/, 'cid[]=' + user_id));
242
243 // create URL
244 const url = 'index.php?option=com_vikappointments&view=customerinfo&tmpl=component&cid[]=' + user_id;
245 // open modal
246 $('#jmodal-custinfo').vapJModal('open', url);
247 });
248 });
249 })(jQuery);
250
251 </script>
252