--- ECHO_content/ECHO_helpers.py 2005/02/07 12:25:54 1.39 +++ ECHO_content/ECHO_helpers.py 2005/09/12 21:51:00 1.59 @@ -6,13 +6,16 @@ import string import xml.dom.minidom import types from Products.PageTemplates.PageTemplateFile import PageTemplateFile +from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate from OFS.SimpleItem import SimpleItem from Globals import package_home import Globals from AccessControl import ClassSecurityInfo import os.path +from OFS.Folder import Folder +import ECHO_collection -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'] +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'] def content_html(self,type): """template fuer content""" @@ -25,7 +28,7 @@ def content_html(self,type): obj=getattr(self,type+"_template") return obj() else: - pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_%s_template_standard.zpt'%type).__of__(self) + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','ECHO_%s_template_standard.zpt'%type)).__of__(self) pt.content_type="text/html" return pt() @@ -33,6 +36,17 @@ def content_html(self,type): class ECHO_basis: """basis eigenschaften fuer echo objekte""" + security=ClassSecurityInfo() + 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): + """sollte uerberschrieben werden, falls von der Klasse eine imagetag zurueckkommt""" + + return "" + def showRDF(self): """showrdf""" self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml') @@ -45,7 +59,18 @@ class ECHO_basis: return ret + def RDF(self): + """showrdf""" + self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml') + ret="""\n\n""" + + ret+=self.getRDF(urn=self.absolute_url())+"\n" + + ret+="""""" + return ret + + def createSubElementRDF(self,urn=None): """rdf list""" if not urn: @@ -97,7 +122,17 @@ class ECHO_basis: def getTitle(self): """title""" - return self.decode(self.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) + + try: return self.title.encode('utf-8','ignore') except: @@ -106,7 +141,24 @@ class ECHO_basis: def getLabel(self): """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=="": + ret=self.getTitle() + if ret=="": + ret=self.getId() + return ret + return self.decode(self.label) try: return self.label.encode('utf-8','ignore') @@ -151,18 +203,50 @@ class ECHO_basis: def getMapAreas(self): """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 - 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 def addMapArea(self, newarea): """add a map area to this object""" if (newarea.id is None): # create new id - areas = self.getMapAreas() - newarea.id = "a%02d"%len(areas) + ids = [a.id for a in self.getMapAreas()] + 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) + 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): """change map coordinates""" if self.hasParentOverview(): @@ -189,19 +273,22 @@ class ECHO_basis: coords = string.split(coordstring, ',') angle = self.REQUEST.get('angle.'+id, '0') type = self.REQUEST.get('type.'+id, 'area') + permanent = self.REQUEST.get('permanent.'+id, '') if len(coords) == 4: area.setCoordString(coordstring) area.setAngle(angle) area.setType(type) - # add new area + area.setPermanent(permanent) + # add the "new" area if self.REQUEST.has_key('add'): coordstring = self.REQUEST.get('coords.new', '') coords = string.split(coordstring, ',') angle = self.REQUEST.get('angle.new', '0') type = self.REQUEST.get('type.new', 'area') + permanent = self.REQUEST.get('permanent.new', '') if len(coords) == 4: coords.append(angle) - area = MapArea(None, coords, type=type) + area = MapArea(None, coords, type=type, permanent=permanent) self.addMapArea(area) # return to edit area menu if RESPONSE is not None: @@ -209,13 +296,16 @@ class ECHO_basis: def createJSAreas(self, areas): """create area calls for JavaScript""" - dynamical="\n" + forceperm = self.REQUEST.get('map_force_permanent', None) + js="\n" for ob in areas: - if ob.isTypeArrow(): - dynamical+="""addArea('%s', 'overview', %s, 'arrow');\n"""%(ob.getFullId(),ob.getCoordString()) + # check for force-permanent + if forceperm is not None: + perm = forceperm else: - dynamical+="""addArea('%s', 'overview', %s, 'area');\n"""%(ob.getFullId(),ob.getCoordString()) - 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): """create javascript include and script tags for head""" @@ -239,7 +329,7 @@ class ECHO_basis: """generate img-tag for map of parent""" return self.aq_parent.createMapImg() - def createMapLink(self, ob, text=None): + def createMapLink(self, ob, text=None, target="_blank"): """generate map link""" bt = BrowserCheck(self) id = ob.getFullId() @@ -248,52 +338,94 @@ class ECHO_basis: text = ob.getLabel() if text is None: text = "link" - tiptext = ob.getText() + tiptext = ob.getTip() tag = "" if bt.isN4: # N4 needs layer for highlighting - tag += '" else: # a-element - 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""" bt = BrowserCheck(self) id = ob.getFullId() link = ob.getLinkId() - tiptext = ob.getText() + tiptext = ob.getTip() tag = "" if bt.isN4: + # # N4 needs layer and img elements + # tag += ''%(id,id,id) if ob.isTypeArrow(): + # N4 - Arrow rot = ob.angle - tag += ''%(link,arrowsrc,rot) + + + if backLink and backLink==self.REQUEST['SERVER_URL']+getattr(self,link).link: + marksrc=alternativArrowsrc + else: + marksrc = arrowsrc + if float(rot) < 0: + marksrc = circlesrc + tag += ''%(link,marksrc,rot) + elif ob.isTypeText(): + # N4 - Text + tag += '
'%(id,id,id,link) + # + # (more or less) DOM capable browser + # + tag = ''%(id,id,id,link,target) if ob.isTypeArrow(): + # DOM - Arrow rot = ob.angle + + if backLink and hasattr(getattr(self,link),'link') and backLink==self.REQUEST['SERVER_URL']+getattr(self,link).link.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: # IE/Win 5.5 has "feature" for PNG transparency - tag += ''%(id,arrowsrc,rot,arrowsrc,rot) + tag += ''%(id,marksrc,rot,marksrc,rot) else: # arrow image - tag += ''%(id,arrowsrc,rot) + tag += ''%(id,marksrc,rot) + elif ob.isTypeText(): + # DOM - Text + tag += '
4: @@ -843,7 +992,8 @@ class MapArea(SimpleItem): self.id = id self.label = label self.setType(type) - self.text = text + self.tip = tip + self.permanent = permanent def setCoords(self, coords): """sets the coords""" @@ -878,6 +1028,8 @@ class MapArea(SimpleItem): self.type = MapArea.TYPE_ARROW elif type == MapArea.TYPE_AREA: self.type = MapArea.TYPE_AREA + elif type == MapArea.TYPE_TEXT: + self.type = MapArea.TYPE_TEXT else: self.type = MapArea.TYPE_AREA @@ -889,6 +1041,10 @@ class MapArea(SimpleItem): """returns if the type is 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): """returns the angle""" return self.angle @@ -897,18 +1053,31 @@ class MapArea(SimpleItem): """sets the angle""" self.angle = angle - def getText(self): + def getTip(self): """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'): parent = self.aq_parent if parent.contentType == 'text-popup': return parent.description - return self.text + return self.tip - def setText(self, text): + def setTip(self, 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): """returns the link label""" @@ -921,12 +1090,115 @@ class MapArea(SimpleItem): """sets the 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): if hasattr(self, 'aq_parent'): return self.aq_parent.id return self.id - # call this to initialize framework classes, which # does the right thing with the security assertions. 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)