fixed typo
[myslice.git] / plugins / googlemap / static / js / googlemap.js
index 5f640b9..3d18757 100644 (file)
@@ -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;
         },
@@ -275,6 +281,29 @@ GOOGLEMAP_BGCOLOR_REMOVED = 2;
                 });
                 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);
+            }
         },
 
         redraw_map: function()
@@ -296,22 +325,8 @@ GOOGLEMAP_BGCOLOR_REMOVED = 2;
                 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) {
@@ -372,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;
             }
         },