oo-ify geotag widget javascript - and fix some other issues that
authorMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 9 Nov 2009 21:00:25 +0000 (16:00 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 9 Nov 2009 21:01:45 +0000 (16:01 -0500)
were brought to light during refactoring.

ansel/js/googlemap.js
ansel/lib/Ajax/Imple/ImageSaveGeotag.php
ansel/lib/Widget/Geotag.php

index 8aeb146..38f3795 100644 (file)
@@ -142,7 +142,7 @@ Ansel_GMap.prototype = {
                 var marker = new anselGOverlay(ll, points[i]);
             }
             // Click handlers only apply to our custom GOverlay.
-            if (!points[i].markerOnly && !options.viewType == 'Block') {
+            if (!points[i].markerOnly && !this.options.viewType == 'Block') {
                 (function() {
                     var p = points[i];
                     GEvent.addDomListener(marker.div_, 'click', function() {
@@ -159,7 +159,7 @@ Ansel_GMap.prototype = {
             // Only put the current image on the small map if we are in the
             // Image view.
             if (this.options.smallMap &&
-                (options.viewType != 'Image' || points[i].markerOnly)) {
+                (this.options.viewType != 'Image' || points[i].markerOnly)) {
                 var marker2 = new GMarker(ll, this.tIO);
                 this.smallMap.addOverlay(marker2);
             }
@@ -379,7 +379,7 @@ Ansel_GMap.prototype = {
     },
 
     _getRelocateLink: function(iid) {
-        if (options.hasEdit) {
+        if (this.options.hasEdit) {
             var a = new Element('a', {href: this.options.relocateUrl + '?image=' + iid}).update(this.options.relocateText);
             a.observe('click', function(e) { Horde.popup({ url: this.options.relocateUrl, params: 'image=' + iid, width: 750, height: 600 }); e.stop();}.bind(this));
             return a;
index ea85f9c..e1ad51d 100644 (file)
@@ -76,7 +76,7 @@ class Ansel_Ajax_Imple_ImageSaveGeotag extends Horde_Ajax_Imple_Base
                     } else {
                         $title = $this->_point2Deg($data['image_latitude'], true) . ' ' . $this->_point2Deg($data['image_longitude']);
                     }
-                    $imgsrc .= Horde::link($addurl, $title, '', '', "setLocation('" . $data['image_latitude'] . "', '" . $data['image_longitude'] . "');return false") . '<img src="' . Ansel::getImageUrl($id, 'mini', true) . '" alt="[image]" /></a>';
+                    $imgsrc .= Horde::link($addurl, $title, '', '', "Ansel.widgets.geotag.setLocation('" . $data['image_latitude'] . "', '" . $data['image_longitude'] . "');return false") . '<img src="' . Ansel::getImageUrl($id, 'mini', true) . '" alt="[image]" /></a>';
                 }
                 $imgsrc .= '</div>';
                 $content = sprintf(_("No location data present. Place using %smap%s or click on image to place at the same location."), $addLink, '</a>') . $imgsrc;
index 3254e7c..256dfce 100644 (file)
@@ -113,7 +113,7 @@ class Ansel_Widget_Geotag extends Ansel_Widget_Base
                             } else {
                                 $title = $this->_point2Deg($data['image_latitude'], true) . ' ' . $this->_point2Deg($data['image_longitude']);
                             }
-                            $imgsrc .= Horde::link($addurl, $title, '', '', "setLocation('" . $data['image_latitude'] . "', '" . $data['image_longitude'] . "');return false") . '<img src="' . Ansel::getImageUrl($id, 'mini', true) . '" alt="[image]" /></a>';
+                            $imgsrc .= Horde::link($addurl, $title, '', '', "Ansel.widgets.geotag.setLocation('" . $data['image_latitude'] . "', '" . $data['image_longitude'] . "');return false") . '<img src="' . Ansel::getImageUrl($id, 'mini', true) . '" alt="[image]" /></a>';
                                                     }
                         $imgsrc .= '</div>';
                         $content .= sprintf(_("No location data present. Place using %s map %s or click on image to place at the same location."), $addLink, '</a>') . $imgsrc;
@@ -138,80 +138,81 @@ class Ansel_Widget_Geotag extends Ansel_Widget_Base
         $json = Horde_Serialize::serialize(array_values($geodata), Horde_Serialize::JSON);
         $html .= <<<EOT
         <script type="text/javascript">
-        var map = {};
-        var pageImages = {$json};
-        options = {
-            smallMap: 'ansel_map_small',
-            mainMap:  'ansel_map',
-            viewType: '{$viewType}',
-            relocateUrl: '{$url}',
-            relocateText: '{$rtext}',
-            deleteGeotagText: '{$dtext}',
-            hasEdit: {$permsEdit},
-            calculateMaxZoom: true,
-            updateEndpoint: '{$impleUrl}',
-            deleteGeotagCallback: function() {deleteLocation();}
-        };
-
-        function setLocation(lat, lng)
-        {
-            var params = { "values": "img={$image_id}/lat=" + lat + "/lng=" + lng };
-
-            url = "{$impleUrl}";
-            new Ajax.Request(url + "/action=geotag/post=values", {
-                method: 'post',
-                parameters: params,
-                onComplete: function(transport) {
-                     if (typeof Horde_ToolTips != 'undefined') {
-                         Horde_ToolTips.out();
-                     }
-                     if (transport.responseJSON.response == 1) {
-                        w = new Element('div');
-                        w.appendChild(new Element('div', {id: 'ansel_map'}));
-                        ag = new Element('div', {'class': 'ansel_geolocation'});
-                        ag.appendChild(new Element('div', {id: 'ansel_locationtext'}));
-                        ag.appendChild(new Element('div', {id: 'ansel_latlng'}));
-                        ag.appendChild(new Element('div', {id: 'ansel_relocate'}));
-                        ag.appendChild(new Element('div', {id: 'ansel_deleteGeotag'}));
-                        w.appendChild(ag);
-                        w.appendChild(new Element('div', {id: 'ansel_map_small'}));
-                        $('ansel_geo_widget').update(w);
-                        pageImages.unshift({image_id: {$image_id}, image_latitude: lat, image_longitude: lng, image_location:'', markerOnly:true});
-                        doMap(pageImages);
-                     }
-                 }
-            });
-        }
-
-        function deleteLocation() {
-            var params = {"values": "img={$image_id}" };
-
-            var url = "{$impleUrl}";
-            new Ajax.Request(url + "/action=untag/post=values", {
-                method: 'post',
-                parameters: params,
-                onComplete: function(transport) {
-                    if (transport.responseJSON.response == 1) {
-                        $('ansel_geo_widget').update(transport.responseJSON.message);
+        Ansel.widgets = Ansel.widgets || {};
+        Ansel.widgets.geotag = {
+            map: {},
+            images: {$json},
+            options: {
+                smallMap: 'ansel_map_small',
+                mainMap:  'ansel_map',
+                viewType: '{$viewType}',
+                relocateUrl: '{$url}',
+                relocateText: '{$rtext}',
+                deleteGeotagText: '{$dtext}',
+                hasEdit: {$permsEdit},
+                calculateMaxZoom: true,
+                updateEndpoint: '{$impleUrl}',
+                deleteGeotagCallback: function() { Ansel.widgets.geotag.deleteLocation(); }.bind(this)
+            },
+
+            setLocation: function(lat, lng)  {
+                var params = { "values": "img={$image_id}/lat=" + lat + "/lng=" + lng };
+
+                var url = "{$impleUrl}";
+                new Ajax.Request(url + "/action=geotag/post=values", {
+                    method: 'post',
+                    parameters: params,
+                    onComplete: function(transport) {
+                         if (typeof Horde_ToolTips != 'undefined') {
+                             Horde_ToolTips.out();
+                         }
+                         if (transport.responseJSON.response == 1) {
+                            var w = new Element('div');
+                            w.appendChild(new Element('div', {id: 'ansel_map'}));
+                            var ag = new Element('div', {'class': 'ansel_geolocation'});
+                            ag.appendChild(new Element('div', {id: 'ansel_locationtext'}));
+                            ag.appendChild(new Element('div', {id: 'ansel_latlng'}));
+                            ag.appendChild(new Element('div', {id: 'ansel_relocate'}));
+                            ag.appendChild(new Element('div', {id: 'ansel_deleteGeotag'}));
+                            w.appendChild(ag);
+                            w.appendChild(new Element('div', {id: 'ansel_map_small'}));
+                            $('ansel_geo_widget').update(w);
+                            this.images.unshift({image_id: {$image_id}, image_latitude: lat, image_longitude: lng, image_location:'', markerOnly:true});
+                            this.doMap();
+                         }
+                     }.bind(this)
+                });
+            },
+
+            deleteLocation: function() {
+                var params = {"values": "img={$image_id}" };
+                var url = "{$impleUrl}";
+                new Ajax.Request(url + "/action=untag/post=values", {
+                    method: 'post',
+                    parameters: params,
+                    onComplete: function(transport) {
+                        if (transport.responseJSON.response == 1) {
+                            $('ansel_geo_widget').update(transport.responseJSON.message);
+                        }
                     }
-                }
-            });
-
-        }
-
-        function doMap(points) {
-            map = new Ansel_GMap(options);
-            map.getLocationCallback_ = map.getLocationCallback;
-            map.getLocationCallback = function(points, marker) {
-                map.getLocationCallback_(points, marker, (typeof points.NoUpdate == 'undefined'));
-            }.bind(map);
-            map.addPoints(points);
-            map.display();
-        }
+                });
+
+            },
+
+            doMap: function() {
+                this.map = new Ansel_GMap(this.options);
+                this.map.getLocationCallback_ = this.map.getLocationCallback;
+                this.map.getLocationCallback = function(points, marker) {
+                    this.map.getLocationCallback_(points, marker, (typeof points.NoUpdate == 'undefined'));
+                }.bind(this);
+                this.map.addPoints(this.images);
+                this.map.display();
+            }
+        };
 EOT;
 
         if (empty($noGeotag)) {
-            $html .= "\n" . 'Event.observe(window, "load", function() {doMap(pageImages);});' . "\n";
+            $html .= "\n" . 'Event.observe(window, "load", function() {Ansel.widgets.geotag.doMap();});' . "\n";
         }
         $html .= '</script>' . "\n";
         $html .= $content. $this->_htmlEnd();