Add multiples maps
[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     refresh: function() {
19       console.log("refresh");
20     },
21     
22     on_show: function(e) {
23       e.data.refresh();
24     },
25     
26     on_all_new_record: function(node) {
27       Senslab.normalize(node);
28       var site = node.site;
29       if (site) {
30         if ($.inArray(site, this.sites) == -1) {
31           this.sites.push(site);
32           this.nodes[site] = [];
33         }
34         this.nodes[site].push(node);
35       } else {
36         console.warn(node);
37         console.warn("-> has no site");
38       }
39     },
40     
41     on_all_query_done: function() {
42       var
43         self = this,
44         maps = {},
45         $container = $('#maps-container');
46   
47       $.each(this.sites, function(i, site) {
48         var $div = $("<div />").appendTo($container);
49         maps[site] = new Senslab.Map($div);
50         maps[site].addNodes(self.nodes[site]);
51       });
52     }
53   });
54   $.plugin('SensLabMap', SensLabMap);
55 })(jQuery);