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