clean code map
[myslice.git] / plugins / senslabmap / static / js / senslabmap.js
1 (function($){
2   var SensLabMap = Plugin.extend({
3     init: function(options, element) {
4       this._super(options, element);
5       
6       this.elmt().on('show', this, this.on_show);
7       
8       this.method = query.object;
9       
10       /* Setup query and record handlers */
11       this.listen_query(options.query_uuid);
12       this.listen_query(options.query_all_uuid, 'all');
13
14       this.sites = [];
15       this.nodes = {};
16     },
17     
18     on_show: function(e) {
19       e.data.refresh();
20     },
21     
22     on_all_new_record: function(node) {
23       Senslab.normalize(node);
24       if (node.normalized) {
25         var site = node.site;
26         if ($.inArray(site, this.sites) == -1) {
27           this.sites.push(site);
28           this.nodes[site] = [];
29         }
30         this.nodes[site].push(node);
31       } else {
32         console.warn("node has no site:");
33         console.warn(node);
34       }
35     },
36     
37     on_all_query_done: function() {
38       var
39         self = this,
40         maps = {},
41         $container = $('#maps-container');
42   
43       $.each(this.sites, function(i, site) {
44         var $div = $("<div />").appendTo($container);
45         maps[site] = new Senslab.Map($div);
46         maps[site].addNodes(self.nodes[site]);
47       });
48     }
49   });
50   $.plugin('SensLabMap', SensLabMap);
51 })(jQuery);