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:
parent
6e3e08c781
commit
a12bead1ba
3 changed files with 44 additions and 39 deletions
|
@ -143,7 +143,6 @@ class BaseView(GenericView):
|
||||||
@Lazy
|
@Lazy
|
||||||
def uniqueId(self):
|
def uniqueId(self):
|
||||||
return util.getUidForObject(self.context)
|
return util.getUidForObject(self.context)
|
||||||
#return zapi.getUtility(IRelationRegistry).getUniqueIdForObject(self.context)
|
|
||||||
|
|
||||||
# type stuff
|
# type stuff
|
||||||
|
|
||||||
|
@ -191,7 +190,7 @@ class BaseView(GenericView):
|
||||||
return types
|
return types
|
||||||
|
|
||||||
def resourceTypes(self):
|
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
|
#if t.factory == Resource]) # ? if necessary -> type.qualifiers
|
||||||
|
|
||||||
def conceptTypes(self):
|
def conceptTypes(self):
|
||||||
|
|
|
@ -42,7 +42,8 @@ from cybertools.ajax import innerHtml
|
||||||
from cybertools.browser.form import FormController
|
from cybertools.browser.form import FormController
|
||||||
from cybertools.typology.interfaces import IType
|
from cybertools.typology.interfaces import IType
|
||||||
from loops.concept import ResourceRelation
|
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.node import NodeView
|
||||||
from loops.browser.concept import ConceptRelationView
|
from loops.browser.concept import ConceptRelationView
|
||||||
from loops.resource import Resource
|
from loops.resource import Resource
|
||||||
|
@ -98,15 +99,32 @@ class ObjectForm(NodeView):
|
||||||
self.loopsRoot.getConceptManager().getDefaultPredicate())
|
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):
|
def modifyWidgetSetup(self, widgets):
|
||||||
widgets['data'].height = 5
|
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):
|
class EditObjectForm(ObjectForm, EditForm):
|
||||||
|
@ -118,6 +136,10 @@ class EditObjectForm(ObjectForm, EditForm):
|
||||||
form_action = 'edit_resource'
|
form_action = 'edit_resource'
|
||||||
dialog_name = 'edit'
|
dialog_name = 'edit'
|
||||||
|
|
||||||
|
def __init__(self, context, request):
|
||||||
|
super(EditObjectForm, self).__init__(context, request)
|
||||||
|
self.context = self.virtualTargetObject
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def typeInterface(self):
|
def typeInterface(self):
|
||||||
return IType(self.context).typeInterface or IDocument
|
return IType(self.context).typeInterface or IDocument
|
||||||
|
@ -125,8 +147,9 @@ class EditObjectForm(ObjectForm, EditForm):
|
||||||
@property
|
@property
|
||||||
def form_fields(self):
|
def form_fields(self):
|
||||||
ff = FormFields(self.typeInterface)
|
ff = FormFields(self.typeInterface)
|
||||||
# if self.typeInterface in (IFile, IExternalFile):
|
if self.typeInterface in widgetControllers:
|
||||||
#ff['data'].custom_widget = UploadWidget
|
wc = widgetControllers[self.typeInterface]()
|
||||||
|
ff = wc.modifyFormFields(ff)
|
||||||
return ff
|
return ff
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -136,10 +159,6 @@ class EditObjectForm(ObjectForm, EditForm):
|
||||||
if r.isProtected: continue
|
if r.isProtected: continue
|
||||||
yield r
|
yield r
|
||||||
|
|
||||||
def __init__(self, context, request):
|
|
||||||
super(EditObjectForm, self).__init__(context, request)
|
|
||||||
self.context = self.virtualTargetObject
|
|
||||||
|
|
||||||
|
|
||||||
class CreateObjectForm(ObjectForm, Form):
|
class CreateObjectForm(ObjectForm, Form):
|
||||||
|
|
||||||
|
@ -161,6 +180,9 @@ class CreateObjectForm(ObjectForm, Form):
|
||||||
self.typeInterface = ifc
|
self.typeInterface = ifc
|
||||||
ff = FormFields(ifc)
|
ff = FormFields(ifc)
|
||||||
#ff['data'].custom_widget = UploadWidget
|
#ff['data'].custom_widget = UploadWidget
|
||||||
|
if self.typeInterface in widgetControllers:
|
||||||
|
wc = widgetControllers[self.typeInterface]()
|
||||||
|
ff = wc.modifyFormFields(ff)
|
||||||
return ff
|
return ff
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -220,7 +242,9 @@ class EditObject(FormController):
|
||||||
#self.request.form['filename'] = filename
|
#self.request.form['filename'] = filename
|
||||||
contentType = guess_content_type(filename, value[:100])
|
contentType = guess_content_type(filename, value[:100])
|
||||||
if contentType:
|
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)
|
setattr(adapted, fn, value)
|
||||||
if self.old or self.selected:
|
if self.old or self.selected:
|
||||||
self.assignConcepts(obj)
|
self.assignConcepts(obj)
|
||||||
|
|
|
@ -6,26 +6,17 @@
|
||||||
<input type="hidden" name="form.action" value="edit"
|
<input type="hidden" name="form.action" value="edit"
|
||||||
tal:attributes="value view/form_action" />
|
tal:attributes="value view/form_action" />
|
||||||
<table cellpadding="3" class="form">
|
<table cellpadding="3" class="form">
|
||||||
<tbody>
|
<tbody><tr><th colspan="5"><br />
|
||||||
<tr>
|
|
||||||
<th colspan="5">
|
|
||||||
<br />
|
|
||||||
<span tal:replace="view/title"
|
<span tal:replace="view/title"
|
||||||
i18n:translate="">Edit Information Object
|
i18n:translate="">Edit Information Object
|
||||||
</span>
|
</span>
|
||||||
</th>
|
</th></tr></tbody>
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
|
|
||||||
<tbody>
|
<tbody><tr><td colspan="5">
|
||||||
<tr>
|
|
||||||
<td colspan="5">
|
|
||||||
<div id="form.fields">
|
<div id="form.fields">
|
||||||
<metal:fields use-macro="view/template/macros/fields" />
|
<metal:fields use-macro="view/template/macros/fields" />
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td></tr></tbody>
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -45,10 +36,7 @@
|
||||||
<input type="hidden" name="form.action" value="create"
|
<input type="hidden" name="form.action" value="create"
|
||||||
tal:attributes="value view/form_action" />
|
tal:attributes="value view/form_action" />
|
||||||
<table cellpadding="3" class="form">
|
<table cellpadding="3" class="form">
|
||||||
<tbody>
|
<tbody><tr><th colspan="5"><br />
|
||||||
<tr>
|
|
||||||
<th colspan="5">
|
|
||||||
<br />
|
|
||||||
<span tal:replace="view/title"
|
<span tal:replace="view/title"
|
||||||
i18n:translate="">Create Information Object</span>
|
i18n:translate="">Create Information Object</span>
|
||||||
<select name="form.type" id="form.type"
|
<select name="form.type" id="form.type"
|
||||||
|
@ -66,19 +54,13 @@
|
||||||
Note
|
Note
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
</th>
|
</th></tr></tbody>
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
|
|
||||||
<tbody>
|
<tbody><tr><td colspan="5">
|
||||||
<tr>
|
|
||||||
<td colspan="5">
|
|
||||||
<div id="form.fields">
|
<div id="form.fields">
|
||||||
<metal:fields use-macro="view/template/macros/fields" />
|
<metal:fields use-macro="view/template/macros/fields" />
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td></tr></tbody>
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
Loading…
Add table
Reference in a new issue