default.php
| 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 | $state = $this->state; |
| 15 | |
| 16 | $vik = VAPApplication::getInstance(); |
| 17 | |
| 18 | /** |
| 19 | * Trigger event to display custom HTML. |
| 20 | * In case it is needed to include any additional fields, |
| 21 | * it is possible to create a plugin and attach it to an event |
| 22 | * called "onDisplayViewState". The event method receives the |
| 23 | * view instance as argument. |
| 24 | * |
| 25 | * @since 1.7 |
| 26 | */ |
| 27 | $forms = $this->onDisplayView(); |
| 28 | |
| 29 | if ($this->isTmpl) |
| 30 | { |
| 31 | // we are in a modal box, add some padding |
| 32 | JFactory::getDocument()->addStyleDeclaration('#adminForm { padding: 10px; }'); |
| 33 | JHtml::fetch('behavior.core'); |
| 34 | } |
| 35 | |
| 36 | ?> |
| 37 | |
| 38 | <form name="adminForm" action="index.php" method="post" id="adminForm" class="managestate"> |
| 39 | |
| 40 | <?php |
| 41 | if ($this->isTmpl) |
| 42 | { |
| 43 | ?> |
| 44 | <div class="btn-toolbar" style="display:none;"> |
| 45 | <div class="btn-group pull-left"> |
| 46 | <button type="button" class="btn btn-success" name="tmplSaveButton" onclick="vapValidateFieldsAndDisableButton(this);"> |
| 47 | <i class="icon-apply"></i> <?php echo JText::translate('VAPSAVE'); ?> |
| 48 | </button> |
| 49 | </div> |
| 50 | </div> |
| 51 | <?php |
| 52 | } |
| 53 | ?> |
| 54 | |
| 55 | <?php echo $vik->openCard(); ?> |
| 56 | |
| 57 | <div class="<?php echo $forms ? 'span6' : 'span12'; ?>"> |
| 58 | <?php echo $vik->openEmptyFieldset(); ?> |
| 59 | |
| 60 | <!-- STATE NAME - Text --> |
| 61 | |
| 62 | <?php echo $vik->openControl(JText::translate('VAPMANAGESTATE1') . '*'); ?> |
| 63 | <input type="text" name="state_name" class="input-xxlarge input-large-text required" value="<?php echo $state->state_name; ?>" size="40" /> |
| 64 | <?php echo $vik->closeControl(); ?> |
| 65 | |
| 66 | <!-- STATE 2 CODE - Text --> |
| 67 | |
| 68 | <?php echo $vik->openControl(JText::translate('VAPMANAGESTATE2') . '*'); ?> |
| 69 | <input type="text" name="state_2_code" class="required" value="<?php echo $state->state_2_code; ?>" size="20" maxlength="2" /> |
| 70 | <?php echo $vik->closeControl(); ?> |
| 71 | |
| 72 | <!-- STATE 3 CODE - Text --> |
| 73 | |
| 74 | <?php echo $vik->openControl(JText::translate('VAPMANAGESTATE3')); ?> |
| 75 | <input type="text" name="state_3_code" value="<?php echo $state->state_3_code; ?>" size="20" maxlength="3" /> |
| 76 | <?php echo $vik->closeControl(); ?> |
| 77 | |
| 78 | <!-- PUBLISHED - Checkbox --> |
| 79 | |
| 80 | <?php |
| 81 | $yes = $vik->initRadioElement('', '', $state->published == 1); |
| 82 | $no = $vik->initRadioElement('', '', $state->published == 0); |
| 83 | |
| 84 | echo $vik->openControl(JText::translate('VAPMANAGESTATE4')); |
| 85 | echo $vik->radioYesNo('published', $yes, $no, false); |
| 86 | echo $vik->closeControl(); |
| 87 | ?> |
| 88 | |
| 89 | <!-- Define role to detect the supported hook --> |
| 90 | <!-- {"rule":"customizer","event":"onDisplayViewState","key":"state","type":"field"} --> |
| 91 | |
| 92 | <?php |
| 93 | /** |
| 94 | * Look for any additional fields to be pushed within |
| 95 | * the "Details" fieldset (left-side). |
| 96 | * |
| 97 | * @since 1.7 |
| 98 | */ |
| 99 | if (isset($forms['state'])) |
| 100 | { |
| 101 | echo $forms['state']; |
| 102 | |
| 103 | // unset details form to avoid displaying it twice |
| 104 | unset($forms['state']); |
| 105 | } |
| 106 | ?> |
| 107 | |
| 108 | <?php echo $vik->closeEmptyFieldset(); ?> |
| 109 | </div> |
| 110 | |
| 111 | <!-- Define role to detect the supported hook --> |
| 112 | <!-- {"rule":"customizer","event":"onDisplayViewState","type":"fieldset"} --> |
| 113 | |
| 114 | <?php |
| 115 | if ($forms) |
| 116 | { |
| 117 | ?> |
| 118 | <div class="span6 full-width"> |
| 119 | <?php |
| 120 | /** |
| 121 | * Iterate remaining forms to be displayed within |
| 122 | * the sidebar. |
| 123 | * |
| 124 | * @since 1.7 |
| 125 | */ |
| 126 | foreach ($forms as $formName => $formHtml) |
| 127 | { |
| 128 | $title = JText::translate($formName); |
| 129 | ?> |
| 130 | <div class="row-fluid"> |
| 131 | <div class="span12"> |
| 132 | <?php |
| 133 | echo $vik->openFieldset($title); |
| 134 | echo $formHtml; |
| 135 | echo $vik->closeFieldset(); |
| 136 | ?> |
| 137 | </div> |
| 138 | </div> |
| 139 | <?php |
| 140 | } |
| 141 | ?> |
| 142 | </div> |
| 143 | <?php |
| 144 | } |
| 145 | ?> |
| 146 | |
| 147 | <?php echo $vik->closeCard(); ?> |
| 148 | |
| 149 | <?php echo JHtml::fetch('form.token'); ?> |
| 150 | |
| 151 | <?php |
| 152 | if ($this->isTmpl) |
| 153 | { |
| 154 | ?> |
| 155 | <input type="hidden" name="tmpl" value="component" /> |
| 156 | <?php |
| 157 | } |
| 158 | ?> |
| 159 | |
| 160 | <input type="hidden" name="id" value="<?php echo $state->id; ?>" /> |
| 161 | <input type="hidden" name="task" value="" /> |
| 162 | <input type="hidden" name="option" value="com_vikappointments" /> |
| 163 | <input type="hidden" name="id_country" value="<?php echo $state->id_country; ?>" /> |
| 164 | </form> |
| 165 | |
| 166 | <script> |
| 167 | |
| 168 | // validate |
| 169 | |
| 170 | var validator = new VikFormValidator('#adminForm'); |
| 171 | |
| 172 | Joomla.submitbutton = function(task) { |
| 173 | // check if we clicked a "save" button and the form is not valid |
| 174 | if (task.indexOf('save') !== -1 && !validator.validate()) { |
| 175 | // abort request |
| 176 | return false; |
| 177 | } |
| 178 | |
| 179 | // submit form |
| 180 | Joomla.submitform(task, document.adminForm); |
| 181 | return true; |
| 182 | } |
| 183 | |
| 184 | <?php |
| 185 | if ($this->isTmpl) |
| 186 | { |
| 187 | ?> |
| 188 | function vapValidateFieldsAndDisableButton(button) { |
| 189 | if (jQuery(button).prop('disabled')) { |
| 190 | // button already submitted |
| 191 | return false; |
| 192 | } |
| 193 | |
| 194 | // disable button |
| 195 | jQuery(button).prop('disabled', true); |
| 196 | |
| 197 | // submit form |
| 198 | if (Joomla.submitbutton('state.save') === false) { |
| 199 | // invalid fields, enable button again |
| 200 | jQuery(button).prop('disabled', false); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | // transfer submit button instance to parent for being clicked |
| 205 | window.parent.modalStateSaveButton = document.adminForm.tmplSaveButton; |
| 206 | |
| 207 | // transfer created ID to parent |
| 208 | window.parent.modalSavedStateData = <?php echo $this->state->id > 0 ? json_encode($this->state) : 0; ?>; |
| 209 | <?php |
| 210 | } |
| 211 | ?> |
| 212 | |
| 213 | </script> |
| 214 |