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
This commit is contained in:
Goffi 2015-11-27 16:45:55 +01:00
commit 6a44221a83

View file

@ -1249,7 +1249,27 @@ def note(message, title='', level=C.XMLUI_DATA_LVL_INFO):
)
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 @@ def deferXMLUI(host, xmlui, action_extra=None, security_limit=C.NO_SECURITY_LIMI
@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)