pui9-components 1.16.4

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 (60) hide show
  1. package/README.md +43 -0
  2. package/dist/demo.html +10 -0
  3. package/dist/pui9-components.common.js +81953 -0
  4. package/dist/pui9-components.common.js.map +1 -0
  5. package/dist/pui9-components.css +5 -0
  6. package/dist/pui9-components.umd.js +81963 -0
  7. package/dist/pui9-components.umd.js.map +1 -0
  8. package/dist/pui9-components.umd.min.js +308 -0
  9. package/dist/pui9-components.umd.min.js.map +1 -0
  10. package/package-lock.json +15945 -0
  11. package/package.json +78 -0
  12. package/src/App.vue +117 -0
  13. package/src/components/PuiCheckbox.vue +105 -0
  14. package/src/components/PuiCodeEditor.vue +123 -0
  15. package/src/components/PuiDateField.vue +1004 -0
  16. package/src/components/PuiField.vue +30 -0
  17. package/src/components/PuiFieldSet.vue +27 -0
  18. package/src/components/PuiFormFooter.vue +64 -0
  19. package/src/components/PuiFormFooterBtns.vue +118 -0
  20. package/src/components/PuiFormHeader.vue +25 -0
  21. package/src/components/PuiFormLoading.vue +12 -0
  22. package/src/components/PuiFormMiniAudit.vue +53 -0
  23. package/src/components/PuiMasterDetail.vue +96 -0
  24. package/src/components/PuiModalDialog.vue +87 -0
  25. package/src/components/PuiModalDialogForm.vue +205 -0
  26. package/src/components/PuiMultiSelect.vue +499 -0
  27. package/src/components/PuiNumberField.vue +503 -0
  28. package/src/components/PuiPasswordField.vue +105 -0
  29. package/src/components/PuiRadioGroup.vue +105 -0
  30. package/src/components/PuiRichTextEditor.vue +117 -0
  31. package/src/components/PuiSelect.vue +1638 -0
  32. package/src/components/PuiSelectDetailDialog.vue +106 -0
  33. package/src/components/PuiSelectTextService.vue +61 -0
  34. package/src/components/PuiSpinnerField.vue +484 -0
  35. package/src/components/PuiSwitch.vue +104 -0
  36. package/src/components/PuiTextArea.vue +203 -0
  37. package/src/components/PuiTextField.vue +272 -0
  38. package/src/dateTimeUtils.js +78 -0
  39. package/src/index.js +73 -0
  40. package/src/main.js +33 -0
  41. package/src/mixins/PuiFormComponentMixin.js +81 -0
  42. package/src/mixins/PuiMultiSelectMixin.js +106 -0
  43. package/src/mixins/PuiUtilsNumberMixin.js +19 -0
  44. package/src/plugins/vuetify.js +32 -0
  45. package/src/tests/TestAutocomplete.vue +138 -0
  46. package/src/tests/TestCodeEditor.vue +48 -0
  47. package/src/tests/TestField.vue +22 -0
  48. package/src/tests/TestFieldSet.vue +30 -0
  49. package/src/tests/TestInputCheckbox.vue +53 -0
  50. package/src/tests/TestInputDate.vue +146 -0
  51. package/src/tests/TestInputNumber.vue +77 -0
  52. package/src/tests/TestInputRadioGroup.vue +86 -0
  53. package/src/tests/TestInputSpinner.vue +77 -0
  54. package/src/tests/TestInputSwitch.vue +52 -0
  55. package/src/tests/TestInputText.vue +120 -0
  56. package/src/tests/TestInputTextArea.vue +73 -0
  57. package/src/tests/TestMultiSelect.vue +127 -0
  58. package/src/tests/TestPuiForm.vue +68 -0
  59. package/src/tests/TestRichTextEditor.vue +54 -0
  60. package/src/utils.js +148 -0
@@ -0,0 +1,1004 @@
1
+ <template>
2
+ <!-- DESKTOP -->
3
+ <div v-if="!isMobile">
4
+ <div v-if="toplabel" class="ml-1 mr-1">
5
+ <v-layout>
6
+ <v-flex xs12>
7
+ <label v-if="getLabel === '$nbsp;'">&nbsp;</label>
8
+ <label v-else :class="getLabelRequiredClass">{{ getLabel }}</label>
9
+ <v-tooltip top v-if="showTooltip">
10
+ <template v-slot:activator="{ on, attrs }">
11
+ <v-icon class="info-tooltip" size="14" v-bind="attrs" v-on="on">fas fa-info-circle info-tooltip</v-icon>
12
+ </template>
13
+ <span>
14
+ <span v-if="this.description !== ''">
15
+ {{ this.description }}
16
+ <hr v-if="this.infoTooltipMessages.length > 0" />
17
+ </span>
18
+ <ul>
19
+ <li v-for="(message, index) in this.infoTooltipMessages" :key="index">{{ message }}</li>
20
+ </ul>
21
+ </span>
22
+ </v-tooltip>
23
+ </v-flex>
24
+ </v-layout>
25
+ <v-layout>
26
+ <v-flex xs12>
27
+ <v-layout>
28
+ <v-flex :xs8="showTime" :xs12="!showTime">
29
+ <!-- use attach on v-menu but it does not working at the moment... -->
30
+ <!-- :attach="`#${attach !== null ? attach : defaultId}`" -->
31
+ <v-menu
32
+ :close-on-content-click="false"
33
+ v-model="modelMenu"
34
+ :nudge-right="40"
35
+ transition="scale-transition"
36
+ offset-y
37
+ min-width="290px"
38
+ :disabled="disabled"
39
+ ><template v-slot:activator="{ on, attrs }">
40
+ <v-text-field
41
+ :id="`${attach !== null ? attach : defaultId}`"
42
+ v-on="on"
43
+ v-bind="attrs"
44
+ v-model="internalDateModel"
45
+ :class="getEditedClass"
46
+ :rules="getDateRules"
47
+ append-icon="far fa-calendar-day"
48
+ solo
49
+ outlined
50
+ flat
51
+ :readonly="disableTextInput"
52
+ :disabled="disabled"
53
+ :mask="getMask"
54
+ :error="internalError"
55
+ :error-messages="internalErrorMessage"
56
+ @input="updateDateField"
57
+ @blur="checkDateSizeEqual6AndReplace"
58
+ @click:append="modelMenu = true"
59
+ :placeholder="getDatePlaceholder"
60
+ ></v-text-field>
61
+ </template>
62
+ <v-date-picker
63
+ v-model="internalPickerModel"
64
+ :first-day-of-week="1"
65
+ :locale="getLocale"
66
+ v-bind="allProps"
67
+ :disabled="disabled"
68
+ :min="minValue"
69
+ :max="maxValue"
70
+ color="var(--primarycolor)"
71
+ ></v-date-picker>
72
+ </v-menu>
73
+ </v-flex>
74
+ <v-flex :xs4="showTime" :xs0="!showTime">
75
+ <v-menu
76
+ v-if="showTime"
77
+ :close-on-content-click="false"
78
+ v-model="modelMenuTime"
79
+ :nudge-right="40"
80
+ transition="scale-transition"
81
+ offset-y
82
+ min-width="150px"
83
+ :disabled="disabled"
84
+ >
85
+ <template v-slot:activator="{ on, attrs }">
86
+ <v-text-field
87
+ v-on="on"
88
+ v-bind="attrs"
89
+ :ref="`timeField${attach !== null ? attach : defaultId}`"
90
+ v-model="internalTimeModel"
91
+ :class="getEditedClass"
92
+ :rules="getTimeRules"
93
+ append-icon="fa-clock"
94
+ solo
95
+ outlined
96
+ flat
97
+ :readonly="disableTextInput"
98
+ :disabled="disabled"
99
+ class="ml-1"
100
+ :mask="getTimeMask"
101
+ :error="internalError"
102
+ @input="updateTimeField"
103
+ @click:append="modelMenuTime = true"
104
+ :placeholder="getTimePlaceholder"
105
+ ></v-text-field>
106
+ </template>
107
+ <v-time-picker
108
+ v-if="modelMenuTime"
109
+ v-model="internalTimeModel"
110
+ v-bind="allProps"
111
+ :disabled="disabled"
112
+ :min="minTimeValue"
113
+ :max="maxTimeValue"
114
+ format="24hr"
115
+ :use-seconds="timesecs"
116
+ color="var(--primarycolor)"
117
+ @input="updateTimeField"
118
+ ></v-time-picker>
119
+ </v-menu>
120
+ </v-flex>
121
+ </v-layout>
122
+ </v-flex>
123
+ </v-layout>
124
+ </div>
125
+ <div v-else class="ml-1 mr-1">
126
+ <v-layout>
127
+ <v-flex :class="labelColumnStyles ? labelColumnStyles : 'xs12 sm6 md4 xl3'">
128
+ <label :class="getLabelRequiredClass">{{ getLabel }}</label>
129
+ <v-tooltip top v-if="showTooltip">
130
+ <template v-slot:activator="{ on, attrs }">
131
+ <v-icon class="info-tooltip" size="14" v-bind="attrs" v-on="on">fas fa-info-circle info-tooltip</v-icon>
132
+ </template>
133
+ <span>
134
+ <span v-if="this.description !== ''">
135
+ {{ this.description }}
136
+ <hr v-if="this.infoTooltipMessages.length > 0" />
137
+ </span>
138
+ <ul>
139
+ <li v-for="(message, index) in this.infoTooltipMessages" :key="index">{{ message }}</li>
140
+ </ul>
141
+ </span>
142
+ </v-tooltip>
143
+ </v-flex>
144
+ <v-flex :class="valueColumnStyles ? valueColumnStyles : 'xs12 sm6 md8 xl9'">
145
+ <v-layout>
146
+ <v-flex :xs8="showTime" :xs12="!showTime">
147
+ <v-menu
148
+ :close-on-content-click="false"
149
+ v-model="modelMenu"
150
+ :nudge-right="40"
151
+ transition="scale-transition"
152
+ offset-y
153
+ min-width="290px"
154
+ :disabled="disabled"
155
+ >
156
+ <template v-slot:activator="{ on, attrs }">
157
+ <v-text-field
158
+ :id="`${attach !== null ? attach : defaultId}`"
159
+ v-on="on"
160
+ v-bind="attrs"
161
+ v-model="internalDateModel"
162
+ :class="getEditedClass"
163
+ :rules="getDateRules"
164
+ append-icon="far fa-calendar-day"
165
+ solo
166
+ outlined
167
+ flat
168
+ :readonly="disableTextInput"
169
+ :disabled="disabled"
170
+ :mask="getMask"
171
+ :error="internalError"
172
+ :error-messages="internalErrorMessage"
173
+ @input="updateDateField"
174
+ @blur="checkDateSizeEqual6AndReplace"
175
+ @click:append="modelMenu = true"
176
+ :placeholder="getDatePlaceholder"
177
+ class="ml-2"
178
+ ></v-text-field>
179
+ </template>
180
+ <v-date-picker
181
+ v-model="internalPickerModel"
182
+ :first-day-of-week="1"
183
+ :locale="getLocale"
184
+ v-bind="allProps"
185
+ :disabled="disabled"
186
+ :min="minValue"
187
+ :max="maxValue"
188
+ color="var(--primarycolor)"
189
+ ></v-date-picker>
190
+ </v-menu>
191
+ </v-flex>
192
+ <v-flex :xs4="showTime" :xs0="!showTime">
193
+ <v-menu
194
+ v-if="showTime"
195
+ :close-on-content-click="false"
196
+ v-model="modelMenuTime"
197
+ :nudge-right="40"
198
+ transition="scale-transition"
199
+ offset-y
200
+ min-width="150px"
201
+ :disabled="disabled"
202
+ >
203
+ <template v-slot:activator="{ on, attrs }">
204
+ <v-text-field
205
+ v-on="on"
206
+ v-bind="attrs"
207
+ :ref="`timeField${attach !== null ? attach : defaultId}`"
208
+ v-model="internalTimeModel"
209
+ :class="getEditedClass"
210
+ :rules="getTimeRules"
211
+ append-icon="fa-clock"
212
+ solo
213
+ outlined
214
+ flat
215
+ :readonly="disableTextInput"
216
+ :disabled="disabled"
217
+ class="ml-1"
218
+ :mask="getTimeMask"
219
+ :error="internalError"
220
+ @input="updateTimeField"
221
+ @click:append="modelMenuTime = true"
222
+ :placeholder="getTimePlaceholder"
223
+ ></v-text-field>
224
+ </template>
225
+ <v-time-picker
226
+ v-if="modelMenuTime"
227
+ v-model="internalTimeModel"
228
+ v-bind="allProps"
229
+ :disabled="disabled"
230
+ :min="minTimeValue"
231
+ :max="maxTimeValue"
232
+ format="24hr"
233
+ :use-seconds="timesecs"
234
+ color="var(--primarycolor)"
235
+ @input="updateTimeField"
236
+ ></v-time-picker>
237
+ </v-menu>
238
+ </v-flex>
239
+ </v-layout>
240
+ </v-flex>
241
+ </v-layout>
242
+ </div>
243
+ </div>
244
+ <!-- MOBILE -->
245
+ <div v-else>
246
+ <v-layout>
247
+ <v-flex xs12>
248
+ <v-layout>
249
+ <v-flex :xs7="showTime" :xs12="!showTime">
250
+ <v-menu
251
+ :close-on-content-click="false"
252
+ v-model="modelMenu"
253
+ :nudge-right="40"
254
+ transition="scale-transition"
255
+ offset-y
256
+ min-width="290px"
257
+ :disabled="disabled"
258
+ ><template v-slot:activator="{ on, attrs }">
259
+ <v-text-field
260
+ :id="`${attach !== null ? attach : defaultId}`"
261
+ v-on="on"
262
+ v-bind="attrs"
263
+ v-model="internalDateModel"
264
+ append-icon="far fa-calendar-day"
265
+ :class="getMobileClass"
266
+ :rules="getDateRules"
267
+ class="v-text-field--mobile"
268
+ :disabled="disabled"
269
+ :label="getLabel"
270
+ :mask="getMask"
271
+ :error="internalError"
272
+ :error-messages="internalErrorMessage"
273
+ @input="updateDateField"
274
+ @blur="checkDateSizeEqual6AndReplace"
275
+ @click:append="modelMenu = true"
276
+ :placeholder="getDatePlaceholder"
277
+ ></v-text-field>
278
+ </template>
279
+ <v-date-picker
280
+ v-model="internalPickerModel"
281
+ :first-day-of-week="1"
282
+ :locale="getLocale"
283
+ v-bind="allProps"
284
+ :disabled="disabled"
285
+ :min="minValue"
286
+ :max="maxValue"
287
+ color="var(--primarycolor)"
288
+ ></v-date-picker>
289
+ </v-menu>
290
+ </v-flex>
291
+ <v-flex :xs5="showTime" :xs0="!showTime">
292
+ <v-menu
293
+ v-if="showTime"
294
+ :close-on-content-click="false"
295
+ v-model="modelMenuTime"
296
+ :nudge-right="40"
297
+ transition="scale-transition"
298
+ offset-y
299
+ min-width="150px"
300
+ :disabled="disabled"
301
+ >
302
+ <template v-slot:activator="{ on, attrs }">
303
+ <v-text-field
304
+ v-on="on"
305
+ v-bind="attrs"
306
+ :ref="`timeField${attach !== null ? attach : defaultId}`"
307
+ v-model="internalTimeModel"
308
+ :class="getEditedClass"
309
+ :rules="getTimeRules"
310
+ append-icon="fa-clock"
311
+ class="ml-1"
312
+ :disabled="disabled"
313
+ :mask="getTimeMask"
314
+ :error="internalError"
315
+ @input="updateTimeField"
316
+ @click:append="modelMenuTime = true"
317
+ :placeholder="getTimePlaceholder"
318
+ ></v-text-field>
319
+ </template>
320
+ <v-time-picker
321
+ v-if="modelMenuTime"
322
+ v-model="internalTimeModel"
323
+ v-bind="allProps"
324
+ :disabled="disabled"
325
+ :min="minTimeValue"
326
+ :max="maxTimeValue"
327
+ format="24hr"
328
+ :use-seconds="timesecs"
329
+ color="var(--primarycolor)"
330
+ @input="updateTimeField"
331
+ ></v-time-picker>
332
+ </v-menu>
333
+ </v-flex>
334
+ </v-layout>
335
+ </v-flex>
336
+ </v-layout>
337
+ </div>
338
+ </template>
339
+
340
+ <script>
341
+ import PuiFormComponentMixin from '../mixins/PuiFormComponentMixin';
342
+ import dateTimeUtils from '../dateTimeUtils';
343
+
344
+ export default {
345
+ name: 'PuiDateField',
346
+ mixins: [PuiFormComponentMixin],
347
+ data: () => ({
348
+ defaultId: `id_${Math.random().toString().replace('.', '')}`,
349
+ internalModel: null,
350
+ internalPickerModel: null,
351
+ internalDateModel: null,
352
+ internalTimeModel: null,
353
+ initialDateValue: null,
354
+ initialTimeValue: null,
355
+ modelMenu: false,
356
+ modelMenuTime: false,
357
+ dateSeparator: '',
358
+ internalDateFormat: 'YYYY-MM-DD',
359
+ internalMask: '##/##/####',
360
+ internalErrorMessage: '',
361
+ infoTooltipMessages: []
362
+ }),
363
+ props: {
364
+ disableTextInput: {
365
+ type: Boolean,
366
+ default: false,
367
+ required: false
368
+ },
369
+ value: {
370
+ type: [Number, String],
371
+ required: false
372
+ },
373
+ today: {
374
+ type: Boolean,
375
+ default: false,
376
+ required: false
377
+ },
378
+ time: {
379
+ type: Boolean,
380
+ default: false,
381
+ required: false
382
+ },
383
+ tooltip: {
384
+ type: Boolean,
385
+ default: false,
386
+ required: false
387
+ },
388
+ description: {
389
+ type: String,
390
+ default: '',
391
+ required: false
392
+ },
393
+ timesecs: {
394
+ type: Boolean,
395
+ default: false,
396
+ required: false
397
+ },
398
+ rules: {
399
+ type: Array,
400
+ default: () => {
401
+ return [];
402
+ }
403
+ },
404
+ isoDateFormat: {
405
+ type: String,
406
+ required: false
407
+ },
408
+ min: {
409
+ type: [Number, String],
410
+ required: false
411
+ },
412
+ max: {
413
+ type: [Number, String],
414
+ required: false
415
+ },
416
+ noLazyModel: {
417
+ type: Boolean,
418
+ default: false,
419
+ required: false
420
+ },
421
+ labelColumnStyles: {
422
+ type: String,
423
+ required: false
424
+ },
425
+ valueColumnStyles: {
426
+ type: String,
427
+ required: false
428
+ },
429
+ attach: {
430
+ type: String,
431
+ default: null,
432
+ required: false
433
+ }
434
+ },
435
+ methods: {
436
+ getInfoTooltip() {
437
+ this.infoTooltipMessages = [];
438
+ if (this.time) {
439
+ this.infoTooltipMessages.push(this.$t('pui9.components.dateField.tooltipFormat') + this.isoDateFormatComp + ' HH:mm');
440
+ } else if (this.timesecs) {
441
+ this.infoTooltipMessages.push(this.$t('pui9.components.dateField.tooltipFormat') + this.isoDateFormatComp + ' HH:mm:ss');
442
+ } else {
443
+ this.infoTooltipMessages.push(this.$t('pui9.components.dateField.tooltipFormat') + this.isoDateFormatComp);
444
+ }
445
+
446
+ if (this.max) {
447
+ let format = '';
448
+ if (this.time) {
449
+ format = this.isoDateFormatComp + ' HH:mm';
450
+ } else if (this.timesecs) {
451
+ format = this.isoDateFormatComp + ' HH:mm:ss';
452
+ } else {
453
+ format = this.isoDateFormatComp;
454
+ }
455
+ var localMaxDate = dateTimeUtils.getLocalFormattedDate(this.max, format);
456
+ this.infoTooltipMessages.push(this.$t('pui9.components.dateField.tooltipMaxDate') + localMaxDate);
457
+ }
458
+ if (this.min) {
459
+ let format = '';
460
+ if (this.time) {
461
+ format = this.isoDateFormatComp + ' HH:mm';
462
+ } else if (this.timesecs) {
463
+ format = this.isoDateFormatComp + ' HH:mm:ss';
464
+ } else {
465
+ format = this.isoDateFormatComp;
466
+ }
467
+ var localMinDate = dateTimeUtils.getLocalFormattedDate(this.min, format);
468
+ this.infoTooltipMessages.push(this.$t('pui9.components.dateField.tooltipMinDate') + localMinDate);
469
+ }
470
+ },
471
+ giveBackUTCDate(dateStr) {
472
+ if (dateStr) {
473
+ var local = dateTimeUtils.getLocalDate(dateStr);
474
+
475
+ if (local) {
476
+ var utc = dateTimeUtils.getUTCDate(local);
477
+ return utc;
478
+ }
479
+ }
480
+ return null;
481
+ },
482
+ /**
483
+ * Este metodo se utiliza para cuando se han introducido el dia y el mes, y el año solo con dos cifras, al cambiar el blur a otro campo del formulario,
484
+ * Cambia el año de dos cifras a 20 + las dos cifras -> 19 a 2019
485
+ */
486
+ checkDateSizeEqual6AndReplace() {
487
+ const val = this.internalDateModel;
488
+ if (val && val.length && val.length === 6) {
489
+ const day = val.substring(0, 2);
490
+ const month = val.substring(2, 4);
491
+ const year2Digits = val.substring(4);
492
+ const dateToReplace = `${day}/${month}/20${year2Digits}`;
493
+ const d = this.parseDateToISO(dateToReplace);
494
+ if (this.validateDate(d) === true) {
495
+ this.internalDateModel = dateTimeUtils.getLocalFormattedDate(d, this.isoDateFormatComp);
496
+ this.internalPickerModel = dateTimeUtils.getLocalFormattedDate(d, this.internalDateFormat);
497
+ }
498
+ }
499
+ },
500
+ updateDateField(val) {
501
+ if (val === null || val === '') {
502
+ this.internalModel = null;
503
+ this.internalDateModel = null;
504
+ this.internalPickerModel = null;
505
+ this.clearErrorMessages();
506
+ if (this.required) {
507
+ this.showRequiredDateMessage();
508
+ }
509
+ } else if (val.length === 10) {
510
+ this.clearErrorMessages();
511
+ var d = this.parseDateToISO(val);
512
+ this.validateDate(d);
513
+ this.internalDateModel = dateTimeUtils.getLocalFormattedDate(d, this.isoDateFormatComp);
514
+ this.internalPickerModel = dateTimeUtils.getLocalFormattedDate(d, this.internalDateFormat);
515
+ this.updateInternalModel(this.internalPickerModel, this.internalTimeModel);
516
+ if (this.showTime && this.internalTimeModel) {
517
+ this.updateTimeField(this.internalTimeModel);
518
+ }
519
+ this.modelMenu = false;
520
+ } else {
521
+ if (val.length === 0 && this.required === false) {
522
+ this.clearErrorMessages();
523
+ } else {
524
+ this.showErrorDateMessage();
525
+ }
526
+ }
527
+ },
528
+ updateTimeField(val) {
529
+ if (val === null || val === '') {
530
+ this.clearErrorMessages();
531
+ if (this.required) {
532
+ this.showRequiredDateMessage();
533
+ }
534
+ } else if (val.length > 0) {
535
+ var t = this.parseTimeToISO(val);
536
+
537
+ var timeValidated = this.validateTime(t);
538
+ if (timeValidated) {
539
+ this.internalTimeModel = t;
540
+ this.updateInternalModel(this.internalPickerModel, t);
541
+ }
542
+ } else {
543
+ if (val.length === 0 && this.required === false) {
544
+ this.clearErrorMessages();
545
+ } else {
546
+ this.showErrorTimeMessage();
547
+ }
548
+ }
549
+ },
550
+ parseDateToISO(date) {
551
+ if (date) {
552
+ var year = '';
553
+ var month = '';
554
+ var day = '';
555
+ var j = 0;
556
+ for (var i = 0, length = this.isoDateFormatComp.length; i < length; i++) {
557
+ var c = this.isoDateFormatComp.charAt(i);
558
+ if (c === 'Y') {
559
+ year += date.charAt(j);
560
+ } else if (c === 'M') {
561
+ month += date.charAt(j);
562
+ } else if (c === 'D') {
563
+ day += date.charAt(j);
564
+ }
565
+ j++;
566
+ }
567
+ return year + '-' + month + '-' + day;
568
+ }
569
+ return null;
570
+ },
571
+ parseTimeToISO(time) {
572
+ if (time) {
573
+ if (time.indexOf(':') !== -1) {
574
+ return time;
575
+ }
576
+ var mask = this.getTimeMask;
577
+ var t = '';
578
+ var j = 0;
579
+ for (var i = 0, length = mask.length; i < length; i++) {
580
+ var c = mask.charAt(i);
581
+ var v = time.charAt(j);
582
+ if (v && v.length > 0) {
583
+ if (c !== ':') {
584
+ t += v;
585
+ j++;
586
+ } else {
587
+ t += ':';
588
+ }
589
+ } else {
590
+ t += 'x';
591
+ j++;
592
+ }
593
+ }
594
+ return t;
595
+ }
596
+ return null;
597
+ },
598
+ getOffset() {
599
+ var offset = dateTimeUtils.getUTCOffset();
600
+ if (offset === 0) {
601
+ return '+00:00';
602
+ }
603
+ var hour = offset / 60;
604
+ if (hour) {
605
+ if (hour && hour.toString().length === 1) {
606
+ if (hour > 0) {
607
+ return '+0' + hour + ':00';
608
+ } else {
609
+ return '-0' + hour + ':00';
610
+ }
611
+ } else if (hour && hour.toString().length === 2) {
612
+ if (hour > 0) {
613
+ return '+' + hour + ':00';
614
+ } else {
615
+ return '-' + hour + ':00';
616
+ }
617
+ }
618
+ }
619
+ return '';
620
+ },
621
+ createLocalDateToUTC(date) {
622
+ if (!this.time && !this.timesecs) {
623
+ return dateTimeUtils.getLocalDate(date);
624
+ } else {
625
+ var dt = date.split(' ');
626
+ if (dt.length === 2) {
627
+ var isoTime = this.parseTimeToISO(dt[1]);
628
+ if (isoTime.length === 5) {
629
+ isoTime += ':00';
630
+ }
631
+ var offset = this.getOffset();
632
+ var dateLocal = dt[0] + ' ' + isoTime + '' + offset;
633
+ return dateLocal;
634
+ } else {
635
+ return null;
636
+ }
637
+ }
638
+ },
639
+ validateDate(date) {
640
+ if (date) {
641
+ var okDate = dateTimeUtils.isLocalDateValid(date);
642
+ var okMinMaxDate = this.validateMinMaxDate(date);
643
+ this.getInfoTooltip();
644
+ if (okDate && okMinMaxDate) {
645
+ this.clearErrorMessages();
646
+ return true;
647
+ } else if (!okDate) {
648
+ this.showErrorDateMessage();
649
+ return false;
650
+ } else if (!okMinMaxDate) {
651
+ this.showErrorMinMaxDateMessage();
652
+ return false;
653
+ }
654
+ } else {
655
+ if (this.required) {
656
+ this.showRequiredDateMessage();
657
+ }
658
+ return false;
659
+ }
660
+ },
661
+ validateMinMaxDate(date) {
662
+ if (!date && !this.required) {
663
+ return true;
664
+ }
665
+ let validateMinMaxFormat = this.internalDateFormat;
666
+ if (this.time && date.length > 10) {
667
+ validateMinMaxFormat += ' ' + this.isoTimeFormatComp;
668
+ }
669
+ if (this.max) {
670
+ const maxFormatted = dateTimeUtils.getLocalFormattedDate(this.max, validateMinMaxFormat);
671
+ const after = dateTimeUtils.isLocalDateAfter(date, maxFormatted);
672
+ if (after) {
673
+ return false;
674
+ }
675
+ }
676
+ if (this.min) {
677
+ const minFormatted = dateTimeUtils.getLocalFormattedDate(this.min, validateMinMaxFormat);
678
+ const before = dateTimeUtils.isLocalDateBefore(date, minFormatted);
679
+ if (before) {
680
+ return false;
681
+ }
682
+ }
683
+ return true;
684
+ },
685
+ validateTime(time) {
686
+ if (this.time || this.timesecs) {
687
+ var t = this.internalPickerModel + ' ' + time;
688
+ var okTime = dateTimeUtils.isLocalDateValid(t);
689
+ if (okTime) {
690
+ this.clearErrorMessages();
691
+ return true;
692
+ }
693
+ this.showErrorTimeMessage();
694
+ return false;
695
+ }
696
+ },
697
+ showErrorDateMessage() {
698
+ this.internalError = true;
699
+ this.internalErrorMessage =
700
+ this.$t('pui9.components.dateField.errorDate') +
701
+ ',' +
702
+ this.$t('pui9.components.dateField.correctFormat') +
703
+ ' ' +
704
+ this.isoDateFormatComp;
705
+ },
706
+ showRequiredDateMessage() {
707
+ this.internalError = true;
708
+ this.internalErrorMessage = this.requiredMessage;
709
+ },
710
+ showErrorMinMaxDateMessage() {
711
+ this.internalError = true;
712
+ let dateformat = this.isoDateFormatComp;
713
+ if (this.time) {
714
+ dateformat += ' ' + this.isoTimeFormatComp;
715
+ }
716
+ var min = dateTimeUtils.getLocalFormattedDate(this.min, dateformat);
717
+ var max = dateTimeUtils.getLocalFormattedDate(this.max, dateformat);
718
+ if (this.min && this.max) {
719
+ this.internalErrorMessage =
720
+ this.$t('pui9.components.dateField.errorRangeDate') + min + ' ' + this.$t('pui9.components.dateField.and') + ' ' + max;
721
+ } else if (this.min && !this.max) {
722
+ this.internalErrorMessage = this.$t('pui9.components.dateField.errorMinDate') + min;
723
+ } else {
724
+ this.internalErrorMessage = this.$t('pui9.components.dateField.errorMaxDate') + max;
725
+ }
726
+ },
727
+ showErrorTimeMessage() {
728
+ this.internalError = true;
729
+ this.internalErrorMessage = this.$t('pui9.components.dateField.errorTime');
730
+ },
731
+ clearErrorMessages() {
732
+ this.internalError = false;
733
+ this.internalErrorMessage = '';
734
+ },
735
+ buildMaskFromCurrentDateFormat() {
736
+ if (!this.isoDateFormatComp) {
737
+ return null;
738
+ }
739
+
740
+ // mask
741
+ var mask = this.isoDateFormatComp.replace(/Y/g, '#');
742
+ mask = mask.replace(/M/g, '#');
743
+ mask = mask.replace(/D/g, '#');
744
+ this.internalMask = mask;
745
+ // separator
746
+ for (let index = 0, length = this.internalMask.length; index < length; index++) {
747
+ const char = this.internalMask.charAt(index);
748
+ if (char !== '#') {
749
+ this.dateSeparator = char;
750
+ break;
751
+ }
752
+ }
753
+ },
754
+ initializeModel(value) {
755
+ if (value !== null && value !== undefined) {
756
+ this.internalPickerModel = dateTimeUtils.getLocalFormattedDate(value, this.internalDateFormat); // iSO FORMAT
757
+ this.internalDateModel = dateTimeUtils.getLocalFormattedDate(value, this.isoDateFormatComp);
758
+ this.internalTimeModel = '00:00:00';
759
+ if (this.time) {
760
+ this.internalTimeModel = dateTimeUtils.getLocalFormattedDate(value, 'HH:mm');
761
+ }
762
+ if (this.timesecs) {
763
+ this.internalTimeModel = dateTimeUtils.getLocalFormattedDate(value, 'HH:mm:ss');
764
+ }
765
+ this.firstLazyLoad = true;
766
+ this.initialDateValue = this.internalDateModel;
767
+ this.initialTimeValue = this.internalTimeModel;
768
+ } else if (this.today) {
769
+ this.internalPickerModel = dateTimeUtils.getLocalDateNow();
770
+ this.internalDateModel = dateTimeUtils.getLocalDateNow(this.isoDateFormatComp);
771
+ this.internalTimeModel = '00:00:00';
772
+ if (this.time) {
773
+ this.internalTimeModel = dateTimeUtils.getLocalTimeNow('HH:mm');
774
+ }
775
+ if (this.timesecs) {
776
+ this.internalTimeModel = dateTimeUtils.getLocalTimeNow();
777
+ }
778
+ this.firstLazyLoad = true;
779
+ this.initialDateValue = this.internalDateModel;
780
+ this.initialTimeValue = this.internalTimeModel;
781
+ }
782
+ },
783
+ updateInternalModel(date, time) {
784
+ var totaldate = date;
785
+ if (this.time || this.timesecs) {
786
+ if (!time) {
787
+ time = '00:00:00';
788
+ }
789
+ totaldate += ' ' + time;
790
+ }
791
+ this.internalModel = totaldate;
792
+ },
793
+ reverseDateIso(date) {
794
+ if (date) {
795
+ var year = '';
796
+ var month = '';
797
+ var day = '';
798
+ var j = 0;
799
+ for (let i = 0, length = this.isoDateFormatComp.length; i < length; i++) {
800
+ const c = this.isoDateFormatComp.charAt(i);
801
+ if (c === 'Y') {
802
+ year += date.charAt(j);
803
+ j++;
804
+ } else if (c === 'M') {
805
+ month += date.charAt(j);
806
+ j++;
807
+ } else if (c === 'D') {
808
+ day += date.charAt(j);
809
+ j++;
810
+ } else {
811
+ j++;
812
+ }
813
+ }
814
+ return year + '-' + month + '-' + day;
815
+ }
816
+ return null;
817
+ },
818
+ removeSeparator(date) {
819
+ if (date) {
820
+ var d = '';
821
+ for (let i = 0, length = date.length; i < length; i++) {
822
+ const c = date.charAt(i);
823
+ if (c !== this.dateSeparator) {
824
+ d += c;
825
+ }
826
+ }
827
+ return d;
828
+ }
829
+ return date;
830
+ }
831
+ },
832
+ computed: {
833
+ minValue() {
834
+ return this.min != null ? dateTimeUtils.getLocalFormattedDate(this.min, this.internalDateFormat) : null;
835
+ },
836
+ maxValue() {
837
+ return this.max != null ? dateTimeUtils.getLocalFormattedDate(this.max, this.internalDateFormat) : null;
838
+ },
839
+ minTimeValue() {
840
+ return this.min != null ? dateTimeUtils.getLocalFormattedDate(this.min, this.isoTimeFormatComp) : null;
841
+ },
842
+ maxTimeValue() {
843
+ return this.max != null ? dateTimeUtils.getLocalFormattedDate(this.max, this.isoTimeFormatComp) : null;
844
+ },
845
+ isoDateFormatComp() {
846
+ if (this.isoDateFormat !== undefined) {
847
+ return this.isoDateFormat;
848
+ }
849
+ return (this.$store && this.$store.getters && this.$store.getters.dateFormat) || 'DD/MM/YYYY';
850
+ },
851
+ isoTimeFormatComp() {
852
+ return (this.$store && this.$store.getters && this.$store.getters.timeFormat) || 'HH:mm';
853
+ },
854
+ getDateRules() {
855
+ const rules = [...this.rules];
856
+ if (this.required) {
857
+ var func = (value) => !!value || this.requiredMessage;
858
+ rules.push(func);
859
+ }
860
+ var func2 = () => !this.internalError || this.internalErrorMessage;
861
+ rules.push(func2);
862
+ return rules;
863
+ },
864
+ getTimeRules() {
865
+ const rules = [...this.rules];
866
+ if (this.required) {
867
+ var func = (value) => !!value || this.requiredMessage;
868
+ rules.push(func);
869
+ }
870
+ var func2 = () => !this.internalError || this.internalErrorMessage;
871
+ rules.push(func2);
872
+ return rules;
873
+ },
874
+ showTime() {
875
+ if (this.time || this.timesecs) {
876
+ return true;
877
+ }
878
+ return false;
879
+ },
880
+ getMask() {
881
+ return this.internalMask;
882
+ },
883
+ getTimeMask() {
884
+ if (this.time) {
885
+ return '##:##';
886
+ } else if (this.timesecs) {
887
+ return '##:##:##';
888
+ }
889
+ return '##:##:##';
890
+ },
891
+ getMobileClass() {
892
+ return { 'v-text-field--edited': this.isEdited, 'v-text-field--required': this.required };
893
+ },
894
+ getLabelRequiredClass() {
895
+ return { 'v-label--required': this.required };
896
+ },
897
+ getEditedClass() {
898
+ return { 'v-text-field--edited': this.isEdited };
899
+ },
900
+ isEdited() {
901
+ if (this.noeditable || this.disabled || this.readonly) {
902
+ return false;
903
+ } else {
904
+ const newDate = this.removeSeparator(this.internalDateModel);
905
+ const initialDate = this.removeSeparator(this.initialDateValue);
906
+ const intTime = this.parseTimeToISO(this.internalTimeModel);
907
+ if (!this.time && !this.timesecs) {
908
+ if (initialDate !== newDate) {
909
+ return true;
910
+ }
911
+ } else {
912
+ if (initialDate !== newDate || this.initialTimeValue !== intTime) {
913
+ return true;
914
+ }
915
+ }
916
+
917
+ return false;
918
+ }
919
+ },
920
+ getDatePlaceholder() {
921
+ return this.isoDateFormatComp;
922
+ },
923
+ getTimePlaceholder() {
924
+ if (this.time) {
925
+ return 'HH:mm';
926
+ } else if (this.timesecs) {
927
+ return 'HH:mm:ss';
928
+ }
929
+ return '';
930
+ },
931
+ showTooltip() {
932
+ if (!this.tooltip || this.getLabel === '' || this.getLabel === null) {
933
+ return false;
934
+ }
935
+ return (this.infoTooltipMessages.length > 0 || this.description !== '') && this.tooltip;
936
+ }
937
+ },
938
+ created() {
939
+ this.buildMaskFromCurrentDateFormat();
940
+ this.initializeModel(this.value);
941
+ this.getInfoTooltip();
942
+ },
943
+ watch: {
944
+ value(val) {
945
+ if (!this.noLazyModel && !this.firstLazyLoad) {
946
+ this.initializeModel(val);
947
+ this.firstLazyLoad = true;
948
+ } else {
949
+ const externalDateModel = dateTimeUtils.getLocalFormattedDate(val, this.isoDateFormatComp);
950
+ const externalTimeModel = this.time
951
+ ? dateTimeUtils.getLocalFormattedDate(val, 'HH:mm')
952
+ : this.timesecs
953
+ ? dateTimeUtils.getLocalFormattedDate(val, 'HH:mm:ss')
954
+ : '00:00:00';
955
+
956
+ if (externalDateModel !== this.internalDateModel || externalTimeModel !== this.internalTimeModel) {
957
+ this.internalPickerModel = dateTimeUtils.getLocalFormattedDate(val, this.internalDateFormat);
958
+ this.internalDateModel = dateTimeUtils.getLocalFormattedDate(val, this.isoDateFormatComp);
959
+ this.internalTimeModel = '00:00:00';
960
+ if (this.time) {
961
+ this.internalTimeModel = dateTimeUtils.getLocalFormattedDate(val, 'HH:mm');
962
+ }
963
+ if (this.timesecs) {
964
+ this.internalTimeModel = dateTimeUtils.getLocalFormattedDate(val, 'HH:mm:ss');
965
+ }
966
+ }
967
+ }
968
+ },
969
+ internalPickerModel(val) {
970
+ this.modelMenu = false;
971
+ this.internalDateModel = dateTimeUtils.getLocalFormattedDate(val, this.isoDateFormatComp);
972
+ this.updateInternalModel(val, this.internalTimeModel);
973
+ },
974
+ internalTimeModel(newValue, oldValue) {
975
+ // Refactor when upgrade vuetify to 2.4.x and use @click:minute and @click:second for autoclose
976
+ this.modelMenuTime = !!oldValue;
977
+ },
978
+ internalModel(val) {
979
+ if (val === 'Invalid date') {
980
+ val = null;
981
+ }
982
+ let utc = this.giveBackUTCDate(val);
983
+ if (utc === 'Invalid date') {
984
+ utc = null;
985
+ }
986
+ this.$emit('input', utc);
987
+ this.getInfoTooltip();
988
+ this.clearErrorMessages();
989
+ if (utc != null && utc !== 'Invalid date') this.validateDate(utc);
990
+ },
991
+ internalErrorMessage() {
992
+ this.$refs[`timeField${this.attach !== null ? this.attach : this.defaultId}`].validate();
993
+ },
994
+ max() {
995
+ this.clearErrorMessages();
996
+ if (this.internalModel != null) this.validateDate(this.internalModel);
997
+ },
998
+ min() {
999
+ this.clearErrorMessages();
1000
+ if (this.internalModel != null) this.validateDate(this.internalModel);
1001
+ }
1002
+ }
1003
+ };
1004
+ </script>