3303c3af06c56d76813d141ce93b62b93b4d18a6
[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 self = this;
39       
40       Senslab.createMaps($('#maps-container'), this.sites, this.nodes);
41       Senslab.notify = function(node) {
42         manifold.raise_event(self.options.query_uuid,
43                              node.boot_state == "Alive" ? SET_REMOVED : SET_ADD,
44                              node.component_id
45                             );
46       }
47     }
48   });
49   $.plugin('SensLabMap', SensLabMap);
50 })(jQuery);