PluginProbe
VikBooking Hotel Booking Engine & PMS / trunk
VikBooking Hotel Booking Engine & PMS vtrunk
1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 All 36 releases
vikbooking / admin / views / backups / tmpl / default_modal.php

default_modal.php in VikBooking Hotel Booking Engine & PMS trunk, at admin/views/backups/tmpl/default_modal.php

268 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
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 ?>
15
16 <div style="padding: 10px;">
17
18 <div class="vbo-admin-container vbo-params-container-wide">
19
20 <div class="vbo-params-container">
21
22 <!-- ACTION - Select -->
23
24 <div class="vbo-param-container">
25 <div class="vbo-param-label"><?php echo JText::translate('VBO_BACKUP_ACTION_LABEL'); ?> <sup>*</sup></div>
26 <div class="vbo-param-setting">
27 <select name="action" id="vbo-create-action-sel">
28 <?php
29 $options = [
30 JHtml::fetch('select.option', 'create', JText::translate('VBO_BACKUP_ACTION_CREATE')),
31 JHtml::fetch('select.option', 'upload', JText::translate('VBO_BACKUP_ACTION_UPLOAD')),
32 ];
33
34 echo JHtml::fetch('select.options', $options);
35 ?>
36 </select>
37 </div>
38 </div>
39
40 <!-- TYPE - Select -->
41
42 <div class="vbo-param-container backup-action-create">
43 <div class="vbo-param-label"><?php echo JText::translate('VBO_CONFIG_BACKUP_TYPE'); ?> <sup>*</sup></div>
44 <div class="vbo-param-setting">
45 <select name="type" id="vbo-create-type-sel">
46 <?php
47 $options = [];
48
49 foreach ($this->exportTypes as $id => $type)
50 {
51 $options[] = JHtml::fetch('select.option', $id, $type->getName());
52 }
53
54 echo JHtml::fetch('select.options', $options, 'value', 'text', VBOFactory::getConfig()->get('backuptype'));
55 ?>
56 </select>
57 </div>
58 </div>
59
60 <div class="backup-action-upload" style="display: none;">
61 <div class="vbo-dropfiles-target" style="position: relative;">
62 <p class="icon">
63 <i class="fas fa-upload" style="font-size: 48px;"></i>
64 </p>
65
66 <div class="lead">
67 <a href="javascript: void(0);" id="upload-file"><?php echo JText::translate('VBOMANUALUPLOAD'); ?></a>&nbsp;<?php echo JText::translate('VBODROPFILES'); ?>
68 </div>
69
70 <p class="maxsize">
71 <?php echo JText::sprintf('JGLOBAL_MAXIMUM_UPLOAD_SIZE_LIMIT', JHtml::fetch('vikbooking.maxuploadsize')); ?>
72 </p>
73
74 <input type="file" id="legacy-upload" multiple style="display: none;"/>
75
76 <div class="vbo-selected-archives" style="position: absolute; bottom: 6px; left: 6px; display: none;">
77
78 </div>
79
80 <div class="vbo-upload-progress" style="position: absolute; bottom: 6px; right: 6px; display: flex; visibility: hidden;">
81 <progress value="0" max="100">0%</progress>
82 </div>
83 </div>
84 </div>
85
86 </div>
87
88 </div>
89
90 </div>
91
92 <script>
93 (function($) {
94 'use strict';
95
96 let dragCounter = 0;
97 let file = 0;
98
99 const addFile = (files) => {
100 const bar = $('.vbo-selected-archives');
101
102 if (files && files.length) {
103 file = files[0];
104 const badge = $('<span class="badge badge-info"></span>').text(file.name);
105 bar.html(badge).show();
106 } else {
107 file = null;
108 bar.hide().html('');
109 }
110 }
111
112 const fileUpload = (formData, progressCallback) => {
113 return new Promise((resolve, reject) => {
114 $.ajax({
115 xhr: () => {
116 let xhrobj = $.ajaxSettings.xhr();
117 if (xhrobj.upload) {
118 xhrobj.upload.addEventListener('progress', (event) => {
119 let percent = 0;
120 let position = event.loaded || event.position;
121 let total = event.total;
122 if (event.lengthComputable) {
123 percent = Math.ceil(position / total * 100);
124 }
125
126 if (progressCallback) {
127 progressCallback(percent);
128 }
129 }, false);
130 }
131 return xhrobj;
132 },
133 url: '<?php echo VBOFactory::getPlatform()->getUri()->ajax('index.php?option=com_vikbooking&task=backup.save'); ?>',
134 type: 'POST',
135 contentType: false,
136 processData: false,
137 cache: false,
138 data: formData,
139 success: (resp) => {
140 resolve(resp);
141 },
142 error: (err) => {
143 reject(err);
144 },
145 });
146 });
147 }
148
149 const openLoadingOverlay = () => {
150 $('body').append('<div class="vbo-info-overlay-block" style="display:block;"><div class="vbo-info-overlay-loading" style="display:block;"><?php VikBookingIcons::e('circle-notch', 'fa-spin fa-fw fa-3x'); ?></div></div>');
151 }
152
153 const closeLoadingOverlay = () => {
154 $('.vbo-info-overlay-block').remove();
155 }
156
157 const saveBackup = (btn) => {
158 const formData = new FormData();
159
160 const action = $('#vbo-create-action-sel').val();
161 formData.append('ajax', 1);
162 formData.append('backup_action', action);
163
164 if (action === 'create') {
165 formData.append('type', $('#vbo-create-type-sel').val());
166 } else {
167 formData.append('file', file);
168 }
169
170 const progressBox = $('.vbo-upload-progress');
171 progressBox.css('visibility', 'visible');
172
173 $(btn).prop('disabled', true);
174
175 fileUpload(formData, (progress) => {
176 // update progress
177 progressBox.find('progress').val(progress).text(progress + '%');
178
179 if (progress >= 100) {
180 // Open loading overlay when reaching the 100% progress.
181 // In case of export, the overlay should immediately appear.
182 // In case of import, the overlay should appear after completing the upload
183 // of the backup file, meaning that the system still have to decompress the
184 // archive and perform all the registered rules. It's ok for us because the
185 // upload status is already tracked by the apposite progress bar.
186 openLoadingOverlay();
187 }
188 }).then((data) => {
189 // auto-close the modal
190 vboCloseJModal('newbackup');
191
192 // then schedule an auto-refresh
193 setTimeout(() => {
194 document.adminForm.submit();
195 }, 1000);
196 }).catch((error) => {
197 $(btn).prop('disabled', false);
198
199 progressBox.css('visibility', 'hidden');
200
201 // delay alert to properly close the overlay first
202 setTimeout(() => {
203 alert(error.responseText || 'Error');
204 }, 128);
205 }).finally(() => {
206 // close overlay at the end of the process
207 closeLoadingOverlay();
208 });
209 }
210
211 $(function() {
212 $('#vbo-create-action-sel').on('change', function() {
213 if ($(this).val() === 'create') {
214 $('.backup-action-upload').hide();
215 $('.backup-action-create').show();
216 } else {
217 $('.backup-action-create').hide();
218 $('.backup-action-upload').show();
219 }
220 });
221
222 // drag&drop actions on target div
223
224 $('.vbo-dropfiles-target').on('drag dragstart dragend dragover dragenter dragleave drop', (e) => {
225 e.preventDefault();
226 e.stopPropagation();
227 });
228
229 $('.vbo-dropfiles-target').on('dragenter', function(e) {
230 // increase the drag counter because we may
231 // enter into a child element
232 dragCounter++;
233
234 $(this).addClass('drag-enter');
235 });
236
237 $('.vbo-dropfiles-target').on('dragleave', function(e) {
238 // decrease the drag counter to check if we
239 // left the main container
240 dragCounter--;
241
242 if (dragCounter <= 0) {
243 $(this).removeClass('drag-enter');
244 }
245 });
246
247 $('.vbo-dropfiles-target').on('drop', function(e) {
248 $(this).removeClass('drag-enter');
249
250 addFile(e.originalEvent.dataTransfer.files);
251 });
252
253 $('.vbo-dropfiles-target #upload-file').on('click', function() {
254 // unset selected files before showing the dialog
255 $('input#legacy-upload').val(null).trigger('click');
256 });
257
258 $('input#legacy-upload').on('change', function() {
259 addFile($(this)[0].files);
260 });
261
262 $('button[data-role="backup.save"]').on('click', function() {
263 saveBackup(this);
264 });
265 });
266 })(jQuery);
267 </script>
268