extend form handling to allow full-page forms
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2801 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
9a3dd79aba
commit
b20b34066c
4 changed files with 41 additions and 9 deletions
|
@ -502,6 +502,13 @@ class BaseView(GenericView, I18NView):
|
|||
jsCall = 'dojo.require("dijit._editor.plugins.LinkDialog");'
|
||||
self.controller.macros.register('js-execute', jsCall, jsCall=jsCall)
|
||||
|
||||
def registerDojoFormAll(self):
|
||||
self.registerDojo()
|
||||
jsCall = ('dojo.require("dijit.form.Form"); '
|
||||
'dojo.require("dijit.form.FilteringSelect"); '
|
||||
'dojo.require("dojox.data.QueryReadStore");')
|
||||
self.controller.macros.register('js-execute', 'dojo.form.all', jsCall=jsCall)
|
||||
|
||||
|
||||
# vocabulary stuff
|
||||
|
||||
|
|
|
@ -609,6 +609,13 @@
|
|||
permission="zope.ManageContent"
|
||||
/>
|
||||
|
||||
<page
|
||||
name="edit_concept_page.html"
|
||||
for="loops.interfaces.INode"
|
||||
class="loops.browser.form.EditConceptPage"
|
||||
permission="zope.ManageContent"
|
||||
/>
|
||||
|
||||
<page
|
||||
name="inner_form.html"
|
||||
for="loops.interfaces.INode"
|
||||
|
|
|
@ -72,6 +72,7 @@ class ObjectForm(NodeView):
|
|||
customMacro = None
|
||||
formState = FormState() # dummy, don't update!
|
||||
isInnerHtml = True
|
||||
isPopup = False
|
||||
|
||||
def __init__(self, context, request):
|
||||
super(ObjectForm, self).__init__(context, request)
|
||||
|
@ -80,16 +81,16 @@ class ObjectForm(NodeView):
|
|||
self.target = context
|
||||
#self.registerDojoForm()
|
||||
|
||||
#@Lazy
|
||||
#def isInnerHtml(self):
|
||||
# return bool(self.request.form.get('dialog'))
|
||||
|
||||
def closeAction(self, submit=False):
|
||||
if self.isPopup:
|
||||
if submit:
|
||||
return ("xhrSubmitPopup('dialog_form', '%s'); return false"
|
||||
% (self.request.URL))
|
||||
else:
|
||||
return 'window.close()'
|
||||
if self.isInnerHtml:
|
||||
return "return closeDialog(%s);" % (submit and 'true' or 'false')
|
||||
if submit:
|
||||
return "xhrSubmitPopup('dialog_form', '%s'); return false" % (self.request.URL)
|
||||
return 'window.close()'
|
||||
return ''
|
||||
|
||||
@Lazy
|
||||
def item(self):
|
||||
|
@ -207,6 +208,8 @@ class EditObjectForm(ObjectForm):
|
|||
|
||||
class EditConceptForm(EditObjectForm):
|
||||
|
||||
isInnerHtml = True
|
||||
|
||||
title = _(u'Edit Concept')
|
||||
form_action = 'edit_concept'
|
||||
|
||||
|
@ -226,6 +229,15 @@ class EditConceptForm(EditObjectForm):
|
|||
yield r
|
||||
|
||||
|
||||
class EditConceptPage(EditConceptForm):
|
||||
|
||||
isInnerHtml = False
|
||||
|
||||
def setupController(self):
|
||||
super(EditConceptPage, self).setupController()
|
||||
self.registerDojoFormAll()
|
||||
|
||||
|
||||
class CreateObjectForm(ObjectForm):
|
||||
|
||||
@property
|
||||
|
@ -298,6 +310,7 @@ class CreateObjectForm(ObjectForm):
|
|||
class CreateObjectPopup(CreateObjectForm):
|
||||
|
||||
isInnerHtml = False
|
||||
isPopup = True
|
||||
nextUrl = '' # no redirect upon submit
|
||||
|
||||
def update(self):
|
||||
|
@ -432,6 +445,7 @@ class EditObject(FormController, I18NView):
|
|||
viewAnnotations['target'] = obj
|
||||
self.object = obj
|
||||
formState = self.updateFields()
|
||||
self.view.formState = formState
|
||||
# TODO: error handling
|
||||
url = self.view.nextUrl
|
||||
if url is None:
|
||||
|
@ -444,7 +458,6 @@ class EditObject(FormController, I18NView):
|
|||
obj = self.object
|
||||
form = self.request.form
|
||||
instance = self.instance
|
||||
#instance.template = self.schema
|
||||
formState = instance.applyTemplate(data=form, fieldHandlers=self.fieldHandlers)
|
||||
self.selected = []
|
||||
self.old = []
|
||||
|
@ -576,7 +589,8 @@ class CreateObject(EditObject):
|
|||
notify(ObjectCreatedEvent(obj))
|
||||
#notify(ObjectAddedEvent(obj))
|
||||
self.object = obj
|
||||
self.updateFields() # TODO: suppress validation
|
||||
formState = self.updateFields() # TODO: suppress validation
|
||||
self.view.formState = formState
|
||||
# TODO: error handling
|
||||
url = self.view.nextUrl
|
||||
if url is None:
|
||||
|
@ -604,7 +618,10 @@ class EditConcept(EditObject):
|
|||
def update(self):
|
||||
self.object = self.view.virtualTargetObject
|
||||
formState = self.updateFields()
|
||||
self.view.formState = formState
|
||||
# TODO: error handling
|
||||
if formState.severity > 0:
|
||||
return True
|
||||
self.request.response.redirect(self.view.virtualTargetUrl)
|
||||
return False
|
||||
|
||||
|
|
|
@ -254,6 +254,7 @@
|
|||
tal:attributes="onClick python: view.closeAction(True)">
|
||||
<input type="button" value="Cancel" onClick="dlg.hide();"
|
||||
i18n:attributes="value"
|
||||
tal:condition="view/isInnerHtml"
|
||||
tal:attributes="onClick view/closeAction">
|
||||
</td>
|
||||
</tr>
|
||||
|
|
Loading…
Add table
Reference in a new issue