Changeset 406

Show
Ignore:
Timestamp:
07/20/06 04:33:28
Author:
piv
Message:

map adapter added, edit_location upgrade to map manipulation, validation

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • geolocation/trunk/browser/location.py

    r405 r406  
    66 
    77# Product imports 
    8 from Products.geolocation.interface import IGEOLocated, IGEOLocatedView 
     8from Products.geolocation.interfaces.geolocation import IGEOLocated, IGEOLocatedView 
    99 
    1010class GEOLocatedView(BrowserView): 
    1111 
    1212    implements(IGEOLocatedView) 
    13            
     13 
    1414    def __init__(self, context, request): 
    1515        """ init view """ 
     
    1919        self.latitude = self.location and self.location.getLatitude() or None 
    2020        self.longitude = self.location and self.location.getLongitude() or None 
    21   
     21 
    2222    def editLocation(self, latitude=None, longitude=None): 
    2323        """ update location properties """ 
    2424        self.location.setLocation(latitude, longitude) 
    2525        self.context.reindexObject() 
    26          
     26 
    2727    def getLatitude(self): 
    2828       """ return location latitude """ 
    2929       return self.latitude 
    30         
     30 
    3131    def getLongitude(self): 
    3232       """ return location longitude """ 
  • geolocation/trunk/configure.zcml

    r405 r406  
    1818        class="Products.ATContentTypes.content.image.ATImage" 
    1919        interface="zope.app.annotation.IAttributeAnnotatable" /> 
    20    
     20 
    2121  <adapter 
    2222      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      /> 
    2626  <adapter 
    2727      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      /> 
    3131  <adapter 
    3232      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      /> 
    3636  <adapter 
    3737      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      /> 
    4141  <adapter 
    4242      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      /> 
    4680 
    4781  <browser:page 
     
    5084      class=".browser.location.GEOLocatedView" 
    5185      permission="zope2.View" 
    52       allowed_interface=".interface.IGEOLocatedView" 
    53       allowed_attributes="getLatitude getLongitude" 
    54       />   
     86      allowed_interface=".interfaces.geolocation.IGEOLocatedView" 
     87      /> 
    5588 
    56 <!--  <browser:page 
    57       for="*" 
    58       name="edit_location" 
    59       template="browser/edit_location.cpt" 
    60       permission="zope2.View" 
    61       />  --> 
    62      
    63   <browser:page 
    64       for="*" 
    65       name="editLocation" 
    66       class=".browser.location.GEOLocatedView" 
    67       attribute="editLocation" 
    68       permission="zope2.View" 
    69       />     
    70      
    7189</configure> 
  • geolocation/trunk/skins/geolocation/editLocation.js

    r405 r406  
    22  if (GBrowserIsCompatible()) { 
    33 
    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'), 
    57        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'), 
    615        lat_val = lat.value!=''?lat.value:0, 
    716        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')); 
    1618 
    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; 
    2923    }; 
    3024 
    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){ 
    3243      if (!marker){ 
    3344      map.clearOverlays(); 
     
    3748      } 
    3849    }; 
     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    }; 
    3956 
    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); 
    4177    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 
    4283  } 
    4384  else window.alert("Google maps aren't compatible with current Browser."); 
     
    4586 
    4687registerPloneFunction(editLocation); 
     88registerEventListener(window, 'unload', GUnload); 
  • geolocation/trunk/skins/geolocation/edit_location.cpt

    r405 r406  
    88 
    99<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"> 
    1213    <script type="text/javascript" src="" 
    13             tal:attributes="src string:http://maps.google.com/maps?file=api&amp;v=2&amp;key=${here/getMapKey}"> 
     14            tal:attributes="src string:http://maps.google.com/maps?file=api&amp;v=2&amp;key=${key}"> 
    1415    </script> 
    1516    <script type="text/javascript" src="" 
     
    2324         id="weblog-topics"> 
    2425 
    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(); 
    2734                       longitude python:location.getLongitude()"> 
    2835        <h1 class="documentFirstHeading" 
     
    3239              action="." 
    3340              tal:attributes="action string:${here_url}/${template/getId}"> 
    34           <fieldset> 
    35             <legend> 
    36               Edit location coordinates 
    37             </legend> 
    3841 
    3942            <div class="field" 
    4043                 tal:define="error errors/latitude|nothing;" 
    4144                 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"> 
    4346                Latitude 
    4447              </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" 
    4750                     tal:attributes="value request/latitude|latitude" /> 
    4851            </div> 
    49  
    5052            <div class="field" 
    5153                 tal:define="error errors/longitude|nothing;" 
    5254                 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"> 
    5456                Longitude 
    5557              </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" 
    5860                        tal:attributes="value request/longitude|longitude" /> 
    5961            </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> 
    61113            <div class="formControls"> 
    62114              <input class="context" 
     
    79131            <input type="hidden" name="form.submitted" value="1" /> 
    80132 
    81           </fieldset> 
    82133        </form> 
    83134 
    84         <div id="map" style="position: relative; height: 480px;"></div> 
     135        <div id="geomap" style="position: relative; height: 480px;"></div> 
    85136 
    86137        </tal:x> 
  • geolocation/trunk/skins/geolocation/edit_location.cpt.metadata

    r405 r406  
    11[validators] 
    2 validators = validate_location 
     2validators = validate_location, validate_map 
    33validators..Cancel= 
    44 
  • geolocation/trunk/skins/geolocation/save_location.cpy

    r405 r406  
    1010# 
    1111 
    12 latitude = context.REQUEST.get('latitude', 0) 
    13 longitude = context.REQUEST.get('longitude', 0) 
     12latitude       = context.REQUEST.get('latitude', 0) 
     13longitude      = context.REQUEST.get('longitude', 0) 
     14maplatitude    = context.REQUEST.get('maplatitude', 0) 
     15maplongitude   = context.REQUEST.get('maplongitude', 0) 
     16mapzoom        = context.REQUEST.get('mapzoom', 0) 
     17maptype        = context.REQUEST.get('maptype', 0) 
     18 
     19if not (maplatitude and maplongitude): mapcenter=() 
     20else: mapcenter = (float(maplatitude), float(maplongitude)) 
    1421 
    1522context.restrictedTraverse('@@LocationView').editLocation(latitude, longitude) 
     23context.restrictedTraverse('@@MapView').editMapOptions(mapcenter, mapzoom, maptype) 
    1624 
    1725return state.set(portal_status_message="geoLocation property updated")