changeset 1692:0fdd8fe34fbf

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
author Goffi <goffi@goffi.org>
date Fri, 27 Nov 2015 16:45:55 +0100
parents cec204c6360c
children 35426d58471c
files src/tools/xml_tools.py
diffstat 1 files changed, 24 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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)