# HG changeset patch # User Sylvain Thénault # Date 1297672637 -3600 # Node ID d62d4ba5ef3e784419747c07ba96d6bb8853a05d # Parent 18343456ee497271d53969e180bf1661ed9eb1d9 [ajax box] fix ajaxBoxShowSelector w/ mono-valued fields + minor cleanups diff -r 18343456ee49 -r d62d4ba5ef3e web/component.py --- 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'') @@ -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'
') jscall = unicode(js.ajaxBoxShowSelector( diff -r 18343456ee49 -r d62d4ba5ef3e web/data/cubicweb.ajax.box.js --- 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();",