[ajax box] fix ajaxBoxShowSelector w/ mono-valued fields + minor cleanups stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 14 Feb 2011 09:37:17 +0100
branchstable
changeset 6987 d62d4ba5ef3e
parent 6986 18343456ee49
child 6989 4a999a647f52
[ajax box] fix ajaxBoxShowSelector w/ mono-valued fields + minor cleanups
web/component.py
web/data/cubicweb.ajax.box.js
--- a/web/component.py	Fri Feb 11 16:45:43 2011 +0100
+++ b/web/component.py	Mon Feb 14 09:37:17 2011 +0100
@@ -577,6 +577,7 @@
         if mayadd or maydel:
             req.add_js(('jquery.ui.js', 'cubicweb.widgets.js'))
             req.add_js(('cubicweb.ajax.js', 'cubicweb.ajax.box.js'))
+            req.add_css('jquery.ui.css')
         _ = req._
         if related:
             w(u'<table class="ajaxEditRelationTable">')
@@ -597,8 +598,6 @@
         else:
             w(_('no related entity'))
         if mayadd:
-            req.add_js(('jquery.ui.js', 'cubicweb.widgets.js'))
-            req.add_css('jquery.ui.css')
             multiple = self.rdef.role_cardinality(self.role) in '*+'
             w(u'<table><tr><td>')
             jscall = unicode(js.ajaxBoxShowSelector(
--- a/web/data/cubicweb.ajax.box.js	Fri Feb 11 16:45:43 2011 +0100
+++ b/web/data/cubicweb.ajax.box.js	Mon Feb 14 09:37:17 2011 +0100
@@ -37,6 +37,26 @@
     });
 }
 
+/**
+ * .. function:: ajaxBoxShowSelector(boxid, eid, unrelfname,
+ *                                  addfname, msg,
+ *                                  oklabel, cancellabel,
+ *                                  separator=None)
+ *
+ * Display an ajax selector within a box of regid `boxid`, for entity with eid
+ * `eid`.
+ *
+ * Other parameters are:
+ *
+ * * `addfname`, name of the json controller method to call to add a relation
+ *
+ * * `msg`, message to display to the user when a relation has been added
+ *
+ * * `oklabel`/`cancellabel`, OK/cancel buttons label
+ *
+ * * `separator`, items separator if the field is multi-valued (will be
+ *   considered mono-valued when not specified)
+ */
 function ajaxBoxShowSelector(boxid, eid,
                              unrelfname,
                              addfname, msg,
@@ -59,11 +79,11 @@
                     ajaxBoxValidateSelectorInput(boxid, eid, separator, addfname, msg);
                 }
             });
-            $input.cwautocomplete(unrelated, {multiple: true});
+            $input.cwautocomplete(unrelated, {multiple: Boolean(separator)});
             var buttons = DIV({'class' : "sgformbuttons"},
                               A({href : "javascript: noop();",
                                  onclick : cw.utils.strFuncCall('ajaxBoxValidateSelectorInput',
-                                                                  boxid, eid, separator, addfname, msg)},
+                                                                boxid, eid, separator, addfname, msg)},
                                 oklabel),
                               ' / ',
                               A({'href' : "javascript: noop();",