merge stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 03 Jul 2009 18:02:24 +0200
branchstable
changeset 2262 d0cec91ff4c5
parent 2259 5d90bd26af8b (diff)
parent 2261 7e635be2c4b2 (current diff)
child 2263 1f59cd5b710f
merge
--- a/utils.py	Fri Jul 03 16:55:16 2009 +0200
+++ b/utils.py	Fri Jul 03 18:02:24 2009 +0200
@@ -206,8 +206,13 @@
     def add_post_inline_script(self, content):
         self.post_inlined_scripts.append(content)
 
-    def add_onload(self, jscode):
-        self.add_post_inline_script(u"""jQuery(document).ready(function () {
+    def add_onload(self, jscode, jsoncall=False):
+        if jsoncall:
+            self.add_post_inline_script(u"""jQuery(CubicWeb).bind('ajax-loaded', function(event) {
+%s
+});""" % jscode)
+        else:
+            self.add_post_inline_script(u"""jQuery(document).ready(function () {
  %s
  });""" % jscode)
 
--- a/web/component.py	Fri Jul 03 16:55:16 2009 +0200
+++ b/web/component.py	Fri Jul 03 18:02:24 2009 +0200
@@ -6,6 +6,7 @@
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
 __docformat__ = "restructuredtext en"
+_ = unicode
 
 from logilab.common.deprecation import class_renamed
 from logilab.mtconverter import html_escape
@@ -18,7 +19,6 @@
     partial_has_related_entities, condition_compat, accepts_compat,
     has_relation_compat)
 
-_ = unicode
 
 class EntityVComponent(Component):
     """abstract base class for additinal components displayed in content
--- a/web/data/cubicweb.ajax.js	Fri Jul 03 16:55:16 2009 +0200
+++ b/web/data/cubicweb.ajax.js	Fri Jul 03 18:02:24 2009 +0200
@@ -11,15 +11,20 @@
 
 function _loadAjaxHtmlHead(node, head, tag, srcattr) {
     var loaded = [];
-    jQuery('head ' + tag).each(function(i) {
+    var jqtagfilter = tag + '[' + srcattr + ']';
+    jQuery('head ' + jqtagfilter).each(function(i) {
 	loaded.push(this.getAttribute(srcattr));
     });
     node.find(tag).each(function(i) {
-	if (!loaded.contains(this.getAttribute(srcattr))) {
+	if (this.getAttribute(srcattr)) {
+	    if (!loaded.contains(this.getAttribute(srcattr))) {
+		jQuery(this).appendTo(head);
+	    }
+	} else {
 	    jQuery(this).appendTo(head);
 	}
     });
-    node.find(tag).remove();
+    node.find(jqtagfilter).remove();
 }
 
 /*
--- a/web/request.py	Fri Jul 03 16:55:16 2009 +0200
+++ b/web/request.py	Fri Jul 03 18:02:24 2009 +0200
@@ -61,6 +61,7 @@
 
 class CubicWebRequestBase(DBAPIRequest):
     """abstract HTTP request, should be extended according to the HTTP backend"""
+    json_request = False # to be set to True by json controllers
 
     def __init__(self, vreg, https, form=None):
         super(CubicWebRequestBase, self).__init__(vreg)
@@ -452,6 +453,9 @@
 
     # high level methods for HTML headers management ##########################
 
+    def add_onload(self, jscode):
+        self.html_headers.add_onload(jscode, self.json_request)
+
     def add_js(self, jsfiles, localfile=True):
         """specify a list of JS files to include in the HTML headers
         :param jsfiles: a JS filename or a list of JS filenames
--- a/web/views/basecontrollers.py	Fri Jul 03 16:55:16 2009 +0200
+++ b/web/views/basecontrollers.py	Fri Jul 03 18:02:24 2009 +0200
@@ -196,7 +196,7 @@
     except NoSelectableObject:
         return (False, {None: req._('not authorized')})
     try:
-        ctrl.publish(None, fromjson=True)
+        ctrl.publish(None)
     except ValidationError, ex:
         req.cnx.rollback()
         return (False, _validation_error(req, ex))
@@ -219,6 +219,7 @@
     id = 'validateform'
 
     def publish(self, rset=None):
+        self.req.json_request = True
         # XXX unclear why we have a separated controller here vs
         # js_validate_form on the json controller
         status, args = _validate_form(self.req, self.vreg)
@@ -243,6 +244,7 @@
         note: it's the responsability of js_* methods to set the correct
         response content type
         """
+        self.req.json_request = True
         self.req.pageid = self.req.form.get('pageid')
         try:
             fname = self.req.form['fname']
--- a/web/views/editcontroller.py	Fri Jul 03 16:55:16 2009 +0200
+++ b/web/views/editcontroller.py	Fri Jul 03 18:02:24 2009 +0200
@@ -25,9 +25,8 @@
 class EditController(ViewController):
     id = 'edit'
 
-    def publish(self, rset=None, fromjson=False):
+    def publish(self, rset=None):
         """edit / create / copy / delete entity / relations"""
-        self.fromjson = fromjson
         for key in self.req.form:
             # There should be 0 or 1 action
             if key.startswith('__action_'):
@@ -113,9 +112,8 @@
                 entity = execute(rql, formparams).get_entity(0, 0)
                 eid = entity.eid
             except ValidationError, ex:
-                # ex.entity may be an int or an entity instance
                 self._to_create[formparams['eid']] = ex.entity
-                if self.fromjson:
+                if self.req.json_request: # XXX (syt) why?
                     ex.entity = formparams['eid']
                 raise
             self._to_create[formparams['eid']] = eid
--- a/web/views/navigation.py	Fri Jul 03 16:55:16 2009 +0200
+++ b/web/views/navigation.py	Fri Jul 03 18:02:24 2009 +0200
@@ -6,6 +6,7 @@
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
 __docformat__ = "restructuredtext en"
+_ = unicode
 
 from rql.nodes import VariableRef, Constant
 
@@ -19,8 +20,6 @@
 from cubicweb.common.uilib import cut
 from cubicweb.web.component import EntityVComponent, NavigationComponent
 
-_ = unicode
-
 
 class PageNavigation(NavigationComponent):
 
--- a/web/views/tabs.py	Fri Jul 03 16:55:16 2009 +0200
+++ b/web/views/tabs.py	Fri Jul 03 18:02:24 2009 +0200
@@ -24,7 +24,7 @@
     """
 
     def _prepare_bindings(self, vid, reloadable):
-        self.req.html_headers.add_onload(u"""
+        self.req.add_onload(u"""
   jQuery('#lazy-%(vid)s').bind('%(event)s', function(event) {
      load_now('#lazy-%(vid)s', '#%(vid)s-hole', %(reloadable)s);
   });""" % {'event': 'load_%s' % vid, 'vid': vid,
@@ -59,7 +59,7 @@
         on dom readyness
         """
         self.req.add_js('cubicweb.lazy.js')
-        self.req.html_headers.add_onload("trigger_load('%s');" % vid)
+        self.req.add_onload("trigger_load('%s');" % vid)
 
 
 class TabsMixin(LazyViewMixin):
@@ -143,7 +143,7 @@
             w(u'</div>')
         # call the set_tab() JS function *after* each tab is generated
         # because the callback binding needs to be done before
-        self.req.html_headers.add_onload(u"""
+        self.req.add_onload(u"""
    jQuery('#entity-tabs-%(eeid)s > ul').tabs( { selected: %(tabindex)s });
    set_tab('%(vid)s', '%(cookiename)s');
  """ % {'tabindex'   : tabs.index(active_tab),