--- a/doc/book/en/devweb/js.rst Thu Mar 06 13:59:24 2014 +0100
+++ b/doc/book/en/devweb/js.rst Fri Mar 07 10:27:14 2014 +0100
@@ -317,67 +317,6 @@
}
-python/ajax dynamic callbacks
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-CubicWeb provides a way to dynamically register a function and make it
-callable from the javascript side. The typical use case for this is a
-situation where you have everything at hand to implement an action
-(whether it be performing a RQL query or executing a few python
-statements) that you'd like to defer to a user click in the web
-interface. In other words, generate an HTML ``<a href=...`` link that
-would execute your few lines of code.
-
-The trick is to create a python function and store this function in
-the user's session data. You will then be able to access it later.
-While this might sound hard to implement, it's actually quite easy
-thanks to the ``_cw.user_callback()``. This method takes a function,
-registers it and returns a javascript instruction suitable for
-``href`` or ``onclick`` usage. The call is then performed
-asynchronously.
-
-Here's a simplified example taken from the vcreview_ cube that will
-generate a link to change an entity state directly without the
-standard intermediate *comment / validate* step:
-
-.. sourcecode:: python
-
- def entity_call(self, entity):
- # [...]
- def change_state(req, eid):
- entity = req.entity_from_eid(eid)
- entity.cw_adapt_to('IWorkflowable').fire_transition('done')
- url = self._cw.user_callback(change_state, (entity.eid,))
- self.w(tags.input(type='button', onclick=url, value=self._cw._('mark as done')))
-
-
-The ``change_state`` callback function is registered with
-``self._cw.user_callback()`` which returns the ``url`` value directly
-used for the ``onclick`` attribute of the button. On the javascript
-side, the ``userCallback()`` function is used but you most probably
-won't have to bother with it.
-
-Of course, when dealing with session data, the question of session
-cleaning pops up immediately. If you use ``user_callback()``, the
-registered function will be deleted automatically at some point
-as any other session data. If you want your function to be deleted once
-the web page is unloaded or when the user has clicked once on your link, then
-``_cw.register_onetime_callback()`` is what you need. It behaves as
-``_cw.user_callback()`` but stores the function in page data instead
-of global session data.
-
-
-.. Warning::
-
- Be careful when registering functions with closures, keep in mind that
- enclosed data will be kept in memory until the session gets cleared. Also,
- if you keep entities or any object referecing the current ``req`` object, you
- might have problems reusing them later because the underlying session
- might have been closed at the time the callback gets executed.
-
-
-.. _vcreview: http://www.cubicweb.org/project/cubicweb-vcreview
-
Javascript library: overview
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--- a/web/action.py Thu Mar 06 13:59:24 2014 +0100
+++ b/web/action.py Fri Mar 07 10:27:14 2014 +0100
@@ -25,43 +25,11 @@
The most important method from a developper point of view in the
:meth:'Action.url' method, which returns a URL on which the navigation
-should directed to perform the action. There are two common ways of
-writing that method:
-
-* do nothing special and simply return a URL to the current rset with
- a special view (with `self._cw.build_url(...)` for instance)
-
-* define an inner function `callback_func(req, *args)` which will do
- the work and call it through `self._cw.user_callback(callback_func,
- args, msg)`: this method will return a URL which calls the inner
- function, and displays the message in the web interface when the
- callback has completed (and report any exception occuring in the
- callback too)
-
-Many examples of the first approach are available in :mod:`cubicweb.web.views.actions`.
-
-Here is an example of the second approach:
-
-.. sourcecode:: python
+should be directed to perform the action. The common way of
+writing that method is to simply return a URL to the current rset with a
+special view (with `self._cw.build_url(...)` for instance)
- from cubicweb.web import action
- class SomeAction(action.Action):
- __regid__ = 'mycube_some_action'
- title = _(some action)
- __select__ = action.Action.__select__ & is_instance('TargetEntity')
-
- def url(self):
- if self.cw_row is None:
- eids = [row[0] for row in self.cw_rset]
- else:
- eids = (self.cw_rset[self.cw_row][self.cw_col or 0],)
- def do_action(req, eids):
- for eid in eids:
- entity = req.entity_from_eid(eid, 'TargetEntity')
- entity.perform_action()
- msg = self._cw._('some_action performed')
- return self._cw.user_callback(do_action, (eids,), msg)
-
+Many examples are available in :mod:`cubicweb.web.views.actions`.
"""
__docformat__ = "restructuredtext en"