From b577b950e9bd01eba771ad12a939505f7a02626e Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Tue, 27 Oct 2009 01:01:57 -0500 Subject: [PATCH] fixed: #10887: Map Point dropdown doesn't update --- docs/changelog/7.x.x.txt | 1 + ...e_map_map-templates_default-map-view.wgpkg | Bin 0 -> 1121 bytes lib/WebGUI/Asset/Wobject/Map.pm | 20 +++- www/extras/yui-webgui/build/map/map.js | 100 +++++++++++++----- 4 files changed, 93 insertions(+), 28 deletions(-) create mode 100644 docs/upgrades/packages-7.7.23/home_map_map-templates_default-map-view.wgpkg diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index ab0400404..0982410e2 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -14,6 +14,7 @@ - fixed #11116: Deleted user's version tags and revisions - fixed #11168: Points do not work with uncommitted Map - fixed #10888: Add Point... how do I enter details? + - fixed #10887: Map Point dropdown doesn't update 7.8.2 - Added scheduled vendor payout workflow activity. (Special thanks to Martin @ Oqapi) diff --git a/docs/upgrades/packages-7.7.23/home_map_map-templates_default-map-view.wgpkg b/docs/upgrades/packages-7.7.23/home_map_map-templates_default-map-view.wgpkg new file mode 100644 index 0000000000000000000000000000000000000000..f3597a0954aae007639398599f53f812a704b641 GIT binary patch literal 1121 zcmV-n1fKgJiwFP!00000|Ls<7Z`(Ey_UHZz!Na~Kwj{@Ptz-exrd_f%soN$?*JUs$ ziME)?Bu7$q9K-*;M^dun*vZzS0Wu&0YzaKx!@K9+*r+}Jh&Q}9#eb*kckaZ0$KQeYyFcjs2Vov7{*4DueKNxN3n;?6 z!egEyg$GC}6eVL!m8?5~^Vi>7MlKZ-XoRavTriG>BG_y+Fd8XEQoXt1Oeh>57!l3V z)Szf_BrqHkznW>NdaJ$^KzS*HU*}nv5}Dw*6jD6BAT(xEqve(Ye4_+9!YDpNBiTpM zHE3zzJ*j3XcGQgHUoOGB8`X@YysYmxrlSFli8?{N&j?jcib9;uVl$G^PcRuJDrmbdzuC3> z?6<=vSPWA(-JS)Gj08*5#a`2RzF$%#XOwYC)RB$GHN1k0t#y%Q^E=KeFiTZSAWRrwdTFEnSY_RrJ2~%8PIj(%FZGV`cAbAV zrC6LxERJnzR&qWQso_0gW854gu7BG_DavMyhbT+cwqBhOJS}62q{J%6>s`5nFWyz_ zx7hvgD*V$&*J0; zF**SEUqg?=Vk4&2JcwfpSss*Yqow2?gMe{kNJ$By2^K`1i}bBv<31EUwcJ#iQ3SnD zo}#hk`2vT(o*xInfsR!WoaG(1giHy=c~7mIp}S!Um%B}We4QXV+SEOD*F9k|8IrsK zdVagp@mrqnmk@ba|In$Vn`E~XDWXzq_MuHW=LB)b>|AzeB6TcKm~X7)i@YZMlqonp zLJIQ0pjU{2agv?=hZD4qnQ2sY#9_Wnsx!dk{3mj2&Gh`2z0!P+1QeJ#_8!`U;OOk+ z-Fgs+d8f9bQ*v8+*Ti1i?`iT nYgC%I%#_?deOp_+SUj2Q<+CBr3_LUNgc96EE?01^NImq9E% literal 0 HcmV?d00001 diff --git a/lib/WebGUI/Asset/Wobject/Map.pm b/lib/WebGUI/Asset/Wobject/Map.pm index 3af388789..6db5861f0 100644 --- a/lib/WebGUI/Asset/Wobject/Map.pm +++ b/lib/WebGUI/Asset/Wobject/Map.pm @@ -388,6 +388,8 @@ sub view { var mapId = "%s"; var mapUrl = "%s"; var map = new GMap2( document.getElementById("map_" + mapId) ); + map.url = mapUrl; + map.assetId = mapId; map.setCenter(new GLatLng(%s, %s), %s); map.setUIToDefault(); map.extrasUrl = "%s"; @@ -414,7 +416,7 @@ ENDHTML } $mapHtml .= <<'ENDHTML'; - markermanager.addMarkers( WebGUI.Map.preparePoints(map, markermanager, mapUrl, points), 0 ); + markermanager.addMarkers( WebGUI.Map.preparePoints(map, markermanager, points), 0 ); ENDHTML } @@ -434,13 +436,13 @@ ENDHTML if ( document.getElementById( "setCenter_" + mapId ) ) { var button = document.getElementById( "setCenter_" + mapId ); GEvent.addDomListener( button, "click", function () { - WebGUI.Map.setCenter( map, mapUrl ); + WebGUI.Map.setCenter( map ); } ); } if ( document.getElementById( "addPoint_" + mapId ) ) { var button = document.getElementById( "addPoint_" + mapId ); GEvent.addDomListener( button, "click", function () { - WebGUI.Map.editPoint( map, markermanager, mapUrl ); + WebGUI.Map.editPoint( map, markermanager ); } ); } }); @@ -463,6 +465,18 @@ ENDHTML id => sprintf( 'setCenter_%s', $self->getId ), } ); + # Select box to choose a map point + tie my %selectPointOptions, 'Tie::IxHash', ( + "" => '-- ' . $i18n->get('select a point'), + map { $_->{assetId} => $_->{title} } sort { $a->{title} cmp $b->{title} } @{$var->{mapPoints}}, + ); + $var->{ selectPoint } + = WebGUI::Form::selectBox( $session, { + extras => q{onchange="WebGUI.Map.focusOn(this.options[this.selectedIndex].value);"}, + id => sprintf( q{selectPoint_%s}, $self->getId ), + options => \%selectPointOptions, + } ); + return $self->processTemplate( $var, undef, $self->{_viewTemplate} ); } diff --git a/www/extras/yui-webgui/build/map/map.js b/www/extras/yui-webgui/build/map/map.js index b2165cf5a..2e2f9ee15 100644 --- a/www/extras/yui-webgui/build/map/map.js +++ b/www/extras/yui-webgui/build/map/map.js @@ -7,38 +7,40 @@ if (typeof WebGUI.Map == "undefined") { } // Keep track of all points on all maps and how to focus on them +// A hash (map) of hashes (markers) WebGUI.Map.markers = {}; // Keep a loading dialog WebGUI.Map.loadingDialog = undefined; /** - * WebGUI.Map.deletePoint( map, mgr, mapUrl, marker ) + * WebGUI.Map.deletePoint( map, mgr, marker ) * Delete a point from the map. * NOTE: We assume the user has already confirmed this action */ WebGUI.Map.deletePoint -= function ( map, mgr, mapUrl, marker ) { += function ( map, mgr, marker ) { var callback = function ( text, code ) { WebGUI.Map.hideLoading(); var response = YAHOO.lang.JSON.parse( text ); // remove the marker from the map if ( !response.error ) { mgr.removeMarker( marker ); + delete WebGUI.Map.markers[ map.assetId ][ marker.assetId ]; } }; WebGUI.Map.showLoading(); - GDownloadUrl( mapUrl + '?func=ajaxDeletePoint;assetId=' + marker.assetId, callback); + GDownloadUrl( map.url + '?func=ajaxDeletePoint;assetId=' + marker.assetId, callback); }; /** - * WebGUI.Map.editPoint( map, mgr, mapUrl, marker ) + * WebGUI.Map.editPoint( map, mgr, marker ) * Edit a point on the map. * up the edit box. mgr is the Marker Manager to add the marker - * to. mapUrl is the URL of the map asset + * to. */ WebGUI.Map.editPoint -= function ( map, mgr, mapUrl, marker ) { += function ( map, mgr, marker ) { var assetId = ''; if ( !marker ) { marker = new GMarker( map.getCenter(), { draggable: true } ); @@ -49,7 +51,7 @@ WebGUI.Map.editPoint assetId = "new"; marker.assetId = "new"; GEvent.addListener( marker, "dragend", function (latlng) { - WebGUI.Map.setPointLocation( marker, latlng, mapUrl ); + WebGUI.Map.setPointLocation( marker, latlng ); } ); } else { @@ -94,6 +96,7 @@ WebGUI.Map.editPoint // Update marker info var point = YAHOO.lang.JSON.parse( o.responseText ); marker.assetId = point.assetId; + marker.title = point.title; GEvent.clearListeners( marker, "click" ); GEvent.clearListeners( marker, "infowindowbeforeclose" ); @@ -115,7 +118,7 @@ WebGUI.Map.editPoint editButton.type = "button"; editButton.value = "Edit"; GEvent.addDomListener( editButton, "click", function () { - WebGUI.Map.editPoint( map, mgr, mapUrl, marker ); + WebGUI.Map.editPoint( map, mgr, marker ); } ); divButton.appendChild( editButton ); @@ -124,16 +127,19 @@ WebGUI.Map.editPoint deleteButton.value = "Delete"; // Replace with i18n GEvent.addDomListener( deleteButton, "click", function () { if ( confirm("Are you sure you want to delete this point?") ) { - WebGUI.Map.deletePoint( map, mgr, mapUrl, marker ); + WebGUI.Map.deletePoint( map, mgr, marker ); } } ); divButton.appendChild( deleteButton ); } marker.bindInfoWindow( infoWin ); GEvent.addListener( marker, "dragend", function (latlng) { - WebGUI.Map.setPointLocation( marker, latlng, mapUrl ); + WebGUI.Map.setPointLocation( marker, latlng ); } ); WebGUI.Map.hideLoading(); + + WebGUI.Map.markers[map.assetId][marker.assetId] = marker; + WebGUI.Map.updateSelectPoint( map ); } }; @@ -145,21 +151,27 @@ WebGUI.Map.editPoint WebGUI.Map.showLoading(); // Get the form - GDownloadUrl( mapUrl + '?func=ajaxEditPoint;assetId=' + assetId, callback ); + GDownloadUrl( map.url + '?func=ajaxEditPoint;assetId=' + assetId, callback ); }; /** - * WebGUI.Map.focusOn( assetId ) + * WebGUI.Map.focusOn( pointId ) * Pan the appropriate map to view the appropriate map point */ WebGUI.Map.focusOn -= function ( assetId ) { - var marker = WebGUI.Map.markers[assetId]; += function ( pointId ) { + var marker; + for ( var mapId in WebGUI.Map.markers ) { + if ( WebGUI.Map.markers[mapId][pointId] ) { + marker = WebGUI.Map.markers[mapId][pointId]; + break; + } + } if ( !marker ) return; var map = marker.map; var infoWin = marker.infoWin; - if ( map.getZoom() < 5 ) { - map.setZoom(6); + if ( map.getZoom() <= 4 ) { + map.setZoom(5); } map.panTo( marker.getLatLng() ); marker.openInfoWindow( marker.infoWin ); @@ -171,11 +183,13 @@ WebGUI.Map.hideLoading }; /** - * WebGUI.Map.preparePoints ( map, mgr, mapUrl, points ) + * WebGUI.Map.preparePoints ( map, mgr, points ) * Prepare the points from WebGUI into Google Map GMarkers */ WebGUI.Map.preparePoints -= function ( map, mgr, mapUrl, points ) { += function ( map, mgr, points ) { + WebGUI.Map.markers[map.assetId] = {}; + // Transform points into markers var markers = []; for ( var i = 0; i < points.length; i++ ) (function(i){ // Create closure for callbacks @@ -186,6 +200,7 @@ WebGUI.Map.preparePoints draggable: point.canEdit } ); marker.assetId = point.assetId; + marker.title = point.title; marker.map = map; // Create info window @@ -201,7 +216,7 @@ WebGUI.Map.preparePoints editButton.type = "button"; editButton.value = "Edit"; // Replace with i18n GEvent.addDomListener( editButton, "click", function () { - WebGUI.Map.editPoint( map, mgr, mapUrl, marker ); + WebGUI.Map.editPoint( map, mgr, marker ); } ); divButton.appendChild( editButton ); @@ -210,19 +225,19 @@ WebGUI.Map.preparePoints deleteButton.value = "Delete"; // Replace with i18n GEvent.addDomListener( deleteButton, "click", function () { if ( confirm("Are you sure you want to delete this point?") ) { - WebGUI.Map.deletePoint( map, mgr, mapUrl, marker ); + WebGUI.Map.deletePoint( map, mgr, marker ); } } ); divButton.appendChild( deleteButton ); infoWin.appendChild( divButton ); GEvent.addListener( marker, "dragend", function (latlng) { - WebGUI.Map.setPointLocation( marker, latlng, mapUrl ); + WebGUI.Map.setPointLocation( marker, latlng ); } ); } // Keep info - WebGUI.Map.markers[point.assetId] = marker; + WebGUI.Map.markers[map.assetId][point.assetId] = marker; marker.bindInfoWindow( infoWin ); @@ -254,12 +269,12 @@ WebGUI.Map.setCenter }; /** - * WebGUI.Map.setPointLocation( marker, latlng, mapUrl, assetId ) + * WebGUI.Map.setPointLocation( marker, latlng ) * Update the point's location in the database. */ WebGUI.Map.setPointLocation -= function ( marker, latlng, mapUrl, assetId ) { - var url = mapUrl + '?func=ajaxSetPointLocation' += function ( marker, latlng ) { + var url = marker.map.url + '?func=ajaxSetPointLocation' + ';assetId=' + marker.assetId + ';latitude=' + latlng.lat() + ';longitude=' + latlng.lng() @@ -294,3 +309,38 @@ WebGUI.Map.showLoading WebGUI.Map.loadingDialog.show(); }; + + +WebGUI.Map.updateSelectPoint += function (map) { + var select = document.getElementById( 'selectPoint_' + map.assetId ); + if ( !select) { + return; + } + + // Clear old points + while ( select.options.length > 1 ) { + select.length = 1; + } + + var markers = WebGUI.Map.markers[map.assetId]; + var sorted = []; + for ( var pointId in markers ) { + sorted.push( pointId ); + } + + sorted.sort( function (a,b) { + var ma = WebGUI.Map.markers[map.assetId][a]; + var mb = WebGUI.Map.markers[map.assetId][b]; + + if ( ma.title > mb.title ) { return 1; } + else if ( ma.title < mb.title ) { return -1; } + else { return 0; } + } ); + + // Add new points + for ( var i = 0; i < sorted.length; i++ ) { + select.options[ select.options.length ] + = new Option( markers[sorted[i]].title, sorted[i] ); + } +};