aboutsummaryrefslogtreecommitdiff
path: root/resources/vue/components/my-courses/ColorPicker.vue
blob: 74c379e0e9370cb568b431455fce7a65280ffe9c (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
<template>
    <ul class="my-courses-color-picker">
        <li v-for="(i, index) in color_count" :id="i" :class="getCSSClasses(index)" :key="index">
            <a @click="selectColor(index)" :title="getTitle(i, index)">
                {{ getTitle(i) }}
            </a>
        </li>
    </ul>
</template>

<script>
export default {
    name: "my-courses-color-picker",
    emits: ['color-picked'],
    props: {
        course: {
            type: Object,
            required: true
        },
        color_count: {
            required: false,
            default: 9
        },
    },
    methods: {
        getCSSClasses (index) {
            let classes = [];
            classes.push(`gruppe${index}`);

            if (this.course.group === index) {
                classes.push('color-selected');
            }

            return classes;
        },
        getTitle (i, index) {
            let title = this.$gettext(
                'Gruppe %{ group }',
                { group: i }
            );
            if (this.course.group === index) {
                title += ' ('  + this.$gettext('ausgewählt') + ')';
            }
            return title;
        },
        selectColor (index) {
            this.$emit('color-picked', this.course, index);
        },
    },
    mounted () {
        // Detect safari
        if (!/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
            return;
        }

        // Force a double redraw in css since safari won't display the
        // colorpicker otherwise
        setTimeout(() => {
            this.$el.style.position = 'static';
            setTimeout(() => {
                this.$el.style.position = '';
            }, 0);
        }, 0);
    }
}
</script>

<style lang="scss">
@use '../../../assets/stylesheets/mixins.scss';

.my-courses-color-picker {
    list-style: none;
    margin: 0;
    padding: 0;

    // Hide text in color groups
    li {
        text-indent: 100%;
        overflow: hidden;
        white-space: nowrap;

        position: relative;
    }

    a {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;

        cursor: pointer;
    }

    .color-selected {
        @include mixins.icon(after, accept, $size: 32px);
        &::after {
            display: block;
            margin: auto;
            height: 100%;
        }
    }
}
</style>