Commit 6f4defc5 authored by 's avatar

*** empty log message ***

parent 9bfec280
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
# rights reserved. # rights reserved.
# #
############################################################################ ############################################################################
__rcs_id__='$Id: TreeTag.py,v 1.3 1997/09/04 22:08:19 brian Exp $' __rcs_id__='$Id: TreeTag.py,v 1.4 1997/09/09 23:09:03 brian Exp $'
__version__='$Revision: 1.3 $'[11:-2] __version__='$Revision: 1.4 $'[11:-2]
from DocumentTemplate.DT_Util import * from DocumentTemplate.DT_Util import *
from DocumentTemplate.DT_String import String from DocumentTemplate.DT_String import String
...@@ -41,37 +41,43 @@ from urllib import quote, unquote ...@@ -41,37 +41,43 @@ from urllib import quote, unquote
pyid=id # Copy builtin pyid=id # Copy builtin
# Generified example of tree support a la discussion...
def tpRender(self, md, section): def tpRender(self, md, section):
# Check for collapse all, expand all, and state # Check for collapse all, expand all, and state
try: collapse_all=md['collapse_all'] try: collapse_all=md['collapse_all']
except: collapse_all=None except: collapse_all=None
if collapse_all: if collapse_all:
state=[] state=[]
else: else:
try: expand_all=md['expand_all'] try: expand_all=md['expand_all']
except: expand_all=None except: expand_all=None
if expand_all: if expand_all:
# in case of expand all - to maintain state correctly we
# have to make state be the ids of ALL subobjects which
# are non-empty (recursively).
state=tpValuesIds(self) state=tpValuesIds(self)
else: else:
try: try:
state=md['state'] state=md['state']
if state[0] != '[': state=unquote(state) if state[0] != '[': state=unquote(state)
state=list(eval(state,{'__builtins__':{}})) state=list(eval(state,{'__builtins__':{}}))
except: except: state=[]
state=[]
# Save state in a cookie # Try to save state in a cookie as well...
if state: md['RESPONSE'].setCookie('state',quote(str(state)[1:-1]+',')) # md['RESPONSE'].setCookie('state',state)
else: md['RESPONSE'].expireCookie('state')
root=md['URL'] root=md['URL']
l=rfind(root, '/') l=rfind(root, '/')
if l >= 0: root=root[l+1:] if l >= 0: root=root[l+1:]
url='' url=''
data =[] data =[]
data.append('<TABLE CELLSPACING="0">\n') data.append('<table cellspacing=0>\n')
colspan=1+tpStateLevel(state) colspan=1+tpStateLevel(state)
treeData={'tree-root-url': root} treeData={'tree-root-url': root}
...@@ -80,9 +86,12 @@ def tpRender(self, md, section): ...@@ -80,9 +86,12 @@ def tpRender(self, md, section):
for item in self.tpValues(): for item in self.tpValues():
data=tpRenderTABLE(item,root,url,state,state,data,colspan, data=tpRenderTABLE(item,root,url,state,state,data,colspan,
section,md,treeData) section,md,treeData)
data.append('</TABLE>\n')
data.append('</table>\n')
result=join(data,'') result=join(data,'')
finally: md.pop(1) finally: md.pop(1)
return result return result
def tpStateLevel(state): def tpStateLevel(state):
...@@ -93,19 +102,15 @@ def tpStateLevel(state): ...@@ -93,19 +102,15 @@ def tpStateLevel(state):
return level return level
def tpValuesIds(self): def tpValuesIds(self):
# This should build the ids of subitems which are
# expandable (non-empty). Leaves should never be
# in the state - it will screw the colspan counting.
r=[] r=[]
try: try:
for item in self.tpValues(): for item in self.tpValues():
try: try:
if item.tpValues(): id=item.tpId()
id=item.tpId() e=tpValuesIds(item)
e=tpValuesIds(item) if e: id=[id,e]
if e: id=[id,e] else: id=[id]
else: id=[id] r.append(id)
r.append(id)
except: pass except: pass
except: pass except: pass
return r return r
...@@ -113,19 +118,20 @@ def tpValuesIds(self): ...@@ -113,19 +118,20 @@ def tpValuesIds(self):
def tpRenderTABLE(self, root_url, url, state, substate, data, def tpRenderTABLE(self, root_url, url, state, substate, data,
colspan, section, md, treeData, level=0): colspan, section, md, treeData, level=0):
try: items=self.tpValues()
# We are being called from above
try: items=self.tpValues()
except: items=None except: items=None
tpUrl=self.tpURL() tpUrl=self.tpURL()
url = (url and ('%s/%s' % (url, tpUrl))) or tpUrl url = (url and ('%s/%s' % (url, tpUrl))) or tpUrl
treeData['tree-item-url']=url treeData['tree-item-url']=url
treeData['tree-item-expanded']=0
try: id=self.tpId() try: id=self.tpId()
except: id=None except: id=None
if id is None: if id is None:
try: id=self._p_oid try: id=self._p_oid
except: id=None except: id=None
if id is None: id=pyid(self) if id is None: id=pyid(self)
...@@ -134,19 +140,20 @@ def tpRenderTABLE(self, root_url, url, state, substate, data, ...@@ -134,19 +140,20 @@ def tpRenderTABLE(self, root_url, url, state, substate, data,
output=data.append output=data.append
# Add prefix # Add prefix
output('<TR>\n') output('<tr>')
if level: output('<TD WIDTH="16"></TD>\n' * level) if level: output('<td></td>' * level)
# Add +/- icon # Add tree expand/contract icon
if items: if items:
output('<TD WIDTH="16" VALIGN="TOP">') output('<td valign=top>')
for i in range(len(substate)): for i in range(len(substate)):
sub=substate[i] sub=substate[i]
if sub[0]==id: if sub[0]==id:
exp=i+1 exp=i+1
break break
if exp: if exp:
treeData['tree-item-expanded']=1
del substate[exp-1] del substate[exp-1]
output('<A HREF="%s?state=%s">%s</A>' % output('<A HREF="%s?state=%s">%s</A>' %
(root_url,quote(str(state)[1:-1]+','), icoMinus)) (root_url,quote(str(state)[1:-1]+','), icoMinus))
...@@ -157,13 +164,14 @@ def tpRenderTABLE(self, root_url, url, state, substate, data, ...@@ -157,13 +164,14 @@ def tpRenderTABLE(self, root_url, url, state, substate, data,
(root_url,quote(str(state)[1:-1]+','), icoPlus)) (root_url,quote(str(state)[1:-1]+','), icoPlus))
del substate[-1] del substate[-1]
else: else:
output('<TD WIDTH="16">') output('<td>')
output('</TD>\n')
output('</td>\n')
# add item text # add item text
output('<TD COLSPAN="%s" VALIGN="TOP">' % (colspan-level)) output('<td colspan=%s valign=top>' % colspan)
output(section(self, md)) output(section(self, md))
output('</TD>\n</TR>\n') output('</td></tr>\n')
if exp: if exp:
for item in items: for item in items:
...@@ -171,10 +179,16 @@ def tpRenderTABLE(self, root_url, url, state, substate, data, ...@@ -171,10 +179,16 @@ def tpRenderTABLE(self, root_url, url, state, substate, data,
data=tpRenderTABLE(item, root_url,url,state,sub[1],data, data=tpRenderTABLE(item, root_url,url,state,sub[1],data,
colspan, section, md, treeData, level+1) colspan, section, md, treeData, level+1)
if not sub[1]: del sub[1] if not sub[1]: del sub[1]
return data return data
icoSpace='<IMG SRC="%s/TreeDisplay/Blank_icon.gif" BORDER="0">' % SOFTWARE_URL
icoPlus ='<IMG SRC="%s/TreeDisplay/Plus_icon.gif" BORDER="0">' % SOFTWARE_URL
icoMinus='<IMG SRC="%s/TreeDisplay/Minus_icon.gif" BORDER="0">' % SOFTWARE_URL
icoSpace='<IMG SRC="%s/TreeDisplay/Blank_icon.gif" ' \
' BORDER="0">' % SOFTWARE_URL
icoPlus ='<IMG SRC="%s/TreeDisplay/Plus_icon.gif" BORDER="0"' \
' ALT="+">' % SOFTWARE_URL
icoMinus='<IMG SRC="%s/TreeDisplay/Minus_icon.gif" BORDER="0"' \
' ALT="-">' % SOFTWARE_URL
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment