some improvements and fixes on dialog form handling

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1607 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2007-03-03 09:55:21 +00:00
parent 6e3e08c781
commit a12bead1ba
3 changed files with 44 additions and 39 deletions

View file

@ -143,7 +143,6 @@ class BaseView(GenericView):
@Lazy
def uniqueId(self):
return util.getUidForObject(self.context)
#return zapi.getUtility(IRelationRegistry).getUniqueIdForObject(self.context)
# type stuff
@ -191,7 +190,7 @@ class BaseView(GenericView):
return types
def resourceTypes(self):
return util.KeywordVocabulary(self.listTypes(('resource',) ('hidden',)))
return util.KeywordVocabulary(self.listTypes(('resource',), ('hidden',)))
#if t.factory == Resource]) # ? if necessary -> type.qualifiers
def conceptTypes(self):

View file

@ -42,7 +42,8 @@ from cybertools.ajax import innerHtml
from cybertools.browser.form import FormController
from cybertools.typology.interfaces import IType
from loops.concept import ResourceRelation
from loops.interfaces import IConcept, IResourceManager, INote, IDocument
from loops.interfaces import IConcept, IResourceManager, IDocument
from loops.interfaces import IFile, IExternalFile, INote
from loops.browser.node import NodeView
from loops.browser.concept import ConceptRelationView
from loops.resource import Resource
@ -98,15 +99,32 @@ class ObjectForm(NodeView):
self.loopsRoot.getConceptManager().getDefaultPredicate())
class NoteWidgetController(object):
class WidgetController(object):
def modifyFormFields(self, formFields):
return formFields
def modifyWidgetSetup(self, widgets):
pass
class NoteWidgetController(WidgetController):
def modifyWidgetSetup(self, widgets):
widgets['data'].height = 5
widgetControllers = {INote: NoteWidgetController}
class FileWidgetController(WidgetController):
# specialWidgets = {(IFile, 'data'): UploadWidget}
def modifyFormFields(self, formFields):
return formFields.omit('contentType')
widgetControllers = {
INote: NoteWidgetController,
IFile: FileWidgetController,
IExternalFile: FileWidgetController,
}
class EditObjectForm(ObjectForm, EditForm):
@ -118,6 +136,10 @@ class EditObjectForm(ObjectForm, EditForm):
form_action = 'edit_resource'
dialog_name = 'edit'
def __init__(self, context, request):
super(EditObjectForm, self).__init__(context, request)
self.context = self.virtualTargetObject
@Lazy
def typeInterface(self):
return IType(self.context).typeInterface or IDocument
@ -125,8 +147,9 @@ class EditObjectForm(ObjectForm, EditForm):
@property
def form_fields(self):
ff = FormFields(self.typeInterface)
# if self.typeInterface in (IFile, IExternalFile):
#ff['data'].custom_widget = UploadWidget
if self.typeInterface in widgetControllers:
wc = widgetControllers[self.typeInterface]()
ff = wc.modifyFormFields(ff)
return ff
@property
@ -136,10 +159,6 @@ class EditObjectForm(ObjectForm, EditForm):
if r.isProtected: continue
yield r
def __init__(self, context, request):
super(EditObjectForm, self).__init__(context, request)
self.context = self.virtualTargetObject
class CreateObjectForm(ObjectForm, Form):
@ -161,6 +180,9 @@ class CreateObjectForm(ObjectForm, Form):
self.typeInterface = ifc
ff = FormFields(ifc)
#ff['data'].custom_widget = UploadWidget
if self.typeInterface in widgetControllers:
wc = widgetControllers[self.typeInterface]()
ff = wc.modifyFormFields(ff)
return ff
@property
@ -220,7 +242,9 @@ class EditObject(FormController):
#self.request.form['filename'] = filename
contentType = guess_content_type(filename, value[:100])
if contentType:
self.request.form['form.contentType'] = contentType[0]
ct = contentType[0]
self.request.form['form.contentType'] = ct
adapted.contentType = ct
setattr(adapted, fn, value)
if self.old or self.selected:
self.assignConcepts(obj)

View file

@ -6,26 +6,17 @@
<input type="hidden" name="form.action" value="edit"
tal:attributes="value view/form_action" />
<table cellpadding="3" class="form">
<tbody>
<tr>
<th colspan="5">
<br />
<tbody><tr><th colspan="5"><br />
<span tal:replace="view/title"
i18n:translate="">Edit Information Object
</span>
</th>
</tr>
</tbody>
</th></tr></tbody>
<tbody>
<tr>
<td colspan="5">
<tbody><tr><td colspan="5">
<div id="form.fields">
<metal:fields use-macro="view/template/macros/fields" />
</div>
</td>
</tr>
</tbody>
</td></tr></tbody>
<tbody>
<tr>
@ -45,10 +36,7 @@
<input type="hidden" name="form.action" value="create"
tal:attributes="value view/form_action" />
<table cellpadding="3" class="form">
<tbody>
<tr>
<th colspan="5">
<br />
<tbody><tr><th colspan="5"><br />
<span tal:replace="view/title"
i18n:translate="">Create Information Object</span>
<select name="form.type" id="form.type"
@ -66,19 +54,13 @@
Note
</option>
</select>
</th>
</tr>
</tbody>
</th></tr></tbody>
<tbody>
<tr>
<td colspan="5">
<tbody><tr><td colspan="5">
<div id="form.fields">
<metal:fields use-macro="view/template/macros/fields" />
</div>
</td>
</tr>
</tbody>
</td></tr></tbody>
<tbody>
<tr>