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

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

        $.post(STUDIP.URLHelper.getURL('dispatch.php/course/dates/add_topic'), {
            title: topic_name,
            termin_id: termin_id,
            cid: course_id
        }).done(function(response) {
            if (response.li !== undefined) {
                $('#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();
        });
    },
    stringToUnixTimestamp: date => ((new Date(date)).getTime() / 1000),
    unixTimestampToISO: timestamp => new Date(timestamp * 1000).toISOString()
};

export default Dates;