fixed typo
[unfold.git] / plugins / googlemap / static / js / googlemap.js
index 0ecf113..3d18757 100644 (file)
@@ -125,7 +125,7 @@ GOOGLEMAP_BGCOLOR_REMOVED = 2;
                 title: object,
                 /* gmap can deal with a DOM element but not a jquery object */
                 content: dom.get(0),
-                keys = Array(),
+                keys: Array(),
             }); 
             //extend the bounds to include each marker's position
             this.bounds.extend(marker.position);
@@ -138,7 +138,7 @@ GOOGLEMAP_BGCOLOR_REMOVED = 2;
          */
         create_record_checkbox: function (record, ul, checked)
         {
-            var key, key_value;
+            var key, key_value, data;
 
             var checkbox = $("<input>", {type:'checkbox', checked:checked, class:'geo'});
             var id = record[this.canonical_key];
@@ -170,7 +170,13 @@ GOOGLEMAP_BGCOLOR_REMOVED = 2;
              */
             var self=this;
             checkbox.change( function (e) {
-                manifold.raise_event (self.options.query_uuid, this.checked ? SET_ADD : SET_REMOVED, id);
+                data = {
+                    state: STATE_SET,
+                    key  : null,
+                    op   : this.checked ? STATE_SET_ADD : STATE_SET_REMOVE,
+                    value: id
+                }
+                manifold.raise_event(self.options.query_uuid, FIELD_STATE_CHANGED, data);
             });
             return checkbox;
         },
@@ -180,19 +186,23 @@ GOOGLEMAP_BGCOLOR_REMOVED = 2;
             if (checked === undefined) checked = true;
 
             var checkbox = this.by_init_id [record_key];
-            if (!checkbox) 
+            if (!checkbox) {
                 console.log("googlemap.set_checkbox_from_record - not found " + record_key);
+                return;
+            }
 
-            checkbox.prop('checked', checked);
+            checkbox.attr('checked', checked);
         },
 
 
         set_checkbox_from_data: function(id, checked) 
         {
             var checkbox = this.by_id[id];
-            if (!checkbox)
+            if (!checkbox) {
                 console.log("googlemap.set_checkbox_from_data - id not found " + id);
-            checkbox.prop('checked', checked);
+                return;
+            }
+            checkbox.attr('checked', checked);
         }, 
 
         set_bgcolor: function(key_value, class_name)
@@ -232,7 +242,7 @@ GOOGLEMAP_BGCOLOR_REMOVED = 2;
 
             /* Add key to the marker */
             record_key = manifold.record_get_value(record, this.canonical_key);
-            marker_s.keys.push(record_key);
+            marker_s.marker.keys.push(record_key);
            
            // now add a line for this resource in the marker
            // xxx should compute checked here ?
@@ -267,9 +277,32 @@ GOOGLEMAP_BGCOLOR_REMOVED = 2;
                  * be visible */
                 visible = false;
                 $.each(marker.keys, function(j, key) {
-                    visible |= manifold.query_store.get_record_state(self.options.query_uuid, key, STATE_VISIBLE);
-                }
+                    visible = visible || manifold.query_store.get_record_state(self.options.query_uuid, key, STATE_VISIBLE);
+                });
                 marker.setVisible(visible);
+            });
+
+            this.do_clustering();
+        },
+
+        do_clustering: function()
+        {
+            this.markerCluster = new MarkerClusterer(this.map, this.markers, {zoomOnClick: false});
+            this.markerCluster.setIgnoreHidden(true);
+            google.maps.event.addListener(this.markerCluster, "clusterclick", function (cluster) {
+                var cluster_markers = cluster.getMarkers();
+                var bounds  = new google.maps.LatLngBounds();
+                $.each(cluster_markers, function(i, marker){
+                    bounds.extend(marker.getPosition()); 
+                });
+                //map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
+                this.map.fitBounds(bounds);
+            });
+            //now fit the map to the bounds
+            this.map.fitBounds(this.bounds);
+            // Fix the zoom of fitBounds function, it's too close when there is only 1 marker
+            if (this.markers.length==1) {
+                this.map.setZoom(this.map.getZoom()-4);
             }
         },
 
@@ -285,30 +318,15 @@ GOOGLEMAP_BGCOLOR_REMOVED = 2;
                 self.new_record(record);
                 record_keys.push(record_key);
             });
-            this.table.fnAddData(lines);
 
             /* Add markers to cluster */
             this.markers = Array();
             $.each(this.by_lat_lon, function (k, s) {
-                this.markers.push(s.marker); 
+                self.markers.push(s.marker); 
             });
 
-            this.markerCluster = new MarkerClusterer(this.map, this.markers, {zoomOnClick: false});
-            google.maps.event.addListener(this.markerCluster, "clusterclick", function (cluster) {
-                var cluster_markers = cluster.getMarkers();
-                var bounds  = new google.maps.LatLngBounds();
-                $.each(cluster_markers, function(i, marker){
-                    bounds.extend(marker.getPosition()); 
-                });
-                //map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
-                this.map.fitBounds(bounds);
-            });
-            //now fit the map to the bounds
-            this.map.fitBounds(this.bounds);
-            // Fix the zoom of fitBounds function, it's too close when there is only 1 marker
-            if (this.markers.length==1) {
-                this.map.setZoom(this.map.getZoom()-4);
-            }
+            this.do_clustering();
+
 
             /* Set checkbox and background color */
             $.each(record_keys, function(i, record_key) {
@@ -333,7 +351,7 @@ GOOGLEMAP_BGCOLOR_REMOVED = 2;
                         self.set_bgcolor(record_key, GOOGLEMAP_BGCOLOR_REMOVED);
                         break;
                 }
-                self.change_status(record_key, warnings); // XXX will retrieve status again
+                //self.change_status(record_key, warnings); // XXX will retrieve status again
             });
         },
 
@@ -369,16 +387,34 @@ GOOGLEMAP_BGCOLOR_REMOVED = 2;
 
         on_field_state_changed: function(data)
         {
-            switch(data.request) {
-                case FIELD_REQUEST_ADD:
-                case FIELD_REQUEST_ADD_RESET:
-                    this.set_checkbox_from_data(data.value, true);
+            switch(data.state) {
+                case STATE_SET:
+                    switch(data.value) {
+                        case STATE_SET_IN:
+                        case STATE_SET_IN_SUCCESS:
+                        case STATE_SET_OUT_FAILURE:
+                            this.set_checkbox_from_data(data.key, true);
+                            this.set_bgcolor(data.key, QUERYTABLE_BGCOLOR_RESET);
+                            break;  
+                        case STATE_SET_OUT:
+                        case STATE_SET_OUT_SUCCESS:
+                        case STATE_SET_IN_FAILURE:
+                            this.set_checkbox_from_data(data.key, false);
+                            this.set_bgcolor(data.key, QUERYTABLE_BGCOLOR_RESET);
+                            break;
+                        case STATE_SET_IN_PENDING:
+                            this.set_checkbox_from_data(data.key, true);
+                            this.set_bgcolor(data.key, QUERYTABLE_BGCOLOR_ADDED);
+                            break;  
+                        case STATE_SET_OUT_PENDING:
+                            this.set_checkbox_from_data(data.key, false);
+                            this.set_bgcolor(data.key, QUERYTABLE_BGCOLOR_REMOVED);
+                            break;
+                    }
                     break;
-                case FIELD_REQUEST_REMOVE:
-                case FIELD_REQUEST_REMOVE_RESET:
-                    this.set_checkbox_from_data(data.value, false);
-                    break;
-                default:
+
+                case STATE_WARNINGS:
+                    //this.change_status(data.key, data.value);
                     break;
             }
         },