1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
<template>
<div v-if="!closed"
role="region"
:aria-label="label"
:aria-describedby="`messagebox-${counter}`"
:class="classNames"
>
<div class="messagebox_buttons">
<a v-if="hideDetails" class="details" href="" :title="$gettext('Detailanzeige umschalten')" @click.prevent.stop="closedDetails = !closedDetails">
<span>{{ $gettext('Detailanzeige umschalten') }}</span>
</a>
<a v-if="!hideClose" class="close" href="" :title="$gettext('Nachrichtenbox schließen')" @click.prevent="close()">
<span>{{ $gettext('Nachrichtenbox schließen') }}</span>
</a>
</div>
<div role="status" :id="`messagebox-${counter}`">
<slot></slot>
<div v-if="showDetails" class="messagebox_details">
<slot name="details">
<ul>
<li v-for="(detail, index) in details" v-html="detail" :key="index"></li>
</ul>
</slot>
</div>
</div>
</div>
</template>
<script>
import {$gettext} from "../../assets/javascripts/lib/gettext";
let counter = 0;
export default {
name: 'studip-message-box',
emits: ['close'],
props: {
type: {
type: String, // exception, error, success, info, warning
default: 'info',
validator (type) {
return ['exception', 'error', 'warning', 'success', 'info'].indexOf(type) !== -1;
}
},
details: {
type: Array,
default: () => [],
},
hideDetails: {
type: Boolean,
default: false
},
hideClose: {
type: Boolean,
default: false,
},
},
computed: {
classNames() {
return {
messagebox: true,
[`messagebox_${this.type}`]: true,
details_hidden: this.hasDetails && !this.showDetails,
};
},
hasDetails() {
return !!this.$slots.details || this.details.length > 0;
},
label() {
const labels = {
exception: $gettext('Systemfehler'),
error: $gettext('Fehler'),
warning: $gettext('Warnung'),
info: $gettext('Hinweis'),
success: $gettext('Erfolg'),
}
return labels[this.type];
},
showDetails() {
return this.hasDetails && !this.closedDetails;
}
},
methods: {
close() {
this.closed = true;
this.$emit('close');
}
},
data() {
return {
closed: false,
closedDetails: this.hideDetails,
counter: counter++
};
},
};
</script>
|