Skip to content
Snippets Groups Projects
CoursewareContainerActions.vue 2.87 KiB
Newer Older
<template>
    <div v-if="canEdit" class="cw-container-actions">
        <studip-action-menu
Ron Lucke's avatar
Ron Lucke committed
            :items="menuItems"
            :context="container.attributes.title"
Ron Lucke's avatar
Ron Lucke committed
            :collapseAt="1"
            @editContainer="editContainer"
            @changeContainer="changeContainer"
            @deleteContainer="deleteContainer"
Ron Lucke's avatar
Ron Lucke committed
            @removeLock="removeLock"
            @copyToClipboard="copyToClipboard"
        />
    </div>
</template>

<script>
Ron Lucke's avatar
Ron Lucke committed
import { mapGetters } from 'vuex';
export default {
    name: 'courseware-container-actions',
    props: {
        canEdit: Boolean,
        container: Object,
    },
    computed: {
Ron Lucke's avatar
Ron Lucke committed
        ...mapGetters({
            userId: 'userId',
            userIsTeacher: 'userIsTeacher',
        }),
        blocked() {
            return this.container?.relationships?.['edit-blocker']?.data !== null;
        },
        blockerId() {
            return this.blocked ? this.container?.relationships?.['edit-blocker']?.data?.id : null;
        },
        blockedByThisUser() {
            return this.blocked && this.userId === this.blockerId;
        },
        blockedByAnotherUser() {
            return this.blocked && this.userId !== this.blockerId;
        },
Ron Lucke's avatar
Ron Lucke committed
            let menuItems = [];
            if (!this.blockedByAnotherUser) {
                if (this.container.attributes["container-type"] !== 'list') {
                    menuItems.push({ id: 1, label: this.$gettext('Abschnitt bearbeiten'), icon: 'edit', emit: 'editContainer' });
                }
                menuItems.push({ id: 2, label: this.$gettext('Abschnitt verändern'), icon: 'settings', emit: 'changeContainer' });
                menuItems.push({ id: 3, label: this.$gettext('Abschnitt merken'), icon: 'clipboard', emit: 'copyToClipboard' });
                menuItems.push({ id: 5, label: this.$gettext('Abschnitt löschen'), icon: 'trash', emit: 'deleteContainer' });
Ron Lucke's avatar
Ron Lucke committed

            if (this.blocked && this.blockedByAnotherUser && this.userIsTeacher) {
                menuItems.push({
Ron Lucke's avatar
Ron Lucke committed
                    label: this.$gettext('Sperre aufheben'),
                    icon: 'lock-unlocked',
                    emit: 'removeLock',
                });
            }

            menuItems.sort((a, b) => {
                return a.id > b.id ? 1 : b.id > a.id ? -1 : 0;
            });
            return menuItems;
Ron Lucke's avatar
Ron Lucke committed

    },
    methods: {
        menuAction(action) {
            this[action]();
        },
        editContainer() {
            this.$emit('editContainer');
        },
        changeContainer() {
            this.$emit('changeContainer');
        },
        deleteContainer() {
            this.$emit('deleteContainer');
        },
Ron Lucke's avatar
Ron Lucke committed
        removeLock() {
            this.$emit('removeLock');
        },
        copyToClipboard() {
            this.$emit('copyToClipboard');
Ron Lucke's avatar
Ron Lucke committed
        }