File: ViewOverview.js

package info (click to toggle)
nagvis 1%3A1.9.47-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,556 kB
  • sloc: php: 28,986; javascript: 16,395; sh: 1,696; makefile: 16; xml: 8
file content (216 lines) | stat: -rw-r--r-- 8,058 bytes parent folder | download | duplicates (4)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*****************************************************************************
 *
 * ViewOverview.js - All NagVis overview related top level code
 *
 * Copyright (c) 2004-2016 NagVis Project (Contact: info@nagvis.org)
 *
 * License:
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *****************************************************************************/

var ViewOverview = View.extend({
    type           : 'overview',
    rendered_maps  : 0,
    processed_maps : 0,

    constructor: function() {
        this.base(null);
    },

    init: function() {
        addEvent(document, 'mousedown', context_handle_global_mousedown);
        this.renderPageBasics();
        this.render();
        this.loadMaps();
        this.loadRotations();
    },

    update: function() {
        var to_update = this.getObjectsToUpdate();
        if (to_update[0].length > 0) {
            this.base({
                mod  : 'Overview',
                data : to_update[0]
            });
        }
    },

    /**
     * END OF PUBLIC METHODS
     */

    render: function() {
        this.dom_obj = document.getElementById('overview');

        // Render maps and the rotations when enabled
        var types = [
            [ oPageProperties.showmaps,      'overviewMaps',      oPageProperties.lang_mapIndex ],
            [ oPageProperties.showrotations, 'overviewRotations', oPageProperties.lang_rotationPools ]
        ];
        for (var i = 0; i < types.length; i++) {
            if (types[i][0] === 1) {
                var h2 = document.createElement('h2');
                h2.innerHTML = types[i][2];
                this.dom_obj.appendChild(h2);

                var container = document.createElement('div');
                container.setAttribute('id', types[i][1]);
                container.className = 'infobox';
                this.dom_obj.appendChild(container);
            }
        }
        this.base();
    },

    // Add the objects dom_obj to the maps dom_obj
    drawObject: function(obj) {
        var container = document.getElementById('overviewMaps');
        container.appendChild(obj.dom_obj);
    },

    // Removes the given objects dom_obj from the maps dom_obj 
    eraseObject: function(obj) {
        var container = document.getElementById('overviewMaps');
        if (obj.dom_obj.parentNode == container)
            container.removeChild(obj.dom_obj);
    },

    // Adds a single map to the overview map list
    addMap: function(objects, data) {
        var map_name           = data[0],
            worldmap_has_bbox  = data[1];

        this.processed_maps += 1;

        // Exit this function on invalid call
        if (objects === null || objects.length != 1)  {
            eventlog("worker", "warning", "addOverviewMap: Invalid call - maybe broken ajax response ("+map_name+")");
            if (this.processed_maps == g_map_names.length)
                finishOverviewMaps();
            return false;
        }
        var map_conf = objects[0];

        // The worldmap preview summary state should reflect the state shown by the worldmap
        // when the user opens it. This means it is needed to calculate which area of the worldmap
        // will be shown to the user and then only deal with the objects within this area.
        // Bad here: For the worldmaps we need to do a second HTTP request which should be avoided
        if (!worldmap_has_bbox && map_conf['sources']
            && map_conf['sources'].indexOf('worldmap') !== -1) {

            var worldmap = L.map('overview', {
                markerZoomAnimation: false,
                maxBounds: [ [-85,-180.0], [85,180.0] ],
                minZoom: 2
            }).setView(map_conf['worldmap_center'].split(','), parseInt(map_conf['worldmap_zoom']));

            worldmap.remove();

            // leaflet does not clean up everything. We do it on our own.
            var overview = document.getElementById('overview');
            remove_class(overview, 'leaflet-container');
            remove_class(overview, 'leaflet-retina');
            remove_class(overview, 'leaflet-fade-anim');

            this.processed_maps -= 1;
            call_ajax(oGeneralProperties.path_server+'?mod=Overview&act=getObjectStates'
                      + '&i[]=map-' + escapeUrlValues(map_name)
                      + getViewParams({'bbox': worldmap.getBounds().toBBoxString()}), {
                response_handler : this.addMap.bind(this),
                handler_data     : [ map_name, true ]
            });
            return;
        }

        this.rendered_maps += 1; // also count errors

        var container = document.getElementById('overviewMaps');

        // Find the map placeholder div (replace it to keep sorting)
        var mapdiv = null;
        var child = null;
        for (var i = 0; i < container.childNodes.length; i++) {
            child = container.childNodes[i];
            if (child.id == map_name) {
                mapdiv = child;
                break;
            }
        }

        // render the map object
        var obj = new NagVisMap(map_conf);
        // Save object to map objects array
        this.objects[obj.conf.object_id] = obj;
        obj.update();
        obj.render();
        container.replaceChild(obj.dom_obj, mapdiv);

        // Finalize rendering after last map...
        if (this.processed_maps == g_map_names.length)
            this.finishMaps();
    },

    finishMaps: function() {
        // Hide the "Loading..." message. This is not the best place since rotations
        // might not have been loaded now but in most cases this is the longest running request
        hideStatusMessage();
    },

    // Does initial parsing of rotations on the overview page
    addRotations: function(rotations) {
        if (oPageProperties.showrotations === 1 && rotations.length > 0) {
            for (var i = 0, len = rotations.length; i < len; i++) {
                new NagVisRotation(rotations[i]).parseOverview();
            }
        } else {
            // Hide the rotations container
            var container = document.getElementById('overviewRotations');
            if (container) {
                container.style.display = 'none';
            }
        }
    },

    // Fetches all maps to be shown on the overview page
    loadMaps: function() {
        var map_container = document.getElementById('overviewMaps');

        if (oPageProperties.showmaps !== 1 || g_map_names.length == 0) {
            if (map_container)
                map_container.parentNode.style.display = 'none';
            hideStatusMessage();
            return false;
        }

        for (var i = 0, len = g_map_names.length; i < len; i++) {
            var mapdiv = document.createElement('div');
            mapdiv.setAttribute('id', g_map_names[i])
            map_container.appendChild(mapdiv);
            call_ajax(oGeneralProperties.path_server+'?mod=Overview&act=getObjectStates'
                      + '&i[]=map-' + escapeUrlValues(g_map_names[i]) + getViewParams(), {
                response_handler : this.addMap.bind(this),
                handler_data     : [ g_map_names[i], false ]
            });
        }
    },

    // Fetches all rotations to be shown on the overview page
    loadRotations: function() {
        call_ajax(oGeneralProperties.path_server+'?mod=Overview&act=getOverviewRotations', {
            response_handler: this.addRotations.bind(this)
        });
    }
});