summaryrefslogtreecommitdiff
path: root/plugins/Bigboard/Asset/js/BoardPolling.js
blob: 6d5499fd826a119e99ef88117ce7c61ecaced294 (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
Kanboard.BoardPolling = function(app) {
    this.app = app;
};

Kanboard.BoardPolling.prototype.execute = function() {
    if (this.app.hasId("board")) {
        var interval = parseInt($("#board").attr("data-check-interval"));

        if (interval > 0) {
            window.setInterval(this.check.bind(this), interval * 1000);
        }
    }
};

Kanboard.BoardPolling.prototype.check = function() {
    if (KB.utils.isVisible() && !this.app.get("BoardDragAndDrop").savingInProgress) {
        var self = this;
        if (!$("#app-loading-icon").length) this.app.showLoadingIcon();
        var pollsinprogress=0;

        $("table.board-project").each(function() {
            var boardId = $(this).attr("data-project-id")            
            var url = $(this).attr("data-check-url");
            pollsinprogress++;
            $.ajax({
                cache: false,
                url: url,
                statusCode: {
                    200: function(data) {                        
                        pollsinprogress--;
                        if (pollsinprogress <= 0) self.app.hideLoadingIcon();
                        self.app.get("BoardDragAndDrop").refresh(boardId, data);
                    },
                    304: function () {
                        pollsinprogress--;
                        if (pollsinprogress <= 0) self.app.hideLoadingIcon();
                    }
                }
            });
        });
        if (pollsinprogress <= 0) self.app.hideLoadingIcon();
    }
};