aboutsummaryrefslogtreecommitdiff
path: root/resources/vue/components/theme/ThemeAddCopyDialog.vue
blob: 399022943062d658351e0eafc1867e8bd8885bff (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
<template>
    <StudipDialog
        v-if="displayThemeAddCopyDialog"
        :title="$gettext('Theme duplizieren')"
        :closeText="$gettext('Schließen')"
        closeClass="cancel"
        :confirmText="$gettext('Duplizieren')"
        confirmClass="accept"
        height="240"
        width="400"
        @close="closeDialog"
        @confirm="copyTheme"
    >
        <template #dialogContent>
            <form class="default">
                <label>
                    {{ $gettext('Theme') }}
                <StudipSelect
                    v-model="theme"
                    :options="props.themes"
                    :label="$gettext('Theme auswählen')"
                    :clearable="false"
                >
                    <template #open-indicator="{ selectAttributes }">
                        <span v-bind="selectAttributes"><studip-icon shape="arr_1down" :size="10" /></span>
                    </template>
                    <template #no-options>
                        {{ $gettext('Es steht keine Auswahl zur Verfügung.') }}
                    </template>
                    <template #selected-option="option">
                        <span>{{ option.attributes.name }}</span>
                    </template>
                    <template #option="option">
                        <span>{{ option.attributes.name }}</span>
                    </template>
                </StudipSelect>
                </label>
            </form>
        </template>
    </StudipDialog>
</template>
<script setup>
import {computed, getCurrentInstance, ref} from 'vue';
import StudipDialog from '../StudipDialog.vue';
import StudipSelect from '../StudipSelect.vue';
import { useStore } from 'vuex';

const { proxy } = getCurrentInstance();

const store = useStore();
const props = defineProps({
    themes: {
        type: Array,
        required: true,
    },
});
const theme = ref('');

const displayThemeAddCopyDialog = computed(() => store.getters['theme-settings-module/showThemeAddCopyDialog']);
const showThemeAddCopyDialog = (show) => {
    store.dispatch('theme-settings-module/setShowThemeAddCopyDialog', show);
};
const closeDialog = () => {
    showThemeAddCopyDialog(false);
};

const copyTheme = async () => {
    const newTheme = theme.value;
    newTheme.attributes.name = `${newTheme.attributes.name} (${proxy.$gettext('Kopie')})`;
    await store.dispatch('theme-settings-module/createThemeFromData', { theme: newTheme });
    closeDialog();
};
</script>