[views,js] remove user_callback feature

Related to #3975260.

authorAurelien Campeas <aurelien.campeas@logilab.fr>
changesetab58a125c7ce
branchdefault
phasedraft
hiddenyes
parent revision#f42205d393b7 [shared data] remove get/set_shared_data api
child revision#9ac06f3c92ce Remove remote repository-access-through-pyro support
files modified by this revision
doc/3.21.rst
view.py
web/data/cubicweb.ajax.js
web/request.py
web/views/ajaxcontroller.py
web/views/ajaxedit.py
# HG changeset patch
# User Aurelien Campeas <aurelien.campeas@logilab.fr>
# Date 1402579321 -7200
# Thu Jun 12 15:22:01 2014 +0200
# Node ID ab58a125c7ce906dc376daa71ebc0498f82366b5
# Parent f42205d393b7a6b6956a1a064c43fd4e04a30140
[views,js] remove user_callback feature

Related to #3975260.

diff --git a/doc/3.21.rst b/doc/3.21.rst
@@ -6,6 +6,7 @@
1  ---------------------
2 
3  * the get/set_shared_data api has been removed; people should use
4    transaction_data or session_data instead
5 
6 -
7 +* the user_callback api has been removed; people should use plain
8 +  ajax functions instead
diff --git a/view.py b/view.py
@@ -1,6 +1,6 @@
9 -# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
10 +# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
11  # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
12  #
13  # This file is part of CubicWeb.
14  #
15  # CubicWeb is free software: you can redistribute it and/or modify it under the
@@ -499,32 +499,10 @@
16  # concrete component base classes #############################################
17 
18  class ReloadableMixIn(object):
19      """simple mixin for reloadable parts of UI"""
20 
21 -    def user_callback(self, cb, args, msg=None, nonify=False):
22 -        """register the given user callback and return a URL to call it ready to be
23 -        inserted in html
24 -        """
25 -        self._cw.add_js('cubicweb.ajax.js')
26 -        if nonify:
27 -            _cb = cb
28 -            def cb(*args):
29 -                _cb(*args)
30 -        cbname = self._cw.register_onetime_callback(cb, *args)
31 -        return self.build_js(cbname, xml_escape(msg or ''))
32 -
33 -    def build_update_js_call(self, cbname, msg):
34 -        rql = self.cw_rset.printable_rql()
35 -        return "javascript: %s" % js.userCallbackThenUpdateUI(
36 -            cbname, self.__regid__, rql, msg, self.__registry__, self.domid)
37 -
38 -    def build_reload_js_call(self, cbname, msg):
39 -        return "javascript: %s" % js.userCallbackThenReloadPage(cbname, msg)
40 -
41 -    build_js = build_update_js_call # expect updatable component by default
42 -
43      @property
44      def domid(self):
45          return domid(self.__regid__)
46 
47      @deprecated('[3.10] use .domid property')
diff --git a/web/data/cubicweb.ajax.js b/web/data/cubicweb.ajax.js
@@ -515,63 +515,10 @@
48          document.location.hash = '#header';
49          updateMessage(_("bookmark has been removed"));
50      });
51  }
52 
53 -userCallback = cw.utils.deprecatedFunction(
54 -    '[3.19] use a plain ajaxfunc instead of user callbacks',
55 -    function userCallback(cbname) {
56 -    setProgressCursor();
57 -    var d = loadRemote(AJAX_BASE_URL, ajaxFuncArgs('user_callback', null, cbname));
58 -    d.addCallback(resetCursor);
59 -    d.addErrback(resetCursor);
60 -    d.addErrback(remoteCallFailed);
61 -    return d;
62 -});
63 -
64 -userCallbackThenUpdateUI = cw.utils.deprecatedFunction(
65 -    '[3.19] use a plain ajaxfunc instead of user callbacks',
66 -    function userCallbackThenUpdateUI(cbname, compid, rql, msg, registry, nodeid) {
67 -    var d = userCallback(cbname);
68 -    d.addCallback(function() {
69 -        $('#' + nodeid).loadxhtml(AJAX_BASE_URL, ajaxFuncArgs('render', {'rql': rql},
70 -                                                       registry, compid));
71 -        if (msg) {
72 -            updateMessage(msg);
73 -        }
74 -    });
75 -});
76 -
77 -userCallbackThenReloadPage = cw.utils.deprecatedFunction(
78 -    '[3.19] use a plain ajaxfunc instead of user callbacks',
79 -    function userCallbackThenReloadPage(cbname, msg) {
80 -    var d = userCallback(cbname);
81 -    d.addCallback(function() {
82 -        window.location.reload();
83 -        if (msg) {
84 -            updateMessage(msg);
85 -        }
86 -    });
87 -});
88 -
89 -/**
90 - * .. function:: unregisterUserCallback(cbname)
91 - *
92 - * unregisters the python function registered on the server's side
93 - * while the page was generated.
94 - */
95 -unregisterUserCallback = cw.utils.deprecatedFunction(
96 -    '[3.19] use a plain ajaxfunc instead of user callbacks',
97 -    function unregisterUserCallback(cbname) {
98 -    setProgressCursor();
99 -    var d = loadRemote(AJAX_BASE_URL, ajaxFuncArgs('unregister_user_callback',
100 -                                            null, cbname));
101 -    d.addCallback(resetCursor);
102 -    d.addErrback(resetCursor);
103 -    d.addErrback(remoteCallFailed);
104 -});
105 -
106 
107  //============= XXX move those functions? ====================================//
108  function openHash() {
109      if (document.location.hash) {
110          var nid = document.location.hash.replace('#', '');
diff --git a/web/request.py b/web/request.py
@@ -1,6 +1,6 @@
111 -# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
112 +# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
113  # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
114  #
115  # This file is part of CubicWeb.
116  #
117  # CubicWeb is free software: you can redistribute it and/or modify it under the
@@ -406,71 +406,10 @@
118          breadcrumbs = self.session.data.get('breadcrumbs')
119          if breadcrumbs:
120              return breadcrumbs.pop()
121          return self.base_url()
122 
123 -    def user_rql_callback(self, rqlargs, *args, **kwargs):
124 -        """register a user callback to execute some rql query, and return a URL
125 -        to call that callback which can be inserted in an HTML view.
126 -
127 -        `rqlargs` should be a tuple containing argument to give to the execute function.
128 -
129 -        The first argument following rqlargs must be the message to be
130 -        displayed after the callback is called.
131 -
132 -        For other allowed arguments, see :meth:`user_callback` method
133 -        """
134 -        def rqlexec(req, rql, args=None, key=None):
135 -            req.execute(rql, args, key)
136 -        return self.user_callback(rqlexec, rqlargs, *args, **kwargs)
137 -
138 -    @deprecated('[3.19] use a traditional ajaxfunc / controller')
139 -    def user_callback(self, cb, cbargs, *args, **kwargs):
140 -        """register the given user callback and return a URL which can
141 -        be inserted in an HTML view. When the URL is accessed, the
142 -        callback function will be called (as 'cb(req, \*cbargs)', and a
143 -        message will be displayed in the web interface. The third
144 -        positional argument must be 'msg', containing the message.
145 -
146 -        You can specify the underlying js function to call using a 'jsfunc'
147 -        named args, to one of :func:`userCallback`,
148 -        ':func:`userCallbackThenUpdateUI`, ':func:`userCallbackThenReloadPage`
149 -        (the default). Take care arguments may vary according to the used
150 -        function.
151 -        """
152 -        self.add_js('cubicweb.ajax.js')
153 -        jsfunc = kwargs.pop('jsfunc', 'userCallbackThenReloadPage')
154 -        if 'msg' in kwargs:
155 -            warn('[3.10] msg should be given as positional argument',
156 -                 DeprecationWarning, stacklevel=2)
157 -            args = (kwargs.pop('msg'),) + args
158 -        assert not kwargs, 'dunno what to do with remaining kwargs: %s' % kwargs
159 -        cbname = self.register_onetime_callback(cb, *cbargs)
160 -        return "javascript: %s" % getattr(js, jsfunc)(cbname, *args)
161 -
162 -    def register_onetime_callback(self, func, *args):
163 -        cbname = build_cb_uid(func.__name__)
164 -        def _cb(req):
165 -            try:
166 -                return func(req, *args)
167 -            finally:
168 -                self.unregister_callback(self.pageid, cbname)
169 -        self.set_page_data(cbname, _cb)
170 -        return cbname
171 -
172 -    def unregister_callback(self, pageid, cbname):
173 -        assert pageid is not None
174 -        assert cbname.startswith('cb_')
175 -        self.info('unregistering callback %s for pageid %s', cbname, pageid)
176 -        self.del_page_data(cbname)
177 -
178 -    def clear_user_callbacks(self):
179 -        if self.session is not None: # XXX
180 -            for key in list(self.session.data):
181 -                if key.startswith('cb_'):
182 -                    del self.session.data[key]
183 -
184      # web edition helpers #####################################################
185 
186      @cached # so it's writed only once
187      def fckeditor_config(self):
188          fckeditor_url = self.build_url('fckeditor/fckeditor.js')
diff --git a/web/views/ajaxcontroller.py b/web/views/ajaxcontroller.py
@@ -425,30 +425,10 @@
189  @ajaxfunc(output_type='json')
190  def external_resource(self, resource):
191      """returns the URL of the external resource named `resource`"""
192      return self._cw.uiprops[resource]
193 
194 -@ajaxfunc(output_type='json', check_pageid=True)
195 -def user_callback(self, cbname):
196 -    """execute the previously registered user callback `cbname`.
197 -
198 -    If matching callback is not found, return None
199 -    """
200 -    page_data = self._cw.session.data.get(self._cw.pageid, {})
201 -    try:
202 -        cb = page_data[cbname]
203 -    except KeyError:
204 -        self.warning('unable to find user callback %s', cbname)
205 -        return None
206 -    return cb(self._cw)
207 -
208 -
209 -@ajaxfunc
210 -def unregister_user_callback(self, cbname):
211 -    """unregister user callback `cbname`"""
212 -    self._cw.unregister_callback(self._cw.pageid, cbname)
213 -
214  @ajaxfunc
215  def unload_page_data(self):
216      """remove user's session data associated to current pageid"""
217      self._cw.session.data.pop(self._cw.pageid, None)
218 
diff --git a/web/views/ajaxedit.py b/web/views/ajaxedit.py
@@ -1,6 +1,6 @@
219 -# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
220 +# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
221  # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
222  #
223  # This file is part of CubicWeb.
224  #
225  # CubicWeb is free software: you can redistribute it and/or modify it under the
@@ -34,12 +34,10 @@
226      __select__ = (match_form_params('rtype', 'target')
227                    | match_kwargs('rtype', 'target'))
228      cw_property_defs = {} # don't want to inherit this from Box
229      expected_kwargs = form_params = ('rtype', 'target')
230 
231 -    build_js = component.EditRelationMixIn.build_reload_js_call
232 -
233      def cell_call(self, row, col, rtype=None, target=None, etype=None):
234          self.rtype = rtype or self._cw.form['rtype']
235          self.target = target or self._cw.form['target']
236          self.etype = etype or self._cw.form.get('etype')
237          entity = self.cw_rset.get_entity(row, col)