Diff for /ECHO_content/ECHO_helpers.py between versions 1.47 and 1.68

version 1.47, 2005/04/13 15:13:19 version 1.68, 2005/12/04 09:10:55
Line 6  import string Line 6  import string
 import xml.dom.minidom  import xml.dom.minidom
 import types  import types
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile  from Products.PageTemplates.PageTemplateFile import PageTemplateFile
   from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
 from OFS.SimpleItem import SimpleItem  from OFS.SimpleItem import SimpleItem
 from Globals import package_home  from Globals import package_home
 import Globals  import Globals
 from AccessControl import ClassSecurityInfo  from AccessControl import ClassSecurityInfo
 import os.path  import os.path
   from OFS.Folder import Folder
   import ECHO_collection
   import base64
   import bz2
   import xmlrpclib
   
 displayTypes = ['ZSQLExtendFolder','ZSQLBibliography','ECHO_group','ECHO_collection','ECHO_resource','ECHO_link','ECHO_sqlElement','ECHO_pageTemplate','ECHO_externalLink','ImageCollectionIFrame','VLP_resource','VLP_essay','ECHO_ZCatalogElement','ImageCollection','versionedFileFolder','ECHO_movie']  displayTypes = ['ZSQLExtendFolder','ZSQLBibliography','ECHO_group','ECHO_collection','ECHO_resource','ECHO_link','ECHO_sqlElement','ECHO_pageTemplate','ECHO_externalLink','ImageCollectionIFrame','VLP_resource','VLP_essay','ECHO_ZCatalogElement','ImageCollection','versionedFileFolder','ECHO_movie']
   
   
   #decode and compress for xmlrpc communication with OSAS_server
   
   def encodeRPC(string):
       return base64.encodestring(bz2.compress(string))
   def decodeRPC(string):
       return bz2.decompress(base64.decodestring(string))
   
 def content_html(self,type):  def content_html(self,type):
         """template fuer content"""          """template fuer content"""
         #templates = self.ZopeFind(self.aq_parent,obj_ids=[type+"_template"])          #templates = self.ZopeFind(self.aq_parent,obj_ids=[type+"_template"])
Line 35  class ECHO_basis: Line 49  class ECHO_basis:
     """basis eigenschaften fuer echo objekte"""      """basis eigenschaften fuer echo objekte"""
     security=ClassSecurityInfo()      security=ClassSecurityInfo()
     security.declarePublic('getImageTag')      security.declarePublic('getImageTag')
   
       def manage_addECHO_locale(self,lang,title,label,text=None,content_type=None,RESPONSE=None):
               return ECHO_collection.manage_addECHO_locale(self,lang,title,label)
               
     def getImageTag(self):      def getImageTag(self):
         """sollte uerberschrieben werden, falls von der Klasse eine imagetag zurueckkommt"""          """sollte uerberschrieben werden, falls von der Klasse eine imagetag zurueckkommt"""
                   
Line 108  class ECHO_basis: Line 126  class ECHO_basis:
   
         return ret          return ret
                   
       def content_html_XMLRpc(self):
           """xml_rpc_version"""
           return encodeRPC(self.content_html())
       
     def content_html(self,type="collection"):      def content_html(self,type="collection"):
         """template fuer content bei einbau und ECHO_Umgebung"""          """template fuer content bei einbau und ECHO_Umgebung"""
                   
Line 115  class ECHO_basis: Line 137  class ECHO_basis:
                   
     def getTitle(self):      def getTitle(self):
     """title"""      """title"""
           lang=self.getLanguage()
           locale=None
           if lang and not (lang =="de"):
                   locale=self.ZopeFind(self,obj_ids=["locale_"+lang])
   
           if locale:
                   return self.decode(locale[0][1].title)
           else:
     return self.decode(self.title)      return self.decode(self.title)
   
   
     try:      try:
         return self.title.encode('utf-8','ignore')           return self.title.encode('utf-8','ignore') 
     except:      except:
Line 124  class ECHO_basis: Line 156  class ECHO_basis:
           
     def getLabel(self):      def getLabel(self):
     """title"""      """title"""
           lang=self.getLanguage()
           locale=None
           if lang and not (lang=="de"):
                   locale=self.ZopeFind(self,obj_ids=["locale_"+lang])
   
           if locale:
                   return self.decode(locale[0][1].label)
           
   
           if not hasattr(self,'label'):
                   self.label=""
                   
     if self.label=="":      if self.label=="":
         ret=self.getTitle                  ret=self.getTitle()
         if ret=="":          if ret=="":
             ret=self.getId()              ret=self.getId()
         return ret          return ret
Line 174  class ECHO_basis: Line 218  class ECHO_basis:
   
     def getMapAreas(self):      def getMapAreas(self):
         """returns the list of MapAreas"""          """returns the list of MapAreas"""
           forcetypes = self.REQUEST.get('map_force_types', None)
           if forcetypes:
               typelist = forcetypes.split(',')
           else:
               typelist = None
           areas = []
     # get all contained MapAreas      # get all contained MapAreas
         areas = [res[1] for res in self.ZopeFind(self, obj_metatypes=('MapArea'))]          for res in self.ZopeFind(self, obj_metatypes=('MapArea')):
               area = res[1]
               # check the allowed types
               if typelist is not None and area.getType() not in typelist:
                   continue
               areas.append(area)
     return areas      return areas
   
     def addMapArea(self, newarea):      def addMapArea(self, newarea):
     """add a map area to this object"""      """add a map area to this object"""
     if (newarea.id is None):      if (newarea.id is None):
         # create new id          # create new id
         areas = self.getMapAreas()              ids = [a.id for a in self.getMapAreas()]
         newarea.id = "a%02d"%len(areas)              i = len(ids)
               while ("a%02d"%i in ids):
                   # if it exists, try the next one
                   i += 1
               newarea.id = "a%02d"%i
     self._setObject(newarea.id, newarea)      self._setObject(newarea.id, newarea)
   
       def getMapText(self):
           """returns the MapText"""
           # get (the first) contained MapText
           #lang="en"
           lang=self.getLanguage()
           res=None
           if lang and not (lang=="de"):
                   resTmp = self.ZopeFind(self, obj_metatypes=('ECHO_mapText'))
                   res = self.ZopeFind(resTmp[0][1])
   
           if not res:
                   res = self.ZopeFind(self, obj_metatypes=('ECHO_mapText'))
           if len(res) > 0:
               text = res[0][1]
               return text
           return None
   
     def ECHO_graphicEntry(self):      def ECHO_graphicEntry(self):
         """change map coordinates"""          """change map coordinates"""
         if self.hasParentOverview():          if self.hasParentOverview():
Line 212  class ECHO_basis: Line 288  class ECHO_basis:
         coords = string.split(coordstring, ',')          coords = string.split(coordstring, ',')
         angle = self.REQUEST.get('angle.'+id, '0')          angle = self.REQUEST.get('angle.'+id, '0')
         type = self.REQUEST.get('type.'+id, 'area')          type = self.REQUEST.get('type.'+id, 'area')
               permanent = self.REQUEST.get('permanent.'+id, '')
         if len(coords) == 4:          if len(coords) == 4:
         area.setCoordString(coordstring)          area.setCoordString(coordstring)
         area.setAngle(angle)          area.setAngle(angle)
         area.setType(type)          area.setType(type)
     # add new area                  area.setPermanent(permanent)
           # add the "new" area
     if self.REQUEST.has_key('add'):      if self.REQUEST.has_key('add'):
         coordstring = self.REQUEST.get('coords.new', '')          coordstring = self.REQUEST.get('coords.new', '')
         coords = string.split(coordstring, ',')          coords = string.split(coordstring, ',')
         angle = self.REQUEST.get('angle.new', '0')          angle = self.REQUEST.get('angle.new', '0')
         type = self.REQUEST.get('type.new', 'area')          type = self.REQUEST.get('type.new', 'area')
               permanent = self.REQUEST.get('permanent.new', '')
         if len(coords) == 4:          if len(coords) == 4:
         coords.append(angle)          coords.append(angle)
         area = MapArea(None, coords, type=type)                  area = MapArea(None, coords, type=type, permanent=permanent)
         self.addMapArea(area)          self.addMapArea(area)
     # return to edit area menu      # return to edit area menu
     if RESPONSE is not None:      if RESPONSE is not None:
Line 232  class ECHO_basis: Line 311  class ECHO_basis:
   
     def createJSAreas(self, areas):      def createJSAreas(self, areas):
         """create area calls for JavaScript"""          """create area calls for JavaScript"""
         dynamical="\n"          forceperm = self.REQUEST.get('map_force_permanent', None)
           js="\n"
         for ob in areas:          for ob in areas:
         if ob.isTypeArrow():              # check for force-permanent
             dynamical+="""addArea('%s', 'overview', %s, 'arrow');\n"""%(ob.getFullId(),ob.getCoordString())              if forceperm is not None:
         else:                  perm = forceperm
             dynamical+="""addArea('%s', 'overview', %s, 'area');\n"""%(ob.getFullId(),ob.getCoordString())              else:
         return dynamical                  perm = ob.isPermanent()
               js+="""addArea('%s', 'overview', %s, '%s', '%s');\n"""%(ob.getFullId(),ob.getCoordString(),ob.getType(),perm)
           return js
   
     def createMapHead(self):      def createMapHead(self):
         """create javascript include and script tags for head"""          """create javascript include and script tags for head"""
Line 262  class ECHO_basis: Line 344  class ECHO_basis:
     """generate img-tag for map of parent"""      """generate img-tag for map of parent"""
     return self.aq_parent.createMapImg()      return self.aq_parent.createMapImg()
   
     def createMapLink(self, ob, text=None):      def createMapLink(self, ob, text=None, target="_blank"):
     """generate map link"""      """generate map link"""
     bt = BrowserCheck(self)      bt = BrowserCheck(self)
     id = ob.getFullId()      id = ob.getFullId()
Line 271  class ECHO_basis: Line 353  class ECHO_basis:
         text = ob.getLabel()          text = ob.getLabel()
     if text is None:      if text is None:
         text = "link"          text = "link"
     tiptext = ob.getText()          tiptext = ob.getTip()
     tag = ""      tag = ""
     if bt.isN4:      if bt.isN4:
         # N4 needs layer for highlighting          # N4 needs layer for highlighting
         tag += '<ilayer id="a.%s"><a onmouseover="highlightPair(\'%s\', true)" onmouseout="highlightPair(\'%s\', false)" href="%s" target="_blank"'%(id,id,id,link)              tag += '<ilayer id="a.%s"><a class="maplink" onmouseover="highlightPair(\'%s\', true)" onmouseout="highlightPair(\'%s\', false)" href="%s" target="%s"'%(id,id,id,link,target)
         tag += ">" + text + "</a></ilayer>"          tag += ">" + text + "</a></ilayer>"
     else:      else:
         # a-element          # a-element
         tag = '<a id="a.%s" onmouseover="highlightPair(\'%s\', true)" onmouseout="highlightPair(\'%s\', false)" href="%s" target="_blank"'%(id,id,id,link)              tag = '<a id="a.%s" class="maplink" onmouseover="highlightPair(\'%s\', true)" onmouseout="highlightPair(\'%s\', false)" href="%s" target="%s"'%(id,id,id,link,target)
         if tiptext:          if tiptext:
         tag += ' title="%s"'%tiptext          tag += ' title="%s"'%tiptext
         tag += ">" + text + "</a>"          tag += ">" + text + "</a>"
     return tag      return tag
   
     def createMapAux(self, ob, arrowsrc="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler/?dw=15&fn=icons/pfeil"):      def createMapAux(self, ob, arrowsrc="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler/?dw=15&fn=icons/pfeil", circlesrc="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler/?dw=15&fn=icons/kreis", target="_blank",backLink=None,alternativArrowsrc="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler/?dw=15&fn=icons/pfeil_blau"):
     """generate map link image, text and other stuff"""      """generate map link image, text and other stuff"""
     bt = BrowserCheck(self)      bt = BrowserCheck(self)
     id = ob.getFullId()      id = ob.getFullId()
     link = ob.getLinkId()      link = ob.getLinkId()
     tiptext = ob.getText()          tiptext = ob.getTip()
     tag = ""      tag = ""
   
     if bt.isN4:      if bt.isN4:
               #
         # N4 needs layer and img elements          # N4 needs layer and img elements
               #
         tag += '<layer id="i.%s" onmouseover="highlightPair(\'%s\', true)" onmouseout="highlightPair(\'%s\', false)">'%(id,id,id)          tag += '<layer id="i.%s" onmouseover="highlightPair(\'%s\', true)" onmouseout="highlightPair(\'%s\', false)">'%(id,id,id)
         if ob.isTypeArrow():          if ob.isTypeArrow():
                   # N4 - Arrow
             rot = ob.angle              rot = ob.angle
         tag += '<a href="%s"><img border="0" src="%s&rot=%s" /></a>'%(link,arrowsrc,rot)                  
                   if hasattr(getattr(self,link),'link'):
                           cLink=getattr(self,link).link
                           # if existing delete virtuell path 
                           cLink=cLink.replace('/'.join(self.REQUEST['VirtualRootPhysicalPath']),'')
   
                   if backLink and hasattr(getattr(self,link),'link') and backLink==self.REQUEST['SERVER_URL']+cLink.lstrip():
                           marksrc=alternativArrowsrc
                   else:
                           marksrc = arrowsrc
   
                   
                   if float(rot) < 0:
                       marksrc = circlesrc
                   tag += '<a href="%s"><img border="0" src="%s&rot=%s" /></a>'%(link,marksrc,rot)
               elif ob.isTypeText():
                   # N4 - Text
                   tag += '<div id="t.%s" class="maptext"'%(id)
                   tag += 'style="visibility:hidden">'
                   tag += ob.getText()
                   tag += '</div>'
         else:          else:
                   # N4 - Area
         tag += '<a href="%s"><img border="0" width="1000" height="1000" src="trans_img"'%(link)          tag += '<a href="%s"><img border="0" width="1000" height="1000" src="trans_img"'%(link)
         if tiptext:          if tiptext:
             tag += ' alt="%s"'%tiptext              tag += ' alt="%s"'%tiptext
         tag += ' /></a>'          tag += ' /></a>'
         tag += '</layer>'          tag += '</layer>'
     else:      else:
         # create a-element              #
         tag = '<a id="b.%s" onmouseover="highlightPair(\'%s\', true)" onmouseout="highlightPair(\'%s\', false)" href="%s" target="_blank">'%(id,id,id,link)              # (more or less) DOM capable browser
               #
               tag = '<a id="b.%s" class="mapmarklink" onmouseover="highlightPair(\'%s\', true)" onmouseout="highlightPair(\'%s\', false)" href="%s" target="%s">'%(id,id,id,link,target)
         if ob.isTypeArrow():          if ob.isTypeArrow():
                   # DOM - Arrow
         rot = ob.angle          rot = ob.angle
                                   
                   if hasattr(getattr(self,link),'link'):
                           cLink=getattr(self,link).link
                           # if existing delete virtuell path 
                           if hasattr(self.REQUEST,'VirtualRootPhysicalPath'):
                               cLink=cLink.replace('/'.join(self.REQUEST['VirtualRootPhysicalPath']),'')
   
                   if backLink and hasattr(getattr(self,link),'link') and backLink==self.REQUEST['SERVER_URL']+cLink.lstrip():
                           marksrc=alternativArrowsrc
                   else:
                           marksrc = arrowsrc
   
                   try:
                      rot=float(rot)
                   except:
                      rot=0
   
                   if float(rot) < 0:
                       marksrc = circlesrc
         if bt.isIEWin and bt.versIE > 5:          if bt.isIEWin and bt.versIE > 5:
             # IE/Win 5.5 has "feature" for PNG transparency              # IE/Win 5.5 has "feature" for PNG transparency
             tag += '<span id="i.%s" style="position:absolute; top:-100px; left:-100px; border-style:none; border-width=1px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'%s&rot=%s\');"><img style="visibility:hidden" src="%s&rot=%s" /></span>'%(id,arrowsrc,rot,arrowsrc,rot)                      tag += '<span id="i.%s" style="position:absolute; top:-100px; left:-100px; border-style:none; border-width=1px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'%s&rot=%s\');"><img style="visibility:hidden" src="%s&rot=%s" /></span>'%(id,marksrc,rot,marksrc,rot)
         else:          else:
             # arrow image              # arrow image
             tag += '<img id="i.%s" src="%s&rot=%s" border="1" style="position:absolute; top:-100px; left:-100px; border-style:none;" />'%(id,arrowsrc,rot)                      tag += '<img id="i.%s" src="%s&rot=%s" border="1" style="position:absolute; top:-100px; left:-100px; border-style:none;" />'%(id,marksrc,rot)
               elif ob.isTypeText():
                   # DOM - Text
                   tag += '<div id="i.%s" style="position:absolute; top:-100px; left:-100px;"'%(id)
                   tag += '><div id="t.%s" class="maptext"'%(id)
                   tag += 'style="visibility:hidden">'
                   tag += ob.getText()
                   tag += '</div></div>'
         else:          else:
                   # DOM - Area
         if bt.isIE:          if bt.isIE:
             # IE needs transparent img for area              # IE needs transparent img for area
             tag += '<img id="i.%s" border="0" style="position:absolute; top:-100px; left:-100px;" src="trans_img"'%(id)              tag += '<img id="i.%s" border="0" style="position:absolute; top:-100px; left:-100px;" src="trans_img"'%(id)
Line 324  class ECHO_basis: Line 460  class ECHO_basis:
             tag += ' title="%s"'%tiptext              tag += ' title="%s"'%tiptext
             tag += " />"              tag += " />"
         else:          else:
             # div for area                      # empty div for area
             tag += '<div id="i.%s" style="position:absolute; top:-100px; left:-100px;"'%(id)              tag += '<div id="i.%s" style="position:absolute; top:-100px; left:-100px;"'%(id)
             if tiptext:              if tiptext:
             tag += ' title="%s"'%tiptext              tag += ' title="%s"'%tiptext
Line 344  def toList(field): Line 480  def toList(field):
         return field          return field
   
 def getText(nodelist):  def getText(nodelist):
   
     rc = ""      rc = ""
     for node in nodelist:      for node in nodelist:
         if node.nodeType == node.TEXT_NODE:          if node.nodeType == node.TEXT_NODE:
Line 411  def checkOnlyOneInGroup(object): Line 546  def checkOnlyOneInGroup(object):
         return displayedObjects[0][1]          return displayedObjects[0][1]
     else:       return object      else:       return object
   
 def getSubCols(self, sortfield=None, subColTypes=displayTypes, sortFieldMD=None,searchMD=None):  
           
   def getSubCols(self, sortfield=None, subColTypes=displayTypes, sortFieldMD=None,searchMD=None,searchSimple=None,generic="yes"):
           
     def sort(x,y):      def sort(x,y):
         return cmp(x[0],y[0])          return cmp(x[0],y[0])
           
     def sortfnc(sortfield,x,y):      def sortfnc(sortfield,x,y):
         try:          try:
             xa=x[1].getMDValue(sortfield)                          xa=x[1].getMDValue(sortfield,generic=generic)
         except:          except:
             xa=""              xa=""
         try:          try:
             ya=y[1].getMDValue(sortfield)                          ya=y[1].getMDValue(sortfield,generic=generic)
         except:          except:
             ya=""              ya=""
         return cmp(xa,ya)          return cmp(xa,ya)
Line 431  def getSubCols(self, sortfield=None, sub Line 566  def getSubCols(self, sortfield=None, sub
     sortWithMD = lambda sortfield : (lambda x,y : sortfnc(sortfield,x,y))      sortWithMD = lambda sortfield : (lambda x,y : sortfnc(sortfield,x,y))
         ids=[]          ids=[]
     displayedObjects=self.ZopeFind(self,obj_metatypes=subColTypes)      displayedObjects=self.ZopeFind(self,obj_metatypes=subColTypes)
           if searchSimple and (not (searchSimple==""))and hasattr(self,'resourceCatalog'):         
                   searchString=" AND ".join(searchSimple.split())         
               ids=[x.getObject() for x in self.resourceCatalog({'getMDValueSimpleSearchField':searchString})]         
           else:
     for entry in displayedObjects:      for entry in displayedObjects:
   
               
         object=entry[1]          object=entry[1]
         if searchMD and hasattr(object,'getMDValue'):          if searchMD and hasattr(object,'getMDValue'):
             flag=0              flag=0
             for field in searchMD.keys():              for field in searchMD.keys():
                 if object.getMDValue(field)==searchMD[field]:                                      #if object.getMDValue(field,generic=generic)==searchMD[field]:
                                       if re.match(searchMD[field],object.getMDValue(field,generic=generic)):
                     flag=1                      flag=1
                 else:                  else:
                     flag=0                      flag=0
Line 449  def getSubCols(self, sortfield=None, sub Line 585  def getSubCols(self, sortfield=None, sub
                 ids.append(object)                  ids.append(object)
         else:          else:
             ids.append(object)              ids.append(object)
   
     if not sortfield:      if not sortfield:
             sortfield=getattr(self,'sortfield','weight')              sortfield=getattr(self,'sortfield','weight')
   
               
         tmplist=[]          tmplist=[]
   
         for x in ids:          for x in ids:
           
         if hasattr(x,sortfield):          if hasattr(x,sortfield):
             try:              try:
                 tmp=int(getattr(x,sortfield))                  tmp=int(getattr(x,sortfield))
Line 474  def getSubCols(self, sortfield=None, sub Line 605  def getSubCols(self, sortfield=None, sub
     else:      else:
         tmplist.sort(sortWithMD(sortFieldMD))          tmplist.sort(sortWithMD(sortFieldMD))
           
         return [x for (key,x) in tmplist]          ret=[x for (key,x) in tmplist]
         
           return ret
   
 def ECHO_rerenderLinksMD(self,obj=None,types=['title','label']):  def ECHO_rerenderLinksMD(self,obj=None,types=['title','label']):
         """Rerender all Links"""          """Rerender all Links"""
Line 488  def ECHO_rerenderLinksMD(self,obj=None,t Line 621  def ECHO_rerenderLinksMD(self,obj=None,t
         for entry in entries:          for entry in entries:
         if entry[1].meta_type == 'ECHO_resource':          if entry[1].meta_type == 'ECHO_resource':
             try:              try:
                 entry[1].ECHO_getResourceMD(template="no")                                  entry[1].ECHO_getResourceMD(template="no",overwrite="yes")
                                 if "title" in types:                                  if "title" in types:
                                     entry[1].generate_title()                                      entry[1].generate_title()
                                 if "label" in types:                                  if "label" in types:
Line 506  def reloadMetaDataFromStorage(self,RESPO Line 639  def reloadMetaDataFromStorage(self,RESPO
         """copy metadata from the storage to ECHO"""          """copy metadata from the storage to ECHO"""
         ret=""          ret=""
         resources=self.ZopeFind(self,obj_metatypes=['ECHO_resource'],search_sub=1)          resources=self.ZopeFind(self,obj_metatypes=['ECHO_resource'],search_sub=1)
               if RESPONSE is not None:
                   RESPONSE.setHeader("Content-Type", type)
                   RESPONSE.write("<html><body>\n")
   
         for resource in resources:          for resource in resources:
             x=str(resource[1].copyIndex_meta2echo_resource())+"<br>"              x=str(resource[1].copyIndex_meta2echo_resource())+"<br>"
                       if RESPONSE is not None:
                           RESPONSE.write(x+"\n")
                       
             ret+=x              ret+=x
   
         if RESPONSE is not None:          if RESPONSE is not None:
             #RESPONSE.redirect('./manage_main')              #RESPONSE.redirect('./manage_main')
             return "<html><body>"+ret+"</html></body>"                      RESPONSE.write( "</html></body>")
   
         return ret          return ret
           
Line 617  def checkDiffs(self,metadict): Line 756  def checkDiffs(self,metadict):
           
         for field in tags[1]:          for field in tags[1]:
             try:              try:
                 if (NoneToEmpty(self.getFieldValue(self.getFieldTag(tags,field)))==metadict[self.getFieldTag(tags,field)]):                              if (NoneToEmpty(self.getMDValue(self.getFieldTag(tags,field)))==metadict[self.getFieldTag(tags,field)]):
                     diffs[self.getFieldTag(tags,field)]=1                      diffs[self.getFieldTag(tags,field)]=1
                 else:                  else:
                                           
Line 645  def findObjectPath(startobject, filename Line 784  def findObjectPath(startobject, filename
     paths = filename.split('/')      paths = filename.split('/')
     object = startobject      object = startobject
     for path in paths:      for path in paths:
               
         if hasattr(object, path):          if hasattr(object, path):
         object = getattr(object, path)          object = getattr(object, path)
     else:      else:
Line 871  class MapArea(SimpleItem): Line 1011  class MapArea(SimpleItem):
     # type constants      # type constants
     TYPE_AREA = 'area'      TYPE_AREA = 'area'
     TYPE_ARROW = 'arrow'      TYPE_ARROW = 'arrow'
       TYPE_TEXT = 'text'
           
     def __init__(self, id, coords, label=None, type=None, text=None):      def __init__(self, id, coords, label=None, type=None, tip=None, permanent=False):
     """init"""      """init"""
     self.coords = coords[0:4]      self.coords = coords[0:4]
     if len(coords) > 4:      if len(coords) > 4:
Line 882  class MapArea(SimpleItem): Line 1023  class MapArea(SimpleItem):
     self.id = id      self.id = id
     self.label = label      self.label = label
     self.setType(type)      self.setType(type)
     self.text = text          self.tip = tip
           self.permanent = permanent
   
     def setCoords(self, coords):      def setCoords(self, coords):
     """sets the coords"""      """sets the coords"""
Line 917  class MapArea(SimpleItem): Line 1059  class MapArea(SimpleItem):
         self.type = MapArea.TYPE_ARROW          self.type = MapArea.TYPE_ARROW
     elif type == MapArea.TYPE_AREA:      elif type == MapArea.TYPE_AREA:
         self.type = MapArea.TYPE_AREA          self.type = MapArea.TYPE_AREA
           elif type == MapArea.TYPE_TEXT:
               self.type = MapArea.TYPE_TEXT
     else:      else:
         self.type = MapArea.TYPE_AREA          self.type = MapArea.TYPE_AREA
                   
Line 928  class MapArea(SimpleItem): Line 1072  class MapArea(SimpleItem):
     """returns if the type is arrow"""      """returns if the type is arrow"""
     return self.type == MapArea.TYPE_ARROW      return self.type == MapArea.TYPE_ARROW
   
       def isTypeText(self):
           """returns if the type is text"""
           return self.type == MapArea.TYPE_TEXT
   
     def getAngle(self):      def getAngle(self):
     """returns the angle"""      """returns the angle"""
     return self.angle      return self.angle
Line 936  class MapArea(SimpleItem): Line 1084  class MapArea(SimpleItem):
     """sets the angle"""      """sets the angle"""
     self.angle = angle      self.angle = angle
   
     def getText(self):      def getTip(self):
     """returns the popup text"""      """returns the popup text"""
     if self.text is None:          # patch old version
           if not hasattr(self, 'tip'):
               self.tip = self.text
   
           if self.tip is None:
         if hasattr(self, 'aq_parent'):          if hasattr(self, 'aq_parent'):
         parent = self.aq_parent          parent = self.aq_parent
         if parent.contentType == 'text-popup':          if parent.contentType == 'text-popup':
             return parent.description              return parent.description
     return self.text          return self.tip
   
     def setText(self, text):      def setTip(self, text):
     """sets the text"""      """sets the text"""
     self.text = text          self.tiptext = text
   
       def getText(self):
           """returns the text fpr the area"""
           if hasattr(self, 'aq_parent'):
               parent = self.aq_parent
               text = parent.getMapText()
               if text is not None:
                   return text.document_src()
           return ""
   
     def getLabel(self):      def getLabel(self):
     """returns the link label"""      """returns the link label"""
Line 960  class MapArea(SimpleItem): Line 1121  class MapArea(SimpleItem):
     """sets the label"""      """sets the label"""
     self.label = label      self.label = label
   
       def isPermanent(self):
           """returns the permanent state"""
           # patch old objects
           if not hasattr(self, 'permanent'):
               self.permanent = False
           return self.permanent
   
       def setPermanent(self, state):
           """sets the permanent state"""
           if state:
               self.permanent = True
           else:
               self.permanent = False
   
     def getLinkId(self):      def getLinkId(self):
     if hasattr(self, 'aq_parent'):      if hasattr(self, 'aq_parent'):
         return self.aq_parent.id          return self.aq_parent.id
     return self.id      return self.id
   
   
 # call this to initialize framework classes, which  # call this to initialize framework classes, which
 # does the right thing with the security assertions.  # does the right thing with the security assertions.
 Globals.InitializeClass(MapArea)  Globals.InitializeClass(MapArea)
   
   
   class MapText(Folder,ZopePageTemplate):
       """class to hold text for map areas"""
   
       meta_type = 'ECHO_mapText'
       # Create a SecurityInfo for this class.
       security = ClassSecurityInfo()
       security.setDefaultAccess("allow")
   
       
       _default_content_fn = os.path.join(package_home(globals()),
                                          'html', 'ECHO_mapText_default.html')
   
       def __init__(self, id, text=None, content_type=None):
           self.id = str(id)
           self.ZBindings_edit(self._default_bindings)
           if text is None:
               text = open(self._default_content_fn).read()
           self.pt_edit(text, content_type)
   
       def createLocale(self):
               """create locale"""
               return ECHO_collection.manage_addECHO_localeForm(self)
   
       manage_main=ZopePageTemplate.pt_editForm
   
       def manage_addECHO_locale(self,lang,title,label,text=None,content_type=None,RESPONSE=None):
               """manage add echo locale in map"""
               ECHO_collection.manage_addECHO_locale(self,lang,title,label,text,content_type)
               if RESPONSE is not None:
                           RESPONSE.redirect('manage_main')
   
   
       def changeLocale(self):
              """change locale"""
              return self.locale_en.change_ECHO_localeForm()
   
       def change_ECHO_locale(self,lang,title,label,text=None,content_type=None,RESPONSE=None):
                   """change echo locale"""
   
                   obj= self.locale_en.change_ECHO_locale(lang,title,label,text,content_type,RESPONSE)
           
   
   
                   if RESPONSE is not None:
                           RESPONSE.redirect('manage_main')
   
                   
   # Product registration and Add support
   manage_addMapTextForm = PageTemplateFile(
       'zpt/AddECHO_mapText', globals(), __name__='manage_addMapTextForm')
   
   def manage_addMapText(self, id, title=None, text=None,
                              REQUEST=None, submit=None):
       "Add a Map Text with optional file content."
   
       id = str(id)
       if REQUEST is None:
           self._setObject(id, MapText(id, text))
           ob = getattr(self, id)
           if title:
               ob.pt_setTitle(title)
           return ob
       else:
           file = REQUEST.form.get('file')
           headers = getattr(file, 'headers', None)
           if headers is None or not file.filename:
               zpt = MapText(id, text)
           else:
               zpt = MapText(id, file, headers.get('content_type'))
   
           self._setObject(id, zpt)
           if title:
               ob = getattr(self, id)
               ob.pt_setTitle(title)
   
           try:
               u = self.DestinationURL()
           except AttributeError:
               u = REQUEST['URL1']
   
           if submit == " Add and Edit ":
               u = "%s/%s" % (u, urllib.quote(id))
           REQUEST.RESPONSE.redirect(u+'/manage_main')
       return ''
   
   # call this to initialize framework classes, which
   # does the right thing with the security assertions.
   Globals.InitializeClass(MapText)

Removed from v.1.47  
changed lines
  Added in v.1.68


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>