[Checkins] SVN: Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/
made jsbuttons work\!
Paul Carduner
paulcarduner at gmail.com
Thu Jun 7 05:45:55 EDT 2007
Log message for revision 76450:
made jsbuttons work\!
Changed:
U Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/README.txt
U Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/browser/button_input.pt
U Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/jsbutton.py
-=-
Modified: Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/README.txt
===================================================================
--- Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/README.txt 2007-06-07 09:29:19 UTC (rev 76449)
+++ Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/README.txt 2007-06-07 09:45:55 UTC (rev 76450)
@@ -99,11 +99,11 @@
... prefix = 'form'
...
... @jsbutton.handler(IButtons['apply'])
- ... def apply(self, action):
+ ... def apply(self):
... return 'alert("You Clicked the Apply Button!");'
...
... @jsbutton.handler(IButtons['cancel'], event=jsevent.DBLCLICK)
- ... def cancel(self, action):
+ ... def cancel(self):
... return 'alert("You Double Clicked the Cancel Button!");'
Notice that the jsbutton.handler decorator takes the keyword argument
@@ -165,17 +165,18 @@
widget. We can now render each action:
>>> print actions['apply'].render()
- <input type="button" id="form.buttons.apply"
+ <input type="button" id="form-buttons-apply"
name="form.buttons.apply" class="buttonWidget"
- value="Apply"
- onClick="alert("You Clicked the Apply Button!");"/>
+ value="Apply" />
+ <script type="text/javascript">$("#form-buttons-apply").bind("click", function(){alert("You Clicked the Apply Button!");});</script>
>>> print actions['cancel'].render()
- <input type="button" id="form.buttons.apply"
- name="form.buttons.apply" class="buttonWidget"
- value="Apply"
- onDblClick="alert("You Double Clicked the Cancel Button!");"/>
+ <input type="button" id="form-buttons-cancel"
+ name="form.buttons.cancel" class="buttonWidget"
+ value="Cancel" />
+ <script type="text/javascript">$("#form-buttons-cancel").bind("dblclick", function(){alert("You Double Clicked the Cancel Button!");});</script>
+
=======
Widgets
Modified: Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/browser/button_input.pt
===================================================================
--- Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/browser/button_input.pt 2007-06-07 09:29:19 UTC (rev 76449)
+++ Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/browser/button_input.pt 2007-06-07 09:45:55 UTC (rev 76450)
@@ -7,5 +7,5 @@
accesskey view/accesskey;
" />
<script type="text/javascript"
- tal:content="structure view/eventHandler">
+ tal:content="view/eventHandler">
</script>
\ No newline at end of file
Modified: Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/jsbutton.py
===================================================================
--- Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/jsbutton.py 2007-06-07 09:29:19 UTC (rev 76449)
+++ Sandbox/pcardune/z3cFormJS/trunk/src/z3c/formjs/jsbutton.py 2007-06-07 09:45:55 UTC (rev 76450)
@@ -22,12 +22,13 @@
import zope.schema
import zope.interface
import zope.location
+import zope.component
from z3c.form import button, util, action, widget
from z3c.form.interfaces import (IButton, IFieldWidget, IValue,
IButtonHandlers, IFormLayer, IButtonForm)
-import interfaces
+import interfaces, jsevent
class ButtonWidget(widget.Widget):
@@ -73,12 +74,17 @@
class Handler(object):
zope.interface.implements(interfaces.IJSButtonHandler)
- def __init__(self, button, func):
+ def __init__(self, button, func, event=jsevent.CLICK):
self.button = button
self.func = func
+ self.event = event
def __call__(self):
- return self.func()
+ ## TODO: Passing None makes the tests work because the handler
+ ## functions take self as the first arg. Instead of passing
+ ## None, I should be passing the form the handler is defined
+ ## in - but how do I get this from here?
+ return self.func(None)
def __repr__(self):
return '<%s for %r>' %(self.__class__.__name__, self.button)
@@ -87,7 +93,7 @@
def handler(button, **kwargs):
"""A decoratore for defining a javascript event handler."""
def createHandler(func):
- handler = Handler(button, func)
+ handler = Handler(button, func, event=kwargs.get('event', jsevent.CLICK))
frame = sys._getframe(1)
f_locals = frame.f_locals
jshandlers = f_locals.setdefault('jshandlers', Handlers())
@@ -116,13 +122,14 @@
def id(self):
return self.name.replace('.', '-')
- @property
def eventHandler(self):
actions = self.__parent__
- handler = actions.form.handlers.getHandler(self.field)
+ handler = actions.form.jshandlers.getHandler(self.field)
if handler is None:
return
- return handler()
+ renderer = zope.component.getMultiAdapter((handler.event, self.request),
+ interfaces.IJSEventRenderer)
+ return renderer.render(handler, self.id)
class JSButtonActions(util.Manager):
More information about the Checkins
mailing list