aboutsummaryrefslogtreecommitdiff
path: root/resources/vue/components/courseware/CoursewareContentLinks.vue
blob: 407543940dfd7e4bc8a4e7a8ee62ea5c24a14ce9 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<template>
    <div>
        <table class="default">
            <caption>
                {{ $gettext('Öffentlich verlinkte Seiten') }}
            </caption>
            <thead>
                <tr>
                    <th>{{ $gettext('Seite') }}</th>
                    <th>{{ $gettext('Link') }}</th>
                    <th>{{ $gettext('Passwort') }}</th>
                    <th>{{ $gettext('Ablaufdatum') }}</th>
                    <th class="actions">{{ $gettext('Aktionen') }}</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="link in links" :key="link.id">
                    <td><a :href="getElementUrl(link)">{{ getPage(link) }}</a></td>
                    <td>
                        <a :href="getLinkUrl(link)" target="_blank" :title="getLinkUrl(link)">
                            <studip-icon shape="link-extern" role="clickable" />
                        </a>
                    </td>
                    <td>{{ link.attributes.password || '-' }}</td>
                    <td>{{ getReadableDate(link.attributes['expire-date']) }}</td>
                    <td class="actions">
                        <studip-action-menu
                            :items="menuItems"
                            @editLink="editLink(link)"
                            @deleteLink="displayDeleteLink(link)"
                            @copyLinkToClipboard="copyLinkToClipboard(link)"
                        />
                    </td>
                </tr>
            </tbody>
        </table>
        <studip-dialog
            v-if="showDeleteDialog"
            :title="$gettext('Link löschen')"
            :question="$gettext('Möchten Sie diesen Link löschen')"
            height="180"
            width="360"
            @confirm="executeDelete"
            @close="closeDeleteDialog"
        ></studip-dialog>
        <studip-dialog
            v-if="showEditDialog"
            :title="$gettext('Link bearbeiten')"
            :confirmText="$gettext('Speichern')"
            confirmClass="accept"
            :closeText="$gettext('Schließen')"
            closeClass="cancel"
            @close="closeEditDialog"
            @confirm="storeLink"
        >
            <template v-slot:dialogContent>
                <form class="default" @submit.prevent="">
                    <label>
                        {{ $gettext('Passwort') }}
                        <input type="text" v-model="currentLink.attributes.password" />
                    </label>
                    <label>
                        {{ $gettext('Ablaufdatum') }}
                        <input v-model="currentLink.attributes['expire-date']" type="date" class="size-l" />
                    </label>
                </form>
            </template>
        </studip-dialog>
    </div>
</template>

<script>
import StudipActionMenu from './../StudipActionMenu.vue';
import { mapActions, mapGetters } from 'vuex';
import StudipIcon from '../StudipIcon.vue';

export default {
    name: 'courseware-content-links',
    components: {
        StudipActionMenu,
        StudipIcon,
    },
    data() {
        return {
            menuItems: [
                { id: 1, label: this.$gettext('Link in Zwischenablage kopieren'), icon: 'clipboard', emit: 'copyLinkToClipboard'},
                { id: 2, label: this.$gettext('Link bearbeiten'), icon: 'edit', emit: 'editLink' },
                { id: 3, label: this.$gettext('Link löschen'), icon: 'trash', emit: 'deleteLink' }
            ],
            showEditDialog: false,
            showDeleteDialog: false,
            currentLink: null
        }
    },
     computed: {
        ...mapGetters({
            context: 'context',
            links: 'courseware-public-links/all',
            getElementById: 'courseware-structural-elements/byId',
        }),
    },
    methods: {
        ...mapActions({
            companionSuccess: 'companionSuccess',
            deleteLink: 'deleteLink',
            updateLink: 'updateLink',
            loadAllLinks: 'courseware-public-links/loadAll'
        }),
        getPage(link) {
            let element = this.getElementById({ id: link.relationships['structural-element'].data.id });
            return element.attributes.title;
        },
        getLinkUrl(link) {
            return STUDIP.URLHelper.getURL('dispatch.php/courseware/public/', { link: link.id });
        },
        getElementUrl(link) {
            return STUDIP.URLHelper.getURL('dispatch.php/contents/courseware/courseware#/structural_element/' + link.relationships['structural-element'].data.id);
        },
        displayDeleteLink(link) {
            this.showDeleteDialog = true;
            this.currentLink = link;
        },
        executeDelete() {
            this.deleteLink({linkId: this.currentLink.id});
            this.closeDeleteDialog();
        },
        closeDeleteDialog() {
            this.showDeleteDialog = false;
            this.currentLink = null;
        },
        editLink(link) {
            this.showEditDialog = true;
            this.currentLink = link;
        },
        closeEditDialog() {
            this.showEditDialog = false;
            this.currentLink = null;
        },
        async storeLink() {
            const date = this.currentLink.attributes['expire-date'];
            let attributes = {
                password: this.currentLink.attributes.password,
                'expire-date': date === '' ? new Date(0).toISOString() : new Date(date).toISOString()
            };

            await this.updateLink({
                attributes: attributes,
                linkId: this.currentLink.id
            });
            this.closeEditDialog();
            this.companionSuccess({
                info: this.$gettext('Änderungen wurden gespeichert.'),
            });
        },
        copyLinkToClipboard(link) {
            navigator.clipboard.writeText(this.getLinkUrl(link));
            this.companionSuccess({
                info: this.$gettext('Link wurde in die Zwischenablage kopiert.'),
            });
        },
        getReadableDate(date) {
            if (!date) {
                return '-';
            }
            return new Date(date).toLocaleDateString(navigator.language, {
                year: 'numeric',
                month: '2-digit',
                day: '2-digit'
            });
        },
    }
}
</script>