aboutsummaryrefslogtreecommitdiff
path: root/resources/vue/components/StudipMessageBox.vue
blob: ad557a55ac0f7037423f4e15d0bfe583043f8476 (plain)
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
<template>
    <div :class="classNames" v-if="!closed">
        <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>
        <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>
</template>

<script>
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.showDetails,
            };
        },
        hasDetails() {
            return !!this.$slots.details || this.details.length > 0;
        },
        showDetails() {
            return this.hasDetails && !this.closedDetails;
        }
    },
    methods: {
        close() {
            this.closed = true;

            this.$emit('close');
        }
    },
    data() {
        return {
            closed: false,
            closedDetails: this.hideDetails,
        };
    },
};
</script>