aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/bootstrap/messages.js
blob: a19bf5024d8780987df295e53c441fb1c67b2fb9 (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
jQuery(document).on('dialog-load', 'form#message-tags', function(event, data) {
    var tags = jQuery.parseJSON(data.xhr.getResponseHeader('X-Tags')),
        all_tags = jQuery.parseJSON(data.xhr.getResponseHeader('X-All-Tags')),
        message_id = jQuery(this)
            .closest('table')
            .data().message_id;
    STUDIP.Messages.setTags(message_id, tags);
    STUDIP.Messages.setAllTags(all_tags);
});

jQuery(document).on('dialog-open', '#messages .title a', function() {
    STUDIP.Messages.whenMessageIsShown(this);
});

STUDIP.domReady(() => {
    /*********** infinity-scroll in the overview ***********/
    if (jQuery('#messages').length > 0) {
        STUDIP.Messages.init();
        jQuery(window.document).on(
            'scroll',
            _.throttle(() => {
                if (
                    jQuery(window).scrollTop() + jQuery(window).height() > jQuery(window.document).height() - 500 &&
                    jQuery('#reloader').hasClass('more')
                ) {
                    //nachladen
                    jQuery('#reloader')
                        .removeClass('more')
                        .addClass('loading');
                    jQuery.ajax({
                        url: STUDIP.ABSOLUTE_URI_STUDIP + 'dispatch.php/messages/more',
                        data: {
                            received: jQuery('#received').val(),
                            offset: jQuery('#messages > tbody > tr').length - 1,
                            tag: jQuery('#tag').val(),
                            search: jQuery('#search').val(),
                            search_autor: jQuery('#search_autor').val(),
                            search_subject: jQuery('#search_subject').val(),
                            search_content: jQuery('#search_content').val(),
                            limit: 50
                        },
                        dataType: 'json',
                        success: function(response) {
                            var more_indicator = jQuery('#reloader').detach();

                            jQuery('#loaded').val(parseInt(jQuery('#loaded').val(), 10) + 1);
                            jQuery.each(response.messages, (index, message) => {
                                jQuery(message).appendTo('#messages > tbody');
                            });

                            if (response.more) {
                                jQuery('#messages > tbody').append(
                                    more_indicator.addClass('more').removeClass('loading')
                                );
                            }
                        }
                    });
                }
            }, 30)
        );
    }

    jQuery(document).on('click', '.adressee .remove_adressee', STUDIP.Messages.remove_adressee);
    jQuery(document).on('click', '.file .remove_attachment', STUDIP.Messages.remove_attachment);
});