adding some tracability into the plugins code
[myslice.git] / plugins / senslabmap / static / js / senslabmap.js
1 (function($){
2   var SensLabMap = Plugin.extend({
3     init: function(options, element) {
4         this.classname="senslabmap";
5       this._super(options, element);
6       
7       this.elmt().on('show', this, this.on_show);
8
9       var query = manifold.query_store.find_analyzed_query(options.query_uuid);
10       this.method = query.object;
11       this.key = manifold.metadata.get_key(this.method);
12       
13       /* Setup query and record handlers */
14       this.listen_query(options.query_uuid);
15       this.listen_query(options.query_all_uuid, 'all');
16
17       this.sites = [];
18       this.nodes = {};
19     },
20     
21     on_show: function(e) {
22       e.data.refresh();
23     },
24     
25     on_all_new_record: function(node) {
26       Senslab.normalize(node);
27       if (node.normalized) {
28         var site = node.site;
29         if ($.inArray(site, this.sites) == -1) {
30           this.sites.push(site);
31           this.nodes[site] = [];
32         }
33         this.nodes[site].push(node);
34       } else {
35 // xxx would need a smarter way to report these only on nodes that deserve it
36 // these messages are all over the place in a PL setup and tend to hide helpful signal
37 //        console.warn("node has no site:");
38 //        console.warn(node);
39       }
40     },
41     
42     on_all_query_done: function() {
43       var uuid = this.options.query_uuid;
44       var key = this.key
45       
46       Senslab.createMaps($("#maps-container"), this.sites, this.nodes);
47       Senslab.notify = function(node) {
48         manifold.raise_event(uuid, node.selected ? SET_ADD : SET_REMOVED, node[key]);
49       }
50     }
51   });
52   $.plugin('SensLabMap', SensLabMap);
53 })(jQuery);