default.php
6 days ago
default_details.php
6 days ago
default_details_calendar.php
6 days ago
default_details_calendar_modal.php
6 days ago
default_details_contact.php
6 days ago
default_details_employee.php
6 days ago
default_details_notifications.php
6 days ago
default_details_visibility.php
6 days ago
default_fields.php
6 days ago
default_workdays.php
6 days ago
default_workdays_import.php
6 days ago
default_workdays_import_sample.php
6 days ago
default_workdays_import_upload.php
6 days ago
default_workdays_modal.php
6 days ago
index.html
6 days ago
default_workdays_import_upload.php
308 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="vap-media-droptarget" id="worktime-upload-box" style="position: relative;"> |
| 19 | <p class="icon"> |
| 20 | <i class="fas fa-upload" style="font-size: 48px;"></i> |
| 21 | </p> |
| 22 | |
| 23 | <div class="lead"> |
| 24 | <a href="javascript: void(0);" id="worktime-upload-file"><?php echo JText::translate('VAPMANUALUPLOAD'); ?></a> <?php echo JText::translate('VAPFILEDRAGDROP'); ?> |
| 25 | </div> |
| 26 | |
| 27 | <p class="maxsize"> |
| 28 | <?php echo JText::sprintf('JGLOBAL_MAXIMUM_UPLOAD_SIZE_LIMIT', JHtml::fetch('vikappointments.maxuploadsize')); ?> |
| 29 | </p> |
| 30 | |
| 31 | <input type="file" id="worktime-legacy-upload" multiple style="display: none;"/> |
| 32 | |
| 33 | <div class="vap-upload-progress" style="position: absolute; bottom: 6px; right: 6px; display: flex; visibility: hidden;"> |
| 34 | <progress value="0" max="100">0%</progress> |
| 35 | </div> |
| 36 | </div> |
| 37 | |
| 38 | <div class="worktime-import-preview" style="display: none;"> |
| 39 | |
| 40 | </div> |
| 41 | |
| 42 | <?php |
| 43 | JText::script('VAPMANAGEWD5'); |
| 44 | JText::script('VAP_WORKTIME_IMPORT_DISABLED_WHY'); |
| 45 | JText::script('VAPCONNECTIONLOSTERROR'); |
| 46 | ?> |
| 47 | |
| 48 | <script> |
| 49 | (function($) { |
| 50 | 'use strict'; |
| 51 | |
| 52 | let dragCounter = 0; |
| 53 | let importData = null; |
| 54 | |
| 55 | const fetchPreview = (file) => { |
| 56 | const progressBox = $('#worktime-upload-box.vap-media-droptarget .vap-upload-progress'); |
| 57 | |
| 58 | importData = null; |
| 59 | |
| 60 | doUpload(file, {layout: 'preview'}, progressBox).then((data) => { |
| 61 | importData = data; |
| 62 | |
| 63 | let ul = $('<ul></ul>'); |
| 64 | |
| 65 | for (let k in data) { |
| 66 | if (!data.hasOwnProperty(k)) { |
| 67 | continue; |
| 68 | } |
| 69 | |
| 70 | let alreadyExists = $('#spday-fieldset-' + importData[k].ymd).length; |
| 71 | |
| 72 | let dateLi = $('<li class="wd-date"></li>'); |
| 73 | |
| 74 | let checkboxDate = $('<input type="checkbox" value="1" checked />'); |
| 75 | checkboxDate.attr('id', 'wd_import_' + k); |
| 76 | |
| 77 | let labelDate = $('<label class="vap-disable-selection"></label>') |
| 78 | .text(k) |
| 79 | .attr('for', 'wd_import_' + k); |
| 80 | |
| 81 | if (alreadyExists) { |
| 82 | checkboxDate.prop('disabled', true); |
| 83 | |
| 84 | labelDate.attr('title', Joomla.JText._('VAP_WORKTIME_IMPORT_DISABLED_WHY')); |
| 85 | labelDate.addClass('hasTooltip'); |
| 86 | } |
| 87 | |
| 88 | dateLi.append(checkboxDate); |
| 89 | dateLi.append(labelDate); |
| 90 | |
| 91 | if (data[k].times.length) { |
| 92 | // open |
| 93 | dateLi.append( |
| 94 | $('<i class="fas fa-check-circle ok hasTooltip"></i>') |
| 95 | .attr('title', Joomla.JText._('VAPMANAGEWD5')) |
| 96 | ); |
| 97 | |
| 98 | let dateLiUl = $('<ul></ul>'); |
| 99 | |
| 100 | data[k].times.forEach((time, index) => { |
| 101 | let timeLi = $('<li class="wd-time"></li>'); |
| 102 | |
| 103 | let checkboxTime = $('<input type="checkbox" value="1" checked />'); |
| 104 | checkboxTime.attr('id', 'wd_import_' + k + '_' + index); |
| 105 | |
| 106 | if (alreadyExists) { |
| 107 | checkboxTime.prop('disabled', true); |
| 108 | } |
| 109 | |
| 110 | timeLi.append(checkboxTime); |
| 111 | timeLi.append( |
| 112 | $('<label class="vap-disable-selection"></label>') |
| 113 | .text(time.fromTime + ' - ' + time.toTime) |
| 114 | .attr('for', 'wd_import_' + k + '_' + index) |
| 115 | ); |
| 116 | |
| 117 | dateLiUl.append(timeLi); |
| 118 | }); |
| 119 | |
| 120 | dateLi.append(dateLiUl); |
| 121 | } else { |
| 122 | // closed |
| 123 | dateLi.append( |
| 124 | $('<i class="fas fa-dot-circle no hasTooltip"></i>') |
| 125 | .attr('title', Joomla.JText._('VAPMANAGEEMPLOYEE22')) |
| 126 | ); |
| 127 | } |
| 128 | |
| 129 | ul.append(dateLi); |
| 130 | } |
| 131 | |
| 132 | ul.find('.hasTooltip').tooltip({ |
| 133 | container: 'body', |
| 134 | }); |
| 135 | |
| 136 | $('#worktime-upload-box').hide(); |
| 137 | $('.worktime-import-preview').html(ul).show(); |
| 138 | |
| 139 | $('#wdimport-save').prop('disabled', false); |
| 140 | }); |
| 141 | } |
| 142 | |
| 143 | const execImport = () => { |
| 144 | if (!importData) { |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | for (let k in importData) { |
| 149 | if (!importData.hasOwnProperty(k)) { |
| 150 | continue; |
| 151 | } |
| 152 | |
| 153 | if ($('#spday-fieldset-' + importData[k].ymd).length) { |
| 154 | // fieldset already exists, avoid overwrite |
| 155 | continue; |
| 156 | } |
| 157 | |
| 158 | if (!$('input[id="wd_import_' + k + '"]').is(':checked')) { |
| 159 | // working date ignored |
| 160 | continue; |
| 161 | } |
| 162 | |
| 163 | let json = []; |
| 164 | |
| 165 | if (importData[k].times.length === 0) { |
| 166 | importData[k].times.push({ |
| 167 | closed: 1, |
| 168 | fromts: 0, |
| 169 | endts: 0, |
| 170 | }); |
| 171 | } |
| 172 | |
| 173 | importData[k].times.forEach((time, index) => { |
| 174 | let checkbox = $('input[id="wd_import_' + k + '_' + index + '"]'); |
| 175 | |
| 176 | if (!checkbox.length || checkbox.is(':checked')) { |
| 177 | json.push({ |
| 178 | id: 0, |
| 179 | closed: time.closed, |
| 180 | from: time.fromts, |
| 181 | to: time.endts, |
| 182 | date: importData[k].date, |
| 183 | ymd: importData[k].ymd, |
| 184 | }); |
| 185 | } |
| 186 | }); |
| 187 | |
| 188 | if (json.length) { |
| 189 | let fieldset = vapAddSpecialDayCard(json); |
| 190 | vapRefreshWorkingDayCard(fieldset, json); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | vapCloseJModal('wdimport'); |
| 195 | } |
| 196 | |
| 197 | const doUpload = (file, request, progressBox) => { |
| 198 | return new Promise((resolve, reject) => { |
| 199 | const formData = new FormData(); |
| 200 | formData.append('file', file); |
| 201 | |
| 202 | for (let k in request) { |
| 203 | if (request.hasOwnProperty(k)) { |
| 204 | formData.append(k, request[k]); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | if (progressBox) { |
| 209 | progressBox.css('visibility', 'visible'); |
| 210 | } |
| 211 | |
| 212 | UIAjax.upload( |
| 213 | // end-point URL |
| 214 | '<?php echo $vik->ajaxUrl('index.php?option=com_vikappointments&task=employee.importworkdays'); ?>', |
| 215 | // file post data |
| 216 | formData, |
| 217 | // success callback |
| 218 | (data) => { |
| 219 | resolve(data); |
| 220 | }, |
| 221 | // failure callback |
| 222 | (error) => { |
| 223 | alert(error.responseText || Joomla.JText._('VAPCONNECTIONLOSTERROR')); |
| 224 | |
| 225 | if (progressBox) { |
| 226 | progressBox.css('visibility', 'hidden'); |
| 227 | } |
| 228 | |
| 229 | reject(error); |
| 230 | }, |
| 231 | // progress callback |
| 232 | (progress) => { |
| 233 | if (progressBox) { |
| 234 | // update progress |
| 235 | progressBox.find('progress').val(progress).text(progress + '%'); |
| 236 | } |
| 237 | } |
| 238 | ); |
| 239 | }); |
| 240 | } |
| 241 | |
| 242 | $(function() { |
| 243 | // drag&drop actions on target div |
| 244 | |
| 245 | $('#worktime-upload-box.vap-media-droptarget').on('drag dragstart dragend dragover dragenter dragleave drop', (e) => { |
| 246 | e.preventDefault(); |
| 247 | e.stopPropagation(); |
| 248 | }); |
| 249 | |
| 250 | $('#worktime-upload-box.vap-media-droptarget').on('dragenter', function(e) { |
| 251 | // increase the drag counter because we may |
| 252 | // enter into a child element |
| 253 | dragCounter++; |
| 254 | |
| 255 | $(this).addClass('drag-enter'); |
| 256 | }); |
| 257 | |
| 258 | $('#worktime-upload-box.vap-media-droptarget').on('dragleave', function(e) { |
| 259 | // decrease the drag counter to check if we |
| 260 | // left the main container |
| 261 | dragCounter--; |
| 262 | |
| 263 | if (dragCounter <= 0) { |
| 264 | $(this).removeClass('drag-enter'); |
| 265 | } |
| 266 | }); |
| 267 | |
| 268 | $('#worktime-upload-box.vap-media-droptarget').on('drop', function(e) { |
| 269 | $(this).removeClass('drag-enter'); |
| 270 | |
| 271 | fetchPreview(e.originalEvent.dataTransfer.files[0]); |
| 272 | }); |
| 273 | |
| 274 | $('#worktime-upload-box.vap-media-droptarget #worktime-upload-file').on('click', function() { |
| 275 | // unset selected files before showing the dialog |
| 276 | $('input#worktime-legacy-upload').val(null).trigger('click'); |
| 277 | }); |
| 278 | |
| 279 | $('#worktime-upload-box.vap-media-droptarget input#worktime-legacy-upload').on('change', function() { |
| 280 | fetchPreview($(this)[0].files[0]); |
| 281 | }); |
| 282 | |
| 283 | $('#wdimport-save').on('click', () => { |
| 284 | execImport(); |
| 285 | }); |
| 286 | |
| 287 | $('#jmodal-wdimport').on('hidden', function(event) { |
| 288 | // make sure the target is the modal because Bootstrap may trigger the same event |
| 289 | // also for a different element placed within the modal (such as a tooltip) |
| 290 | if ($(event.target).is(this)) { |
| 291 | $('#worktime-upload-box.vap-media-droptarget .vap-upload-progress').css('visibility', 'hidden'); |
| 292 | $('.worktime-import-preview').html('').hide(); |
| 293 | $('#worktime-upload-box').show(); |
| 294 | $('#wdimport-save').prop('disabled', true); |
| 295 | } |
| 296 | }); |
| 297 | |
| 298 | $('#jmodal-wdimport').on('click', 'input[id^="wd_import_"]', function() { |
| 299 | let ul = $(this).nextAll('ul'); |
| 300 | |
| 301 | if (ul.length) { |
| 302 | ul.find('input[id^="' + $(this).attr('id') + '"]').prop('disabled', $(this).is(':checked') ? false : true); |
| 303 | } |
| 304 | }); |
| 305 | }); |
| 306 | })(jQuery); |
| 307 | </script> |
| 308 |