Changeset 406
- Timestamp:
- 07/20/06 04:33:28
- Files:
-
- geolocation/trunk/adapter.py (deleted)
- geolocation/trunk/adapters (added)
- geolocation/trunk/adapters/__init__.py (added)
- geolocation/trunk/adapters/geolocaion.py (added)
- geolocation/trunk/adapters/geomap.py (added)
- geolocation/trunk/browser/location.py (modified) (2 diffs)
- geolocation/trunk/configure.zcml (modified) (2 diffs)
- geolocation/trunk/interface.py (deleted)
- geolocation/trunk/interfaces (added)
- geolocation/trunk/interfaces/__init__.py (added)
- geolocation/trunk/interfaces/geolocation.py (added)
- geolocation/trunk/interfaces/geomap.py (added)
- geolocation/trunk/skins/geolocation/editLocation.js (modified) (3 diffs)
- geolocation/trunk/skins/geolocation/edit_location.cpt (modified) (4 diffs)
- geolocation/trunk/skins/geolocation/edit_location.cpt.metadata (modified) (1 diff)
- geolocation/trunk/skins/geolocation/save_location.cpy (modified) (1 diff)
- geolocation/trunk/skins/geolocation/validate_map.vpy (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
geolocation/trunk/browser/location.py
r405 r406 6 6 7 7 # Product imports 8 from Products.geolocation.interface import IGEOLocated, IGEOLocatedView8 from Products.geolocation.interfaces.geolocation import IGEOLocated, IGEOLocatedView 9 9 10 10 class GEOLocatedView(BrowserView): 11 11 12 12 implements(IGEOLocatedView) 13 13 14 14 def __init__(self, context, request): 15 15 """ init view """ … … 19 19 self.latitude = self.location and self.location.getLatitude() or None 20 20 self.longitude = self.location and self.location.getLongitude() or None 21 21 22 22 def editLocation(self, latitude=None, longitude=None): 23 23 """ update location properties """ 24 24 self.location.setLocation(latitude, longitude) 25 25 self.context.reindexObject() 26 26 27 27 def getLatitude(self): 28 28 """ return location latitude """ 29 29 return self.latitude 30 30 31 31 def getLongitude(self): 32 32 """ return location longitude """ geolocation/trunk/configure.zcml
r405 r406 18 18 class="Products.ATContentTypes.content.image.ATImage" 19 19 interface="zope.app.annotation.IAttributeAnnotatable" /> 20 20 21 21 <adapter 22 22 for="Products.ATContentTypes.interface.document.IATDocument" 23 provides=".interface .IGEOLocated"24 factory=".adapter .GEOLocated"25 /> 23 provides=".interfaces.geolocation.IGEOLocated" 24 factory=".adapters.geolocaion.GEOLocated" 25 /> 26 26 <adapter 27 27 for="Products.ATContentTypes.interface.event.IATEvent" 28 provides=".interface .IGEOLocated"29 factory=".adapter .GEOLocated"30 /> 28 provides=".interfaces.geolocation.IGEOLocated" 29 factory=".adapters.geolocaion.GEOLocated" 30 /> 31 31 <adapter 32 32 for="Products.ATContentTypes.interface.link.IATLink" 33 provides=".interface .IGEOLocated"34 factory=".adapter .GEOLocated"35 /> 33 provides=".interfaces.geolocation.IGEOLocated" 34 factory=".adapters.geolocaion.GEOLocated" 35 /> 36 36 <adapter 37 37 for="Products.ATContentTypes.interface.image.IATImage" 38 provides=".interface .IGEOLocated"39 factory=".adapter .GEOLocated"40 /> 38 provides=".interfaces.geolocation.IGEOLocated" 39 factory=".adapters.geolocaion.GEOLocated" 40 /> 41 41 <adapter 42 42 for="Products.ATContentTypes.interface.news.IATNewsItem" 43 provides=".interface.IGEOLocated" 44 factory=".adapter.GEOLocated" 45 /> 43 provides=".interfaces.geolocation.IGEOLocated" 44 factory=".adapters.geolocaion.GEOLocated" 45 /> 46 47 <adapter 48 for="Products.ATContentTypes.interface.document.IATDocument" 49 provides=".interfaces.geomap.IGEOMap" 50 factory=".adapters.geomap.GEOMap" 51 /> 52 <adapter 53 for="Products.ATContentTypes.interface.event.IATEvent" 54 provides=".interfaces.geomap.IGEOMap" 55 factory=".adapters.geomap.GEOMap" 56 /> 57 <adapter 58 for="Products.ATContentTypes.interface.link.IATLink" 59 provides=".interfaces.geomap.IGEOMap" 60 factory=".adapters.geomap.GEOMap" 61 /> 62 <adapter 63 for="Products.ATContentTypes.interface.image.IATImage" 64 provides=".interfaces.geomap.IGEOMap" 65 factory=".adapters.geomap.GEOMap" 66 /> 67 <adapter 68 for="Products.ATContentTypes.interface.news.IATNewsItem" 69 provides=".interfaces.geomap.IGEOMap" 70 factory=".adapters.geomap.GEOMap" 71 /> 72 73 <browser:page 74 for="*" 75 name="MapView" 76 class=".browser.map.GEOMapView" 77 permission="zope2.View" 78 allowed_interface=".interfaces.geomap.IGEOMapView" 79 /> 46 80 47 81 <browser:page … … 50 84 class=".browser.location.GEOLocatedView" 51 85 permission="zope2.View" 52 allowed_interface=".interface.IGEOLocatedView" 53 allowed_attributes="getLatitude getLongitude" 54 /> 86 allowed_interface=".interfaces.geolocation.IGEOLocatedView" 87 /> 55 88 56 <!-- <browser:page57 for="*"58 name="edit_location"59 template="browser/edit_location.cpt"60 permission="zope2.View"61 /> -->62 63 <browser:page64 for="*"65 name="editLocation"66 class=".browser.location.GEOLocatedView"67 attribute="editLocation"68 permission="zope2.View"69 />70 71 89 </configure> geolocation/trunk/skins/geolocation/editLocation.js
r405 r406 2 2 if (GBrowserIsCompatible()) { 3 3 4 var lat = document.getElementById('latitude'), 4 var mapping = {'Map':G_NORMAL_MAP, 'Satellite':G_SATELLITE_MAP,'Hybrid':G_HYBRID_MAP}, 5 map_t='', 6 lat = document.getElementById('latitude'), 5 7 lng = document.getElementById('longitude'), 8 lat_el = document.getElementById('maplatitude'), 9 lng_el = document.getElementById('maplongitude'), 10 map_lat = lat_el.value, 11 map_lng = lng_el.value, 12 zoom_el = document.getElementById('mapzoom'), 13 map_zoom = zoom_el.value, 14 map_type = document.getElementsByName('maptype'), 6 15 lat_val = lat.value!=''?lat.value:0, 7 16 lng_val = lng.value!=''?lng.value:0, 8 map = new GMap2(document.getElementById('map')), 9 button = document.getElementById('cancel_button'); 10 f = function(){ 11 lat.value = lat_val, 12 lng.value = lng_val; 13 map.clearOverlays(); 14 addMarker(lat_val, lng_val); 15 }; 17 map = new GMap2(document.getElementById('geomap')); 16 18 17 if (button.addEventListener) button.addEventListener("click", f, false); 18 else if (button.attachEvent) button.attachEvent("onclick", f); 19 20 map.addControl(new GLargeMapControl()); 21 map.addControl(new GMapTypeControl()); 22 map.addControl(new GOverviewMapControl()); 23 map.setCenter(new GLatLng(parseFloat(lat_val), parseFloat(lng_val)), 6, G_HYBRID_MAP); 24 25 function addMarker(lat, lng){ 26 var point = new GLatLng(lat, lng); 27 var marker = new GMarker(point) 28 map.addOverlay(marker); 19 function validator(a,b){ 20 if (isNaN(a) || isNaN(b) || a=='' || b=='') return false; 21 if (-90<=a && a<=90 && -180<=b && b<=180) return true; 22 return false; 29 23 }; 30 24 31 var listener = function(marker, point) { 25 function selectlistener(){ 26 var z = zoom_el.value!=''?zoom_el.value:6; 27 map.setZoom(parseInt(z)); 28 }; 29 function fieldlistener(){ 30 if (validator(lat_el.value, lng_el.value)) 31 map.setCenter(new GLatLng(parseFloat(lat_el.value), parseFloat(lng_el.value))); 32 }; 33 function boxlistener(){ 34 var el = window.event?window.event.srcElement:this; 35 map.setMapType(mapping[el.value]); 36 }; 37 function addMarker(lat, lng){ 38 var point = new GLatLng(lat, lng); 39 var marker = new GMarker(point) 40 map.addOverlay(marker); 41 }; 42 function mapmarkerlistener(marker, point){ 32 43 if (!marker){ 33 44 map.clearOverlays(); … … 37 48 } 38 49 }; 50 function maptypelistener(){document.getElementById(map.getCurrentMapType().getName()).click();}; 51 function mapzoomlistener(oldzoom, newzoom){zoom_el.selectedIndex = newzoom+1;}; 52 function mapcenterlistener(){ 53 lat_el.value = map.getCenter().lat(); 54 lng_el.value = map.getCenter().lng(); 55 }; 39 56 40 GEvent.addListener(map, 'click', listener); 57 map.addControl(new GLargeMapControl()); 58 map.addControl(new GMapTypeControl()); 59 map.addControl(new GOverviewMapControl()); 60 61 for (var i=0; i<map_type.length; i++) { 62 if (map_type[i].checked) map_t = map_type[i].value; 63 registerEventListener(map_type[i], 'click', boxlistener, false); 64 }; 65 66 var map_x = map_lat!=''?map_lat:lat_val, map_t, 67 map_y = map_lng!=''?map_lng:lng_val, 68 map_z = map_zoom!=''?map_zoom:6, 69 map_t = map_t=='Map'?G_NORMAL_MAP:map_t=='Satellite'?G_SATELLITE_MAP:G_HYBRID_MAP; 70 71 map.setCenter(new GLatLng(parseFloat(map_x), parseFloat(map_y)), parseInt(map_z), map_t); 72 73 GEvent.addListener(map, 'maptypechanged', maptypelistener); 74 GEvent.addListener(map, 'zoomend', mapzoomlistener); 75 GEvent.addListener(map, 'moveend', mapcenterlistener); 76 GEvent.addListener(map, 'click', mapmarkerlistener); 41 77 addMarker(parseFloat(lat_val), parseFloat(lng_val)); 78 79 registerEventListener(zoom_el, 'change', selectlistener, false); 80 registerEventListener(lat_el, 'change', fieldlistener, false); 81 registerEventListener(lng_el, 'change', fieldlistener, false); 82 42 83 } 43 84 else window.alert("Google maps aren't compatible with current Browser."); … … 45 86 46 87 registerPloneFunction(editLocation); 88 registerEventListener(window, 'unload', GUnload); geolocation/trunk/skins/geolocation/edit_location.cpt
r405 r406 8 8 9 9 <head> 10 <metal:block fill-slot="javascript_head_slot"> 11 10 <metal:block fill-slot="javascript_head_slot" 11 tal:define="key here/getMapKey|nothing" 12 tal:condition="key"> 12 13 <script type="text/javascript" src="" 13 tal:attributes="src string:http://maps.google.com/maps?file=api&v=2&key=${ here/getMapKey}">14 tal:attributes="src string:http://maps.google.com/maps?file=api&v=2&key=${key}"> 14 15 </script> 15 16 <script type="text/javascript" src="" … … 23 24 id="weblog-topics"> 24 25 25 <div tal:define="location context/@@LocationView"> 26 <tal:x define="latitude python:location and location.getLatitude(); 26 <div tal:define="location context/@@LocationView; 27 mapoptions context/@@MapView"> 28 <tal:x define="mapcenter python:mapoptions and mapoptions.getMapCenter(); 29 maplatitude python:mapcenter and len(mapcenter)==2 and mapcenter[0] or None; 30 maplongitude python:mapcenter and len(mapcenter)==2 and mapcenter[1] or None; 31 mapzoom python:mapoptions and mapoptions.getMapZoom(); 32 maptype python:mapoptions and mapoptions.getMapType(); 33 latitude python:location and location.getLatitude(); 27 34 longitude python:location.getLongitude()"> 28 35 <h1 class="documentFirstHeading" … … 32 39 action="." 33 40 tal:attributes="action string:${here_url}/${template/getId}"> 34 <fieldset>35 <legend>36 Edit location coordinates37 </legend>38 41 39 42 <div class="field" 40 43 tal:define="error errors/latitude|nothing;" 41 44 tal:attributes="class python:test(error, 'field error', 'field')"> 42 <label for="latitude" i18n:translate="label_latitude">45 <!-- <label for="latitude" i18n:translate="label_latitude"> 43 46 Latitude 44 47 </label> 45 <div tal:content="error">Validation error output</div> 46 <input type=" text" name="latitude" id="latitude"48 <div tal:content="error">Validation error output</div>--> 49 <input type="hidden" name="latitude" id="latitude" 47 50 tal:attributes="value request/latitude|latitude" /> 48 51 </div> 49 50 52 <div class="field" 51 53 tal:define="error errors/longitude|nothing;" 52 54 tal:attributes="class python:test(error, 'field error', 'field')"> 53 <label for="longitude" i18n:translate="label_longitude">55 <!-- <label for="longitude" i18n:translate="label_longitude"> 54 56 Longitude 55 57 </label> 56 <div tal:content="error">Validation error output</div> 57 <input type=" text" name="longitude" id="longitude"58 <div tal:content="error">Validation error output</div>--> 59 <input type="hidden" name="longitude" id="longitude" 58 60 tal:attributes="value request/longitude|longitude" /> 59 61 </div> 60 62 <div class="field" 63 tal:define="error errors/maplatitude|nothing;" 64 tal:attributes="class python:test(error, 'field error', 'field')"> 65 <label for="maplatitude" i18n:translate="label_maplatitude"> 66 Map Latitude 67 </label> 68 <div tal:content="error">Validation error output</div> 69 <input type="text" name="maplatitude" id="maplatitude" 70 tal:attributes="value request/maplatitude|maplatitude" /> 71 </div> 72 <div class="field" 73 tal:define="error errors/maplongitude|nothing;" 74 tal:attributes="class python:test(error, 'field error', 'field')"> 75 <label for="maplongitude" i18n:translate="label_maplongitude"> 76 Map Longitude 77 </label> 78 <div tal:content="error">Validation error output</div> 79 <input type="text" name="maplongitude" id="maplongitude" 80 tal:attributes="value request/maplongitude|maplongitude" /> 81 </div> 82 <div class="field" 83 tal:define="error errors/mapzoom|nothing;" 84 tal:attributes="class python:test(error, 'field error', 'field')"> 85 <label for="mapzoom" i18n:translate="label_mapzoom"> 86 Map Zoom 87 </label> 88 <div tal:content="error">Validation error output</div> 89 <select name="mapzoom" id="mapzoom"> 90 <option tal:repeat="zoom python:['',] + range(20)" 91 tal:content="zoom" 92 tal:attributes="selected python:str(zoom) == mapzoom; 93 value zoom">Zoom</option> 94 </select> 95 </div> 96 <div class="field" 97 tal:define="error errors/maptype|nothing;" 98 tal:attributes="class python:test(error, 'field error', 'field')"> 99 <label for="maptype" i18n:translate="label_maptype"> 100 Map Type 101 </label> 102 <div tal:content="error">Validation error output</div> 103 <input type="radio" name="maptype" id="Map" value="Map" 104 tal:attributes="checked python:maptype=='Map'" /> 105 <label for="maptype1">Map</label> 106 <input type="radio" name="maptype" id="Satellite" value="Satellite" 107 tal:attributes="checked python:maptype=='Satellite'" /> 108 <label for="maptype2">Satellite</label> 109 <input type="radio" name="maptype" id="Hybrid" value="Hybrid" 110 tal:attributes="checked python:maptype=='Hybrid'" /> 111 <label for="maptype3">Hybrid</label> 112 </div> 61 113 <div class="formControls"> 62 114 <input class="context" … … 79 131 <input type="hidden" name="form.submitted" value="1" /> 80 132 81 </fieldset>82 133 </form> 83 134 84 <div id=" map" style="position: relative; height: 480px;"></div>135 <div id="geomap" style="position: relative; height: 480px;"></div> 85 136 86 137 </tal:x> geolocation/trunk/skins/geolocation/edit_location.cpt.metadata
r405 r406 1 1 [validators] 2 validators = validate_location 2 validators = validate_location, validate_map 3 3 validators..Cancel= 4 4 geolocation/trunk/skins/geolocation/save_location.cpy
r405 r406 10 10 # 11 11 12 latitude = context.REQUEST.get('latitude', 0) 13 longitude = context.REQUEST.get('longitude', 0) 12 latitude = context.REQUEST.get('latitude', 0) 13 longitude = context.REQUEST.get('longitude', 0) 14 maplatitude = context.REQUEST.get('maplatitude', 0) 15 maplongitude = context.REQUEST.get('maplongitude', 0) 16 mapzoom = context.REQUEST.get('mapzoom', 0) 17 maptype = context.REQUEST.get('maptype', 0) 18 19 if not (maplatitude and maplongitude): mapcenter=() 20 else: mapcenter = (float(maplatitude), float(maplongitude)) 14 21 15 22 context.restrictedTraverse('@@LocationView').editLocation(latitude, longitude) 23 context.restrictedTraverse('@@MapView').editMapOptions(mapcenter, mapzoom, maptype) 16 24 17 25 return state.set(portal_status_message="geoLocation property updated")
