PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.20
VikAppointments Services Booking Calendar v1.2.20
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / views / caldays / tmpl / default_create_modal.php
vikappointments / admin / views / caldays / tmpl Last commit date
default.php 1 month ago default_calendar.php 1 month ago default_create_modal.php 1 month ago default_day.php 1 month ago default_filterbar.php 1 month ago default_modal.php 1 month ago default_sidebar.php 1 month ago index.html 1 month ago
default_create_modal.php
199 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 JHtml::fetch('vaphtml.assets.select2');
15
16 $vik = VAPApplication::getInstance();
17
18 ?>
19
20 <form action="index.php?option=com_vikappointments&task=reservation.add" method="post" id="newAppForm" class="inspector-form">
21
22 <div class="inspector-fieldset">
23
24 <!-- SERVICE - Select -->
25
26 <?php echo $vik->openControl(JText::translate('VAPMANAGERESERVATION4') . '*'); ?>
27 <select name="id_ser" id="vap-service-select">
28
29 </select>
30 <?php echo $vik->closeControl(); ?>
31
32 <!-- TIMELINE - Select -->
33
34 <?php echo $vik->openControl(JText::translate('VAPMANAGERESERVATION26') . '*'); ?>
35 <select id="vap-checkin-select">
36
37 </select>
38
39 <p id="vap-checkin-error" style="display: none; color: #b00;"></p>
40 <?php echo $vik->closeControl(); ?>
41
42 </div>
43
44 <input type="hidden" name="day" value="<?php echo JFactory::getDate($this->calendar->start)->format('Y-m-d'); ?>" />
45 <input type="hidden" name="id_emp" value="" />
46 <input type="hidden" name="hour" value="" />
47 <input type="hidden" name="min" value="" />
48
49 <input type="hidden" name="option" value="com_vikappointments" />
50 <input type="hidden" name="task" value="reservation.add" />
51 <input type="hidden" name="from" value="caldays" />
52
53 </form>
54
55 <?php
56 JText::script('VAPFINDRESNODAYEMPLOYEE');
57 ?>
58
59 <script>
60
61 jQuery(function($) {
62 $('button[data-role="reservation.create"]').on('click', function() {
63 // extract hour and minute
64 var hm = $('#vap-checkin-select').select2('val');
65
66 if (!hm) {
67 return false;
68 }
69
70 hm = hm.split(':');
71
72 var form = $('#newAppForm');
73
74 // inject hour and minute within the form
75 form.find('input[name="hour"]').val(hm[0]);
76 form.find('input[name="min"]').val(hm[1]);
77
78 form.submit();
79 });
80
81 $('#vap-service-select, #vap-checkin-select').select2({
82 allowClear: false,
83 width: 300,
84 });
85
86 $('#vap-service-select').on('change', function() {
87 let id_employee = $('#newAppForm').find('input[name="id_emp"]').val();
88 let id_service = $(this).val();
89 let time = $('#vap-checkin-select').val();
90
91 if (time) {
92 // fetch selected time in minutes format
93 time = time.split(':');
94
95 time = parseInt(time[0]) * 60 + parseInt(time[1]);
96 }
97
98 $('#vap-checkin-select').prop('disabled', true);
99
100 // load timeline
101 getEmployeeServiceTimeline(id_employee, id_service).then((timeline) => {
102 fillTimelineDropdown(timeline.timeline, time);
103 }).catch((error) => {
104 // something went wrong...
105 setTimelineError(error.responseText ? error.responseText : Joomla.JText._('VAPCONNECTIONLOSTERROR'));
106 });
107 });
108
109 });
110
111 function fillServicesDropdown(services, id_employee) {
112 // register employee ID
113 jQuery('#newAppForm').find('input[name="id_emp"]').val(id_employee);
114
115 // get select
116 var select = jQuery('#vap-service-select');
117
118 // reset options
119 var html = '';
120
121 // iterate services
122 for (var i = 0; i < services.length; i++) {
123 html += '<option value="' + services[i].id + '">' + services[i].name + '</option>\n';
124 }
125
126 // replace options
127 select.html(html);
128
129 // always select first value
130 select.select2('val', select.select2('val'));
131
132 // disable dropdown in case the employee doesn't own any services
133 select.prop('disabled', services.length == 0);
134
135 // disable check-in dropdown
136 jQuery('#vap-checkin-select').prop('disabled', true);
137
138 // get selected service
139 return select.select2('val');
140 }
141
142 function fillTimelineDropdown(timeline, value) {
143 // hide error
144 jQuery('#vap-checkin-error').hide().html('');
145
146 // reset options
147 var html = '';
148
149 var found = false;
150
151 // iterate timeline
152 for (var i = 0; i < timeline.length; i++) {
153 // scan minutes of working shift
154 timeline[i].forEach((time) => {
155 // create Date instance with check-in time
156 let dt = new Date(time.checkin);
157
158 let h = dt.getHours();
159 let m = dt.getMinutes();
160
161 // format time
162 var str = getFormattedTime(h, m, '<?php echo VAPFactory::getConfig()->get('timeformat'); ?>');
163
164 // build option
165 html += '<option value="' + h + ':' + m + '"' + (time.status != 1 ? ' disabled="disabled"' : '') + '>' + str + '</option>\n';
166
167 // find closest value
168 if (found === false && (h * 60 + m) >= value) {
169 found = h + ':' + m;
170 }
171 });
172 }
173
174 // get select
175 var select = jQuery('#vap-checkin-select');
176
177 // build options
178 select.prop('disabled', false).html(html);
179
180 if (found) {
181 // select value found
182 select.select2('val', found);
183 } else {
184 // select first value otherwise
185 select.select2('val', select.select2('val'));
186 }
187
188 if (!timeline.length) {
189 setTimelineError(Joomla.JText._('VAPFINDRESNODAYEMPLOYEE'));
190 }
191 }
192
193 function setTimelineError(error) {
194 jQuery('#vap-checkin-select').prop('disabled', true);
195 jQuery('#vap-checkin-error').html(error).show();
196 }
197
198 </script>
199