Commit d676a933 authored by 's avatar

Decoupled Document from DT editing ui.

parent 85101020
"""Document object""" """Document object"""
__version__='$Revision: 1.19 $'[11:-2] __version__='$Revision: 1.20 $'[11:-2]
from Globals import HTML from Globals import HTML, HTMLFile,MessageDialog
from Globals import HTMLFile from string import join,split,strip,rfind,atoi
from string import join, split, strip, rfind
from AccessControl.Role import RoleManager from AccessControl.Role import RoleManager
import regex import SimpleItem, regex
import SimpleItem
class Document(HTML, RoleManager, SimpleItem.Item_w__name__): class Document(HTML, RoleManager, SimpleItem.Item_w__name__):
"""A Document object""" """Document object"""
meta_type ='Document' meta_type ='Document'
icon ='OFS/Document_icon.gif' icon ='OFS/Document_icon.gif'
__state_names__=HTML.__state_names__+('title','__roles__') __state_names__=HTML.__state_names__+('title','__roles__')
_formhead="""
<TABLE CELLSPACING="2">
<TR>
<TD ALIGN="LEFT" VALIGN="TOP">
<STRONG>Id</STRONG>
</TD>
<TD ALIGN="LEFT" VALIGN="TOP">%s</TD>
</TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="TOP">
<EM><STRONG>Title</STRONG></EM>
</TD>
<TD ALIGN="LEFT" VALIGN="TOP">
<INPUT TYPE="TEXT" NAME="title" SIZE="40" VALUE="%s">
</TD>
</TR>
<TR>
<TD><STRONG>Access<BR>Control</STRONG></TD>
<TD>
<TABLE>
<TR>
<TD VALIGN="TOP">
<INPUT TYPE="RADIO" NAME="acl_type" VALUE="E"%s>
Allow users with selected roles
<BR>
<INPUT TYPE="RADIO" NAME="acl_type" VALUE="A"%s>
Allow based on default roles
<BR>
<INPUT TYPE="RADIO" NAME="acl_type" VALUE="P"%s>
Allow all users
</TD>
<TD VALIGN="TOP">
<SELECT NAME="acl_roles:list" SIZE="3" MULTIPLE>
%s
</SELECT>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>"""
def document_template_form_header(self):
try:
return self._formhead % (self.id(),self.title, self.aclEChecked(),
self.aclAChecked(),self.aclPChecked(),
join(self.selectedRoles(),'\n')
)
except:
import sys
return '%s %s' % (sys.exc_type, sys.exc_value)
def initvars(self, mapping, vars): def initvars(self, mapping, vars):
"""Hook to override signature so we can detect whether we are """Hook to override signature so we can detect whether we are
running from the web""" running from the web"""
...@@ -83,13 +30,6 @@ class Document(HTML, RoleManager, SimpleItem.Item_w__name__): ...@@ -83,13 +30,6 @@ class Document(HTML, RoleManager, SimpleItem.Item_w__name__):
if RESPONSE is None: return r if RESPONSE is None: return r
return decapitate(r, RESPONSE) return decapitate(r, RESPONSE)
def manage_edit(self,data,title,acl_type='A',acl_roles=[],REQUEST=None):
"""Edit method"""
self.title=title
self._setRoles(acl_type,acl_roles)
REQUEST['CANCEL_ACTION']="%s/manage_main" % REQUEST['URL2']
return HTML.manage_edit(self,data,REQUEST)
def validate(self, inst, parent, name, value, md): def validate(self, inst, parent, name, value, md):
if hasattr(value, '__roles__'): if hasattr(value, '__roles__'):
roles=value.__roles__ roles=value.__roles__
...@@ -102,18 +42,53 @@ class Document(HTML, RoleManager, SimpleItem.Item_w__name__): ...@@ -102,18 +42,53 @@ class Document(HTML, RoleManager, SimpleItem.Item_w__name__):
try: roles=parent.aq_acquire('__roles__') try: roles=parent.aq_acquire('__roles__')
except AttributeError: return 0 except AttributeError: return 0
else: return 0 else: return 0
if roles is None: return 1 if roles is None: return 1
try: return md.AUTHENTICATED_USER.hasRole(roles) try: return md.AUTHENTICATED_USER.hasRole(roles)
except AttributeError: return 0 except AttributeError: return 0
manage_editForm=HTMLFile('OFS/documentEdit')
manage=manage_editDocument=manage_editForm
def manage_edit(self,data,title,acl_type='A',acl_roles=[],SUBMIT='Change',
dtpref_cols='50',dtpref_rows='20',REQUEST=None):
"""Edit method"""
if SUBMIT=='Smaller':
rows=atoi(dtpref_rows)-5
cols=atoi(dtpref_cols)-5
e='Friday, 31-Dec-99 23:59:59 GMT'
resp=REQUEST['RESPONSE']
resp.setCookie('dtpref_rows',str(rows),path='/',expires=e)
resp.setCookie('dtpref_cols',str(cols),path='/',expires=e)
return self.manage_editForm(self,REQUEST,title=title,__str__=data,
acl_type=acl_type,acl_roles=acl_roles,
dtpref_cols=cols,dtpref_rows=rows)
if SUBMIT=='Bigger':
rows=atoi(dtpref_rows)+5
cols=atoi(dtpref_cols)+5
e='Friday, 31-Dec-99 23:59:59 GMT'
resp=REQUEST['RESPONSE']
resp.setCookie('dtpref_rows',str(rows),path='/',expires=e)
resp.setCookie('dtpref_cols',str(cols),path='/',expires=e)
return self.manage_editForm(self,REQUEST,title=title,__str__=data,
acl_type=acl_type,acl_roles=acl_roles,
dtpref_cols=cols,dtpref_rows=rows)
if SUBMIT=='Cancel':
return MessageDialog(title='Changes Cancelled',
message='Your changes have been discarded',
action='%s/manage_main' % REQUEST['URL2'])
self.title=title
self._setRoles(acl_type,acl_roles)
self.munge(data)
if REQUEST:
return MessageDialog(title='Change Successful',
message='Your changes have been saved',
action='%s/manage_main' % REQUEST['URL2'])
default_html="""<!--#var standard_html_header--> default_html="""<!--#var standard_html_header-->
New Document <H2><!--#var document_title--></H2>
<P>This is the <!--#var document_id--> Document in
the <!--#var title_or_id--> Folder.</P>
<!--#var standard_html_footer-->""" <!--#var standard_html_footer-->"""
......
<HTML>
<HEAD>
<TITLE>Edit Document</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555">
<FORM ACTION="<!--#var PARENT_URL-->/manage_edit" METHOD="POST">
<H2>Edit Document</H2>
<TABLE CELLSPACING="2">
<TR>
<TD ALIGN="LEFT" VALIGN="TOP">
<STRONG>Id</STRONG>
</TD>
<TD ALIGN="LEFT" VALIGN="TOP">
<!--#var id-->
</TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="TOP">
<EM><STRONG>Title</STRONG></EM>
</TD>
<TD ALIGN="LEFT" VALIGN="TOP">
<!--#if title-->
<INPUT TYPE="TEXT" NAME="title" SIZE="40" VALUE="<!--#var title-->">
<!--#else title-->
<INPUT TYPE="TEXT" NAME="title" SIZE="40" VALUE="">
<!--#/if title-->
</TD>
</TR>
<!--#var smallRolesWidget-->
<TR>
<TD COLSPAN="2" ALIGN="CENTER">
<TEXTAREA NAME="data:text"
<!--#if dtpref_cols-->
COLS="<!--#var dtpref_cols-->"
<!--#else dtpref_cols-->
COLS="50"
<!--#/if dtpref_cols-->
<!--#if dtpref_rows-->
ROWS="<!--#var dtpref_rows-->"
<!--#else dtpref_rows-->
ROWS="20"
<!--#/if dtpref_rows-->><!--#var __str__--></TEXTAREA>
</TD>
</TR>
<TR>
<TD></TD>
<TD>
<INPUT NAME=SUBMIT TYPE="SUBMIT" VALUE="Change">
<INPUT NAME=SUBMIT TYPE="SUBMIT" VALUE="Cancel">
<INPUT NAME=SUBMIT TYPE="SUBMIT" VALUE="Smaller">
<INPUT NAME=SUBMIT TYPE="SUBMIT" VALUE="Bigger">
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
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