Changeset 404

Show
Ignore:
Timestamp:
07/18/06 04:01:35
Author:
piv
Message:

automatic selecting map api key

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • qPloneGoogleMaps/trunk/Extensions/Install.py

    r403 r404  
    55from Products.CMFCore.DirectoryView import addDirectoryViews 
    66 
     7try: 
     8    from Products.CMFCore.permissions import ManagePortal 
     9except ImportError: 
     10    from Products.CMFCore.CMFCorePermissions import ManagePortal 
     11 
     12from Products.CMFPlone.migrations.migration_util import safeEditProperty 
     13 
    714from Products.Archetypes.Extensions.utils import installTypes 
    815from Products.Archetypes.public import listTypes 
     
    1017from Products.qPloneGoogleMaps.config import * 
    1118 
     19configlets = \ 
     20({'id':PROJECTNAME, 
     21  'name':'Google Map Api Keys', 
     22  'action':'string:${portal_url}/prefs_mapkeys_form', 
     23  'condition':'', 
     24  'category':'Products', 
     25  'visible':1, 
     26  'appId':PROJECTNAME, 
     27  'permission':ManagePortal},) 
     28  #'imageUrl':'niimportablefooter.gif'},) 
     29 
     30def addProperty(self, out): 
     31    """ Add property sheet to portal_properties """ 
     32 
     33    portal_props = getToolByName(self, 'portal_properties') 
     34    if not hasattr(portal_props, PROPERTY_SHEET): 
     35        portal_props.addPropertySheet(PROPERTY_SHEET, 'Maps Properties') 
     36        out.write('Added %s property sheet...\n' % PROPERTY_SHEET) 
     37    ap = getattr(portal_props, PROPERTY_SHEET) 
     38    if not hasattr(ap, PROPERTY_FIELD): 
     39        safeEditProperty(ap, PROPERTY_FIELD, MAP_API_KEYS, 'lines') 
     40        out.write('Added %s property field to %s property sheet...\n' % (PROPERTY_FIELD, PROPERTY_SHEET)) 
     41    else: out.write('Skipped adding property...\n') 
     42 
     43def removeProperty(self, out): 
     44    """ Remove property sheet from portal_properties """ 
     45 
     46    portal_props = getToolByName(self, 'portal_properties') 
     47    if hasattr(portal_props, PROPERTY_SHEET): 
     48        portal_props.manage_delObjects(PROPERTY_SHEET) 
     49        out.write('Deleted %s property sheet...\n' % PROPERTY_SHEET) 
     50 
     51def addConfiglets(self, out): 
     52    """ Add configlets to portal control panel """ 
     53 
     54    configTool = getToolByName(self, 'portal_controlpanel', None) 
     55    if configTool: 
     56        for conf in configlets: 
     57            out.write('Added configlet %s\n' % conf['id']) 
     58            configTool.registerConfiglet(**conf) 
     59 
     60def removeConfiglets(self, out): 
     61    """ Remove the configlet from the portal control panel """ 
     62 
     63    configTool = getToolByName(self, 'portal_controlpanel', None) 
     64    if configTool: 
     65        for conf in configlets: 
     66            out.write('Removed configlet %s\n' % conf['id']) 
     67            configTool.unregisterConfiglet('%s' % conf['id']) 
     68 
    1269def addCatalogIndex(self, name, out): 
    1370    """ Add to portal catalog given index """ 
     71 
    1472    portal_catalog = getToolByName(self, 'portal_catalog') 
    1573    if name not in portal_catalog.indexes(): 
     
    1977def removeCatalogIndex(self, name, out): 
    2078    """ Remove from portal catalog given index """ 
     79 
    2180    portal_catalog = getToolByName(self, 'portal_catalog') 
    2281    if name in portal_catalog.indexes(): 
     
    2685def addCatalogColumn(self, name, out): 
    2786    """ Add to portal catalog given metadata column """ 
     87 
    2888    portal_catalog = getToolByName(self, 'portal_catalog') 
    2989    if name not in portal_catalog.schema(): 
     
    3494def removeCatalogColumn(self, name, out): 
    3595    """ Remove from portal catalog given metadata column """ 
     96 
    3697    portal_catalog = getToolByName(self, 'portal_catalog') 
    3798    if name in portal_catalog.schema(): 
     
    45106    installTypes(self, out, typesInfo, PROJECTNAME) 
    46107    out.write("Installed types\n") 
    47  
    48108    factory_tool = getToolByName(self, 'portal_factory') 
    49109    types = factory_tool.getFactoryTypes().keys() 
     
    82142                    out.write("Removed maps view template from '%s' FTI.\n" % tp) 
    83143 
    84 def addPortlet(self, out, slot): 
     144def addPortlets(self, out, slots=[]): 
    85145    """ Add portlet to right slot """ 
    86146 
    87147    right_slots = getattr(self, 'right_slots', None) 
    88148    if right_slots != None: 
    89         if slot not in right_slots: 
    90             right_slots = list(right_slots) + [slot,] 
     149        for slot in slots: 
     150            if slot not in right_slots: 
     151                right_slots = list(right_slots) + [slot,] 
     152                self.right_slots = right_slots 
     153                out.write('Added %s portlet to right_slots property.\n' % slot) 
     154 
     155def removePortlets(self, out, slots=[]): 
     156    """ Remove portlet from right slot """ 
     157 
     158    right_slots = list(getattr(self, 'right_slots', ())) 
     159    for slot in slots: 
     160        if slot in right_slots: 
     161            right_slots.remove(slot) 
    91162            self.right_slots = right_slots 
    92             out.write('Added %s portlet to right_slots property.\n' % slot) 
    93  
    94 def removePortlet(self, out, slot): 
    95     """ Remove portlet from right slot """ 
    96  
    97     right_slots = list(getattr(self, 'right_slots', ())) 
    98     if slot in right_slots: 
    99         right_slots.remove(slot) 
    100         self.right_slots = right_slots 
    101         out.write('Removed %s portlet from right slots property.\n' % slot) 
     163            out.write('Removed %s portlet from right slots property.\n' % slot) 
    102164 
    103165def setupSkin(self, out, skinFolder): 
     
    143205    out = StringIO() 
    144206 
     207    # add property field to 'maps_properties' sheet 
     208    addProperty(self, out) 
     209 
     210    # installing configlet 
     211    addConfiglets(self, out) 
     212 
    145213    # adding indexes and metadata columns to portal_catalog 
    146     addCatalogIndex(self, 'geoLocation', out) 
    147     addCatalogColumn(self, 'geoLocation', out) 
     214    addCatalogIndex(self, GEO_INDEX, out) 
     215    addCatalogColumn(self, GEO_INDEX, out) 
    148216 
    149217    out.write('Update catalog...\n') 
     
    154222 
    155223    # add portlets to right slot 
    156     addPortlet(self, out, 'here/portlet_maps/macros/portlet') 
    157     addPortlet(self, out, 'here/portlet_overlays/macros/portlet') 
     224    addPortlets(self, out, MAP_PORTLETS) 
    158225 
    159226    # add map view template to the topic portal type 
     
    171238    out = StringIO() 
    172239 
     240    # remove property sheet 'maps_properties' from portal_properties 
     241    removeProperty(self, out) 
     242 
     243    # removing configlet 
     244    removeConfiglets(self, out) 
     245 
    173246    # removing indexes and metadata columns from portal_catalog 
    174     removeCatalogIndex(self, 'geoLocation', out) 
    175     removeCatalogColumn(self, 'geoLocation', out) 
     247    removeCatalogIndex(self, GEO_INDEX, out) 
     248    removeCatalogColumn(self, GEO_INDEX, out) 
    176249 
    177250    # remove portlets from right slot 
    178     removePortlet(self, out, 'here/portlet_maps/macros/portlet') 
    179     removePortlet(self, out, 'here/portlet_overlays/macros/portlet') 
     251    removePortlets(self, out, MAP_PORTLETS) 
    180252 
    181253    # remove map view template from the topic portal type 
  • qPloneGoogleMaps/trunk/TODO.txt

    r403 r404  
    1111 
    1212#   * navigation portlet view (turn on/off overlay functionality) 
     13 
     14#   * automatic selecting map api key 
     15 
     16    * google maps adaptor for edit_location form 
     17 
     18    * IE compatibility 
  • qPloneGoogleMaps/trunk/config.py

    r403 r404  
    88 
    99NEW_PORTAL_TYPES = ['Map', 'Marker', 'Overlay'] 
     10MAP_API_KEYS = ["http://gewgaw.office.quintagroup.com:8888/map|ABQIAAAAPKXXAksH6LF9wD3-iB3Z9hR-_Derz1M-sZYUdeXG3J1uZOMrKxT98efydo7fhYu6kuaFv5ESjlw4mw", ] 
    1011 
    11 #MAP_API_KEY = 'ABQIAAAAPKXXAksH6LF9wD3-iB3Z9hTb-vLQlFZmc2N8bgWI8YDPp5FEVBSikjDVULf3tCyc8gRIqTf-_TRyPw' 
    12  
    13 MAP_API_KEY = 'ABQIAAAAPKXXAksH6LF9wD3-iB3Z9hR-_Derz1M-sZYUdeXG3J1uZOMrKxT98efydo7fhYu6kuaFv5ESjlw4mw
    14 #MAP_API_KEY=ABQIAAAAYYyEmQ6EGtXuqElDoueMKBQD6ra-3WW7G3Dx0BPiIwGBloz-IhRd7rSu5fzEEX_rrGcbuQTBDjeYjw 
     12MAP_PORTLETS = ['here/portlet_maps/macros/portlet', 'here/portlet_overlays/macros/portlet',] 
     13PROPERTY_SHEET = 'maps_properties' 
     14PROPERTY_FIELD = 'map_api_keys
     15GEO_INDEX = 'geoLocation' 
    1516 
    1617setDefaultRoles(DEFAULT_ADD_CONTENT_PERMISSION, ('Manager', 'Owner',)) 
  • qPloneGoogleMaps/trunk/skins/qPloneGoogleMaps/edit_js.py

    r403 r404  
    88##title= 
    99## 
    10  
    11 from Products.qPloneGoogleMaps.config import MAP_API_KEY 
    1210 
    1311lat = [] 
     
    3735<script type="text/javascript"> 
    3836//<![CDATA[ 
    39  
    40 function registerUnloadFunction(func){ 
    41   if (window.addEventListener) window.addEventListener("unload", func, false); 
    42   else if (window.attachEvent) window.attachEvent("onunload", func); 
    43 }; 
    4437 
    4538function onMapLoad() { 
     
    8073var globMap = onMapLoad(); 
    8174 
    82 registerUnloadFunction(GUnload); 
     75registerEventListener(window, 'unload', GUnload); 
    8376 
    8477//]]> 
    8578</script> """ % { 
    86                  'key'       : MAP_API_KEY
     79                 'key'       : context.getMapKey()
    8780                  'lat'      : map_center[0], 
    8881                  'lng'      : map_center[1], 
  • qPloneGoogleMaps/trunk/skins/qPloneGoogleMaps/getCenterZoom.py

    r403 r404  
    1212<script type="text/javascript"> 
    1313//<![CDATA[ 
    14  
    15 function registerUnloadFunction(func) { 
    16   if (window.addEventListener) window.addEventListener("unload", func, false); 
    17   else if (window.attachEvent) window.attachEvent("onunload", func); 
    18 }; 
    1914 
    2015var node = document.getElementById('autozoom'); 
     
    3631}}; 
    3732 
    38 registerUnloadFunction(GUnload); 
     33registerEventListener(window, 'unload', GUnload); 
    3934 
    4035//]]> 
  • qPloneGoogleMaps/trunk/skins/qPloneGoogleMaps/map_view.pt

    r403 r404  
    66  <metal:block fill-slot="javascript_head_slot"> 
    77    <script type="text/javascript" src="" 
    8             tal:define="key python:modules['Products.qPloneGoogleMaps.config'].MAP_API_KEY
    9             tal:attributes="src string:http://maps.google.com/maps?file=api&amp;v=2&amp;key=${key}"> 
     8            tal:define="key here/getMapKey
     9            tal:attributes="src string:http://maps.google.com/maps?file=api&amp;v=2&amp;key=${here/getMapKey}"> 
    1010    </script> 
    1111    <span tal:replace="structure python:here.maps_markers(longlat=here.getOverlayMarkers(), node='map', controls=here.getMapControl(), loc=here.geoLocation(), typeControls=here.getTypeControl(), overviewControls=here.getOverviewControl(), events=True, maptype=here.getMapType(), color=False, zoom=here.getZoom(), mapevents=True, auto=here.getAuto())" /> 
     
    3636    </p> 
    3737 
    38     <div id="map" style="position: relative; height: 480px;" 
    39          tal:define="height here/getHeight" 
    40          tal:attributes="style string:height:${height}px"></div> 
     38    <div id="map" style="position: relative; height: 480px;"></div> 
     39<!--         tal:define="height here/getHeight" 
     40         tal:attributes="style string:height:${height}px"></div>--> 
    4141 
    4242  </tal:main-macro> 
  • qPloneGoogleMaps/trunk/skins/qPloneGoogleMaps/maps_markers.py

    r403 r404  
    3333    lat = [float(e.geoLocation[0]) for el in longlat.values() for e in el] 
    3434    lon = [float(e.geoLocation[1]) for el in longlat.values() for e in el] 
    35     #raise str(longlat.items()[0][1].items()[0][1]) 
    36 #{id:{color:[markers]}} 
    3735    sMarkers = "\n".join([""" 
    3836addMarker(%(lt)f, %(lg)f, "%(title)s", "%(url)s/view", "%(desc)s", "%(c)s"); 
     
    10199//<![CDATA[ 
    102100 
    103 function addEvent(el, evt, func){ 
    104   if (el.addEventListener) el.addEventListener(evt, func, false); 
    105   else if (el.attachEvent) el.attachEvent("on"+evt, func); 
    106 }; 
    107  
    108101function onLoadMap(){ 
    109102  if (GBrowserIsCompatible()) { 
     
    129122      %(event)s 
    130123    }; 
     124 
    131125    %(mapevents)s 
    132126    %(markers)s 
     
    136130        var over_obj = getData(); 
    137131        if (over_obj) { 
    138             for (var i=0; i < over_obj['boxes'].length; i++) addEvent(over_obj['boxes'][i], 'click', 
     132            for (var i=0; i < over_obj['boxes'].length; i++) registerEventListener(over_obj['boxes'][i], 'click', 
    139133                function (){ 
    140134                    map.clearOverlays(); 
     
    144138                            for (var j=0; j < overLays[id].length; j++) { 
    145139                                var opts = overLays[id][j]; 
    146                                 //alert(opts); 
    147140                                addMarker(opts[0], opts[1], opts[2], opts[3], opts[4], opts[5]); 
    148141                            }; 
     
    154147 
    155148  } 
    156   else window.alert("Google maps aren't compatible with current Browser."); 
     149  else window.alert("Google maps aren't compatible with current browser or your map api key doesn't match your portal root."); 
    157150}; 
    158151 
    159 addEvent(window, 'load', onLoadMap); 
    160 addEvent(window, 'unload', GUnload); 
     152registerEventListener(window, 'load', onLoadMap); 
     153registerEventListener(window, 'unload', GUnload); 
    161154 
    162155//]]> 
  • qPloneGoogleMaps/trunk/skins/qPloneGoogleMaps/maps_view.pt

    r403 r404  
    66  <metal:block fill-slot="javascript_head_slot"> 
    77    <script type="text/javascript" src="" 
    8             tal:define="key python:modules['Products.qPloneGoogleMaps.config'].MAP_API_KEY" 
    9             tal:attributes="src string:http://maps.google.com/maps?file=api&amp;v=2&amp;key=${key}"> 
     8            tal:attributes="src string:http://maps.google.com/maps?file=api&amp;v=2&amp;key=${here/getMapKey}"> 
    109    </script> 
    1110    <span tal:define="brain python:here.portal_catalog(path='/'.join(here.getPhysicalPath())); 
    1211                      longlat python:test(len(brain)==1 and brain[0].portal_type != 'Map' and brain[0].geoLocation, brain, [])" 
    13           tal:replace="structure python:here.maps_markers(longlat, node='map', events=True, controls='large', typeControls=True, overviewControls=True, zoom=6, loc=longlat[0].geoLocation)" /> 
     12          tal:replace="structure python:here.maps_markers(longlat, node='map', events=True, controls='large', typeControls=True, overviewControls=True, zoom=6, loc=longlat[0].geoLocation, auto=None)" /> 
    1413  </metal:block> 
    1514</head> 
  • qPloneGoogleMaps/trunk/skins/qPloneGoogleMaps/marker_view.pt

    r403 r404  
    66  <metal:block fill-slot="javascript_head_slot"> 
    77    <script type="text/javascript" src="" 
    8             tal:define="key python:modules['Products.qPloneGoogleMaps.config'].MAP_API_KEY" 
    9             tal:attributes="src string:http://maps.google.com/maps?file=api&amp;v=2&amp;key=${key}"> 
     8            tal:attributes="src string:http://maps.google.com/maps?file=api&amp;v=2&amp;key=${here/getMapKey}"> 
    109    </script> 
    1110    <span tal:replace="structure python:here.maps_markers(here.portal_catalog(path='/'.join(here.getPhysicalPath())), node='map', events=True, loc=here.geoLocation(), controls='large', typeControls=True, overviewControls=True, color=here.getColor(), zoom=6, auto='None')" /> 
  • qPloneGoogleMaps/trunk/skins/qPloneGoogleMaps/overlay_view.pt

    r403 r404  
    66  <metal:block fill-slot="javascript_head_slot"> 
    77    <script type="text/javascript" src="" 
    8             tal:define="key python:modules['Products.qPloneGoogleMaps.config'].MAP_API_KEY" 
    9             tal:attributes="src string:http://maps.google.com/maps?file=api&amp;v=2&amp;key=${key}"> 
     8            tal:attributes="src string:http://maps.google.com/maps?file=api&amp;v=2&amp;key=${here/getMapKey}"> 
    109    </script> 
    1110    <span tal:replace="structure python:here.maps_markers(here.getMarkers(), node='map', events=True, color=here.getMarkersColor(), loc=here.geoLocation(), controls=here.getMapControl(), typeControls=here.getTypeControl(), overviewControls=here.getOverviewControl(), maptype=here.getMapType(),)" /> 
  • qPloneGoogleMaps/trunk/skins/qPloneGoogleMaps/portlet_maps.pt

    r403 r404  
    99 
    1010    <script type="text/javascript" src="" 
    11             tal:define="key python:modules['Products.qPloneGoogleMaps.config'].MAP_API_KEY" 
    12             tal:attributes="src string:http://maps.google.com/maps?file=api&amp;v=2&amp;key=${key}"> 
     11            tal:attributes="src string:http://maps.google.com/maps?file=api&amp;v=2&amp;key=${here/getMapKey}"> 
    1312    </script> 
    1413    <span tal:replace="structure python:here.maps_markers(longlat, loc=longlat[0].geoLocation, zoom=5, node='portlet_map', controls='small', auto='None')" /> 
  • qPloneGoogleMaps/trunk/skins/qPloneGoogleMaps/portlet_overlays.pt

    r403 r404  
    99       tal:define="mapContent python:context.folderlistingFolderContents(contentFilter={'portal_type':'Overlay',})"> 
    1010 
    11 <dl class="portlet" id="portlet-navigation-tree" 
    12     tal:condition="python:context.portal_type == 'Map'"> 
     11<dl class="portlet" id="portlet-overlays"> 
    1312    <dt class="portletHeader"> 
    1413        <span class="portletTopLeft"></span> 
     
    1615           class="tile" 
    1716           tal:attributes="href string:${context/absolute_url}" 
    18            tal:content="string:${context/getId} Overlays"></a> 
     17           tal:content="string:${context/getId}'s Overlays"></a> 
    1918        <span class="portletTopRight"></span> 
    2019    </dt> 
     
    2322        <ul class="portletNavigationTree" id="listOverlays"> 
    2423            <tal:navitem repeat="item mapContent"> 
    25             <li class="navTreeItem visualNoMarker" 
    26                 tal:define="wf_tool nocall:context/portal_workflow; 
    27                             viewActions here/portal_properties/site_properties/typesUseViewActionInListings|python:(); 
    28                             useView python:item.portal_type in viewActions; 
    29                             itemUrl python:test(useView, item.absolute_url() + '/view', item.absolute_url()); 
    30                             r_state python:wf_tool.getInfoFor(context, 'review_state'); 
    31                             item_wf_state_class python: 'state-' + normalizeString(r_state)"> 
     24            <li class="visualNoMarker"> 
    3225                    <input type="checkbox" id="overlayId" value="1" style="float: left" checked 
    3326                           tal:attributes="id string:${item/getId}Box; 
    3427                                           value string:${item/getMarkersColor}" /> 
    35                     <div tal:define="itemClass string:$item_wf_state_class visualIconPadding"> 
    36                         <a tal:attributes="href itemUrl; 
    37                                            title item/Description; 
    38                                            class string:$itemClass" 
    39                            tal:content="item/Title">Item Title</a> 
    40                     </div> 
     28                    <div class="visualIconPadding" 
     29                         tal:content="item/Title">Item Title</div> 
    4130            </li> 
    4231            </tal:navitem> 
  • qPloneGoogleMaps/trunk/skins/qPloneGoogleMaps/switchOverlays.py

    r403 r404  
    1313//<![CDATA[ 
    1414 
    15 function registerUnloadFunction(func) { 
    16   if (window.addEventListener) window.addEventListener("unload", func, false); 
    17   else if (window.attachEvent) window.attachEvent("onunload", func); 
    18 }; 
    19  
    2015function getData(){ 
    2116  var ul = document.getElementById('listOverlays'),  result = {}; 
     
    2924}; 
    3025 
    31 registerUnloadFunction(GUnload); 
     26registerEventListener(window, 'unload', GUnload); 
    3227 
    3328//]]> 
  • qPloneGoogleMaps/trunk/skins/qPloneGoogleMaps/topic_maps_view.pt

    r403 r404  
    66  <metal:block fill-slot="javascript_head_slot"> 
    77    <script type="text/javascript" src="" 
    8             tal:define="key python:modules['Products.qPloneGoogleMaps.config'].MAP_API_KEY" 
    9             tal:attributes="src string:http://maps.google.com/maps?file=api&amp;v=2&amp;key=${key}"> 
     8            tal:attributes="src string:http://maps.google.com/maps?file=api&amp;v=2&amp;key=${here/getMapKey}"> 
    109    </script> 
    1110    <span tal:define="contentsMethod python:test(here.portal_type=='Topic', here.queryCatalog, here.getFolderContents); 
  • qPloneGoogleMaps/trunk/skins/qPloneGoogleMaps/view_js.py

    r403 r404  
    88##title= 
    99## 
    10  
    11 from Products.qPloneGoogleMaps.config import MAP_API_KEY 
    1210 
    1311map_center = (0,0) 
     
    2523//<![CDATA[ 
    2624 
    27 function registerUnloadFunction(func){ 
    28   if (window.addEventListener) window.addEventListener("unload", func, false); 
    29   else if (window.attachEvent) window.attachEvent("onunload", func); 
    30 }; 
    31  
    3225function onMapLoad() { 
    3326    if (GBrowserIsCompatible()) { 
     
    4235} 
    4336 
    44 registerPloneFunction(onMapLoad) 
    45 registerUnloadFunction(GUnload); 
     37registerEventListener(window, 'load', onMapLoad) 
     38registerEventListener(window, 'unload', GUnload); 
    4639 
    4740//]]> 
    4841</script> """ % { 
    49                  'key'      : MAP_API_KEY
     42                 'key'      : context.getMapKey()
    5043                  'lat'     : map_center[0], 
    5144                  'lng'     : map_center[1],