PluginProbe
VikBooking Hotel Booking Engine & PMS / trunk
VikBooking Hotel Booking Engine & PMS vtrunk
1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 All 36 releases
vikbooking / admin / layouts / taskmanager / dates / contextmenu.php

contextmenu.php in VikBooking Hotel Booking Engine & PMS trunk, at admin/layouts/taskmanager/dates/contextmenu.php

338 lines 14.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2025 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 * Obtain vars from arguments received in the layout file.
16 *
17 * @var string $caller The identifier of who's calling this layout file.
18 * @var array $events List of JS events to trigger.
19 * @var array $filters The current View filters.
20 */
21 extract($displayData);
22
23 // load assets
24 $vbo_app = VikBooking::getVboApplication();
25 $vbo_app->loadContextMenuAssets();
26 $vbo_app->loadDatePicker();
27 $vbo_app->loadDatesRangePicker();
28
29 // define the default events
30 if (!isset($events) || !is_array($events)) {
31 $events = [];
32 }
33 $events['filter_dates'] = $events['filter_dates'] ?? 'vbo-tm-apply-filters';
34
35 // get current filters
36 $filters = (array) ($filters ?? []);
37
38 // list of allowed date filter types
39 $allowedTypes = [
40 'today' => JText::translate('VBTODAY'),
41 'tomorrow' => JText::translate('VBOTOMORROW'),
42 'yesterday' => JText::translate('VBOYESTERDAY'),
43 'week' => JText::translate('VBO_THIS_WEEK'),
44 // month needs to be the second last type, because it will use a separator
45 'month' => JText::translate('VBO_THIS_MONTH'),
46 'custom' => JText::translate('VBO_CUSTOM'),
47 ];
48
49 // the currently active dates filter
50 $activeDates = $filters['dates'] ?? null;
51
52 ?>
53
54 <button type="button" class="btn vbo-context-menu-btn vbo-context-menu-tm-dates<?php echo $activeDates ? ' vbo-tm-filter-active' : ''; ?>">
55 <?php
56 if ($activeDates) {
57 // active filter
58 $dt_filter_name = isset($allowedTypes[$activeDates]) ? $allowedTypes[$activeDates] : $activeDates;
59 ?>
60 <span class="vbo-context-menu-lbl" title="<?php echo JHtml::fetch('esc_attr', $dt_filter_name); ?>"><?php echo $dt_filter_name; ?></span>
61 <span class="vbo-context-menu-lbl-orig" style="display: none;"><?php echo JText::translate('VBPVIEWORDERSONE'); ?></span>
62 <?php
63 } else {
64 // filter not set
65 ?>
66 <span class="vbo-context-menu-lbl"><?php echo JText::translate('VBPVIEWORDERSONE'); ?></span>
67 <?php
68 }
69 ?>
70 <span class="vbo-context-menu-ico"><?php VikBookingIcons::e('sort-down'); ?></span>
71 </button>
72
73 <div class="vbo-tm-dates-filter-helper-wrap" style="display: none;">
74 <div class="vbo-tm-dates-filter-helper">
75 <div class="vbo-admin-container vbo-admin-container-full vbo-admin-container-compact">
76 <div class="vbo-params-wrap">
77 <div class="vbo-params-container">
78 <div class="vbo-params-block">
79 <div class="vbo-param-container">
80 <div class="vbo-param-label"><?php echo JText::translate('VBNEWRESTRICTIONDFROMRANGE'); ?></div>
81 <div class="vbo-param-setting">
82 <div class="vbo-field-calendar">
83 <div class="input-append">
84 <input type="text" id="vbo-tm-dates-filter-dt-from" value="" autocomplete="off" />
85 <button type="button" class="btn btn-secondary vbo-tm-dates-filter-dt-from-trigger"><?php VikBookingIcons::e('calendar'); ?></button>
86 </div>
87 </div>
88 </div>
89 </div>
90 <div class="vbo-param-container">
91 <div class="vbo-param-label"><?php echo JText::translate('VBNEWRESTRICTIONDTORANGE'); ?></div>
92 <div class="vbo-param-setting">
93 <div class="vbo-field-calendar">
94 <div class="input-append">
95 <input type="text" id="vbo-tm-dates-filter-dt-to" value="" autocomplete="off" />
96 <button type="button" class="btn btn-secondary vbo-tm-dates-filter-dt-to-trigger"><?php VikBookingIcons::e('calendar'); ?></button>
97 </div>
98 </div>
99 </div>
100 </div>
101 </div>
102 </div>
103 </div>
104 </div>
105 </div>
106 </div>
107
108 <script type="text/javascript">
109 jQuery(function() {
110
111 // all date types
112 const dateTypes = <?php echo json_encode($allowedTypes); ?>;
113
114 // build buttons
115 let btns = [];
116
117 // push unset date filter button
118 btns.push({
119 statusId: null,
120 class: 'vbo-context-menu-entry-secondary',
121 separator: true,
122 text: <?php echo json_encode(JText::translate('VBANYTHING')); ?>,
123 icon: '<?php echo VikBookingIcons::i('times'); ?>',
124 visible: () => {
125 return vboTmFilters && vboTmFilters?.dates;
126 },
127 action: function(root, config) {
128 // remove date filter
129 VBOCore.emitEvent('<?php echo $events['filter_dates']; ?>', {
130 filters: {
131 dates: null,
132 },
133 });
134
135 if (jQuery(root).find('.vbo-context-menu-lbl-orig').length) {
136 // restore default label
137 jQuery(root)
138 .find('.vbo-context-menu-lbl')
139 .remove();
140
141 jQuery(root)
142 .find('.vbo-context-menu-lbl-orig')
143 .attr('class', '')
144 .attr('title', '')
145 .addClass('vbo-context-menu-lbl')
146 .show();
147 }
148
149 jQuery(root).removeClass('vbo-tm-filter-active');
150 },
151 });
152
153 for (const [dateId, dateName] of Object.entries(dateTypes)) {
154 // push date button
155 btns.push({
156 dateId: dateId,
157 class: 'vbo-context-menu-entry-secondary',
158 text: dateName,
159 icon: '<?php echo VikBookingIcons::i('calendar'); ?>',
160 separator: dateId == 'month',
161 disabled: () => {
162 return vboTmFilters && vboTmFilters?.dates && vboTmFilters.dates == dateId;
163 },
164 action: function(root, config) {
165 if (dateId !== 'custom') {
166 // apply status filter
167 VBOCore.emitEvent('<?php echo $events['filter_dates']; ?>', {
168 filters: {
169 dates: dateId,
170 },
171 });
172
173 if (jQuery(root).find('.vbo-context-menu-lbl-orig').length) {
174 // filter changed
175 jQuery(root)
176 .find('.vbo-context-menu-lbl')
177 .attr('class', '')
178 .addClass('vbo-context-menu-lbl')
179 .text(dateName)
180 .attr('title', dateName);
181 } else {
182 // filter set for the first time
183 jQuery(root)
184 .find('.vbo-context-menu-lbl')
185 .attr('class', '')
186 .addClass('vbo-context-menu-lbl-orig')
187 .hide();
188
189 jQuery(root)
190 .find('.vbo-context-menu-lbl-orig')
191 .parent()
192 .prepend(
193 jQuery('<span></span>')
194 .addClass('vbo-context-menu-lbl')
195 .text(dateName)
196 .attr('title', dateName)
197 );
198 }
199
200 jQuery(root).addClass('vbo-tm-filter-active');
201 } else {
202 // display modal to apply a custom dates filter
203
204 // define the modal cancel button
205 let cancel_btn = jQuery('<button></button>')
206 .attr('type', 'button')
207 .addClass('btn')
208 .text(<?php echo json_encode(JText::translate('VBANNULLA')); ?>)
209 .on('click', () => {
210 VBOCore.emitEvent('vbo-tm-filter-dates-dismiss');
211 });
212
213 // define the modal apply button
214 let apply_btn = jQuery('<button></button>')
215 .attr('type', 'button')
216 .addClass('btn btn-success')
217 .text(<?php echo json_encode(JText::translate('VBAPPLY')); ?>)
218 .on('click', function() {
219 // disable button to prevent double submissions
220 let submit_btn = jQuery(this);
221 submit_btn.prop('disabled', true);
222
223 // dismiss the modal
224 VBOCore.emitEvent('vbo-tm-filter-dates-dismiss');
225
226 let dtFrom = jQuery('#vbo-tm-dates-filter-dt-from').val();
227 let dtTo = jQuery('#vbo-tm-dates-filter-dt-to').val();
228 if (!dtFrom || !dtTo) {
229 alert(<?php echo json_encode(JText::translate('VBO_PLEASE_SELECT')); ?>);
230 return false;
231 }
232
233 let readFilter = dtFrom + ' : ' + dtTo;
234
235 // apply the dates filter
236 VBOCore.emitEvent('<?php echo $events['filter_dates']; ?>', {
237 filters: {
238 dates: readFilter,
239 },
240 });
241
242 if (jQuery(root).find('.vbo-context-menu-lbl-orig').length) {
243 // filter changed
244 jQuery(root)
245 .find('.vbo-context-menu-lbl')
246 .attr('class', '')
247 .addClass('vbo-context-menu-lbl')
248 .text(readFilter)
249 .attr('title', readFilter);
250 } else {
251 // filter set for the first time
252 jQuery(root)
253 .find('.vbo-context-menu-lbl')
254 .attr('class', '')
255 .addClass('vbo-context-menu-lbl-orig')
256 .hide();
257
258 jQuery(root)
259 .find('.vbo-context-menu-lbl-orig')
260 .parent()
261 .prepend(
262 jQuery('<span></span>')
263 .addClass('vbo-context-menu-lbl')
264 .text(readFilter)
265 .attr('title', readFilter)
266 );
267 }
268
269 jQuery(root).addClass('vbo-tm-filter-active');
270 });
271
272 // display modal
273 let modalBody = VBOCore.displayModal({
274 suffix: 'tm_filter_dates',
275 title: <?php echo json_encode(JText::translate('VBOFILTERBYDATES')); ?>,
276 extra_class: 'vbo-modal-rounded vbo-modal-dialog',
277 body_prepend: true,
278 lock_scroll: true,
279 footer_left: cancel_btn,
280 footer_right: apply_btn,
281 dismiss_event: 'vbo-tm-filter-dates-dismiss',
282 onDismiss: () => {
283 jQuery('.vbo-tm-dates-filter-helper').appendTo(jQuery('.vbo-tm-dates-filter-helper-wrap'));
284 },
285 });
286
287 jQuery('.vbo-tm-dates-filter-helper').appendTo(modalBody);
288 }
289 },
290 });
291 }
292
293 // start context menu on the proper button element
294 jQuery('.vbo-context-menu-tm-dates').vboContextMenu({
295 placement: 'bottom-left',
296 buttons: btns,
297 });
298
299 // start date-range-picker calendar
300 jQuery('#vbo-tm-dates-filter-dt-from').vboDatesRangePicker({
301 checkout: jQuery('#vbo-tm-dates-filter-dt-to'),
302 dateFormat: 'yy-mm-dd',
303 numberOfMonths: 1,
304 changeMonth: true,
305 changeYear: true,
306 minDate: '-10y',
307 maxDate: '+5y',
308 onSelect: {
309 checkin: (selectedDate) => {
310 if (!selectedDate) {
311 return;
312 }
313 let nowstart = jQuery('#vbo-tm-dates-filter-dt-from').vboDatesRangePicker('getCheckinDate');
314 let nowstartdate = new Date(nowstart.getTime());
315 jQuery('#vbo-tm-dates-filter-dt-from').vboDatesRangePicker('checkout', 'minDate', nowstartdate);
316 },
317 checkout: function(selectedDate) {
318 // do nothing
319 },
320 },
321 labels: {
322 checkin: <?php echo json_encode(JText::translate('VBNEWRESTRICTIONDFROMRANGE')); ?>,
323 checkout: <?php echo json_encode(JText::translate('VBNEWRESTRICTIONDTORANGE')); ?>,
324 },
325 environment: {
326 section: 'admin',
327 autoHide: true,
328 },
329 });
330
331 // register click events on calendar triggers
332 jQuery('.vbo-tm-dates-filter-dt-from-trigger, .vbo-tm-dates-filter-dt-to-trigger').on('click', () => {
333 jQuery('#vbo-tm-dates-filter-dt-from').trigger('focus');
334 });
335
336 });
337 </script>
338