From: Michael J. Rubinsky Date: Mon, 9 Nov 2009 21:00:25 +0000 (-0500) Subject: oo-ify geotag widget javascript - and fix some other issues that X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=d8cc870d8e9dd06408142d37c726807b73f79bdd;p=horde.git oo-ify geotag widget javascript - and fix some other issues that were brought to light during refactoring. --- diff --git a/ansel/js/googlemap.js b/ansel/js/googlemap.js index 8aeb14622..38f3795b0 100644 --- a/ansel/js/googlemap.js +++ b/ansel/js/googlemap.js @@ -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; diff --git a/ansel/lib/Ajax/Imple/ImageSaveGeotag.php b/ansel/lib/Ajax/Imple/ImageSaveGeotag.php index ea85f9ca5..e1ad51da3 100644 --- a/ansel/lib/Ajax/Imple/ImageSaveGeotag.php +++ b/ansel/lib/Ajax/Imple/ImageSaveGeotag.php @@ -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") . '[image]'; + $imgsrc .= Horde::link($addurl, $title, '', '', "Ansel.widgets.geotag.setLocation('" . $data['image_latitude'] . "', '" . $data['image_longitude'] . "');return false") . '[image]'; } $imgsrc .= ''; $content = sprintf(_("No location data present. Place using %smap%s or click on image to place at the same location."), $addLink, '') . $imgsrc; diff --git a/ansel/lib/Widget/Geotag.php b/ansel/lib/Widget/Geotag.php index 3254e7cb5..256dfce09 100644 --- a/ansel/lib/Widget/Geotag.php +++ b/ansel/lib/Widget/Geotag.php @@ -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") . '[image]'; + $imgsrc .= Horde::link($addurl, $title, '', '', "Ansel.widgets.geotag.setLocation('" . $data['image_latitude'] . "', '" . $data['image_longitude'] . "');return false") . '[image]'; } $imgsrc .= ''; $content .= sprintf(_("No location data present. Place using %s map %s or click on image to place at the same location."), $addLink, '') . $imgsrc; @@ -138,80 +138,81 @@ class Ansel_Widget_Geotag extends Ansel_Widget_Base $json = Horde_Serialize::serialize(array_values($geodata), Horde_Serialize::JSON); $html .= << - 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 .= '' . "\n"; $html .= $content. $this->_htmlEnd();