aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/lib/dates.js
blob: 1fc983068202da61910315716d2b38d21f42fd6d (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
const Dates = {
    addTopic: function() {
        var topic_name = $('#new_topic').val(),
            termin_id = $('#new_topic')
                .closest('[data-termin-id]')
                .data().terminId;

        if (!topic_name) {
            $('#new_topic').focus();
            return;
        }

        $.post(STUDIP.URLHelper.getURL('dispatch.php/course/dates/add_topic'), {
            title: topic_name,
            termin_id: termin_id
        }).done(function(response) {
            if (response.hasOwnProperty('li')) {
                $('#new_topic')
                    .closest('[data-termin-id]')
                    .find('.themen-list')
                    .append(response.li);
                $('#date_' + termin_id)
                    .find('.themen-list')
                    .append(response.li);
            }

            $('#new_topic')
                .val('')
                .focus();
        });
    },
    removeTopicFromIcon: function() {
        var topic_id = $(this)
                .closest('li')
                .data('issue_id'),
            termin_id = $(this)
                .closest('[data-termin-id]')
                .data().terminId;
        Dates.removeTopic(termin_id, topic_id);
    },
    removeTopic: function(termin_id, topic_id) {
        $.ajax({
            url: STUDIP.URLHelper.getURL('dispatch.php/course/dates/remove_topic'),
            data: {
                issue_id: topic_id,
                termin_id: termin_id
            },
            dataType: 'json',
            type: 'post'
        }).done(function() {
            $('.topic_' + termin_id + '_' + topic_id).remove();
        });
    }
};

export default Dates;