aboutsummaryrefslogtreecommitdiff
path: root/resources/vue/components/form_inputs/CalendarPermissionsTable.vue
blob: e958a02c580df158c3c387d8066a49ce9cad540a (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
<template>
    <div class="formpart">
        <quicksearch v-if="searchtype" :searchtype="searchtype" name="qs" @input="addContact"
                     :placeholder="$gettext('Personen hinzufügen')"></quicksearch>
        <table class="default">
            <caption>{{ $gettext('Kontakte, mit denen der Kalender geteilt wird')}}</caption>
            <thead>
                <tr>
                    <th>{{ $gettext('Name') }}</th>
                    <th>{{ $gettext('Schreibzugriff') }}</th>
                    <th class="actions">{{ $gettext('Nicht mehr teilen') }}</th>
                </tr>
            </thead>
            <tbody>
                <tr v-if="this.users.length === 0">
                    <td colspan="3">
                        <studip-message-box type="info">
                            {{ $gettext('Der Kalender wird mit keinem Kontakt geteilt.') }}
                        </studip-message-box>
                    </td>
                </tr>
                <tr v-for="user in this.users" :key="user.id">
                    <td>
                        <input type="hidden" :name="name + '_permissions[]'"
                               :value="user.id">
                        {{ user.name }}
                    </td>
                    <td>
                        <input type="checkbox" :name="name + '_write_permissions[]'" :value="user.id"
                               v-model="user.write_permissions"
                               :aria-label="$gettext(
                                   'Schreibzugriff für %{name}',
                                   {name: user.name},
                                   true
                               )">
                    </td>
                    <td class="actions">
                        <studip-icon shape="trash" aria-role="button" @click="removeContact(user.id)"
                                     :title="$gettext(
                                         'Kalender nicht mehr mit %{name} teilen',
                                         {name: user.name},
                                         true
                                     )"
                        ></studip-icon>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script>
import StudipMessageBox from "../StudipMessageBox.vue";

export default {
    name: "calendar-permissions-table",
    components: {StudipMessageBox},
    props: {
        name: {
            type: String,
            required: true
        },
        selected_users: {
            type: Object,
            required: false,
            default: () => {},
        },
        searchtype: {
            type: String,
            required: true,
        }
    },
    data() {
        return {
            users: {...this.selected_users},
        }
    },
    methods: {
        addContact(user_id, name) {
            this.users[user_id] = {
                id: user_id,
                name: name,
                write_permissions: false
            };
        },
        removeContact(user_id) {
            if (this.users[user_id] !== undefined) {
                delete this.users[user_id];
            }
        }
    }
}
</script>