[views,js] remove user_callback feature

Related to #3975260.

authorAurelien Campeas <aurelien.campeas@logilab.fr>
changeset96085e379066
branchdefault
phasepublic
hiddenno
parent revision#88f60d4b9952 [newcube] Make the generated code PEP-8 compliant
child revision#ae8df3692fba [server/test] fix test_zmq
files modified by this revision
doc/3.21.rst
web/data/cubicweb.ajax.js
web/request.py
web/views/ajaxcontroller.py
# HG changeset patch
# User Aurelien Campeas <aurelien.campeas@logilab.fr>
# Date 1402579321 -7200
# Thu Jun 12 15:22:01 2014 +0200
# Node ID 96085e37906612a30b53f8af8622e561a0e2885d
# Parent 88f60d4b9952e3321c5ce2df26b5440fe3ca76b7
[views,js] remove user_callback feature

Related to #3975260.

diff --git a/doc/3.21.rst b/doc/3.21.rst
@@ -0,0 +1,9 @@
1 +What's new in CubicWeb 3.21?
2 +============================
3 +
4 +
5 +Deprecated code drops
6 +---------------------
7 +
8 +* the user_callback api has been removed; people should use plain
9 +  ajax functions instead
diff --git a/web/data/cubicweb.ajax.js b/web/data/cubicweb.ajax.js
@@ -515,63 +515,10 @@
10          document.location.hash = '#header';
11          updateMessage(_("bookmark has been removed"));
12      });
13  }
14 
15 -userCallback = cw.utils.deprecatedFunction(
16 -    '[3.19] use a plain ajaxfunc instead of user callbacks',
17 -    function userCallback(cbname) {
18 -    setProgressCursor();
19 -    var d = loadRemote(AJAX_BASE_URL, ajaxFuncArgs('user_callback', null, cbname));
20 -    d.addCallback(resetCursor);
21 -    d.addErrback(resetCursor);
22 -    d.addErrback(remoteCallFailed);
23 -    return d;
24 -});
25 -
26 -userCallbackThenUpdateUI = cw.utils.deprecatedFunction(
27 -    '[3.19] use a plain ajaxfunc instead of user callbacks',
28 -    function userCallbackThenUpdateUI(cbname, compid, rql, msg, registry, nodeid) {
29 -    var d = userCallback(cbname);
30 -    d.addCallback(function() {
31 -        $('#' + nodeid).loadxhtml(AJAX_BASE_URL, ajaxFuncArgs('render', {'rql': rql},
32 -                                                       registry, compid), null, 'swap');
33 -        if (msg) {
34 -            updateMessage(msg);
35 -        }
36 -    });
37 -});
38 -
39 -userCallbackThenReloadPage = cw.utils.deprecatedFunction(
40 -    '[3.19] use a plain ajaxfunc instead of user callbacks',
41 -    function userCallbackThenReloadPage(cbname, msg) {
42 -    var d = userCallback(cbname);
43 -    d.addCallback(function() {
44 -        window.location.reload();
45 -        if (msg) {
46 -            updateMessage(msg);
47 -        }
48 -    });
49 -});
50 -
51 -/**
52 - * .. function:: unregisterUserCallback(cbname)
53 - *
54 - * unregisters the python function registered on the server's side
55 - * while the page was generated.
56 - */
57 -unregisterUserCallback = cw.utils.deprecatedFunction(
58 -    '[3.19] use a plain ajaxfunc instead of user callbacks',
59 -    function unregisterUserCallback(cbname) {
60 -    setProgressCursor();
61 -    var d = loadRemote(AJAX_BASE_URL, ajaxFuncArgs('unregister_user_callback',
62 -                                            null, cbname));
63 -    d.addCallback(resetCursor);
64 -    d.addErrback(resetCursor);
65 -    d.addErrback(remoteCallFailed);
66 -});
67 -
68 
69  //============= XXX move those functions? ====================================//
70  function openHash() {
71      if (document.location.hash) {
72          var nid = document.location.hash.replace('#', '');
diff --git a/web/request.py b/web/request.py
@@ -1,6 +1,6 @@
73 -# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
74 +# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
75  # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
76  #
77  # This file is part of CubicWeb.
78  #
79  # CubicWeb is free software: you can redistribute it and/or modify it under the
@@ -401,71 +401,10 @@
80          breadcrumbs = self.session.data.get('breadcrumbs')
81          if breadcrumbs:
82              return breadcrumbs.pop()
83          return self.base_url()
84 
85 -    @deprecated('[3.19] use a traditional ajaxfunc / controller')
86 -    def user_rql_callback(self, rqlargs, *args, **kwargs):
87 -        """register a user callback to execute some rql query, and return a URL
88 -        to call that callback which can be inserted in an HTML view.
89 -
90 -        `rqlargs` should be a tuple containing argument to give to the execute function.
91 -
92 -        The first argument following rqlargs must be the message to be
93 -        displayed after the callback is called.
94 -
95 -        For other allowed arguments, see :meth:`user_callback` method
96 -        """
97 -        def rqlexec(req, rql, args=None, key=None):
98 -            req.execute(rql, args, key)
99 -        return self.user_callback(rqlexec, rqlargs, *args, **kwargs)
100 -
101 -    @deprecated('[3.19] use a traditional ajaxfunc / controller')
102 -    def user_callback(self, cb, cbargs, *args, **kwargs):
103 -        """register the given user callback and return a URL which can
104 -        be inserted in an HTML view. When the URL is accessed, the
105 -        callback function will be called (as 'cb(req, \*cbargs)', and a
106 -        message will be displayed in the web interface. The third
107 -        positional argument must be 'msg', containing the message.
108 -
109 -        You can specify the underlying js function to call using a 'jsfunc'
110 -        named args, to one of :func:`userCallback`,
111 -        ':func:`userCallbackThenUpdateUI`, ':func:`userCallbackThenReloadPage`
112 -        (the default). Take care arguments may vary according to the used
113 -        function.
114 -        """
115 -        self.add_js('cubicweb.ajax.js')
116 -        jsfunc = kwargs.pop('jsfunc', 'userCallbackThenReloadPage')
117 -        assert not kwargs, 'dunno what to do with remaining kwargs: %s' % kwargs
118 -        cbname = self.register_onetime_callback(cb, *cbargs)
119 -        return "javascript: %s" % getattr(js, jsfunc)(cbname, *args)
120 -
121 -    @deprecated('[3.19] use a traditional ajaxfunc / controller')
122 -    def register_onetime_callback(self, func, *args):
123 -        cbname = build_cb_uid(func.__name__)
124 -        def _cb(req):
125 -            try:
126 -                return func(req, *args)
127 -            finally:
128 -                self.unregister_callback(self.pageid, cbname)
129 -        self.set_page_data(cbname, _cb)
130 -        return cbname
131 -
132 -    @deprecated('[3.19] use a traditional ajaxfunc / controller')
133 -    def unregister_callback(self, pageid, cbname):
134 -        assert pageid is not None
135 -        assert cbname.startswith('cb_')
136 -        self.info('unregistering callback %s for pageid %s', cbname, pageid)
137 -        self.del_page_data(cbname)
138 -
139 -    @deprecated('[3.19] use a traditional ajaxfunc / controller')
140 -    def clear_user_callbacks(self):
141 -        if self.session is not None: # XXX
142 -            for key in list(self.session.data):
143 -                if key.startswith('cb_'):
144 -                    del self.session.data[key]
145 -
146      # web edition helpers #####################################################
147 
148      @cached # so it's writed only once
149      def fckeditor_config(self):
150          fckeditor_url = self.build_url('fckeditor/fckeditor.js')
diff --git a/web/views/ajaxcontroller.py b/web/views/ajaxcontroller.py
@@ -425,30 +425,10 @@
151  @ajaxfunc(output_type='json')
152  def external_resource(self, resource):
153      """returns the URL of the external resource named `resource`"""
154      return self._cw.uiprops[resource]
155 
156 -@ajaxfunc(output_type='json', check_pageid=True)
157 -def user_callback(self, cbname):
158 -    """execute the previously registered user callback `cbname`.
159 -
160 -    If matching callback is not found, return None
161 -    """
162 -    page_data = self._cw.session.data.get(self._cw.pageid, {})
163 -    try:
164 -        cb = page_data[cbname]
165 -    except KeyError:
166 -        self.warning('unable to find user callback %s', cbname)
167 -        return None
168 -    return cb(self._cw)
169 -
170 -
171 -@ajaxfunc
172 -def unregister_user_callback(self, cbname):
173 -    """unregister user callback `cbname`"""
174 -    self._cw.unregister_callback(self._cw.pageid, cbname)
175 -
176  @ajaxfunc
177  def unload_page_data(self):
178      """remove user's session data associated to current pageid"""
179      self._cw.session.data.pop(self._cw.pageid, None)
180