# HG changeset patch # User Goffi # Date 1448639155 -3600 # Node ID 0fdd8fe34fbf06b259f8beb16f2932532bc00657 # Parent cec204c6360c9a409c9db3283f084c2bfda20162 core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling: - this differ from deferXMLUI, as it can be used in ui returned to frontend after a bridge call (deferXMLUI use actionNew only) - the "chained" argument allow to manage series of XMLUIs - this argument is also present in deferXMLUI diff -r cec204c6360c -r 0fdd8fe34fbf src/tools/xml_tools.py --- a/src/tools/xml_tools.py Fri Nov 27 11:21:51 2015 +0100 +++ b/src/tools/xml_tools.py Fri Nov 27 16:45:55 2015 +0100 @@ -1249,7 +1249,27 @@ ) return note_xmlui -def deferXMLUI(host, xmlui, action_extra=None, security_limit=C.NO_SECURITY_LIMIT, profile=C.PROF_KEY_NONE): + +def deferredUI(host, xmlui, chained=False): + r"""Create a deferred linked to XMLUI + + @param xmlui(XMLUI): instance of the XMLUI + Must be an XMLUI that you can submit, with submit_id set to '' + @param chained(bool): True if the Deferred result must be returned to the frontend + useful when backend is in a series of dialogs with an ui + @return (D(data)): a deferred which fire the data + """ + assert xmlui.submit_id == '' + xmlui_d = defer.Deferred() + + def onSubmit(data, profile): + xmlui_d.callback(data) + return xmlui_d if chained else {} + + xmlui.submit_id = host.registerCallback(onSubmit, with_data=True, one_shot=True) + return xmlui_d + +def deferXMLUI(host, xmlui, action_extra=None, security_limit=C.NO_SECURITY_LIMIT, chained=False, profile=C.PROF_KEY_NONE): """Create a deferred linked to XMLUI @param xmlui(XMLUI): instance of the XMLUI @@ -1258,16 +1278,11 @@ @param action_extra(None, dict): extra action to merge with xmlui mainly used to add meta informations (see actionNew doc) @param security_limit: %(doc_security_limit)s + @param chained(bool): True if the Deferred result must be returned to the frontend + useful when backend is in a series of dialogs with an ui @return (data): a deferred which fire the data """ - assert xmlui.submit_id == '' - xmlui_d = defer.Deferred() - - def onSubmit(data, profile): - xmlui_d.callback(data) - return {} - - xmlui.submit_id = host.registerCallback(onSubmit, with_data=True, one_shot=True) + xmlui_d = deferredUI(xmlui) action_data = {'xmlui': xmlui.toXml()} if action_extra is not None: action_data.update(action_extra)