8075be9cf81bd1965201e4fd808d6e6e22d11200
[myslice.git] / plugins / senslabmap / static / js / senslabmap.js
1 /**
2  * Description: SensLab display of 3D-geolocated data
3  * Copyright (c) 2012 UPMC Sorbonne Universite - INRIA
4  * License: GPLv3
5  */
6
7 // xxx TODO -- this plugin has never been tested 
8 // update_map looks suspiciously empty...
9 // in addition it could use a bit of cleaning like what was done for the first plugins
10 // especially wrt using 'instance' and 'data' in such a confusing way
11
12 (function( $ ){
13
14     $.fn.SensLabMap = function( method ) {
15         /* Method calling logic */
16         if ( methods[method] ) {
17             return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
18         } else if ( typeof method === 'object' || ! method ) {
19             return methods.init.apply( this, arguments );
20         } else {
21             $.error( 'Method ' +  method + ' does not exist on $.SensLabMap' );
22         }    
23     };
24
25     var methods = {
26         init : function( options ) {
27             return this.each(function(){
28                 var $this = $(this),
29                 data = $this.data('SensLabMap'), SensLabMap = $('<div />', { text : $this.attr('title') });
30                 // If the plugin hasn't been initialized yet
31                 if ( ! data ) {
32                     /* Plugin initialization */
33                     //google.load('maps', '3', { other_params: 'sensor=false' });
34                     //google.setOnLoadCallback(initialize);
35                     init();
36                     /* End of plugin initialization */
37                     $(this).data('SensLabMap', {
38                         plugin_uuid: options.plugin_uuid,
39                         query_uuid: options.query_uuid,
40                         target : $this,
41                         SensLabMap : SensLabMap
42                     });
43                     /* Subscribe to query updates */
44                     $.subscribe('/results/' + options.query_uuid + '/changed', {instance: $this}, update_map);
45                 }
46             });
47         },
48         destroy : function( ) {
49             return this.each(function(){
50                 var $this = $(this), data = $this.data('SensLabMap');
51                 $(window).unbind('SensLabMap');
52                 data.SensLabMap.remove();
53                 $this.removeData('SensLabMap');
54             });
55         },
56 /*
57     reposition : function( ) { // ... },
58     show : function( ) { // ... },
59     hide : function( ) { // ... },
60 */
61         update : function( content ) { 
62             // should be made a private function
63             set3dsize()
64         },
65   };
66
67     /* Private methods */
68     function update_map(e, rows) {
69         var $plugindiv = e.data.instance;
70         $plugindiv.closest('.need-spin').spin(false);
71         
72         if(rows) {
73             /* TODO rendering */   
74         } else {
75             alert('error');
76         }
77         
78     }
79
80 })( jQuery );