improvement of popup form for creating notes via javascript
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2269 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
525ec7d5ac
commit
306d88b1eb
5 changed files with 43 additions and 45 deletions
|
@ -41,6 +41,7 @@ from zope.security.proxy import isinstance, removeSecurityProxy
|
|||
|
||||
from cybertools.ajax import innerHtml
|
||||
from cybertools.browser.form import FormController
|
||||
from cybertools.browser.view import popupTemplate
|
||||
from cybertools.composer.interfaces import IInstance
|
||||
from cybertools.composer.schema.interfaces import ISchemaFactory
|
||||
from cybertools.composer.schema.browser.common import schema_macros, schema_edit_macros
|
||||
|
@ -61,8 +62,6 @@ from loops.util import _
|
|||
from loops.versioning.interfaces import IVersionable
|
||||
|
||||
|
||||
popupTemplate = ViewPageTemplateFile('popup.pt')
|
||||
|
||||
# forms
|
||||
|
||||
class ObjectForm(NodeView):
|
||||
|
@ -80,10 +79,12 @@ class ObjectForm(NodeView):
|
|||
# the same object as the context (the object the view was created for)
|
||||
self.target = context
|
||||
|
||||
@Lazy
|
||||
def closeAction(self):
|
||||
return (self.isInnerHtml and 'dialogs["%s"].hide()' % self.dialog_name
|
||||
or 'window.close()')
|
||||
def closeAction(self, submit=False):
|
||||
if self.isInnerHtml:
|
||||
return 'dialogs["%s"].hide()' % self.dialog_name
|
||||
if submit:
|
||||
return "xhrSubmitPopup('dialog_form', '%s'); return false" % (self.request.URL)
|
||||
return 'window.close()'
|
||||
|
||||
@Lazy
|
||||
def item(self):
|
||||
|
@ -267,11 +268,16 @@ class CreateObjectForm(ObjectForm):
|
|||
class CreateObjectPopup(CreateObjectForm):
|
||||
|
||||
isInnerHtml = False
|
||||
nextUrl = '' # no redirect upon submit
|
||||
|
||||
def update(self):
|
||||
super(ObjectForm, self).update()
|
||||
show = super(ObjectForm, self).update()
|
||||
if not show:
|
||||
return False
|
||||
self.registerDojo()
|
||||
cm = self.controller.macros
|
||||
cm.register('css', identifier='popup.css', resourceName='popup.css',
|
||||
media='all', position=4)
|
||||
jsCall = ('dojo.require("dojo.widget.Dialog");'
|
||||
'dojo.require("dojo.widget.ComboBox");')
|
||||
cm.register('js-execute', jsCall, jsCall=jsCall)
|
||||
|
@ -389,7 +395,10 @@ class EditObject(FormController, I18NView):
|
|||
self.object = obj
|
||||
formState = self.updateFields()
|
||||
# TODO: error handling
|
||||
url = self.view.nextUrl
|
||||
if url is None:
|
||||
url = self.view.virtualTargetUrl + '?version=this'
|
||||
if url:
|
||||
self.request.response.redirect(url)
|
||||
return False
|
||||
|
||||
|
@ -512,8 +521,12 @@ class CreateObject(EditObject):
|
|||
notify(ObjectCreatedEvent(obj))
|
||||
self.object = obj
|
||||
self.updateFields() # TODO: suppress validation
|
||||
#self.request.response.redirect(self.view.virtualTargetUrl)
|
||||
# TODO: error handling
|
||||
url = self.view.nextUrl
|
||||
if url is None:
|
||||
self.request.response.redirect(self.view.request.URL)
|
||||
if url:
|
||||
self.request.response.redirect(url)
|
||||
return False
|
||||
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
|
||||
|
||||
<metal:block define-macro="create" i18n:domain="loops">
|
||||
<form method="post" enctype="multipart/form-data"
|
||||
<form method="post" enctype="multipart/form-data" id="dialog_form"
|
||||
tal:define="qualifier request/qualifier | string:resource;
|
||||
innerForm request/inner_form | string:inner_form.html;
|
||||
typeToken python: request.get('form.type')
|
||||
|
@ -226,7 +226,7 @@
|
|||
<td colspan="5">
|
||||
<input value="Save" type="submit"
|
||||
i18n:attributes="value"
|
||||
tal:attributes="onClick view/closeAction">
|
||||
tal:attributes="onClick python: view.closeAction(True)">
|
||||
<input type="button" value="Cancel" onClick="dlg.hide();"
|
||||
i18n:attributes="value"
|
||||
tal:attributes="onClick view/closeAction">
|
||||
|
|
|
@ -34,6 +34,18 @@ function submitReplacing(targetId, formId, actionUrl) {
|
|||
return false;
|
||||
}
|
||||
|
||||
function xhrSubmitPopup(formId, actionUrl) {
|
||||
dojo.io.bind({
|
||||
url: actionUrl,
|
||||
formNode: dojo.byId(formId),
|
||||
method: 'post',
|
||||
mimetype: "text/html",
|
||||
load: function(t, d, e) {
|
||||
window.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function submitReplacingOrReloading(targetId, formId, actionUrl) {
|
||||
node = dojo.byId(targetId);
|
||||
var args = {
|
||||
|
|
|
@ -369,13 +369,16 @@ class NodeView(BaseView):
|
|||
|
||||
actions = dict(portlet=getPortletActions)
|
||||
|
||||
nextUrl = None
|
||||
|
||||
@Lazy
|
||||
def popupCreateObjectForm(self):
|
||||
return ("javascript:function%%20openDialog(url){"
|
||||
"window.open('%s/create_object_popup.html"
|
||||
"?title='+document.title+'"
|
||||
"&form.type=.loops/concepts/note&linkUrl='+url,"
|
||||
"'loops_dialog','width=650,height=450,left=300,top=200');;"
|
||||
"&form.type=.loops/concepts/note&fixed_type=yes&linkUrl='+url,"
|
||||
"'loops_dialog',"
|
||||
"'width=650,height=550,left=300,top=200');;"
|
||||
"}"
|
||||
"openDialog(window.location.href);" % self.topMenu.url)
|
||||
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
<tal:block i18n:domain="loops">
|
||||
<div class="body"
|
||||
metal:define-macro="body"
|
||||
tal:define="controller nocall:view/controller;
|
||||
resourceBase controller/resourceBase;">
|
||||
|
||||
<div id="content" metal:define-macro="content" style="padding-left: 2em">
|
||||
<div metal:define-slot="actions"></div>
|
||||
<div metal:define-slot="message"></div>
|
||||
<metal:content define-slot="content">
|
||||
<tal:content define="item nocall:view/item;
|
||||
level level|python: 1;
|
||||
macro item/macro;"
|
||||
condition="macro">
|
||||
<metal:block use-macro="macro" />
|
||||
</tal:content>
|
||||
</metal:content>
|
||||
</div>
|
||||
|
||||
<div id="footer" class="footer" define-macro="footer">
|
||||
<metal:footer define-slot="footer">
|
||||
Powered by <b><a href="http://www.python.org">Python</a></b> ·
|
||||
<b><a href="http://wiki.zope.org/zope3">Zope 3</a></b> ·
|
||||
<b><a href="http://loops.cy55.de">
|
||||
loops</a></b>.
|
||||
</metal:footer>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</tal:block>
|
Loading…
Add table
Reference in a new issue