[Checkins] SVN: z3c.formjs/trunk/ - Feature: Now the
``jsevent.subscribe`` and ``jsaction.handler`` decorators
Stephan Richter
srichter at cosmos.phy.tufts.edu
Wed Jul 25 22:44:56 EDT 2007
Log message for revision 78340:
- Feature: Now the ``jsevent.subscribe`` and ``jsaction.handler`` decorators
can be chained together, allowing them to be called multiple time for the
same methods.
Changed:
U z3c.formjs/trunk/CHANGES.txt
U z3c.formjs/trunk/src/z3c/formjs/jsaction.py
U z3c.formjs/trunk/src/z3c/formjs/jsaction.txt
U z3c.formjs/trunk/src/z3c/formjs/jsevent.py
U z3c.formjs/trunk/src/z3c/formjs/jsevent.txt
U z3c.formjs/trunk/src/z3c/formjs/jsvalidator.txt
-=-
Modified: z3c.formjs/trunk/CHANGES.txt
===================================================================
--- z3c.formjs/trunk/CHANGES.txt 2007-07-25 22:55:36 UTC (rev 78339)
+++ z3c.formjs/trunk/CHANGES.txt 2007-07-26 02:44:55 UTC (rev 78340)
@@ -2,8 +2,19 @@
CHANGES
=======
+
+Version 0.3.0 (?/??/2007)
+-------------------------
+
+- Feature: Now the ``jsevent.subscribe`` and ``jsaction.handler`` decorators
+ can be chained together, allowing them to be called multiple time for the
+ same methods.
+
+- Feature: Implemented ability to switch widget modes on a form.
+
+
Version 0.2.0 (7/18/2007)
---------------------------
+-------------------------
- Feature: Registration of public AJAX server calls via a simple
decorator. The calls are made available via a special ``ajax`` view on the
Modified: z3c.formjs/trunk/src/z3c/formjs/jsaction.py
===================================================================
--- z3c.formjs/trunk/src/z3c/formjs/jsaction.py 2007-07-25 22:55:36 UTC (rev 78339)
+++ z3c.formjs/trunk/src/z3c/formjs/jsaction.py 2007-07-26 02:44:55 UTC (rev 78340)
@@ -155,7 +155,7 @@
f_locals = frame.f_locals
handlers = f_locals.setdefault('jshandlers', JSHandlers())
handlers.addHandler(field, event, handler)
- return handler
+ return func
return createHandler
Modified: z3c.formjs/trunk/src/z3c/formjs/jsaction.txt
===================================================================
--- z3c.formjs/trunk/src/z3c/formjs/jsaction.txt 2007-07-25 22:55:36 UTC (rev 78339)
+++ z3c.formjs/trunk/src/z3c/formjs/jsaction.txt 2007-07-26 02:44:55 UTC (rev 78340)
@@ -396,7 +396,33 @@
a more specific directive takes precendence over the more generic one. This is
due to the built-in adapter registry of the ``JSHandlers`` class.
+Finally, handler declarations can also be chained, allowing a handler to be
+registered for multiple field-event combinations that cannot be expressed by
+common interfaces:
+ >>> class Form(form.Form):
+ ... buttons = button.Buttons(IButtons)
+ ...
+ ... @jsaction.handler(IButtons['hello'], jsevent.CLICK)
+ ... @jsaction.handler(IButtons['hello'], jsevent.DBLCLICK)
+ ... def showHelloWorldMessage(self, event, selector):
+ ... return '''alert("The event '%s' occured.");''' %event.name
+
+ >>> demoform = Form(None, request)
+ >>> demoform.update()
+
+Rendering the subscriptions gives the following result:
+
+ >>> renderer = zope.component.getMultiAdapter(
+ ... (demoform.jsSubscriptions, request), interfaces.IRenderer)
+ >>> renderer.update()
+ >>> print renderer.render()
+ $(document).ready(function(){
+ $("#form-buttons-hello").bind("click", function(){alert("The ...");});
+ $("#form-buttons-hello").bind("dblclick", function(){alert("The ...");});
+ })
+
+
Attaching Events to Form Fields
-------------------------------
Modified: z3c.formjs/trunk/src/z3c/formjs/jsevent.py
===================================================================
--- z3c.formjs/trunk/src/z3c/formjs/jsevent.py 2007-07-25 22:55:36 UTC (rev 78339)
+++ z3c.formjs/trunk/src/z3c/formjs/jsevent.py 2007-07-26 02:44:55 UTC (rev 78340)
@@ -111,7 +111,8 @@
frame = sys._getframe(1)
f_locals = frame.f_locals
subs = f_locals.setdefault('jsSubscriptions', JSSubscriptions())
- return subs.subscribe(event, selector, func)
+ subs.subscribe(event, selector, func)
+ return func
return createSubscription
Modified: z3c.formjs/trunk/src/z3c/formjs/jsevent.txt
===================================================================
--- z3c.formjs/trunk/src/z3c/formjs/jsevent.txt 2007-07-25 22:55:36 UTC (rev 78339)
+++ z3c.formjs/trunk/src/z3c/formjs/jsevent.txt 2007-07-26 02:44:55 UTC (rev 78340)
@@ -151,7 +151,29 @@
$("#myid").bind("dblclick",
function(){alert('`dblclick` event occured on DOM element `myid`');});
+Subscribe-decorators can also be chained, so that the same handler can be used
+for multiple selectors and events:
+ >>> class MyView(object):
+ ...
+ ... @jsevent.subscribe(jsevent.IdSelector('myid'), jsevent.CLICK)
+ ... @jsevent.subscribe(jsevent.IdSelector('myid'), jsevent.DBLCLICK)
+ ... def alertUser(event, selector, request):
+ ... return u"alert('`%s` event occured on DOM element `%s`');" %(
+ ... event.name, selector.id)
+
+In this example we register this handler for both the click and double click
+event for the DOM element with the id "myid".
+
+ >>> list(MyView.jsSubscriptions)
+ [<JSSubscription event=<JSEvent "dblclick">,
+ selector=<IdSelector "myid">,
+ handler=<function alertUser at ...>>,
+ <JSSubscription event=<JSEvent "click">,
+ selector=<IdSelector "myid">,
+ handler=<function alertUser at ...>>]
+
+
Javascript Viewlet
------------------
Modified: z3c.formjs/trunk/src/z3c/formjs/jsvalidator.txt
===================================================================
--- z3c.formjs/trunk/src/z3c/formjs/jsvalidator.txt 2007-07-25 22:55:36 UTC (rev 78339)
+++ z3c.formjs/trunk/src/z3c/formjs/jsvalidator.txt 2007-07-26 02:44:55 UTC (rev 78340)
@@ -66,7 +66,7 @@
>>> from z3c.formjs import jsaction
>>> print edit.fieldValidator(
- ... None, jsaction.WidgetSelector(edit.widgets['zip']), request)
+ ... None, jsaction.WidgetSelector(edit.widgets['zip']))
$.get('/validate', function(data){ alert(data) })
Validators use AJAX handlers to communicate with the server. Commonly the AJAX
More information about the Checkins
mailing list