default.php
6 days ago
default_assoc.php
6 days ago
default_assoc_employees.php
6 days ago
default_assoc_employees_modal.php
6 days ago
default_assoc_options.php
6 days ago
default_assoc_options_modal.php
6 days ago
default_details.php
6 days ago
default_details_appearance.php
6 days ago
default_details_booking.php
6 days ago
default_details_capacity.php
6 days ago
default_details_publishing.php
6 days ago
default_details_service.php
6 days ago
default_details_settings.php
6 days ago
default_details_visibility.php
6 days ago
default_metadata.php
6 days ago
index.html
6 days ago
default_assoc_options.php
211 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 | $currency = VAPFactory::getCurrency(); |
| 15 | |
| 16 | $optLayout = new JLayoutFile('blocks.card'); |
| 17 | |
| 18 | ?> |
| 19 | |
| 20 | <div class="vap-cards-container cards-service-options" id="cards-service-options"> |
| 21 | |
| 22 | <!-- ADD PLACEHOLDER --> |
| 23 | |
| 24 | <div class="vap-card-fieldset up-to-1 add add-service-option"> |
| 25 | <div class="vap-card compress"> |
| 26 | <i class="fas fa-plus"></i> |
| 27 | </div> |
| 28 | </div> |
| 29 | |
| 30 | <?php |
| 31 | foreach ($this->service->options as $i => $option) |
| 32 | { |
| 33 | ?> |
| 34 | <div class="vap-card-fieldset up-to-1" id="service-option-fieldset-<?php echo $i; ?>" data-id="<?php echo $option->id_assoc; ?>" data-id-option="<?php echo $option->id; ?>"> |
| 35 | |
| 36 | <?php |
| 37 | $displayData = array(); |
| 38 | |
| 39 | // reduce card size |
| 40 | $displayData['class'] = 'compress'; |
| 41 | |
| 42 | if ($option->published) |
| 43 | { |
| 44 | $displayData['class'] .= ' published'; |
| 45 | |
| 46 | $icon = 'fas fa-check-circle'; |
| 47 | } |
| 48 | else |
| 49 | { |
| 50 | $icon = 'far fa-circle'; |
| 51 | } |
| 52 | |
| 53 | // fetch primary text |
| 54 | $displayData['primary'] = $option->name; |
| 55 | |
| 56 | // fetch badge |
| 57 | $displayData['badge'] = '<i class="' . $icon . '"></i>'; |
| 58 | |
| 59 | // fetch edit button |
| 60 | $displayData['edit'] = 'vapDeleteServiceOptionCard(\'' . $i . '\');'; |
| 61 | // use different text |
| 62 | $displayData['editText'] = JText::translate('VAPDELETE'); |
| 63 | // use custom class |
| 64 | $displayData['editClass'] = 'btn-danger'; |
| 65 | |
| 66 | // render layout |
| 67 | echo $optLayout->render($displayData); |
| 68 | ?> |
| 69 | |
| 70 | <input type="hidden" name="id_option_copy[]" value="<?php echo $option->id; ?>" /> |
| 71 | |
| 72 | </div> |
| 73 | <?php |
| 74 | } |
| 75 | ?> |
| 76 | |
| 77 | </div> |
| 78 | |
| 79 | <div style="display:none;" id="service-option-struct"> |
| 80 | |
| 81 | <?php |
| 82 | // create structure for records |
| 83 | $displayData = array(); |
| 84 | $displayData['class'] = 'compress'; |
| 85 | $displayData['badge'] = '<i class="far fa-circle"></i>'; |
| 86 | $displayData['primary'] = ''; |
| 87 | $displayData['secondary'] = ''; |
| 88 | $displayData['edit'] = true; |
| 89 | $displayData['editText'] = JText::translate('VAPDELETE'); |
| 90 | $displayData['editClass'] = 'btn-danger'; |
| 91 | |
| 92 | echo $optLayout->render($displayData); |
| 93 | ?> |
| 94 | |
| 95 | </div> |
| 96 | |
| 97 | <?php |
| 98 | JText::script('VAPSYSTEMCONFIRMATIONMSG'); |
| 99 | ?> |
| 100 | |
| 101 | <script> |
| 102 | var OPTIONS_COUNT = <?php echo count($this->service->options); ?>; |
| 103 | var SELECTED_OPTION = null; |
| 104 | |
| 105 | jQuery(function($) { |
| 106 | // open inspector for new options |
| 107 | $('.vap-card-fieldset.add-service-option').on('click', () => { |
| 108 | // open inspector |
| 109 | vapOpenInspector('service-options-inspector'); |
| 110 | }); |
| 111 | |
| 112 | // apply the changes |
| 113 | $('#service-options-inspector').on('inspector.show', function() { |
| 114 | let options = []; |
| 115 | |
| 116 | // load list of already selected options |
| 117 | $('[data-id-option]').each(function() { |
| 118 | options.push(parseInt($(this).attr('data-id-option'))); |
| 119 | }); |
| 120 | |
| 121 | fillServiceOptionsForm(options); |
| 122 | }); |
| 123 | |
| 124 | // apply the changes |
| 125 | $('#service-options-inspector').on('inspector.save', function() { |
| 126 | if (!optValidator.validate()) { |
| 127 | return false; |
| 128 | } |
| 129 | |
| 130 | // get saved record |
| 131 | var options = getServiceOptionsData(); |
| 132 | |
| 133 | options.forEach((option) => { |
| 134 | // create new card |
| 135 | let fieldset = vapAddServiceOptionCard(option); |
| 136 | |
| 137 | // refresh card details |
| 138 | vapRefreshServiceOptionCard(fieldset.find('.vap-card'), option); |
| 139 | }); |
| 140 | |
| 141 | // auto-close on save |
| 142 | $(this).inspector('dismiss'); |
| 143 | }); |
| 144 | }); |
| 145 | |
| 146 | function vapDeleteServiceOptionCard(index) { |
| 147 | // ask confirmation |
| 148 | if (!confirm(Joomla.JText._('VAPSYSTEMCONFIRMATIONMSG'))) { |
| 149 | return false; |
| 150 | } |
| 151 | |
| 152 | // get fieldset to delete |
| 153 | let fieldset = jQuery('#service-option-fieldset-' + index); |
| 154 | |
| 155 | // get database option ID |
| 156 | let id = fieldset.data('id'); |
| 157 | |
| 158 | if (id) { |
| 159 | // register option to delete |
| 160 | jQuery('#adminForm').append('<input type="hidden" name="option_deleted[]" value="' + id + '" />'); |
| 161 | } |
| 162 | |
| 163 | fieldset.remove(); |
| 164 | } |
| 165 | |
| 166 | function vapAddServiceOptionCard(data) { |
| 167 | let index = OPTIONS_COUNT++; |
| 168 | |
| 169 | SELECTED_OPTION = 'service-option-fieldset-' + index; |
| 170 | |
| 171 | var html = jQuery('#service-option-struct').clone().html(); |
| 172 | |
| 173 | html = html.replace(/{id}/, index); |
| 174 | |
| 175 | jQuery('#cards-service-options').append( |
| 176 | '<div class="vap-card-fieldset up-to-1" id="service-option-fieldset-' + index + '" data-id-option="' + data.id + '">' + html + '</div>' |
| 177 | ); |
| 178 | |
| 179 | // get created fieldset |
| 180 | let fieldset = jQuery('#' + SELECTED_OPTION); |
| 181 | |
| 182 | fieldset.vapcard('edit', 'vapDeleteServiceOptionCard(' + index + ')'); |
| 183 | |
| 184 | // create input to hold option ID |
| 185 | let input = jQuery('<input type="hidden" name="id_option[]" />').val(data.id); |
| 186 | |
| 187 | // append input to fieldset |
| 188 | fieldset.append(input); |
| 189 | |
| 190 | return fieldset; |
| 191 | } |
| 192 | |
| 193 | function vapRefreshServiceOptionCard(elem, data) { |
| 194 | // update badge |
| 195 | var icon; |
| 196 | |
| 197 | elem.vapcard('primary', data.name); |
| 198 | |
| 199 | if (parseInt(data.published) == 1) { |
| 200 | icon = 'fas fa-check-circle'; |
| 201 | elem.addClass('published'); |
| 202 | } else { |
| 203 | icon = 'far fa-circle'; |
| 204 | elem.removeClass('published'); |
| 205 | } |
| 206 | |
| 207 | elem.vapcard('badge', '<i class="' + icon + '"></i>'); |
| 208 | } |
| 209 | |
| 210 | </script> |
| 211 |