comand-component-library 4.3.28 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/comand-component-library.css +1 -1
  2. package/dist/comand-component-library.js +9587 -9482
  3. package/dist/styles/demopage-only.css +12 -2
  4. package/package.json +47 -46
  5. package/src/ComponentLibrary.vue +2697 -2688
  6. package/src/assets/data/component-structure.json +1 -1
  7. package/src/assets/data/form-elements.json +224 -224
  8. package/src/assets/data/social-networks-page-by-json.json +43 -43
  9. package/src/assets/styles/component-library-global-styles.scss +296 -295
  10. package/src/componentSettingsDataAndControls.vue +1 -18
  11. package/src/components/CmdAccordion.vue +1 -1
  12. package/src/components/CmdAddressData.vue +6 -1
  13. package/src/components/CmdAddressDataItem.vue +6 -1
  14. package/src/components/CmdBasicForm.vue +2 -2
  15. package/src/components/CmdBox.vue +1103 -1092
  16. package/src/components/CmdBoxWrapper.vue +7 -1
  17. package/src/components/CmdBreadcrumbs.vue +2 -2
  18. package/src/components/CmdCodeOutput.vue +1 -1
  19. package/src/components/CmdCookieDisclaimer.vue +480 -480
  20. package/src/components/CmdFakeSelect.vue +930 -916
  21. package/src/components/CmdFlexibleScrollContainer.vue +42 -42
  22. package/src/components/CmdForm.vue +481 -481
  23. package/src/components/CmdFormElement.vue +1110 -1091
  24. package/src/components/CmdFormFilters.vue +146 -146
  25. package/src/components/CmdGoogleMaps.vue +1 -1
  26. package/src/components/CmdHeadline.vue +21 -4
  27. package/src/components/CmdIcon.vue +8 -2
  28. package/src/components/CmdImage.vue +14 -16
  29. package/src/components/CmdImageZoom.vue +9 -8
  30. package/src/components/CmdInputGroup.vue +436 -435
  31. package/src/components/CmdLink.vue +1 -1
  32. package/src/components/CmdList.vue +1 -1
  33. package/src/components/CmdListOfRequirements.vue +192 -192
  34. package/src/components/CmdLoginForm.vue +618 -618
  35. package/src/components/CmdMailToolFilter.vue +217 -217
  36. package/src/components/CmdMainNavigation.vue +581 -572
  37. package/src/components/CmdMultistepFormProgressBar.vue +9 -9
  38. package/src/components/CmdNewsletterSubscription.vue +199 -199
  39. package/src/components/CmdPagination.vue +4 -2
  40. package/src/components/CmdParagraph.vue +10 -4
  41. package/src/components/CmdProgressBar.vue +72 -72
  42. package/src/components/CmdSiteHeader.vue +382 -389
  43. package/src/components/CmdSiteSearch.vue +420 -420
  44. package/src/components/CmdSiteWrapper.vue +12 -5
  45. package/src/components/CmdSlideshow.vue +519 -519
  46. package/src/components/CmdSmartSearch.vue +291 -291
  47. package/src/components/CmdSystemMessage.vue +3 -2
  48. package/src/components/CmdTable.vue +401 -401
  49. package/src/components/CmdTabs.vue +262 -262
  50. package/src/components/CmdTag.vue +1 -1
  51. package/src/components/CmdTextImageBlock.vue +8 -2
  52. package/src/components/CmdThumbnailScroller.vue +0 -7
  53. package/src/components/CmdToggleDarkMode.vue +13 -11
  54. package/src/components/CmdTooltip.vue +305 -301
  55. package/src/components/CmdUploadForm.vue +1299 -1305
  56. package/src/components/CmdWidthLimitationWrapper.vue +1 -1
  57. package/src/components/EditComponentWrapper.vue +5 -5
  58. package/src/index.js +5 -0
  59. package/src/main.js +4 -3
  60. package/src/utils/template.js +57 -0
  61. package/src/assets/styles/template.css +0 -1
@@ -1,1305 +1,1299 @@
1
- <template>
2
- <!-- begin CmdUploadForm ---------------------------------------------------------------------------------------- -->
3
- <!-- begin advanced mode -->
4
- <fieldset v-if="advancedMode" :class="['cmd-upload-form flex-container flex-direction-column', { 'upload-initiated': uploadInitiated }]">
5
- <legend :class="{hidden : !legend.show, 'align-left': legend.align === 'left'}">{{ legend.text }}</legend>
6
- <CmdHeadline
7
- v-if="(cmdHeadlineForFieldsetProperties?.show && cmdHeadlineForFieldsetProperties?.headlineText) || editModeContext"
8
- v-bind="cmdHeadlineForFieldsetProperties"
9
- />
10
-
11
- <!-- begin CmdSystemMessage -->
12
- <CmdSystemMessage
13
- v-if="systemMessageStatus && allSystemMessages.length"
14
- :iconClose="{ show: false }"
15
- :validationStatus="systemMessageStatus"
16
- :systemMessage="allSystemMessages.length === 1 ? allSystemMessages[0] : getMessage('upload_form.system_message.the_following_errors_occurred')"
17
- >
18
- <ul v-if="allSystemMessages.length > 1">
19
- <li v-for="(systemMessage, index) in allSystemMessages" :key="index">
20
- {{ systemMessage }}
21
- </li>
22
- </ul>
23
- </CmdSystemMessage>
24
- <!-- end CmdSystemMessage -->
25
-
26
- <div :class="['box flex-container flex-direction-column', { 'drop-area': enableDragAndDrop, 'allow-drop': allowDrop }]"
27
- v-on="dragAndDropHandler">
28
- <CmdHeadline v-if="!listOfFiles.length && allowMultipleFileUploads" v-bind="cmdHeadlineNoFilesToUploadProperties" />
29
-
30
- <!-- begin total-upload information -->
31
- <div v-else class="flex-container flex-direction-column">
32
- <div v-if="showTotalUpload && listOfFiles.length > 1"
33
- class="flex-container flex-direction-column list-files-wrapper">
34
- <CmdHeadline v-bind="cmdHeadlineSummaryOfAllFilesProperties" />
35
-
36
- <ul class="list-of-files total-files">
37
- <li class="flex-container flex-items-flex-none">
38
- <CmdLink
39
- v-bind="cmdLinkCancelUploadProperties"
40
- @click="cancelUpload"
41
- />
42
- <span>
43
- {{ listOfFiles.length }}
44
- <template v-if="!allowMultipleFileUploads">
45
- {{ getMessage("upload_form.labeltext.file_uploading") }}
46
- </template>
47
- <template v-else>
48
- {{ getMessage("upload_form.labeltext.files_uploading") }}
49
- </template>
50
- </span>
51
- <small
52
- :class="[
53
- 'text-align-right',
54
- { error: maxTotalUploadSize > 0 && totalSize > maxTotalUploadSize }
55
- ]">
56
- ({{ formatSize(totalSize) }})
57
- </small>
58
- <span class="progressbar" v-if="uploadInitiated">
59
- <span>{{ getPercentage(totalUploadProgress) }}</span>
60
- <progress
61
- max="100"
62
- :value="totalUploadProgress"
63
- :title="totalBytesUploaded"
64
- ></progress>
65
- </span>
66
- </li>
67
- </ul>
68
- <hr/>
69
- </div>
70
- <!-- end total-upload information -->
71
-
72
- <div v-if="listOfFiles.length" class="flex-container flex-direction-column list-files-wrapper">
73
- <CmdHeadline v-bind="cmdHeadlineListOfSelectedFilesProperties" />
74
- <!-- begin list of selected files -->
75
- <ul class="list-of-files">
76
- <li
77
- v-for="(uploadFile, index) in listOfFiles"
78
- :key="index"
79
- class="flex-container flex-items-flex-none"
80
- >
81
- <CmdLink
82
- v-bind="cmdLinkRemoveFilesFromListProperties"
83
- :title="getMessage('upload_form.labeltext.remove_file_from_list', uploadFile.file.name)"
84
- @click="removeFile(index)"
85
- />
86
-
87
- <span
88
- :class="[
89
- 'text-align-right',
90
- uploadFile.allowedType ? 'allowed' : 'not-allowed',
91
- { error: uploadFile.error }
92
- ]">
93
- {{ uploadFile.file.name }} <small>({{ formatSize(uploadFile.file.size) }})</small>
94
- </span>
95
-
96
- <!-- begin progressbar -->
97
- <span class="progressbar" v-if="uploadInitiated && !uploadFile.error">
98
- <span>{{ getPercentage(uploadFile.progress) }}</span>
99
- <!-- do not place inside progress-tag (will not be displayed then) -->
100
- <progress
101
- max="100"
102
- :value="uploadFile.progress"
103
- :title="
104
- formatSize(uploadFile.uploadedBytes) + '/' + formatSize(uploadFile.file.size)
105
- "
106
- ></progress>
107
- </span>
108
- <!-- end progressbar -->
109
- </li>
110
- </ul>
111
- <CmdLink
112
- v-if="failedUpload"
113
- v-bind="cmdLinkResetUploadProperties"
114
- @click="cancel"
115
- />
116
- <hr/>
117
- </div>
118
- </div>
119
- <!-- end list of selected files -->
120
-
121
- <!-- begin upload conditions -->
122
- <div class="upload-conditions">
123
- <CmdHeadline
124
- v-if="listOfFiles.length"
125
- v-bind="cmdHeadlineSelectFilesProperties"
126
- />
127
-
128
- <dl class="small">
129
- <template v-if="maxTotalUploadSize > 0">
130
- <dt :class="{ error: totalSize > maxTotalUploadSize }">
131
- {{ getMessage("upload_form.max_total_upload_size") }}
132
- </dt>
133
- <dd :class="['text-align-right', { error: totalSize > maxTotalUploadSize }]">
134
- {{ formatSize(maxTotalUploadSize) }}
135
- </dd>
136
- </template>
137
- <dt :class="{ error: errors.fileSize }">
138
- {{ getMessage("upload_form.max_file_upload_size") }}
139
- </dt>
140
- <dd :class="['text-align-right', { error: errors.fileSize }]">
141
- {{ formatSize(maxFileUploadSize) }}
142
- </dd>
143
- <dt :class="{ error: errors.fileType }">
144
- {{ getMessage("upload_form.allowed_file_types") }}
145
- </dt>
146
- <dd>
147
- <CmdLink
148
- @click="showListOfFileExtensions = !showListOfFileExtensions"
149
- v-bind="cmdLinkToggleListOfFileExtensionsProperties"
150
- />
151
-
152
- <!-- begin list of file extensions -->
153
- <transition :name="transitionListOfFileExtensions">
154
- <ul v-if="showListOfFileExtensions" class="list-of-file-extensions">
155
- <li
156
- v-for="(fileExtension, index) in allowedFileExtensions"
157
- :key="index"
158
- :class="{ error: errors.fileType }"
159
- >
160
- {{ fileExtension }}
161
- </li>
162
- </ul>
163
- </transition>
164
- <!-- end list of file extensions -->
165
- </dd>
166
- </dl>
167
- </div>
168
- <!-- end upload conditions -->
169
-
170
- <!-- begin upload-button and drag-and-drop-text -->
171
- <div class="flex-container flex-direction-column no-gap">
172
- <CmdLink
173
- :class="['upload', { disabled: uploadInitiated }]"
174
- :disabled="uploadInitiated"
175
- @click="selectFiles()"
176
- v-bind="cmdLinkSelectFilesProperties"
177
- />
178
- <p v-if="enableDragAndDrop" :class="['text-drag-and-drop', { disabled: uploadInitiated }]">
179
- <span>{{ getMessage("upload_form.or") }}</span>
180
- <strong>
181
- {{ getMessage("upload_form.drag_and_drop") }}
182
- <template v-if="allowMultipleFileUploads && listOfFiles.length">
183
- {{ getMessage("upload_form.additional") }}
184
- </template>
185
- <template v-if="!allowMultipleFileUploads && listOfFiles.length">
186
- {{ getMessage("upload_form.new") }}
187
- </template>
188
- {{ getMessage("upload_form.files_to_this_area") }}
189
- </strong>
190
- </p>
191
- </div>
192
- <!-- end upload-button and drag-and-drop-text -->
193
- </div>
194
-
195
- <!-- begin CmdFormElement -->
196
- <CmdFormElement
197
- v-if="enableComment"
198
- element="textarea"
199
- :labelText="getMessage('upload_form.labeltext.comment')"
200
- v-model="comment"
201
- :required="commentRequired"
202
- :validationMessage="commentStatusMessage"
203
- :placeholder="getMessage('upload_form.placeholder.comment')"
204
- :status="commentStatusMessage ? 'error' : ''"
205
- />
206
- <!-- end CmdFormElement -->
207
-
208
- <!-- begin button-wrapper -->
209
- <div class="button-wrapper stretch-on-small-devices">
210
- <CmdLink
211
- :class="{
212
- disabled:
213
- listOfFiles.length === 0 ||
214
- (maxTotalUploadSize > 0 && totalSize > maxTotalUploadSize) ||
215
- uploadInitiated
216
- }"
217
- :disabled="
218
- listOfFiles.length === 0 ||
219
- (maxTotalUploadSize > 0 && totalSize > maxTotalUploadSize) ||
220
- uploadInitiated"
221
- v-bind="cmdLinkUploadFilesProperties"
222
- @click="uploadFiles"
223
- />
224
-
225
- <CmdLink
226
- @click="cancel"
227
- v-bind="cmdLinkCancelIconProperties"
228
- :class="{ disabled: listOfFiles.length === 0 }"
229
- />
230
- </div>
231
- <!-- end button-wrapper -->
232
- </fieldset>
233
- <!-- end advanced mode -->
234
-
235
- <!-- begin simple mode -->
236
- <a v-else href="#" @click.prevent="selectFiles"
237
- :class="['cmd-upload-form box', { 'drop-area': enableDragAndDrop, 'allow-drop': allowDrop }]"
238
- v-on="dragAndDropHandler">
239
- <!-- begin progressbar -->
240
- <span v-if="uploadInitiated" class="progressbar">
241
- <span>{{ getPercentage(totalUploadProgress) }}</span>
242
- <progress
243
- max="100"
244
- :value="totalUploadProgress"
245
- :title="totalBytesUploaded">
246
- </progress>
247
- </span>
248
- <!-- end progressbar -->
249
-
250
- <!-- begin slot-content -->
251
- <slot>
252
- <template v-if="!enableDragAndDrop">
253
- <template v-if="fileTypeImage">
254
- <span>{{ getMessage("upload_form.select_image") }}</span>
255
- <!-- begin CmdIcon -->
256
- <CmdIcon v-bind="cmdIconImage" />
257
- <!-- end CmdIcon -->
258
- </template>
259
- <template v-else>
260
- <span>{{ getMessage("upload_form.select_file") }}</span>
261
- <!-- begin CmdIcon -->
262
- <CmdIcon v-bind="cmdIconFileUpload" />
263
- <!-- end CmdIcon -->
264
- </template>
265
- </template>
266
- <template v-else>
267
- <span>{{ getMessage("upload_form.drag_and_drop_file_here") }}</span>
268
- <!-- begin CmdIcon -->
269
- <CmdIcon v-bind="cmdIconDragAndDrop" />
270
- <!-- end CmdIcon -->
271
- </template>
272
- <small>{{ getMessage("upload_form.max_upload_size") }} {{ formatSize(maxFileUploadSize) }}</small>
273
- <small>{{ getMessage("upload_form.allowed_file_types") }} {{ allowedFileExtensions }}</small>
274
- </slot>
275
- <!-- end slot-content -->
276
- </a>
277
- <!-- end simple mode -->
278
-
279
- <!-- begin CmdFormElement -->
280
- <CmdFormElement
281
- element="input"
282
- type="file"
283
- :labelText="getMessage('upload_form.labeltext.select_files')"
284
- :disabled="uploadInitiated"
285
- :multiple="allowMultipleFileUploads"
286
- @change="filesSelected"
287
- ref="formElement"
288
- />
289
- <!-- end CmdFormElement -->
290
- <!-- end CmdUploadForm ---------------------------------------------------------------------------------------- -->
291
- </template>
292
-
293
- <script>
294
- // import mixins
295
- import I18n from "../mixins/I18n"
296
- import DefaultMessageProperties from "../mixins/CmdUploadForm/DefaultMessageProperties"
297
-
298
- import {getFileExtension} from "../utils/getFileExtension.js"
299
- import axios from "axios"
300
-
301
- export default {
302
- name: "CmdUploadForm",
303
- emits: ["click", "error", "upload-complete", "upload-file-success"],
304
- mixins: [I18n, DefaultMessageProperties],
305
- inject: {
306
- editModeContext: {
307
- default: null
308
- }
309
- },
310
- data() {
311
- return {
312
- comment: "",
313
- allowDrop: false,
314
- listOfFiles: [],
315
- systemMessages: [],
316
- defaultSystemMessageStatus: "",
317
- showListOfFileExtensions: false,
318
- resetForm: {},
319
- uploadInitiated: false,
320
- errors: {}
321
- }
322
- },
323
- created() {
324
- // Set initial data for resetForm.
325
- this.resetForm.comment = this.presetComment
326
- this.resetForm.allowDrop = this.allowDrop
327
- this.resetForm.listOfFiles = JSON.parse(JSON.stringify(this.listOfFiles))
328
- this.resetForm.systemMessages = this.systemMessages
329
- this.resetForm.systemMessageStatus = this.systemMessageStatus
330
- },
331
- props: {
332
- /**
333
- * define the transition when the list of file extensions is toggled
334
- *
335
- * @allowedValues: "none", "fade", "scroll"
336
- */
337
- transitionListOfFileExtensions: {
338
- type: String,
339
- default: "fade"
340
- },
341
- /**
342
- * activate if transition for hiding list of file extensions
343
- */
344
- useTransition: {
345
- type: Boolean,
346
- default: true
347
- },
348
- /**
349
- * toggle visibility of total upload (number of files, total size, total progress
350
- */
351
- showTotalUpload: {
352
- type: Boolean,
353
- default: true
354
- },
355
- /**
356
- * toggle if upload is handled by component itself or by outer component
357
- */
358
- componentHandlesUpload: {
359
- type: Boolean,
360
- default: true
361
- },
362
- /**
363
- * list of allowed file extensions to upload (all can be selected)
364
- */
365
- allowedFileExtensions: {
366
- type: Array,
367
- required: true
368
- },
369
- /**
370
- * activate if the comment given by the user should be mandatory
371
- *
372
- * enableComment-property must be set to true
373
- */
374
- commentRequired: {
375
- type: Boolean,
376
- default: true
377
- },
378
- /**
379
- * show a message if mandatory comment-textarea is not filled
380
- *
381
- * enableComment-property and commentRequired-property must be set to true
382
- */
383
- commentStatusMessage: {
384
- type: String,
385
- default: ""
386
- },
387
- /**
388
- * enable if files can also be dragged (and dropped) into upload-area
389
- */
390
- enableDragAndDrop: {
391
- type: Boolean,
392
- default: false
393
- },
394
- /**
395
- * enable if a comment should be possible to left by the user
396
- */
397
- enableComment: {
398
- type: Boolean,
399
- default: true
400
- },
401
- /**
402
- * preset the comment-textarea
403
- *
404
- * enableComment-property must be set to true
405
- */
406
- presetComment: {
407
- type: String,
408
- default: ""
409
- },
410
- /**
411
- * set to 0 if no maximum for total upload size should be set
412
- */
413
- maxTotalUploadSize: {
414
- type: Number,
415
- default: 5242880
416
- },
417
- /**
418
- * max file size (in bytes) for each single file
419
- */
420
- maxFileUploadSize: {
421
- type: Number,
422
- default: 10485760
423
- },
424
- /**
425
- * enable if more than file should be enabled to be selected for upload
426
- */
427
- allowMultipleFileUploads: {
428
- type: Boolean,
429
- default: false
430
- },
431
- /**
432
- * defines upload options if component handles upload itself
433
- *
434
- * componentHandlesUpload-property must be true
435
- */
436
- uploadOptions: {
437
- type: Object,
438
- required: false
439
- },
440
- /**
441
- * activate to use full upload-form-style and -functionality
442
- *
443
- * @affectsStyling: true
444
- */
445
- advancedMode: {
446
- type: Boolean,
447
- default: true
448
- },
449
- /**
450
- * legend for form
451
- *
452
- * useFieldset-property must be activated
453
- *
454
- * @requiredForAccessiblity: true
455
- */
456
- legend: {
457
- type: Object,
458
- default() {
459
- return {
460
- show: true,
461
- align: "left",
462
- text: "Legend"
463
- }
464
- }
465
- },
466
- /**
467
- * set icon for invisible-icon
468
- */
469
- iconInvisible: {
470
- type: Object,
471
- default() {
472
- return {
473
- iconClass: "icon-not-visible"
474
- }
475
- }
476
- },
477
- /**
478
- * set icon class for visible-icon
479
- */
480
- iconVisible: {
481
- type: Object,
482
- default() {
483
- return {
484
- iconClass: "icon-visible"
485
- }
486
- }
487
- },
488
- /**
489
- * properties for CmdIcon for "drag-and-drop"-icon
490
- */
491
- cmdIconDragAndDrop: {
492
- type: Object,
493
- default() {
494
- return {
495
- iconClass: "icon-not-visible"
496
- }
497
- }
498
- },
499
- /**
500
- * properties for CmdIcon for "image"-icon
501
- */
502
- cmdIconFileUpload: {
503
- type: Object,
504
- default() {
505
- return {
506
- iconClass: "icon-file"
507
- }
508
- }
509
- },
510
- /**
511
- * properties for CmdIcon for "image"-icon
512
- */
513
- cmdIconImage: {
514
- type: Object,
515
- default() {
516
- return {
517
- iconClass: "icon-image"
518
- }
519
- }
520
- },
521
- /**
522
- * properties for CmdLink-component for removing (before added) files from list
523
- *
524
- */
525
- cmdLinkRemoveFilesFromList: {
526
- type: Object,
527
- required: false
528
- },
529
- /**
530
- * properties for CmdLink-component for selecting file(s)
531
- */
532
- cmdLinkSelectFiles: {
533
- type: Object,
534
- required: false
535
- },
536
- /**
537
- * properties for CmdLink-component for uploading file(s)
538
- */
539
- cmdLinkUploadFiles: {
540
- type: Object,
541
- required: false
542
- },
543
- /**
544
- * properties for CmdLink-component for cancel-icon
545
- */
546
- cmdLinkCancelIcon: {
547
- type: Object,
548
- required: false
549
- },
550
- /**
551
- * properties for CmdLink-component to toggle the list of file extensions
552
- *
553
- * icon is set by iconVisible- and iconInvisible-properties
554
- */
555
- cmdLinkToggleListOfFileExtensions: {
556
- type: Object,
557
- required: false
558
- },
559
- /**
560
- * properties for CmdLink-component to reset upload (if upload failed before)
561
- */
562
- cmdLinkResetUpload: {
563
- type: Object,
564
- required: false
565
- },
566
- /**
567
- * properties for CmdHeadline-component at top of the fieldset
568
- */
569
- cmdHeadlineForFieldset: {
570
- type: Object,
571
- required: false
572
- },
573
- /**
574
- * properties for CmdHeadline-component shown if no files for upload exist
575
- */
576
- cmdHeadlineNoFilesToUpload: {
577
- type: Object,
578
- required: false
579
- },
580
- /**
581
- * properties for CmdHeadline-component shown if no file for upload exist
582
- */
583
- cmdHeadlineNoFileToUpload: {
584
- type: Object,
585
- required: false
586
- },
587
- /**
588
- * properties for CmdHeadline-component for 'summary of all files'
589
- */
590
- cmdHeadlineSummaryOfAllFiles: {
591
- type: Object,
592
- required: false
593
- },
594
- /**
595
- * properties for CmdHeadline-component for 'list of selected files'
596
- */
597
- cmdHeadlineListOfSelectedFiles: {
598
- type: Object,
599
- required: false
600
- },
601
- /**
602
- * properties for CmdHeadline-component for 'select additional/new file(s)'
603
- */
604
- cmdHeadlineSelectFiles: {
605
- type: Object,
606
- required: false
607
- },
608
- },
609
- computed: {
610
- cmdHeadlineForFieldsetProperties() {
611
- return {
612
- show: true,
613
- headlineLevel: 3,
614
- ...this.cmdHeadlineForFieldset
615
- }
616
- },
617
- cmdHeadlineNoFilesToUploadProperties() {
618
- return {
619
- headlineLevel: 4,
620
- ...this.cmdHeadlineNoFilesToUpload,
621
- headlineText: this.allowMultipleFileUploads ? this.getMessage("upload_form.no_files_to_upload") : this.getMessage("upload_form.no_file_to_upload")
622
- }
623
- },
624
- cmdHeadlineListOfSelectedFilesProperties() {
625
- return {
626
- headlineLeveL: 4,
627
- headlineText: this.getMessage("upload_form.headline.list_of_selected_files"),
628
- ...this.cmdHeadlineListOfSelectedFiles
629
- }
630
- },
631
- cmdHeadlineSummaryOfAllFilesProperties() {
632
- return {
633
- headlineLevel: 4,
634
- headlineText: this.getMessage("upload_form.headline.summary_of_all_files"),
635
- ...this.cmdHeadlineSummaryOfAllFiles
636
- }
637
- },
638
- cmdHeadlineSelectFilesProperties() {
639
- return {
640
- headlineLevel: 4,
641
- headlineText: this.allowMultipleFileUploads ? this.getMessage("upload_form.headline.select_additional_files") : this.getMessage("upload_form.headline.select_new_file"),
642
- ...this.cmdHeadlineSelectFiles
643
- }
644
- },
645
- cmdLinkCancelIconProperties() {
646
- return {
647
- linkType: "button",
648
- highlightLevel: null,
649
- icon: {
650
- iconClass: "icon-cancel-circle"
651
- },
652
- text: this.getMessage("upload_form.buttontext.cancel"),
653
- ...this.cmdLinkCancelIcon
654
- }
655
- },
656
- cmdLinkSelectFilesProperties() {
657
- return {
658
- linkType: "button",
659
- icon: {
660
- iconClass: "icon-file-upload"
661
- },
662
- text: this.allowMultipleFileUploads ? this.getMessage("upload_form.labeltext.select_files") : this.getMessage("upload_form.labeltext.select_file") ,
663
- ...this.cmdLinkSelectFiles
664
- }
665
- },
666
- cmdLinkToggleListOfFileExtensionsProperties() {
667
- return {
668
- icon: {
669
- iconClass: this.showListOfFileExtensions ? this.iconInvisible?.iconClass : this.iconVisible?.iconClass,
670
- type: this.showListOfFileExtensions ? this.iconInvisible?.iconType : this.iconVisible?.iconType,
671
- tooltip: this.getMessage('upload_form.tooltip.toggle_list_of_allowed_file_types')
672
- },
673
- ...this.cmdLinkToggleListOfFileExtensions
674
- }
675
- },
676
- cmdLinkUploadFilesProperties() {
677
- return {
678
- linkType: "button",
679
- icon: {
680
- iconClass: "icon-upload"
681
- },
682
- text: this.listOfFiles.length === 1 || !this.allowMultipleFileUploads ? this.getMessage("upload_form.buttontext.upload_file") : this.getMessage("upload_form.buttontext.upload_files"),
683
- ...this.cmdLinkUploadFiles
684
- }
685
- },
686
- cmdLinkCancelUploadProperties() {
687
- return {
688
- icon: {
689
- iconClass: "icon-delete",
690
- tooltip: this.getMessage('upload_form.labeltext.remove_all_files_from_list')
691
- },
692
- ...this.cmdLinkCancelUpload
693
- }
694
- },
695
- cmdLinkRemoveFilesFromListProperties() {
696
- return {
697
- icon: {
698
- iconClass: "icon-delete"
699
- },
700
- ...this.cmdLinkRemoveFilesFromList
701
- }
702
- },
703
- cmdLinkResetUploadProperties() {
704
- return {
705
- icon: {
706
- iconClass: "icon-loop-left",
707
- tooltip: this.getMessage('upload_form.all_files_will_be_removed')
708
- },
709
- text: this.getMessage("upload_form.reset_upload"),
710
- ...this.cmdLinkResetUpload
711
- }
712
- },
713
- fileTypeImage() {
714
- return this.allowedFileExtensions.some(extension => extension.includes('jpg'));
715
- },
716
- failedUpload() {
717
- return this.listOfFiles.some(file => file.error)
718
- },
719
- totalBytesUploaded() {
720
- const bytes = this.listOfFiles
721
- .map(uploadFile => [
722
- uploadFile.file.size,
723
- ((uploadFile.progress || 0) * uploadFile.file.size) / 100
724
- ])
725
- .reduce((a, b) => [a[0] + b[0], a[1] + b[1]])
726
- return this.formatSize(bytes[1]) + "/" + this.formatSize(bytes[0])
727
- },
728
- totalSize() {
729
- let totalSize = 0
730
- for (let i = 0; i < this.listOfFiles.length; i++) {
731
- totalSize = totalSize + this.listOfFiles[i].file.size
732
- }
733
- return totalSize
734
- },
735
- allSystemMessages() {
736
- if (this.maxTotalUploadSize > 0 && this.totalSize > this.maxTotalUploadSize) {
737
- return [
738
- this.getMessage("upload_form.system_message_total_size_of_files_too_large"),
739
- ...this.systemMessages
740
- ]
741
- }
742
- return this.systemMessages
743
- },
744
- systemMessageStatus() {
745
- return this.defaultSystemMessageStatus || (this.allSystemMessages.length ? "error" : "")
746
- },
747
- dragAndDropHandler() {
748
- // register handlers only if drag-and-drop is enabled
749
- if (this.enableDragAndDrop) {
750
- return {
751
- dragenter: this.dragEnter,
752
- dragover: this.dragOver,
753
- dragleave: this.dragLeave,
754
- drop: this.drop
755
- }
756
- }
757
- return {}
758
- },
759
- totalUploadProgress() {
760
- const progress = this.listOfFiles
761
- .map(uploadFile => [
762
- uploadFile.file.size,
763
- ((uploadFile.progress || 0) * uploadFile.file.size) / 100
764
- ])
765
- .reduce((a, b) => [a[0] + b[0], a[1] + b[1]])
766
- return (progress[1] / progress[0]) * 100
767
- }
768
- },
769
- watch: {
770
- presetComment: {
771
- handler(newValue) {
772
- this.comment = newValue
773
- },
774
- immediate: true
775
- }
776
- },
777
- methods: {
778
- getPercentage(percentage) {
779
- if (percentage) {
780
- return percentage.toFixed(2) + "%"
781
- }
782
- return "0.00%"
783
- },
784
- // use imported function as method (to use in template)
785
- getFileExtension(filename) {
786
- return getFileExtension(filename)
787
- },
788
- selectFiles() {
789
- let inputFile = this.$refs.formElement.getDomElement().querySelector("input[type='file']")
790
- inputFile.click()
791
- },
792
- dragEnter(event) {
793
- this.dragOver(event)
794
- },
795
- dragOver(event) {
796
- if (event.dataTransfer && event.dataTransfer.items && event.dataTransfer.items.length > 0) {
797
- event.dataTransfer.dropEffect = "none"
798
- let allowed = true
799
- for (let i = 0, c = event.dataTransfer.items.length; i < c; ++i) {
800
- let item = event.dataTransfer.items[i]
801
- if (item.kind !== "file" /*|| !this._allowedTypes[item.type]*/) {
802
- allowed = false
803
- break
804
- }
805
- }
806
- if (allowed) {
807
- event.preventDefault()
808
- event.dataTransfer.dropEffect = "copy"
809
- this.allowDrop = true
810
- // this._handle_dragover(event)
811
- }
812
- }
813
- },
814
- dragLeave() {
815
- this.allowDrop = false
816
- },
817
- /*
818
- drag(event) {
819
- alert("dropped")
820
- event.dataTransfer.setData("text", event.target.id)
821
- },
822
- */
823
- drop(event) {
824
- this.allowDrop = false
825
- if (event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files.length > 0) {
826
- event.preventDefault()
827
- this.checkFiles(event.dataTransfer.files)
828
- }
829
- },
830
- cancelUpload() {
831
- // cancel upload for each file
832
- this.listOfFiles.forEach(file => {
833
- if (file.abortController) {
834
- file.abortController.abort()
835
- }
836
- })
837
-
838
- // clear list of files, remove error-highlighting and hide all system-messages afterwards
839
- this.errors = {}
840
- this.listOfFiles = []
841
- this.hideAllSystemMessages()
842
-
843
- // set uploadInitiated to false to enable all disabled buttons
844
- this.uploadInitiated = false
845
- },
846
- cancel() {
847
- this.cancelUpload()
848
-
849
- // emit click event with argument "cancel" to react in outer component
850
- this.$emit("click", "cancel")
851
- },
852
- filesSelected(event) {
853
- this.checkFiles(event.target.files)
854
- },
855
- checkFiles(files) {
856
- if (!files.length) {
857
- return
858
- }
859
-
860
- this.defaultSystemMessageStatus = ""; // hide systemMessage if already is shown
861
- this.systemMessages = [] // hide systemMessage if already is shown
862
- this.errors = {}
863
-
864
- for (let i = 0; i < files.length; i++) {
865
- // define file-object which will be pushed in listOfFiles
866
- const uploadFile = {
867
- file: files[i],
868
- progress: null,
869
- uploadedBytes: 0
870
- }
871
-
872
- // check size for current file
873
- if (files[i].size > this.maxFileUploadSize) {
874
- this.errors.fileSize = true
875
- this.systemMessages.push(
876
- this.getMessage(
877
- "upload_form.system_message.file_size_too_large",
878
- files[i].name,
879
- files[i].size
880
- )
881
- )
882
- continue
883
- }
884
-
885
- // check if current file has allowed file-type (else continue with next file)
886
- if (!this.allowedFileExtensions.includes(getFileExtension(files[i].name))) {
887
- this.showListOfFileExtensions = true
888
- this.errors.fileType = true
889
- this.systemMessages.push(
890
- this.getMessage(
891
- "upload_form.system_message.not_allowed_file_type",
892
- files[i].name,
893
- getFileExtension(files[i].name)
894
- )
895
- )
896
- continue
897
- }
898
-
899
- // check (if multiple files can be selected) if current file already exists in listOfFiles
900
- if (
901
- this.allowMultipleFileUploads &&
902
- this.listOfFiles.some(listOfFilesEntry =>
903
- this.compareFiles(listOfFilesEntry.file, files[i])
904
- )
905
- ) {
906
- this.systemMessages.push(
907
- this.getMessage(
908
- "upload_form.system_message.duplicate_file",
909
- files[i].name,
910
- getFileExtension(files[i].name)
911
- )
912
- )
913
- continue
914
- }
915
-
916
- if (this.allowMultipleFileUploads) {
917
- // push file-object (for each valid file) to listOfFiles-array
918
- this.listOfFiles.push(uploadFile)
919
- } else {
920
- if (files.length > 1) {
921
- this.systemMessages.push(
922
- this.getMessage("upload_form.system_message.only_one_file_allowed")
923
- )
924
- }
925
- // assign uploadFile-object (which contains current (and valid) file to listOfFiles-array
926
- this.listOfFiles = [uploadFile]
927
- break
928
- }
929
- }
930
-
931
- if (!this.advancedMode) {
932
- if (this.systemMessages.length) {
933
- this.$emit("error", {messages: this.systemMessages})
934
- return
935
- }
936
- if (this.listOfFiles.length) {
937
- this.uploadFiles()
938
- }
939
- }
940
- },
941
- compareFiles(file1, file2) {
942
- return (
943
- file1.name === file2.name &&
944
- file1.lastModified === file2.lastModified &&
945
- file1.size === file2.size
946
- )
947
- },
948
- removeFile(index) {
949
- /* remove specific file from list */
950
- this.listOfFiles.splice(index, 1)
951
- if (!this.listOfFiles.length) {
952
- this.uploadInitiated = false
953
- }
954
- this.hideAllSystemMessages()
955
- },
956
- hideAllSystemMessages() {
957
- // hide all system-messages if all files are removed from list
958
- if (!this.listOfFiles.length) {
959
- this.systemMessages = []
960
- }
961
- },
962
- formatSize(size) {
963
- if (size < 1024) {
964
- return size
965
- } else if (size < 1048576) {
966
- return (size = Math.round((size / 1024) * 100) / 100 + " KB")
967
- } else {
968
- return (size = Math.round((size / 1048576) * 100) / 100 + " MB")
969
- }
970
- },
971
- uploadFiles() {
972
- this.systemMessages = []
973
- this.errors = {}
974
- this.defaultSystemMessageStatus = ""
975
-
976
- if (
977
- this.enableComment &&
978
- !this.comment &&
979
- this.commentRequired &&
980
- this.commentStatusMessage
981
- ) {
982
- this.defaultSystemMessageStatus = "error"
983
- this.systemMessages.push(this.getMessage("upload_form.system_message.fill_required"))
984
- } else {
985
- this.uploadInitiated = true
986
-
987
- if (this.componentHandlesUpload && this.uploadOptions && this.uploadOptions.url) {
988
- const url = new URL(this.uploadOptions.url, location.href)
989
- const formData = new FormData()
990
-
991
- // // append information about files to formData-object
992
- // formData.append(
993
- // this.uploadOptions.filesParam ? this.uploadOptions.filesParam : "files",
994
- // this.listOfFiles.map(uploadFile => uploadFile.file)
995
- // )
996
-
997
- // iterate over additionalParams-object and append to formData-object
998
- Object.entries(this.uploadOptions.additionalParams || {}).forEach(([key, value]) =>
999
- formData.append(key, value)
1000
- )
1001
-
1002
- // append comment to formData-object
1003
- if (this.enableComment) {
1004
- formData.append("comment", this.comment)
1005
- }
1006
-
1007
- const requests = []
1008
-
1009
- // iterate over list-of-files to send upload request for each file individually
1010
- this.listOfFiles.forEach(file => {
1011
- requests.push(this.uploadSingleFile(url, file, formData))
1012
- })
1013
-
1014
- // check upload-status for each file individually
1015
- Promise.allSettled(requests).then(results => {
1016
- // if status equals "rejected" the upload was not successful and the file will not be deleted from list
1017
- const rejectedFiles = results.filter(result => result.status === "rejected")
1018
- this.uploadInitiated = false
1019
-
1020
- if (rejectedFiles.length) {
1021
- this.defaultSystemMessageStatus = "error"
1022
- this.systemMessages.push(
1023
- this.getMessage(
1024
- "upload_form.system_message.some_files_are_not_uploaded_successfully"
1025
- )
1026
- )
1027
- } else {
1028
- this.defaultSystemMessageStatus = "success"
1029
- this.systemMessages.push(
1030
- this.getMessage("upload_form.system_message.all_files_are_uploaded_successfully")
1031
- )
1032
- }
1033
-
1034
- this.$emit("upload-complete", {success: !rejectedFiles.length})
1035
- })
1036
- } else {
1037
- let uploadObj = {}
1038
- uploadObj.listOfFiles = this.listOfFiles
1039
- uploadObj.type = "upload"
1040
- uploadObj.comment = this.comment
1041
-
1042
- // emit uploadObj to handle upload by outer component
1043
- this.$emit("click", uploadObj, this.showMessage)
1044
- }
1045
- }
1046
- },
1047
- onUploadProgress(event, uploadFile) {
1048
- if (event.lengthComputable) {
1049
- uploadFile.progress = (event.loaded / event.total) * 100
1050
- uploadFile.uploadedBytes = event.loaded
1051
- } else {
1052
- uploadFile.progress = null
1053
- uploadFile.uploadedBytes = 0
1054
- }
1055
- this.$forceUpdate()
1056
- },
1057
- uploadSingleFile(url, file, formData) {
1058
- file.abortController = new AbortController()
1059
-
1060
- // append information about given file to formData-object
1061
- formData.set(
1062
- this.uploadOptions.filesParam ? this.uploadOptions.filesParam : "files",
1063
- file.file
1064
- )
1065
-
1066
- return (
1067
- axios
1068
- .post(url, formData, {
1069
- signal: file.abortController.signal,
1070
- onUploadProgress: event => this.onUploadProgress(event, file)
1071
- })
1072
- // emit information about successful-upload + file
1073
- .then(response => {
1074
- this.$emit("upload-file-success", file)
1075
- return response
1076
- })
1077
- // delete uploaded file from list-of-files-array
1078
- .then(response => {
1079
- const positionOfFile = this.listOfFiles.indexOf(file)
1080
- if (positionOfFile !== -1) {
1081
- this.listOfFiles.splice(positionOfFile, 1)
1082
- }
1083
- return response
1084
- })
1085
- .catch(error => {
1086
- this.defaultSystemMessageStatus = "error"
1087
- this.systemMessages.push(error)
1088
- file.error = true
1089
- throw new Error()
1090
- })
1091
- )
1092
- },
1093
- showMessage(result) {
1094
- if (result === true) {
1095
- this.defaultSystemMessageStatus = "success"
1096
- this.systemMessages.push(this.getMessage("upload_form.system_message.upload_success"))
1097
- } else if (result === false) {
1098
- this.defaultSystemMessageStatus = "error"
1099
- this.systemMessages.push(this.getMessage("upload_form.system_message.upload_failed"))
1100
- }
1101
- },
1102
- resetFields() {
1103
- if (typeof this.resetForm === "object") {
1104
- const resetArr = Object.keys(this.resetForm)
1105
- for (let key of resetArr) {
1106
- if (typeof this.resetForm[key] === "object") {
1107
- this[key] = JSON.parse(JSON.stringify(this.resetForm[key]))
1108
- } else {
1109
- this[key] = this.resetForm[key]
1110
- }
1111
- }
1112
- }
1113
- }
1114
- }
1115
- }
1116
- </script>
1117
-
1118
- <style>
1119
- /* begin cmd-upload-form -------------------------------------------------------------------------------------------- */
1120
- .cmd-upload-form {
1121
- .cmd-custom-headline {
1122
- margin: 0;
1123
- justify-content: center;
1124
- }
1125
-
1126
- /* begin box for simple-mode */
1127
- &.box {
1128
- display: inline-flex;
1129
- flex-direction: column;
1130
- background: var(--default-background);
1131
-
1132
- text-decoration: none;
1133
- text-align: center;
1134
- padding: var(--default-padding);
1135
-
1136
- span {
1137
- margin: 0;
1138
-
1139
- &[class*="icon-"] {
1140
- font-size: 5rem;
1141
- }
1142
- }
1143
- }
1144
- /* end box for simple-mode */
1145
-
1146
- .box {
1147
- box-shadow: none;
1148
- background: var(--color-scheme-background);
1149
- border: var(--default-border);
1150
- align-items: center;
1151
-
1152
- dl {
1153
- justify-content: center;
1154
- text-align: left;
1155
-
1156
- .list-of-file-extensions {
1157
- display: table;
1158
-
1159
- > li:only-child {
1160
- list-style-type: none;
1161
- margin: 0;
1162
- }
1163
- }
1164
- }
1165
- }
1166
-
1167
- .total-files {
1168
- > * {
1169
- white-space: nowrap;
1170
-
1171
- &:not(a) {
1172
- font-weight: bold;
1173
- }
1174
- }
1175
- }
1176
-
1177
- [class*="list-of-file"] {
1178
- max-height: 10rem;
1179
- overflow-x: hidden;
1180
- overflow-y: auto;
1181
- border: var(--default-border);
1182
- padding: var(--default-padding);
1183
- margin: 0;
1184
-
1185
- > li {
1186
- flex-wrap: nowrap;
1187
-
1188
- .progressbar {
1189
- display: table;
1190
- align-self: center;
1191
-
1192
- progress {
1193
- &[value] {
1194
- background: var(--color-scheme-background);
1195
-
1196
- &::-moz-progress-bar {
1197
- border-top-left-radius: var(--default-border-radius);
1198
- border-bottom-left-radius: var(--default-border-radius);
1199
- background: var(--primary-color);
1200
- }
1201
- }
1202
- }
1203
-
1204
- & > span {
1205
- position: absolute;
1206
- left: 50%;
1207
- transform: translateX(-50%);
1208
- z-index: 1;
1209
- display: table;
1210
- top: .2rem;
1211
- padding: .1rem .2rem;
1212
- line-height: 100%;
1213
- background: var(--color-scheme-background);
1214
- }
1215
- }
1216
- }
1217
- }
1218
-
1219
- .list-files-wrapper {
1220
- justify-content: center;
1221
- align-items: center;
1222
-
1223
- .list-of-files {
1224
- display: inline-flex;
1225
- flex-direction: column;
1226
- gap: calc(var(--default-gap) / 2);
1227
-
1228
- li {
1229
- list-style-type: none;
1230
- margin-left: 0;
1231
- gap: calc(var(--default-gap) / 2);
1232
-
1233
- > a:hover, a:active, a:focus {
1234
- ~ * {
1235
- color: var(--hyperlink-color-highlighted);
1236
- }
1237
- }
1238
- }
1239
-
1240
- & + a {
1241
- display: table;
1242
- margin: 0 auto;
1243
- }
1244
- }
1245
-
1246
- hr {
1247
- width: 100%; /* will be 0 instead (because of align-items: center for parent) */
1248
- }
1249
- }
1250
-
1251
- .upload-conditions {
1252
- .cmd-headline > * {
1253
- text-align: center;
1254
- }
1255
-
1256
- dl {
1257
- margin: 0;
1258
- }
1259
- }
1260
-
1261
- p {
1262
- &.text-drag-and-drop {
1263
- &.disabled {
1264
- background: none !important; /* overwrite default styling for .disabled */
1265
- }
1266
- }
1267
- }
1268
-
1269
- .button.upload {
1270
- align-self: center;
1271
-
1272
- & ~ p {
1273
- & > * {
1274
- display: block;
1275
- }
1276
- }
1277
- }
1278
-
1279
- .error {
1280
- color: var(--error-color);
1281
- }
1282
-
1283
- & + .cmd-form-element {
1284
- display: none;
1285
- }
1286
-
1287
- .drop-area, &.drop-area {
1288
- border: var(--default-border);
1289
- border-style: dashed;
1290
- background: var(--color-scheme-background);
1291
- padding: var(--default-padding);
1292
- text-align: center;
1293
-
1294
- &.allow-drop {
1295
- border-style: solid;
1296
- }
1297
-
1298
- > [class*="icon-"] {
1299
- font-size: 5rem;
1300
- }
1301
- }
1302
- }
1303
-
1304
- /* end cmd-upload-form ---------------------------------------------------------------------------------------------- */
1305
- </style>
1
+ <template>
2
+ <!-- begin CmdUploadForm ---------------------------------------------------------------------------------------- -->
3
+ <!-- begin advanced mode -->
4
+ <fieldset v-if="advancedMode" :class="['cmd-upload-form flex-container flex-direction-column', { 'upload-initiated': uploadInitiated }]">
5
+ <legend :class="{'visually-hidden' : !legend.show, 'align-left': legend.align === 'left'}">{{ legend.text }}</legend>
6
+ <CmdHeadline
7
+ v-if="(cmdHeadlineForFieldsetProperties?.show && cmdHeadlineForFieldsetProperties?.headlineText) || editModeContext"
8
+ v-bind="cmdHeadlineForFieldsetProperties"
9
+ />
10
+
11
+ <!-- begin CmdSystemMessage -->
12
+ <CmdSystemMessage
13
+ v-if="systemMessageStatus && allSystemMessages.length"
14
+ :allowUserToCloseMessage="false"
15
+ :validationStatus="systemMessageStatus"
16
+ :systemMessage="allSystemMessages.length === 1 ? allSystemMessages[0] : getMessage('upload_form.system_message.the_following_errors_occurred')"
17
+ >
18
+ <ul v-if="allSystemMessages.length > 1">
19
+ <li v-for="(systemMessage, index) in allSystemMessages" :key="index">
20
+ {{ systemMessage }}
21
+ </li>
22
+ </ul>
23
+ </CmdSystemMessage>
24
+ <!-- end CmdSystemMessage -->
25
+
26
+ <div :class="['box flex-container flex-direction-column', { 'drop-area': enableDragAndDrop, 'allow-drop': allowDrop }]"
27
+ v-on="dragAndDropHandler">
28
+ <CmdHeadline v-if="!listOfFiles.length && allowMultipleFileUploads" v-bind="cmdHeadlineNoFilesToUploadProperties" />
29
+
30
+ <!-- begin total-upload information -->
31
+ <div v-else class="flex-container flex-direction-column">
32
+ <div v-if="showTotalUpload && listOfFiles.length > 1"
33
+ class="flex-container flex-direction-column list-files-wrapper">
34
+ <CmdHeadline v-bind="cmdHeadlineSummaryOfAllFilesProperties" />
35
+
36
+ <ul class="list-of-files total-files">
37
+ <li class="flex-container flex-items-flex-none">
38
+ <CmdLink
39
+ v-bind="cmdLinkCancelUploadProperties"
40
+ @click="cancelUpload"
41
+ />
42
+ <span>
43
+ {{ listOfFiles.length }}
44
+ <template v-if="!allowMultipleFileUploads">
45
+ {{ getMessage("upload_form.labeltext.file_uploading") }}
46
+ </template>
47
+ <template v-else>
48
+ {{ getMessage("upload_form.labeltext.files_uploading") }}
49
+ </template>
50
+ </span>
51
+ <small
52
+ :class="[
53
+ 'text-align-right',
54
+ { error: maxTotalUploadSize > 0 && totalSize > maxTotalUploadSize }
55
+ ]">
56
+ ({{ formatSize(totalSize) }})
57
+ </small>
58
+ <span class="progressbar" v-if="uploadInitiated">
59
+ <span>{{ getPercentage(totalUploadProgress) }}</span>
60
+ <progress
61
+ max="100"
62
+ :value="totalUploadProgress"
63
+ :title="totalBytesUploaded"
64
+ ></progress>
65
+ </span>
66
+ </li>
67
+ </ul>
68
+ <hr/>
69
+ </div>
70
+ <!-- end total-upload information -->
71
+
72
+ <div v-if="listOfFiles.length" class="flex-container flex-direction-column list-files-wrapper">
73
+ <CmdHeadline v-bind="cmdHeadlineListOfSelectedFilesProperties" />
74
+ <!-- begin list of selected files -->
75
+ <ul class="list-of-files">
76
+ <li
77
+ v-for="(uploadFile, index) in listOfFiles"
78
+ :key="index"
79
+ class="flex-container flex-items-flex-none"
80
+ >
81
+ <CmdLink
82
+ v-bind="cmdLinkRemoveFilesFromListProperties"
83
+ :title="getMessage('upload_form.labeltext.remove_file_from_list', uploadFile.file.name)"
84
+ @click="removeFile(index)"
85
+ />
86
+
87
+ <span
88
+ :class="[
89
+ 'text-align-right',
90
+ uploadFile.allowedType ? 'allowed' : 'not-allowed',
91
+ { error: uploadFile.error }
92
+ ]">
93
+ {{ uploadFile.file.name }} <small>({{ formatSize(uploadFile.file.size) }})</small>
94
+ </span>
95
+
96
+ <!-- begin progressbar -->
97
+ <span class="progressbar" v-if="uploadInitiated && !uploadFile.error">
98
+ <span>{{ getPercentage(uploadFile.progress) }}</span>
99
+ <!-- do not place inside progress-tag (will not be displayed then) -->
100
+ <progress
101
+ max="100"
102
+ :value="uploadFile.progress"
103
+ :title="
104
+ formatSize(uploadFile.uploadedBytes) + '/' + formatSize(uploadFile.file.size)
105
+ "
106
+ ></progress>
107
+ </span>
108
+ <!-- end progressbar -->
109
+ </li>
110
+ </ul>
111
+ <CmdLink
112
+ v-if="failedUpload"
113
+ v-bind="cmdLinkResetUploadProperties"
114
+ @click="cancel"
115
+ />
116
+ <hr/>
117
+ </div>
118
+ </div>
119
+ <!-- end list of selected files -->
120
+
121
+ <!-- begin upload conditions -->
122
+ <div class="upload-conditions">
123
+ <CmdHeadline
124
+ v-if="listOfFiles.length"
125
+ v-bind="cmdHeadlineSelectFilesProperties"
126
+ />
127
+
128
+ <dl class="small">
129
+ <template v-if="maxTotalUploadSize > 0">
130
+ <dt :class="{ error: totalSize > maxTotalUploadSize }">
131
+ {{ getMessage("upload_form.max_total_upload_size") }}
132
+ </dt>
133
+ <dd :class="['text-align-right', { error: totalSize > maxTotalUploadSize }]">
134
+ {{ formatSize(maxTotalUploadSize) }}
135
+ </dd>
136
+ </template>
137
+ <dt :class="{ error: errors.fileSize }">
138
+ {{ getMessage("upload_form.max_file_upload_size") }}
139
+ </dt>
140
+ <dd :class="['text-align-right', { error: errors.fileSize }]">
141
+ {{ formatSize(maxFileUploadSize) }}
142
+ </dd>
143
+ <dt :class="{ error: errors.fileType }">
144
+ {{ getMessage("upload_form.allowed_file_types") }}
145
+ </dt>
146
+ <dd>
147
+ <CmdLink
148
+ @click="showListOfFileExtensions = !showListOfFileExtensions"
149
+ v-bind="cmdLinkToggleListOfFileExtensionsProperties"
150
+ />
151
+
152
+ <!-- begin list of file extensions -->
153
+ <transition :name="transitionListOfFileExtensions">
154
+ <ul v-if="showListOfFileExtensions" class="list-of-file-extensions">
155
+ <li
156
+ v-for="(fileExtension, index) in allowedFileExtensions"
157
+ :key="index"
158
+ :class="{ error: errors.fileType }"
159
+ >
160
+ {{ fileExtension }}
161
+ </li>
162
+ </ul>
163
+ </transition>
164
+ <!-- end list of file extensions -->
165
+ </dd>
166
+ </dl>
167
+ </div>
168
+ <!-- end upload conditions -->
169
+
170
+ <!-- begin upload-button and drag-and-drop-text -->
171
+ <div class="flex-container flex-direction-column no-gap">
172
+ <CmdLink
173
+ class="upload"
174
+ :disabled="uploadInitiated"
175
+ @click="selectFiles()"
176
+ v-bind="cmdLinkSelectFilesProperties"
177
+ />
178
+ <p v-if="enableDragAndDrop" :class="['text-drag-and-drop', { disabled: uploadInitiated }]">
179
+ <span>{{ getMessage("upload_form.or") }}</span>
180
+ <strong>
181
+ {{ getMessage("upload_form.drag_and_drop") }}
182
+ <template v-if="allowMultipleFileUploads && listOfFiles.length">
183
+ {{ getMessage("upload_form.additional") }}
184
+ </template>
185
+ <template v-if="!allowMultipleFileUploads && listOfFiles.length">
186
+ {{ getMessage("upload_form.new") }}
187
+ </template>
188
+ {{ getMessage("upload_form.files_to_this_area") }}
189
+ </strong>
190
+ </p>
191
+ </div>
192
+ <!-- end upload-button and drag-and-drop-text -->
193
+ </div>
194
+
195
+ <!-- begin CmdFormElement -->
196
+ <CmdFormElement
197
+ v-if="enableComment"
198
+ element="textarea"
199
+ :labelText="getMessage('upload_form.labeltext.comment')"
200
+ v-model="comment"
201
+ :required="commentRequired"
202
+ :validationMessage="commentStatusMessage"
203
+ :placeholder="getMessage('upload_form.placeholder.comment')"
204
+ :status="commentStatusMessage ? 'error' : ''"
205
+ />
206
+ <!-- end CmdFormElement -->
207
+
208
+ <!-- begin button-wrapper -->
209
+ <div class="button-wrapper stretch-on-small-devices">
210
+ <CmdLink
211
+ :disabled="
212
+ listOfFiles.length === 0 ||
213
+ (maxTotalUploadSize > 0 && totalSize > maxTotalUploadSize) ||
214
+ uploadInitiated"
215
+ v-bind="cmdLinkUploadFilesProperties"
216
+ @click="uploadFiles"
217
+ />
218
+
219
+ <CmdLink
220
+ @click="cancel"
221
+ v-bind="cmdLinkCancelIconProperties"
222
+ :class="{ disabled: listOfFiles.length === 0 }"
223
+ />
224
+ </div>
225
+ <!-- end button-wrapper -->
226
+ </fieldset>
227
+ <!-- end advanced mode -->
228
+
229
+ <!-- begin simple mode -->
230
+ <a v-else href="#" @click.prevent="selectFiles"
231
+ :class="['cmd-upload-form box', { 'drop-area': enableDragAndDrop, 'allow-drop': allowDrop }]"
232
+ v-on="dragAndDropHandler">
233
+ <!-- begin progressbar -->
234
+ <span v-if="uploadInitiated" class="progressbar">
235
+ <span>{{ getPercentage(totalUploadProgress) }}</span>
236
+ <progress
237
+ max="100"
238
+ :value="totalUploadProgress"
239
+ :title="totalBytesUploaded">
240
+ </progress>
241
+ </span>
242
+ <!-- end progressbar -->
243
+
244
+ <!-- begin slot-content -->
245
+ <slot>
246
+ <template v-if="!enableDragAndDrop">
247
+ <template v-if="fileTypeImage">
248
+ <span>{{ getMessage("upload_form.select_image") }}</span>
249
+ <!-- begin CmdIcon -->
250
+ <CmdIcon v-bind="cmdIconImage" />
251
+ <!-- end CmdIcon -->
252
+ </template>
253
+ <template v-else>
254
+ <span>{{ getMessage("upload_form.select_file") }}</span>
255
+ <!-- begin CmdIcon -->
256
+ <CmdIcon v-bind="cmdIconFileUpload" />
257
+ <!-- end CmdIcon -->
258
+ </template>
259
+ </template>
260
+ <template v-else>
261
+ <span>{{ getMessage("upload_form.drag_and_drop_file_here") }}</span>
262
+ <!-- begin CmdIcon -->
263
+ <CmdIcon v-bind="cmdIconDragAndDrop" />
264
+ <!-- end CmdIcon -->
265
+ </template>
266
+ <small>{{ getMessage("upload_form.max_upload_size") }} {{ formatSize(maxFileUploadSize) }}</small>
267
+ <small>{{ getMessage("upload_form.allowed_file_types") }} {{ allowedFileExtensions }}</small>
268
+ </slot>
269
+ <!-- end slot-content -->
270
+ </a>
271
+ <!-- end simple mode -->
272
+
273
+ <!-- begin CmdFormElement -->
274
+ <CmdFormElement
275
+ element="input"
276
+ type="file"
277
+ :labelText="getMessage('upload_form.labeltext.select_files')"
278
+ :disabled="uploadInitiated"
279
+ :multiple="allowMultipleFileUploads"
280
+ @change="filesSelected"
281
+ ref="formElement"
282
+ />
283
+ <!-- end CmdFormElement -->
284
+ <!-- end CmdUploadForm ---------------------------------------------------------------------------------------- -->
285
+ </template>
286
+
287
+ <script>
288
+ // import mixins
289
+ import I18n from "../mixins/I18n"
290
+ import DefaultMessageProperties from "../mixins/CmdUploadForm/DefaultMessageProperties"
291
+
292
+ import {getFileExtension} from "../utils/getFileExtension.js"
293
+ import axios from "axios"
294
+
295
+ export default {
296
+ name: "CmdUploadForm",
297
+ emits: ["click", "error", "upload-complete", "upload-file-success"],
298
+ mixins: [I18n, DefaultMessageProperties],
299
+ inject: {
300
+ editModeContext: {
301
+ default: null
302
+ }
303
+ },
304
+ data() {
305
+ return {
306
+ comment: "",
307
+ allowDrop: false,
308
+ listOfFiles: [],
309
+ systemMessages: [],
310
+ defaultSystemMessageStatus: "",
311
+ showListOfFileExtensions: false,
312
+ resetForm: {},
313
+ uploadInitiated: false,
314
+ errors: {}
315
+ }
316
+ },
317
+ created() {
318
+ // Set initial data for resetForm.
319
+ this.resetForm.comment = this.presetComment
320
+ this.resetForm.allowDrop = this.allowDrop
321
+ this.resetForm.listOfFiles = JSON.parse(JSON.stringify(this.listOfFiles))
322
+ this.resetForm.systemMessages = this.systemMessages
323
+ this.resetForm.systemMessageStatus = this.systemMessageStatus
324
+ },
325
+ props: {
326
+ /**
327
+ * define the transition when the list of file extensions is toggled
328
+ *
329
+ * @allowedValues: "none", "fade", "scroll"
330
+ */
331
+ transitionListOfFileExtensions: {
332
+ type: String,
333
+ default: "fade"
334
+ },
335
+ /**
336
+ * activate if transition for hiding list of file extensions
337
+ */
338
+ useTransition: {
339
+ type: Boolean,
340
+ default: true
341
+ },
342
+ /**
343
+ * toggle visibility of total upload (number of files, total size, total progress
344
+ */
345
+ showTotalUpload: {
346
+ type: Boolean,
347
+ default: true
348
+ },
349
+ /**
350
+ * toggle if upload is handled by component itself or by outer component
351
+ */
352
+ componentHandlesUpload: {
353
+ type: Boolean,
354
+ default: true
355
+ },
356
+ /**
357
+ * list of allowed file extensions to upload (all can be selected)
358
+ */
359
+ allowedFileExtensions: {
360
+ type: Array,
361
+ required: true
362
+ },
363
+ /**
364
+ * activate if the comment given by the user should be mandatory
365
+ *
366
+ * enableComment-property must be set to true
367
+ */
368
+ commentRequired: {
369
+ type: Boolean,
370
+ default: true
371
+ },
372
+ /**
373
+ * show a message if mandatory comment-textarea is not filled
374
+ *
375
+ * enableComment-property and commentRequired-property must be set to true
376
+ */
377
+ commentStatusMessage: {
378
+ type: String,
379
+ default: ""
380
+ },
381
+ /**
382
+ * enable if files can also be dragged (and dropped) into upload-area
383
+ */
384
+ enableDragAndDrop: {
385
+ type: Boolean,
386
+ default: false
387
+ },
388
+ /**
389
+ * enable if a comment should be possible to left by the user
390
+ */
391
+ enableComment: {
392
+ type: Boolean,
393
+ default: true
394
+ },
395
+ /**
396
+ * preset the comment-textarea
397
+ *
398
+ * enableComment-property must be set to true
399
+ */
400
+ presetComment: {
401
+ type: String,
402
+ default: ""
403
+ },
404
+ /**
405
+ * set to 0 if no maximum for total upload size should be set
406
+ */
407
+ maxTotalUploadSize: {
408
+ type: Number,
409
+ default: 5242880
410
+ },
411
+ /**
412
+ * max file size (in bytes) for each single file
413
+ */
414
+ maxFileUploadSize: {
415
+ type: Number,
416
+ default: 10485760
417
+ },
418
+ /**
419
+ * enable if more than file should be enabled to be selected for upload
420
+ */
421
+ allowMultipleFileUploads: {
422
+ type: Boolean,
423
+ default: false
424
+ },
425
+ /**
426
+ * defines upload options if component handles upload itself
427
+ *
428
+ * componentHandlesUpload-property must be true
429
+ */
430
+ uploadOptions: {
431
+ type: Object,
432
+ required: false
433
+ },
434
+ /**
435
+ * activate to use full upload-form-style and -functionality
436
+ *
437
+ * @affectsStyling: true
438
+ */
439
+ advancedMode: {
440
+ type: Boolean,
441
+ default: true
442
+ },
443
+ /**
444
+ * legend for form
445
+ *
446
+ * useFieldset-property must be activated
447
+ *
448
+ * @requiredForAccessiblity: true
449
+ */
450
+ legend: {
451
+ type: Object,
452
+ default() {
453
+ return {
454
+ show: true,
455
+ align: "left",
456
+ text: "Legend"
457
+ }
458
+ }
459
+ },
460
+ /**
461
+ * set icon for invisible-icon
462
+ */
463
+ iconInvisible: {
464
+ type: Object,
465
+ default() {
466
+ return {
467
+ iconClass: "icon-not-visible"
468
+ }
469
+ }
470
+ },
471
+ /**
472
+ * set icon class for visible-icon
473
+ */
474
+ iconVisible: {
475
+ type: Object,
476
+ default() {
477
+ return {
478
+ iconClass: "icon-visible"
479
+ }
480
+ }
481
+ },
482
+ /**
483
+ * properties for CmdIcon for "drag-and-drop"-icon
484
+ */
485
+ cmdIconDragAndDrop: {
486
+ type: Object,
487
+ default() {
488
+ return {
489
+ iconClass: "icon-not-visible"
490
+ }
491
+ }
492
+ },
493
+ /**
494
+ * properties for CmdIcon for "image"-icon
495
+ */
496
+ cmdIconFileUpload: {
497
+ type: Object,
498
+ default() {
499
+ return {
500
+ iconClass: "icon-file"
501
+ }
502
+ }
503
+ },
504
+ /**
505
+ * properties for CmdIcon for "image"-icon
506
+ */
507
+ cmdIconImage: {
508
+ type: Object,
509
+ default() {
510
+ return {
511
+ iconClass: "icon-image"
512
+ }
513
+ }
514
+ },
515
+ /**
516
+ * properties for CmdLink-component for removing (before added) files from list
517
+ *
518
+ */
519
+ cmdLinkRemoveFilesFromList: {
520
+ type: Object,
521
+ required: false
522
+ },
523
+ /**
524
+ * properties for CmdLink-component for selecting file(s)
525
+ */
526
+ cmdLinkSelectFiles: {
527
+ type: Object,
528
+ required: false
529
+ },
530
+ /**
531
+ * properties for CmdLink-component for uploading file(s)
532
+ */
533
+ cmdLinkUploadFiles: {
534
+ type: Object,
535
+ required: false
536
+ },
537
+ /**
538
+ * properties for CmdLink-component for cancel-icon
539
+ */
540
+ cmdLinkCancelIcon: {
541
+ type: Object,
542
+ required: false
543
+ },
544
+ /**
545
+ * properties for CmdLink-component to toggle the list of file extensions
546
+ *
547
+ * icon is set by iconVisible- and iconInvisible-properties
548
+ */
549
+ cmdLinkToggleListOfFileExtensions: {
550
+ type: Object,
551
+ required: false
552
+ },
553
+ /**
554
+ * properties for CmdLink-component to reset upload (if upload failed before)
555
+ */
556
+ cmdLinkResetUpload: {
557
+ type: Object,
558
+ required: false
559
+ },
560
+ /**
561
+ * properties for CmdHeadline-component at top of the fieldset
562
+ */
563
+ cmdHeadlineForFieldset: {
564
+ type: Object,
565
+ required: false
566
+ },
567
+ /**
568
+ * properties for CmdHeadline-component shown if no files for upload exist
569
+ */
570
+ cmdHeadlineNoFilesToUpload: {
571
+ type: Object,
572
+ required: false
573
+ },
574
+ /**
575
+ * properties for CmdHeadline-component shown if no file for upload exist
576
+ */
577
+ cmdHeadlineNoFileToUpload: {
578
+ type: Object,
579
+ required: false
580
+ },
581
+ /**
582
+ * properties for CmdHeadline-component for 'summary of all files'
583
+ */
584
+ cmdHeadlineSummaryOfAllFiles: {
585
+ type: Object,
586
+ required: false
587
+ },
588
+ /**
589
+ * properties for CmdHeadline-component for 'list of selected files'
590
+ */
591
+ cmdHeadlineListOfSelectedFiles: {
592
+ type: Object,
593
+ required: false
594
+ },
595
+ /**
596
+ * properties for CmdHeadline-component for 'select additional/new file(s)'
597
+ */
598
+ cmdHeadlineSelectFiles: {
599
+ type: Object,
600
+ required: false
601
+ },
602
+ },
603
+ computed: {
604
+ cmdHeadlineForFieldsetProperties() {
605
+ return {
606
+ show: true,
607
+ headlineLevel: 3,
608
+ ...this.cmdHeadlineForFieldset
609
+ }
610
+ },
611
+ cmdHeadlineNoFilesToUploadProperties() {
612
+ return {
613
+ headlineLevel: 4,
614
+ ...this.cmdHeadlineNoFilesToUpload,
615
+ headlineText: this.allowMultipleFileUploads ? this.getMessage("upload_form.no_files_to_upload") : this.getMessage("upload_form.no_file_to_upload")
616
+ }
617
+ },
618
+ cmdHeadlineListOfSelectedFilesProperties() {
619
+ return {
620
+ headlineLeveL: 4,
621
+ headlineText: this.getMessage("upload_form.headline.list_of_selected_files"),
622
+ ...this.cmdHeadlineListOfSelectedFiles
623
+ }
624
+ },
625
+ cmdHeadlineSummaryOfAllFilesProperties() {
626
+ return {
627
+ headlineLevel: 4,
628
+ headlineText: this.getMessage("upload_form.headline.summary_of_all_files"),
629
+ ...this.cmdHeadlineSummaryOfAllFiles
630
+ }
631
+ },
632
+ cmdHeadlineSelectFilesProperties() {
633
+ return {
634
+ headlineLevel: 4,
635
+ headlineText: this.allowMultipleFileUploads ? this.getMessage("upload_form.headline.select_additional_files") : this.getMessage("upload_form.headline.select_new_file"),
636
+ ...this.cmdHeadlineSelectFiles
637
+ }
638
+ },
639
+ cmdLinkCancelIconProperties() {
640
+ return {
641
+ linkType: "button",
642
+ highlightLevel: null,
643
+ icon: {
644
+ iconClass: "icon-cancel-circle"
645
+ },
646
+ text: this.getMessage("upload_form.buttontext.cancel"),
647
+ ...this.cmdLinkCancelIcon
648
+ }
649
+ },
650
+ cmdLinkSelectFilesProperties() {
651
+ return {
652
+ linkType: "button",
653
+ icon: {
654
+ iconClass: "icon-file-upload"
655
+ },
656
+ text: this.allowMultipleFileUploads ? this.getMessage("upload_form.labeltext.select_files") : this.getMessage("upload_form.labeltext.select_file") ,
657
+ ...this.cmdLinkSelectFiles
658
+ }
659
+ },
660
+ cmdLinkToggleListOfFileExtensionsProperties() {
661
+ return {
662
+ icon: {
663
+ iconClass: this.showListOfFileExtensions ? this.iconInvisible?.iconClass : this.iconVisible?.iconClass,
664
+ type: this.showListOfFileExtensions ? this.iconInvisible?.iconType : this.iconVisible?.iconType,
665
+ tooltip: this.getMessage('upload_form.tooltip.toggle_list_of_allowed_file_types')
666
+ },
667
+ ...this.cmdLinkToggleListOfFileExtensions
668
+ }
669
+ },
670
+ cmdLinkUploadFilesProperties() {
671
+ return {
672
+ linkType: "button",
673
+ icon: {
674
+ iconClass: "icon-upload"
675
+ },
676
+ text: this.listOfFiles.length === 1 || !this.allowMultipleFileUploads ? this.getMessage("upload_form.buttontext.upload_file") : this.getMessage("upload_form.buttontext.upload_files"),
677
+ ...this.cmdLinkUploadFiles
678
+ }
679
+ },
680
+ cmdLinkCancelUploadProperties() {
681
+ return {
682
+ icon: {
683
+ iconClass: "icon-delete",
684
+ tooltip: this.getMessage('upload_form.labeltext.remove_all_files_from_list')
685
+ },
686
+ ...this.cmdLinkCancelUpload
687
+ }
688
+ },
689
+ cmdLinkRemoveFilesFromListProperties() {
690
+ return {
691
+ icon: {
692
+ iconClass: "icon-delete"
693
+ },
694
+ ...this.cmdLinkRemoveFilesFromList
695
+ }
696
+ },
697
+ cmdLinkResetUploadProperties() {
698
+ return {
699
+ icon: {
700
+ iconClass: "icon-loop-left",
701
+ tooltip: this.getMessage('upload_form.all_files_will_be_removed')
702
+ },
703
+ text: this.getMessage("upload_form.reset_upload"),
704
+ ...this.cmdLinkResetUpload
705
+ }
706
+ },
707
+ fileTypeImage() {
708
+ return this.allowedFileExtensions.some(extension => extension.includes('jpg'));
709
+ },
710
+ failedUpload() {
711
+ return this.listOfFiles.some(file => file.error)
712
+ },
713
+ totalBytesUploaded() {
714
+ const bytes = this.listOfFiles
715
+ .map(uploadFile => [
716
+ uploadFile.file.size,
717
+ ((uploadFile.progress || 0) * uploadFile.file.size) / 100
718
+ ])
719
+ .reduce((a, b) => [a[0] + b[0], a[1] + b[1]])
720
+ return this.formatSize(bytes[1]) + "/" + this.formatSize(bytes[0])
721
+ },
722
+ totalSize() {
723
+ let totalSize = 0
724
+ for (let i = 0; i < this.listOfFiles.length; i++) {
725
+ totalSize = totalSize + this.listOfFiles[i].file.size
726
+ }
727
+ return totalSize
728
+ },
729
+ allSystemMessages() {
730
+ if (this.maxTotalUploadSize > 0 && this.totalSize > this.maxTotalUploadSize) {
731
+ return [
732
+ this.getMessage("upload_form.system_message_total_size_of_files_too_large"),
733
+ ...this.systemMessages
734
+ ]
735
+ }
736
+ return this.systemMessages
737
+ },
738
+ systemMessageStatus() {
739
+ return this.defaultSystemMessageStatus || (this.allSystemMessages.length ? "error" : "")
740
+ },
741
+ dragAndDropHandler() {
742
+ // register handlers only if drag-and-drop is enabled
743
+ if (this.enableDragAndDrop) {
744
+ return {
745
+ dragenter: this.dragEnter,
746
+ dragover: this.dragOver,
747
+ dragleave: this.dragLeave,
748
+ drop: this.drop
749
+ }
750
+ }
751
+ return {}
752
+ },
753
+ totalUploadProgress() {
754
+ const progress = this.listOfFiles
755
+ .map(uploadFile => [
756
+ uploadFile.file.size,
757
+ ((uploadFile.progress || 0) * uploadFile.file.size) / 100
758
+ ])
759
+ .reduce((a, b) => [a[0] + b[0], a[1] + b[1]])
760
+ return (progress[1] / progress[0]) * 100
761
+ }
762
+ },
763
+ watch: {
764
+ presetComment: {
765
+ handler(newValue) {
766
+ this.comment = newValue
767
+ },
768
+ immediate: true
769
+ }
770
+ },
771
+ methods: {
772
+ getPercentage(percentage) {
773
+ if (percentage) {
774
+ return percentage.toFixed(2) + "%"
775
+ }
776
+ return "0.00%"
777
+ },
778
+ // use imported function as method (to use in template)
779
+ getFileExtension(filename) {
780
+ return getFileExtension(filename)
781
+ },
782
+ selectFiles() {
783
+ let inputFile = this.$refs.formElement.getDomElement().querySelector("input[type='file']")
784
+ inputFile.click()
785
+ },
786
+ dragEnter(event) {
787
+ this.dragOver(event)
788
+ },
789
+ dragOver(event) {
790
+ if (event.dataTransfer && event.dataTransfer.items && event.dataTransfer.items.length > 0) {
791
+ event.dataTransfer.dropEffect = "none"
792
+ let allowed = true
793
+ for (let i = 0, c = event.dataTransfer.items.length; i < c; ++i) {
794
+ let item = event.dataTransfer.items[i]
795
+ if (item.kind !== "file" /*|| !this._allowedTypes[item.type]*/) {
796
+ allowed = false
797
+ break
798
+ }
799
+ }
800
+ if (allowed) {
801
+ event.preventDefault()
802
+ event.dataTransfer.dropEffect = "copy"
803
+ this.allowDrop = true
804
+ // this._handle_dragover(event)
805
+ }
806
+ }
807
+ },
808
+ dragLeave() {
809
+ this.allowDrop = false
810
+ },
811
+ /*
812
+ drag(event) {
813
+ alert("dropped")
814
+ event.dataTransfer.setData("text", event.target.id)
815
+ },
816
+ */
817
+ drop(event) {
818
+ this.allowDrop = false
819
+ if (event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files.length > 0) {
820
+ event.preventDefault()
821
+ this.checkFiles(event.dataTransfer.files)
822
+ }
823
+ },
824
+ cancelUpload() {
825
+ // cancel upload for each file
826
+ this.listOfFiles.forEach(file => {
827
+ if (file.abortController) {
828
+ file.abortController.abort()
829
+ }
830
+ })
831
+
832
+ // clear list of files, remove error-highlighting and hide all system-messages afterwards
833
+ this.errors = {}
834
+ this.listOfFiles = []
835
+ this.hideAllSystemMessages()
836
+
837
+ // set uploadInitiated to false to enable all disabled buttons
838
+ this.uploadInitiated = false
839
+ },
840
+ cancel() {
841
+ this.cancelUpload()
842
+
843
+ // emit click event with argument "cancel" to react in outer component
844
+ this.$emit("click", "cancel")
845
+ },
846
+ filesSelected(event) {
847
+ this.checkFiles(event.target.files)
848
+ },
849
+ checkFiles(files) {
850
+ if (!files.length) {
851
+ return
852
+ }
853
+
854
+ this.defaultSystemMessageStatus = ""; // hide systemMessage if already is shown
855
+ this.systemMessages = [] // hide systemMessage if already is shown
856
+ this.errors = {}
857
+
858
+ for (let i = 0; i < files.length; i++) {
859
+ // define file-object which will be pushed in listOfFiles
860
+ const uploadFile = {
861
+ file: files[i],
862
+ progress: null,
863
+ uploadedBytes: 0
864
+ }
865
+
866
+ // check size for current file
867
+ if (files[i].size > this.maxFileUploadSize) {
868
+ this.errors.fileSize = true
869
+ this.systemMessages.push(
870
+ this.getMessage(
871
+ "upload_form.system_message.file_size_too_large",
872
+ files[i].name,
873
+ files[i].size
874
+ )
875
+ )
876
+ continue
877
+ }
878
+
879
+ // check if current file has allowed file-type (else continue with next file)
880
+ if (!this.allowedFileExtensions.includes(getFileExtension(files[i].name))) {
881
+ this.showListOfFileExtensions = true
882
+ this.errors.fileType = true
883
+ this.systemMessages.push(
884
+ this.getMessage(
885
+ "upload_form.system_message.not_allowed_file_type",
886
+ files[i].name,
887
+ getFileExtension(files[i].name)
888
+ )
889
+ )
890
+ continue
891
+ }
892
+
893
+ // check (if multiple files can be selected) if current file already exists in listOfFiles
894
+ if (
895
+ this.allowMultipleFileUploads &&
896
+ this.listOfFiles.some(listOfFilesEntry =>
897
+ this.compareFiles(listOfFilesEntry.file, files[i])
898
+ )
899
+ ) {
900
+ this.systemMessages.push(
901
+ this.getMessage(
902
+ "upload_form.system_message.duplicate_file",
903
+ files[i].name,
904
+ getFileExtension(files[i].name)
905
+ )
906
+ )
907
+ continue
908
+ }
909
+
910
+ if (this.allowMultipleFileUploads) {
911
+ // push file-object (for each valid file) to listOfFiles-array
912
+ this.listOfFiles.push(uploadFile)
913
+ } else {
914
+ if (files.length > 1) {
915
+ this.systemMessages.push(
916
+ this.getMessage("upload_form.system_message.only_one_file_allowed")
917
+ )
918
+ }
919
+ // assign uploadFile-object (which contains current (and valid) file to listOfFiles-array
920
+ this.listOfFiles = [uploadFile]
921
+ break
922
+ }
923
+ }
924
+
925
+ if (!this.advancedMode) {
926
+ if (this.systemMessages.length) {
927
+ this.$emit("error", {messages: this.systemMessages})
928
+ return
929
+ }
930
+ if (this.listOfFiles.length) {
931
+ this.uploadFiles()
932
+ }
933
+ }
934
+ },
935
+ compareFiles(file1, file2) {
936
+ return (
937
+ file1.name === file2.name &&
938
+ file1.lastModified === file2.lastModified &&
939
+ file1.size === file2.size
940
+ )
941
+ },
942
+ removeFile(index) {
943
+ /* remove specific file from list */
944
+ this.listOfFiles.splice(index, 1)
945
+ if (!this.listOfFiles.length) {
946
+ this.uploadInitiated = false
947
+ }
948
+ this.hideAllSystemMessages()
949
+ },
950
+ hideAllSystemMessages() {
951
+ // hide all system-messages if all files are removed from list
952
+ if (!this.listOfFiles.length) {
953
+ this.systemMessages = []
954
+ }
955
+ },
956
+ formatSize(size) {
957
+ if (size < 1024) {
958
+ return size
959
+ } else if (size < 1048576) {
960
+ return (size = Math.round((size / 1024) * 100) / 100 + " KB")
961
+ } else {
962
+ return (size = Math.round((size / 1048576) * 100) / 100 + " MB")
963
+ }
964
+ },
965
+ uploadFiles() {
966
+ this.systemMessages = []
967
+ this.errors = {}
968
+ this.defaultSystemMessageStatus = ""
969
+
970
+ if (
971
+ this.enableComment &&
972
+ !this.comment &&
973
+ this.commentRequired &&
974
+ this.commentStatusMessage
975
+ ) {
976
+ this.defaultSystemMessageStatus = "error"
977
+ this.systemMessages.push(this.getMessage("upload_form.system_message.fill_required"))
978
+ } else {
979
+ this.uploadInitiated = true
980
+
981
+ if (this.componentHandlesUpload && this.uploadOptions && this.uploadOptions.url) {
982
+ const url = new URL(this.uploadOptions.url, location.href)
983
+ const formData = new FormData()
984
+
985
+ // // append information about files to formData-object
986
+ // formData.append(
987
+ // this.uploadOptions.filesParam ? this.uploadOptions.filesParam : "files",
988
+ // this.listOfFiles.map(uploadFile => uploadFile.file)
989
+ // )
990
+
991
+ // iterate over additionalParams-object and append to formData-object
992
+ Object.entries(this.uploadOptions.additionalParams || {}).forEach(([key, value]) =>
993
+ formData.append(key, value)
994
+ )
995
+
996
+ // append comment to formData-object
997
+ if (this.enableComment) {
998
+ formData.append("comment", this.comment)
999
+ }
1000
+
1001
+ const requests = []
1002
+
1003
+ // iterate over list-of-files to send upload request for each file individually
1004
+ this.listOfFiles.forEach(file => {
1005
+ requests.push(this.uploadSingleFile(url, file, formData))
1006
+ })
1007
+
1008
+ // check upload-status for each file individually
1009
+ Promise.allSettled(requests).then(results => {
1010
+ // if status equals "rejected" the upload was not successful and the file will not be deleted from list
1011
+ const rejectedFiles = results.filter(result => result.status === "rejected")
1012
+ this.uploadInitiated = false
1013
+
1014
+ if (rejectedFiles.length) {
1015
+ this.defaultSystemMessageStatus = "error"
1016
+ this.systemMessages.push(
1017
+ this.getMessage(
1018
+ "upload_form.system_message.some_files_are_not_uploaded_successfully"
1019
+ )
1020
+ )
1021
+ } else {
1022
+ this.defaultSystemMessageStatus = "success"
1023
+ this.systemMessages.push(
1024
+ this.getMessage("upload_form.system_message.all_files_are_uploaded_successfully")
1025
+ )
1026
+ }
1027
+
1028
+ this.$emit("upload-complete", {success: !rejectedFiles.length})
1029
+ })
1030
+ } else {
1031
+ let uploadObj = {}
1032
+ uploadObj.listOfFiles = this.listOfFiles
1033
+ uploadObj.type = "upload"
1034
+ uploadObj.comment = this.comment
1035
+
1036
+ // emit uploadObj to handle upload by outer component
1037
+ this.$emit("click", uploadObj, this.showMessage)
1038
+ }
1039
+ }
1040
+ },
1041
+ onUploadProgress(event, uploadFile) {
1042
+ if (event.lengthComputable) {
1043
+ uploadFile.progress = (event.loaded / event.total) * 100
1044
+ uploadFile.uploadedBytes = event.loaded
1045
+ } else {
1046
+ uploadFile.progress = null
1047
+ uploadFile.uploadedBytes = 0
1048
+ }
1049
+ this.$forceUpdate()
1050
+ },
1051
+ uploadSingleFile(url, file, formData) {
1052
+ file.abortController = new AbortController()
1053
+
1054
+ // append information about given file to formData-object
1055
+ formData.set(
1056
+ this.uploadOptions.filesParam ? this.uploadOptions.filesParam : "files",
1057
+ file.file
1058
+ )
1059
+
1060
+ return (
1061
+ axios
1062
+ .post(url, formData, {
1063
+ signal: file.abortController.signal,
1064
+ onUploadProgress: event => this.onUploadProgress(event, file)
1065
+ })
1066
+ // emit information about successful-upload + file
1067
+ .then(response => {
1068
+ this.$emit("upload-file-success", file)
1069
+ return response
1070
+ })
1071
+ // delete uploaded file from list-of-files-array
1072
+ .then(response => {
1073
+ const positionOfFile = this.listOfFiles.indexOf(file)
1074
+ if (positionOfFile !== -1) {
1075
+ this.listOfFiles.splice(positionOfFile, 1)
1076
+ }
1077
+ return response
1078
+ })
1079
+ .catch(error => {
1080
+ this.defaultSystemMessageStatus = "error"
1081
+ this.systemMessages.push(error)
1082
+ file.error = true
1083
+ throw new Error()
1084
+ })
1085
+ )
1086
+ },
1087
+ showMessage(result) {
1088
+ if (result === true) {
1089
+ this.defaultSystemMessageStatus = "success"
1090
+ this.systemMessages.push(this.getMessage("upload_form.system_message.upload_success"))
1091
+ } else if (result === false) {
1092
+ this.defaultSystemMessageStatus = "error"
1093
+ this.systemMessages.push(this.getMessage("upload_form.system_message.upload_failed"))
1094
+ }
1095
+ },
1096
+ resetFields() {
1097
+ if (typeof this.resetForm === "object") {
1098
+ const resetArr = Object.keys(this.resetForm)
1099
+ for (let key of resetArr) {
1100
+ if (typeof this.resetForm[key] === "object") {
1101
+ this[key] = JSON.parse(JSON.stringify(this.resetForm[key]))
1102
+ } else {
1103
+ this[key] = this.resetForm[key]
1104
+ }
1105
+ }
1106
+ }
1107
+ }
1108
+ }
1109
+ }
1110
+ </script>
1111
+
1112
+ <style>
1113
+ /* begin cmd-upload-form -------------------------------------------------------------------------------------------- */
1114
+ .cmd-upload-form {
1115
+ .cmd-custom-headline {
1116
+ margin: 0;
1117
+ justify-content: center;
1118
+ }
1119
+
1120
+ /* begin box for simple-mode */
1121
+ &.box {
1122
+ display: inline-flex;
1123
+ flex-direction: column;
1124
+ background: var(--color-scheme-background-subtle);
1125
+
1126
+ text-decoration: none;
1127
+ text-align: center;
1128
+ padding: var(--default-padding);
1129
+
1130
+ span {
1131
+ margin: 0;
1132
+
1133
+ &[class*="icon-"] {
1134
+ font-size: 5rem;
1135
+ }
1136
+ }
1137
+ }
1138
+ /* end box for simple-mode */
1139
+
1140
+ .box {
1141
+ box-shadow: none;
1142
+ background: var(--color-scheme-background);
1143
+ border: var(--default-border);
1144
+ align-items: center;
1145
+
1146
+ dl {
1147
+ justify-content: center;
1148
+ text-align: left;
1149
+
1150
+ .list-of-file-extensions {
1151
+ display: table;
1152
+
1153
+ > li:only-child {
1154
+ list-style-type: none;
1155
+ margin: 0;
1156
+ }
1157
+ }
1158
+ }
1159
+ }
1160
+
1161
+ .total-files {
1162
+ > * {
1163
+ white-space: nowrap;
1164
+
1165
+ &:not(a) {
1166
+ font-weight: bold;
1167
+ }
1168
+ }
1169
+ }
1170
+
1171
+ [class*="list-of-file"] {
1172
+ max-height: 10rem;
1173
+ overflow-x: hidden;
1174
+ overflow-y: auto;
1175
+ border: var(--default-border);
1176
+ padding: var(--default-padding);
1177
+ margin: 0;
1178
+
1179
+ > li {
1180
+ flex-wrap: nowrap;
1181
+
1182
+ .progressbar {
1183
+ display: table;
1184
+ align-self: center;
1185
+
1186
+ progress {
1187
+ &[value] {
1188
+ background: var(--color-scheme-background);
1189
+
1190
+ &::-moz-progress-bar {
1191
+ border-top-left-radius: var(--default-border-radius);
1192
+ border-bottom-left-radius: var(--default-border-radius);
1193
+ background: var(--primary-color);
1194
+ }
1195
+ }
1196
+ }
1197
+
1198
+ & > span {
1199
+ position: absolute;
1200
+ left: 50%;
1201
+ transform: translateX(-50%);
1202
+ z-index: 1;
1203
+ display: table;
1204
+ top: .2rem;
1205
+ padding: .1rem .2rem;
1206
+ line-height: 100%;
1207
+ background: var(--color-scheme-background);
1208
+ }
1209
+ }
1210
+ }
1211
+ }
1212
+
1213
+ .list-files-wrapper {
1214
+ justify-content: center;
1215
+ align-items: center;
1216
+
1217
+ .list-of-files {
1218
+ display: inline-flex;
1219
+ flex-direction: column;
1220
+ gap: calc(var(--default-gap) / 2);
1221
+
1222
+ li {
1223
+ list-style-type: none;
1224
+ margin-left: 0;
1225
+ gap: calc(var(--default-gap) / 2);
1226
+
1227
+ > a:hover, a:active, a:focus {
1228
+ ~ * {
1229
+ color: var(--hyperlink-color-highlighted);
1230
+ }
1231
+ }
1232
+ }
1233
+
1234
+ & + a {
1235
+ display: table;
1236
+ margin: 0 auto;
1237
+ }
1238
+ }
1239
+
1240
+ hr {
1241
+ width: 100%; /* will be 0 instead (because of align-items: center for parent) */
1242
+ }
1243
+ }
1244
+
1245
+ .upload-conditions {
1246
+ .cmd-headline > * {
1247
+ text-align: center;
1248
+ }
1249
+
1250
+ dl {
1251
+ margin: 0;
1252
+ }
1253
+ }
1254
+
1255
+ p {
1256
+ &.text-drag-and-drop {
1257
+ &.disabled {
1258
+ background: none !important; /* overwrite default styling for .disabled */
1259
+ }
1260
+ }
1261
+ }
1262
+
1263
+ .button.upload {
1264
+ align-self: center;
1265
+
1266
+ & ~ p {
1267
+ & > * {
1268
+ display: block;
1269
+ }
1270
+ }
1271
+ }
1272
+
1273
+ .error {
1274
+ color: var(--error-color-text);
1275
+ }
1276
+
1277
+ & + .cmd-form-element {
1278
+ display: none;
1279
+ }
1280
+
1281
+ .drop-area, &.drop-area {
1282
+ border: var(--default-border);
1283
+ border-style: dashed;
1284
+ background: var(--color-scheme-background);
1285
+ padding: var(--default-padding);
1286
+ text-align: center;
1287
+
1288
+ &.allow-drop {
1289
+ border-style: solid;
1290
+ }
1291
+
1292
+ > [class*="icon-"] {
1293
+ font-size: 5rem;
1294
+ }
1295
+ }
1296
+ }
1297
+
1298
+ /* end cmd-upload-form ---------------------------------------------------------------------------------------------- */
1299
+ </style>