sampledata.php
144 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments - Libraries |
| 4 | * @subpackage html.wizard |
| 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 | /** |
| 15 | * Layout variables |
| 16 | * ----------------- |
| 17 | * @var VAPWizardStep $step The wizard step instance. |
| 18 | */ |
| 19 | extract($displayData); |
| 20 | |
| 21 | if ($step->isCompleted()) |
| 22 | { |
| 23 | return; |
| 24 | } |
| 25 | |
| 26 | $id = $step->getID(); |
| 27 | |
| 28 | // load supported sample data packages |
| 29 | $sampledata = $step->getSampleData(); |
| 30 | |
| 31 | $vik = VAPApplication::getInstance(); |
| 32 | |
| 33 | if ($sampledata) |
| 34 | { |
| 35 | JText::script('VAPSAVE'); |
| 36 | |
| 37 | ?> |
| 38 | <p> |
| 39 | <?php _e('Select one of the available sample data and proceed with the installation.', 'vikappointments'); ?> |
| 40 | </p> |
| 41 | |
| 42 | <div class="wizard-form"> |
| 43 | |
| 44 | <?php echo $vik->openControl(__('Sample Data')); ?> |
| 45 | <select name="wizard[<?php echo $id; ?>][sampledata]" class="required"> |
| 46 | <?php |
| 47 | $options = array(); |
| 48 | $options[] = JHtml::fetch('select.option', '', JText::translate('JGLOBAL_SELECT_AN_OPTION')); |
| 49 | |
| 50 | foreach ($sampledata as $sd) |
| 51 | { |
| 52 | $options[] = JHtml::fetch('select.option', $sd->id, $sd->title); |
| 53 | } |
| 54 | |
| 55 | echo JHtml::fetch('select.options', $options); |
| 56 | ?> |
| 57 | </select> |
| 58 | <?php echo $vik->closeControl(); ?> |
| 59 | |
| 60 | </div> |
| 61 | |
| 62 | <script> |
| 63 | (function($) { |
| 64 | 'use strict'; |
| 65 | |
| 66 | let progressInterval; |
| 67 | |
| 68 | VAPWizard.addPreflight('<?php echo $id; ?>', (role, step) => { |
| 69 | if (role != 'process') { |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | // create form validator |
| 74 | const validator = new VikFormValidator(step); |
| 75 | |
| 76 | // validate form |
| 77 | if (!validator.validate()) { |
| 78 | // prevent request |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | let savingText = wp.i18n.__('Saving'); |
| 83 | let stepButton = $(step).find('button[data-role="process"]'); |
| 84 | |
| 85 | // change text button to inform the user that the step is processing the request |
| 86 | stepButton.html(savingText + ' <i class="fas fa-hourglass-start"></i>'); |
| 87 | |
| 88 | let iter = 0; |
| 89 | |
| 90 | let icons = [ |
| 91 | 'fa-hourglass-start', |
| 92 | 'fa-hourglass-half', |
| 93 | 'fa-hourglass-end', |
| 94 | ]; |
| 95 | |
| 96 | // simulate progress |
| 97 | progressInterval = setInterval(() => { |
| 98 | iter = (iter + 1) % 3; |
| 99 | |
| 100 | stepButton.html(savingText + ' <i class="fas ' + icons[iter] + '"></i>'); |
| 101 | }, 512); |
| 102 | |
| 103 | // retrieve form data |
| 104 | let data = VAPWizard.getFormData('<?php echo $id; ?>', true); |
| 105 | |
| 106 | // inject argument to reload all steps |
| 107 | data.push({name: 'reload_all', value: true}); |
| 108 | |
| 109 | return $.param(data); |
| 110 | }); |
| 111 | |
| 112 | VAPWizard.addPostflight('<?php echo $id; ?>', (role, step) => { |
| 113 | clearInterval(progressInterval); |
| 114 | |
| 115 | // restore text button on both success and failure |
| 116 | $(step).find('button[data-role="process"]').text(Joomla.JText._('VAPSAVE')); |
| 117 | }); |
| 118 | |
| 119 | $(function() { |
| 120 | VikRenderer.chosen('[data-id="<?php echo $id; ?>"] select'); |
| 121 | }); |
| 122 | })(jQuery); |
| 123 | </script> |
| 124 | <?php |
| 125 | |
| 126 | echo $vik->alert(__('Notice that the installation of the sample data might restore the database to the factory settings. So, if you already created some records, you might lose them.', 'vikappointments')); |
| 127 | } |
| 128 | else |
| 129 | { |
| 130 | // no available sample data |
| 131 | echo $vik->alert(__('There are no sample data available for your version. Please try to update the plugin to the latest version.', 'vikappointments'), 'error'); |
| 132 | ?> |
| 133 | <script> |
| 134 | (function($) { |
| 135 | 'use strict'; |
| 136 | |
| 137 | $(function() { |
| 138 | $('[data-id="<?php echo $id; ?>"] button[data-role="process"]').hide(); |
| 139 | }); |
| 140 | })(jQuery); |
| 141 | </script> |
| 142 | <?php |
| 143 | } |
| 144 |