dropdown.php
90 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 | $formname = isset($displayData['formname']) ? $displayData['formname'] : 'confirmapp'; |
| 15 | $autofill = isset($displayData['autofill']) ? (int) $displayData['autofill'] : 1; |
| 16 | |
| 17 | echo |
| 18 | <<<JS |
| 19 | function checkinSelectValueChanged(select) { |
| 20 | |
| 21 | var link = -1; |
| 22 | var checkin = jQuery(select).val(); |
| 23 | var selected = 0; |
| 24 | var count = 1; |
| 25 | var html = ''; |
| 26 | |
| 27 | if (checkin.length) { |
| 28 | jQuery('#vap-checkin-sel option').each(function() { |
| 29 | |
| 30 | var checkout = jQuery(this).val(); |
| 31 | var ok = false; |
| 32 | |
| 33 | if (checkin == checkout) { |
| 34 | // first checkout available found, register chain value (link) |
| 35 | link = jQuery(this).data('link'); |
| 36 | ok = true; |
| 37 | } else if (link == jQuery(this).data('link')) { |
| 38 | // keep all next elements that belong to the same chain |
| 39 | ok = true; |
| 40 | count++; |
| 41 | } |
| 42 | |
| 43 | if (ok) { |
| 44 | html += '<option value="' + count + '">' + jQuery(this).data('checkout-date') + '</option>'; |
| 45 | |
| 46 | if (!selected) { |
| 47 | selected = count; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | }); |
| 52 | } |
| 53 | |
| 54 | if (!html || !{$autofill}) { |
| 55 | html = '<option></option>' + html; |
| 56 | } |
| 57 | |
| 58 | jQuery('#vap-checkout-sel').html(html); |
| 59 | jQuery('#vap-checkout-sel').prop('disabled', checkin.length ? false : true); |
| 60 | |
| 61 | if (selected && {$autofill}) { |
| 62 | jQuery('#vap-checkout-sel').select2('val', selected); |
| 63 | } else { |
| 64 | jQuery('#vap-checkout-sel').select2('val', ''); |
| 65 | } |
| 66 | |
| 67 | if (checkin) { |
| 68 | var option = jQuery(select).find('option:selected'); |
| 69 | vapTimeClicked(option.data('hour'), option.data('min'), 0); |
| 70 | |
| 71 | if (!document.{$formname}.duration_factor) { |
| 72 | jQuery('form[name="{$formname}"]').append('<input type="hidden" name="duration_factor" value="" />'); |
| 73 | } |
| 74 | |
| 75 | // use false to avoid triggering "checkout-changed" event |
| 76 | checkoutSelectValueChanged(jQuery('#vap-checkout-sel'), false); |
| 77 | } |
| 78 | |
| 79 | } |
| 80 | |
| 81 | function checkoutSelectValueChanged(select, trigger) { |
| 82 | document.{$formname}.duration_factor.value = jQuery(select).val(); |
| 83 | |
| 84 | if (trigger === undefined || trigger === true) { |
| 85 | jQuery(document).trigger('checkout-changed'); |
| 86 | } |
| 87 | } |
| 88 | JS |
| 89 | ; |
| 90 |