utils.py
changeset 4830 10e8bc190695
parent 4693 1eaf5ce04844
child 4844 ad78b118b124
equal deleted inserted replaced
4829:3b79a0fc91db 4830:10e8bc190695
     9 
     9 
    10 import sys
    10 import sys
    11 import decimal
    11 import decimal
    12 import datetime
    12 import datetime
    13 import random
    13 import random
       
    14 from warnings import warn
    14 
    15 
    15 from logilab.mtconverter import xml_escape
    16 from logilab.mtconverter import xml_escape
    16 from logilab.common.deprecation import deprecated
    17 from logilab.common.deprecation import deprecated
       
    18 
       
    19 _MARKER = object()
    17 
    20 
    18 # initialize random seed from current time
    21 # initialize random seed from current time
    19 random.seed()
    22 random.seed()
    20 
    23 
    21 if sys.version_info[:2] < (2, 5):
    24 if sys.version_info[:2] < (2, 5):
   164         self.jsvars.append( (var, value, override) )
   167         self.jsvars.append( (var, value, override) )
   165 
   168 
   166     def add_post_inline_script(self, content):
   169     def add_post_inline_script(self, content):
   167         self.post_inlined_scripts.append(content)
   170         self.post_inlined_scripts.append(content)
   168 
   171 
   169     def add_onload(self, jscode, jsoncall=False):
   172     def add_onload(self, jscode, jsoncall=_MARKER):
   170         if jsoncall:
   173         if jsoncall is not _MARKER:
   171             self.add_post_inline_script(u"""jQuery(CubicWeb).bind('ajax-loaded', function(event) {
   174             warn('[3.7] specifying jsoncall is not needed anymore',
       
   175                  DeprecationWarning, stacklevel=2)
       
   176         self.add_post_inline_script(u"""jQuery(CubicWeb).one('server-response', function(event) {
   172 %s
   177 %s
   173 });""" % jscode)
   178 });""" % jscode)
   174         else:
       
   175             self.add_post_inline_script(u"""jQuery(document).ready(function () {
       
   176  %s
       
   177  });""" % jscode)
       
   178 
   179 
   179 
   180 
   180     def add_js(self, jsfile):
   181     def add_js(self, jsfile):
   181         """adds `jsfile` to the list of javascripts used in the webpage
   182         """adds `jsfile` to the list of javascripts used in the webpage
   182 
   183