summaryrefslogtreecommitdiffstats
path: root/modules/monitoring/public/js/module.js
blob: d665e6ba69d7589ced65facc6da522470b60c628 (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
/*! Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */

(function(Icinga) {

    var Monitoring = function(module) {
        /**
         * The Icinga.Module instance
         */
        this.module = module;

        /**
         * The observer used to handle the timeline's infinite loading
         */
        this.scrollCheckTimer = null;

        /**
         * Whether to skip the timeline's scroll-check
         */
        this.skipScrollCheck = false;

        this.initialize();
    };

    Monitoring.prototype = {

        initialize: function()
        {
            this.module.on('rendered', this.enableScrollCheck);
            this.module.icinga.logger.debug('Monitoring module loaded');
        },

        /**
         * Enable the timeline's scroll-check
         */
        enableScrollCheck: function()
        {
            /**
             * Re-enable the scroll-check in case the timeline has just been extended
             */
            if (this.skipScrollCheck) {
                this.skipScrollCheck = false;
            }

            /**
             * Prepare the timer to handle the timeline's infinite loading
             */
            var $timeline = $('div.timeline');
            if ($timeline.length && !$timeline.closest('.dashboard').length) {
                if (this.scrollCheckTimer === null) {
                    this.scrollCheckTimer = this.module.icinga.timer.register(
                        this.checkTimelinePosition,
                        this,
                        800
                    );
                    this.module.icinga.logger.debug('Enabled timeline scroll-check');
                }
            }
        },

        /**
         * Check whether the user scrolled to the end of the timeline
         */
        checkTimelinePosition: function()
        {
            if (!$('div.timeline').length) {
                this.module.icinga.timer.unregister(this.scrollCheckTimer);
                this.scrollCheckTimer = null;
                this.module.icinga.logger.debug('Disabled timeline scroll-check');
            } else if (!this.skipScrollCheck && this.module.icinga.utils.isVisible('#end')) {
                this.skipScrollCheck = true;
                this.module.icinga.loader.loadUrl(
                    $('#end').remove().attr('href'),
                    $('div.timeline'),
                    undefined,
                    undefined,
                    'append'
                ).addToHistory = false;
            }
        }
    };

    Icinga.availableModules.monitoring = Monitoring;

}(Icinga));