aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/lib/overlapping.js
blob: 05b1a223ac98254eabe85c659c5ca958373e9558 (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
import { $gettext } from './gettext';

const Overlapping = {

    /**
     * Initialize Select2 select boxes.
     * @returns {undefined}
     */
    init: function () {
        let base_selection = $('#base-version-select');
        base_selection.select2({
            placeholder: $gettext('Studiengangteil suchen'),
            minimumInputLength: 3,
            ajax: {
                url: STUDIP.URLHelper.getURL('dispatch.php/admin/overlapping/base_version'),
                dataType: 'json'
            }
        });

        $('#comp-versions-select').select2({
            placeholder: $gettext('Optional weitere Studiengangteile (max. 5)'),
            minimumInputLength: 3,
            ajax: {
                url: STUDIP.URLHelper.getURL('dispatch.php/admin/overlapping/comp_versions'),
                dataType: 'json'
            }
        });

        $('#fachsem-select').select2({
            placeholder: $gettext('Fachsemester auswählen (optional)')
        });
        $('#semtype-select').select2({
            placeholder: $gettext('Veranstaltungstyp auswählen (optional)')
        });
        base_selection.on('select2:select', function () {
            $('#comp-versions-select').val(null).trigger('change');
            $.ajax({
                url: STUDIP.URLHelper.getURL('dispatch.php/admin/overlapping/comp_versions'),
                dataType: 'json',
                data: {
                    version_id: $('#base-version-select').select2('data')[0].id
                },
                success: function(data) {
                    if (data.results.length) {
                        let inputlength = 3;
                        if (data.results.length < 4) {
                            inputlength = 0;
                        }
                        $('#comp-versions-select').select2({
                            placeholder: $gettext('Optional weitere Studiengangteile (max. 5)'),
                            minimumInputLength: inputlength,
                            ajax: {
                                url: STUDIP.URLHelper.getURL('dispatch.php/admin/overlapping/comp_versions',
                                    {'version_id': $('#base-version-select').select2('data')[0].id}),
                                dataType: 'json'
                            }
                        });
                    } else {
                        base_selection.select2({
                            placeholder: $gettext('Keine weitere Auswahl möglich')
                        });
                        base_selection.prop('disabled', true).trigger('change');
                    }
                }
            });
        });

        $('span.mvv-overlapping-exclude').on('click', function () {
            const conflict_id = $(this).data('mvv-ovl-conflict');
            $.ajax({
                method: 'get',
                url: STUDIP.URLHelper.getURL('dispatch.php/admin/overlapping/exclude'),
                data: {
                    'conflict_id': conflict_id
                },
                success() {
                    $('.mvv-overlapping-exclude').each(function () {
                        if ($(this).data('mvv-ovl-conflict') === conflict_id) {
                            $(this).toggleClass('mvv-overlapping-invisible');
                        }
                        $(this).attr('title', $gettext('Veranstaltung berücksichtigen'));
                    });
                    $('.mvv-overlapping-invisible').attr('title', $gettext('Veranstaltung nicht berücksichtigen'));

                }
            })
            return false;
        });
    }
};

export default Overlapping;