add tabs for 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       var query = manifold.query_store.find_analyzed_query(options.query_uuid);
9       this.method = query.object;
10       this.key = manifold.metadata.get_key(this.method);
11       
12       /* Setup query and record handlers */
13       this.listen_query(options.query_uuid);
14       this.listen_query(options.query_all_uuid, 'all');
15
16       this.sites = [];
17       this.nodes = {};
18     },
19     
20     on_show: function(e) {
21       e.data.refresh();
22     },
23     
24     on_all_new_record: function(node) {
25       Senslab.normalize(node);
26       if (node.normalized) {
27         var site = node.site;
28         if ($.inArray(site, this.sites) == -1) {
29           this.sites.push(site);
30           this.nodes[site] = [];
31         }
32         this.nodes[site].push(node);
33       } else {
34         console.warn("node has no site:");
35         console.warn(node);
36       }
37     },
38     
39     on_all_query_done: function() {
40       var self = this;
41       
42       Senslab.createMaps($('#maps-container'), this.sites, this.nodes);
43       Senslab.notify = function(node) {
44         manifold.raise_event(self.options.query_uuid,
45                              node.boot_state == "Alive" ? SET_REMOVED : SET_ADD,
46                              node[self.key]
47                             );
48       }
49     }
50   });
51   $.plugin('SensLabMap', SensLabMap);
52 })(jQuery);