default.php
4 days ago
default_services.php
4 days ago
default_services_modal.php
4 days ago
index.html
4 days ago
default_services_modal.php
416 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 | $vik = VAPApplication::getInstance(); |
| 15 | |
| 16 | ?> |
| 17 | |
| 18 | <div class="inspector-form" id="inspector-service-employee-form"> |
| 19 | |
| 20 | <?php echo $vik->bootStartTabSet('serempassoc', array('active' => 'serempassoc_details')); ?> |
| 21 | |
| 22 | <?php echo $vik->bootAddTab('serempassoc', 'serempassoc_details', JText::translate('VAPCUSTFIELDSLEGEND1')); ?> |
| 23 | |
| 24 | <div class="inspector-fieldset"> |
| 25 | |
| 26 | <h3 id="service_name" style="display:none;"></h3> |
| 27 | |
| 28 | <!-- SERVICE - Select --> |
| 29 | |
| 30 | <?php |
| 31 | echo $vik->openControl(JText::translate('VAPMANAGEEMPLOYEE32') . '*', 'service-new'); |
| 32 | |
| 33 | // load services and group them |
| 34 | $options = JHtml::fetch('vaphtml.admin.services', $strict = false, $blank = '', $group = true); |
| 35 | |
| 36 | if ($options) |
| 37 | { |
| 38 | // create dropdown attributes |
| 39 | $params = array( |
| 40 | 'id' => 'vap-services-sel', |
| 41 | 'group.items' => null, |
| 42 | 'list.select' => null, |
| 43 | 'list.attr' => 'class="required"', |
| 44 | ); |
| 45 | |
| 46 | // render select |
| 47 | echo JHtml::fetch('select.groupedList', $options, '', $params); |
| 48 | } |
| 49 | else |
| 50 | { |
| 51 | // no available services |
| 52 | echo $vik->alert(JText::translate('JGLOBAL_NO_MATCHING_RESULTS')); |
| 53 | } |
| 54 | |
| 55 | echo $vik->closeControl(); |
| 56 | ?> |
| 57 | |
| 58 | <!-- USE GLOBAL --> |
| 59 | |
| 60 | <?php |
| 61 | $yes = $vik->initRadioElement('', JText::translate('JYES'), true, 'onclick="serviceGlobalValueChanged(1);"'); |
| 62 | $no = $vik->initRadioElement('', JText::translate('JNO'), false, 'onclick="serviceGlobalValueChanged(0);"'); |
| 63 | |
| 64 | $help = $vik->createPopover(array( |
| 65 | 'title' => JText::translate('VAPMANAGESERVICE40'), |
| 66 | 'content' => JText::translate('VAPMANAGESERVICE40_HELP'), |
| 67 | )); |
| 68 | |
| 69 | echo $vik->openControl(JText::translate('VAPMANAGESERVICE40') . $help); |
| 70 | echo $vik->radioYesNo('service_global', $yes, $no, false); |
| 71 | echo $vik->closeControl(); |
| 72 | ?> |
| 73 | |
| 74 | <!-- PRICE --> |
| 75 | |
| 76 | <?php echo $vik->openControl(JText::translate('VAPMANAGESERVICE5'), 'service-global-child', array('style' => 'display: none;')); ?> |
| 77 | <div class="input-prepend currency-field"> |
| 78 | <span class="btn"><?php echo VAPFactory::getCurrency()->getSymbol(); ?></span> |
| 79 | |
| 80 | <input type="number" id="service_rate" size="10" min="0" max="99999999" step="any" /> |
| 81 | </div> |
| 82 | <?php echo $vik->closeControl(); ?> |
| 83 | |
| 84 | <!-- DURATION --> |
| 85 | |
| 86 | <?php echo $vik->openControl(JText::translate('VAPMANAGESERVICE4'), 'service-global-child', array('style' => 'display: none;')); ?> |
| 87 | <div class="input-append"> |
| 88 | <input type="number" id="service_duration" size="10" min="1" max="99999999" /> |
| 89 | |
| 90 | <span class="btn"><?php echo JText::translate('VAPSHORTCUTMINUTE'); ?></span> |
| 91 | </div> |
| 92 | <?php echo $vik->closeControl(); ?> |
| 93 | |
| 94 | <!-- SLEEP --> |
| 95 | |
| 96 | <?php |
| 97 | $help = $vik->createPopover(array( |
| 98 | 'title' => JText::translate('VAPMANAGESERVICE19'), |
| 99 | 'content' => JText::translate('VAPMANAGESERVICE19_DESC'), |
| 100 | )); |
| 101 | |
| 102 | echo $vik->openControl(JText::translate('VAPMANAGESERVICE19') . $help, 'service-global-child', array('style' => 'display: none;')); ?> |
| 103 | <div class="input-append"> |
| 104 | <input type="number" id="service_sleep" size="10" min="-9999999" max="99999999" /> |
| 105 | |
| 106 | <span class="btn"><?php echo JText::translate('VAPSHORTCUTMINUTE'); ?></span> |
| 107 | </div> |
| 108 | <?php echo $vik->closeControl(); ?> |
| 109 | |
| 110 | <!-- MAX CAPACITY - Number --> |
| 111 | |
| 112 | <?php |
| 113 | $help = $vik->createPopover(array( |
| 114 | 'title' => JText::translate('VAPMANAGESERVICE21'), |
| 115 | 'content' => JText::translate('VAPMANAGESERVICE21_DESC'), |
| 116 | )); |
| 117 | |
| 118 | echo $vik->openControl(JText::translate('VAPMANAGESERVICE21') . $help, 'service-global-child', array('style' => 'display: none;')); ?> |
| 119 | <input type="number" id="service_max_capacity" size="10" min="1" max="999999" /> |
| 120 | <?php echo $vik->closeControl(); ?> |
| 121 | |
| 122 | <!-- DESCRIPTION --> |
| 123 | |
| 124 | <?php |
| 125 | $help = $vik->createPopover(array( |
| 126 | 'title' => JText::translate('VAPMANAGESERVICE3'), |
| 127 | 'content' => JText::translate('VAPDESCOVERRIDE_HELP'), |
| 128 | )); |
| 129 | |
| 130 | echo $vik->openControl(JText::translate('VAPMANAGESERVICE3') . $help, 'service-global-child', array('style' => 'display: none;')); |
| 131 | // wrap editor within a form in order to avoid TinyMCE errors |
| 132 | echo '<form>' . $vik->getEditor()->display('service_description', '', '100%', 550, 40, 20) . '</form>'; |
| 133 | echo $vik->closeControl(); |
| 134 | ?> |
| 135 | |
| 136 | <input type="hidden" id="service_id" value="0" /> |
| 137 | <input type="hidden" id="service_assoc_id" value="0" /> |
| 138 | |
| 139 | </div> |
| 140 | |
| 141 | <?php echo $vik->bootEndTab(); ?> |
| 142 | |
| 143 | <?php echo $vik->bootAddTab('serempassoc', 'serempassoc_import', JText::translate('VAPMANAGEEMPLOYEE33')); ?> |
| 144 | |
| 145 | <div class="inspector-fieldset"> |
| 146 | |
| 147 | <!-- DESCRIPTION --> |
| 148 | |
| 149 | <?php echo $vik->alert(JText::translate('VAPMANAGEEMPLOYEE33_DESC2'), 'info', false, ['style' => 'margin-top: 0;']); ?> |
| 150 | |
| 151 | <!-- URL --> |
| 152 | |
| 153 | <div> |
| 154 | <select id="service_ical_url_type"> |
| 155 | <?php |
| 156 | $options = [ |
| 157 | JHtml::fetch('select.option', 0, JText::translate('VAP_SELECT_USE_DEFAULT')), |
| 158 | JHtml::fetch('select.option', 1, JText::translate('VAPMANAGECONFIG97')), |
| 159 | ]; |
| 160 | |
| 161 | echo JHtml::fetch('select.options', $options); |
| 162 | ?> |
| 163 | </select> |
| 164 | </div> |
| 165 | |
| 166 | <div class="service_ical_url_type_1" style="display: none;"> |
| 167 | <input type="text" id="service_ical_url" placeholder="https://" style="margin-top: 10px;"/> |
| 168 | </div> |
| 169 | |
| 170 | </div> |
| 171 | |
| 172 | <?php echo $vik->bootEndTab(); ?> |
| 173 | |
| 174 | <?php echo $vik->bootEndTabSet(); ?> |
| 175 | |
| 176 | </div> |
| 177 | |
| 178 | <script> |
| 179 | |
| 180 | var serValidator = new VikFormValidator('#inspector-service-employee-form'); |
| 181 | |
| 182 | jQuery(function($) { |
| 183 | $('#vap-services-sel').select2({ |
| 184 | placeholder: '--', |
| 185 | allowClear: true, |
| 186 | width: '100%', |
| 187 | }); |
| 188 | |
| 189 | $('#service_ical_url_type').select2({ |
| 190 | allowClear: false, |
| 191 | width: '100%', |
| 192 | }).on('change', function() { |
| 193 | if ($(this).val() == 1) { |
| 194 | $('.service_ical_url_type_1').show(); |
| 195 | } else { |
| 196 | $('.service_ical_url_type_1').hide(); |
| 197 | } |
| 198 | }); |
| 199 | |
| 200 | // use default settings when service change |
| 201 | $('#vap-services-sel').on('change', function() { |
| 202 | let id_service = parseInt($(this).val()); |
| 203 | |
| 204 | resetServiceSettings(id_service); |
| 205 | }); |
| 206 | |
| 207 | $('#adminForm').on('submit', () => { |
| 208 | const editor = Joomla.editors.instances.service_description; |
| 209 | |
| 210 | if (editor.onSave) { |
| 211 | editor.onSave(); |
| 212 | } |
| 213 | }); |
| 214 | }); |
| 215 | |
| 216 | function fillServiceEmployeesForm(data) { |
| 217 | let select = jQuery('#vap-services-sel'); |
| 218 | |
| 219 | // clear selection |
| 220 | select.select2('val', []); |
| 221 | |
| 222 | if (Array.isArray(data)) { |
| 223 | // iterate all services inside select and fetch their status |
| 224 | select.find('option').each(function() { |
| 225 | let id = parseInt(jQuery(this).val()); |
| 226 | |
| 227 | jQuery(this).prop('disabled', data.indexOf(id) !== -1); |
| 228 | }); |
| 229 | |
| 230 | // clear hidden input with service ID |
| 231 | jQuery('#service_id').val(0); |
| 232 | |
| 233 | // hide service name |
| 234 | jQuery('#service_name').hide().html(''); |
| 235 | |
| 236 | // show service selection |
| 237 | jQuery('.service-new').show(); |
| 238 | |
| 239 | // service selection is required |
| 240 | serValidator.registerFields(select); |
| 241 | |
| 242 | // clear data |
| 243 | data = {}; |
| 244 | } else { |
| 245 | // set current service ID |
| 246 | jQuery('#service_id').val(data.id_service); |
| 247 | |
| 248 | // set service name |
| 249 | jQuery('#service_name').html(data.name).show(); |
| 250 | |
| 251 | // hide service selection |
| 252 | jQuery('.service-new').hide(); |
| 253 | |
| 254 | // service selection is not required |
| 255 | serValidator.unregisterFields(select); |
| 256 | } |
| 257 | |
| 258 | // set assoc ID |
| 259 | jQuery('#service_assoc_id').val(data.id ? data.id : 0); |
| 260 | |
| 261 | // set global status |
| 262 | var globalInput = jQuery('input[name="service_global"]'); |
| 263 | |
| 264 | if (data.global === undefined) { |
| 265 | data.global = 1; |
| 266 | } else { |
| 267 | data.global = parseInt(data.global); |
| 268 | } |
| 269 | |
| 270 | if (globalInput.attr('type') == 'checkbox') { |
| 271 | globalInput.prop('checked', data.global); |
| 272 | } else { |
| 273 | globalInput.val(data.global ? 1 : 0); |
| 274 | } |
| 275 | |
| 276 | serviceGlobalValueChanged(data.global); |
| 277 | |
| 278 | // set price |
| 279 | if (data.rate === undefined) { |
| 280 | data.rate = 0; |
| 281 | } |
| 282 | |
| 283 | jQuery('#service_rate').val(data.rate); |
| 284 | |
| 285 | // set duration |
| 286 | if (data.duration === undefined) { |
| 287 | data.duration = 0; |
| 288 | } |
| 289 | |
| 290 | jQuery('#service_duration').val(data.duration); |
| 291 | |
| 292 | // set sleep |
| 293 | if (data.sleep === undefined) { |
| 294 | data.sleep = 0; |
| 295 | } |
| 296 | |
| 297 | jQuery('#service_sleep').val(data.sleep); |
| 298 | |
| 299 | // set max capacity |
| 300 | if (data.max_capacity === undefined) { |
| 301 | data.max_capacity = 1; |
| 302 | } |
| 303 | |
| 304 | jQuery('#service_max_capacity').val(data.max_capacity); |
| 305 | |
| 306 | // set description |
| 307 | Joomla.editors.instances.service_description.setValue(data.description ? data.description : ''); |
| 308 | |
| 309 | // set ical url |
| 310 | if (data.ical_url === undefined) { |
| 311 | data.ical_url = ''; |
| 312 | } |
| 313 | |
| 314 | jQuery('#service_ical_url').val(data.ical_url); |
| 315 | jQuery('#service_ical_url_type').select2('val', data.ical_url ? 1 : 0).trigger('change'); |
| 316 | } |
| 317 | |
| 318 | function getServiceEmployeesData() { |
| 319 | let service = extractServiceEmployeeData(); |
| 320 | |
| 321 | let select = jQuery('#vap-services-sel'); |
| 322 | |
| 323 | let id_service = select.select2('val'); |
| 324 | |
| 325 | if (id_service) { |
| 326 | // get selected option |
| 327 | let option = select.find('option[value="' + id_service + '"]'); |
| 328 | |
| 329 | // create service |
| 330 | Object.assign(service, { |
| 331 | id: 0, |
| 332 | id_service: parseInt(id_service), |
| 333 | name: option.text(), |
| 334 | }); |
| 335 | } else { |
| 336 | // update existing service |
| 337 | service.id = parseInt(jQuery('#service_assoc_id').val()); |
| 338 | |
| 339 | service.id_service = parseInt(jQuery('#service_id').val()); |
| 340 | |
| 341 | // get name from head |
| 342 | service.name = jQuery('#service_name').html(); |
| 343 | } |
| 344 | |
| 345 | return service; |
| 346 | } |
| 347 | |
| 348 | function extractServiceEmployeeData() { |
| 349 | let data = {}; |
| 350 | |
| 351 | // get global value |
| 352 | if (jQuery('input[name="service_global"]').attr('type') == 'checkbox') { |
| 353 | data.global = jQuery('input[name="service_global"]').is(':checked') ? 1 : 0; |
| 354 | } else { |
| 355 | data.global = parseInt(jQuery('input[name="service_global"]').val()); |
| 356 | } |
| 357 | |
| 358 | // get rate |
| 359 | data.rate = parseFloat(jQuery('#service_rate').val()); |
| 360 | |
| 361 | // get duration |
| 362 | data.duration = parseInt(jQuery('#service_duration').val()); |
| 363 | |
| 364 | // get sleep |
| 365 | data.sleep = parseInt(jQuery('#service_sleep').val()); |
| 366 | |
| 367 | // get max capacity |
| 368 | data.max_capacity = parseInt(jQuery('#service_max_capacity').val()); |
| 369 | |
| 370 | // get description |
| 371 | data.description = Joomla.editors.instances.service_description.getValue(); |
| 372 | |
| 373 | // get ical url |
| 374 | if (jQuery('#service_ical_url_type').val() == 1) { |
| 375 | data.ical_url = jQuery('#service_ical_url').val(); |
| 376 | } else { |
| 377 | data.ical_url = ''; |
| 378 | } |
| 379 | |
| 380 | return data; |
| 381 | } |
| 382 | |
| 383 | function resetServiceSettings(id) { |
| 384 | if (!SERVICES_LOOKUP.hasOwnProperty(id)) { |
| 385 | return false; |
| 386 | } |
| 387 | |
| 388 | let service = SERVICES_LOOKUP[id]; |
| 389 | |
| 390 | jQuery('#service_rate').val(service.price); |
| 391 | jQuery('#service_duration').val(service.duration); |
| 392 | jQuery('#service_sleep').val(service.sleep); |
| 393 | jQuery('#service_max_capacity').val(service.max_capacity); |
| 394 | } |
| 395 | |
| 396 | function serviceGlobalValueChanged(is) { |
| 397 | if (is) { |
| 398 | jQuery('.service-global-child').hide(); |
| 399 | |
| 400 | // get selected service |
| 401 | let id_service = jQuery('#vap-services-sel').val(); |
| 402 | |
| 403 | if (!id_service) { |
| 404 | // get registered service |
| 405 | id_service = jQuery('#service_id').val(); |
| 406 | } |
| 407 | |
| 408 | // reset settings to service values |
| 409 | resetServiceSettings(parseInt(id_service)); |
| 410 | } else { |
| 411 | jQuery('.service-global-child').show(); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | </script> |
| 416 |