comparison src/tools/xml_tools.py @ 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 f1da3a8d08ce
children cf11cfc87ef9
comparison
equal deleted inserted replaced
1691:cec204c6360c 1692:0fdd8fe34fbf
1247 C.XMLUI_DATA_LVL: level}, 1247 C.XMLUI_DATA_LVL: level},
1248 title=title 1248 title=title
1249 ) 1249 )
1250 return note_xmlui 1250 return note_xmlui
1251 1251
1252 def deferXMLUI(host, xmlui, action_extra=None, security_limit=C.NO_SECURITY_LIMIT, profile=C.PROF_KEY_NONE): 1252
1253 def deferredUI(host, xmlui, chained=False):
1254 r"""Create a deferred linked to XMLUI
1255
1256 @param xmlui(XMLUI): instance of the XMLUI
1257 Must be an XMLUI that you can submit, with submit_id set to ''
1258 @param chained(bool): True if the Deferred result must be returned to the frontend
1259 useful when backend is in a series of dialogs with an ui
1260 @return (D(data)): a deferred which fire the data
1261 """
1262 assert xmlui.submit_id == ''
1263 xmlui_d = defer.Deferred()
1264
1265 def onSubmit(data, profile):
1266 xmlui_d.callback(data)
1267 return xmlui_d if chained else {}
1268
1269 xmlui.submit_id = host.registerCallback(onSubmit, with_data=True, one_shot=True)
1270 return xmlui_d
1271
1272 def deferXMLUI(host, xmlui, action_extra=None, security_limit=C.NO_SECURITY_LIMIT, chained=False, profile=C.PROF_KEY_NONE):
1253 """Create a deferred linked to XMLUI 1273 """Create a deferred linked to XMLUI
1254 1274
1255 @param xmlui(XMLUI): instance of the XMLUI 1275 @param xmlui(XMLUI): instance of the XMLUI
1256 Must be an XMLUI that you can submit, with submit_id set to '' 1276 Must be an XMLUI that you can submit, with submit_id set to ''
1257 @param profile: %(doc_profile)s 1277 @param profile: %(doc_profile)s
1258 @param action_extra(None, dict): extra action to merge with xmlui 1278 @param action_extra(None, dict): extra action to merge with xmlui
1259 mainly used to add meta informations (see actionNew doc) 1279 mainly used to add meta informations (see actionNew doc)
1260 @param security_limit: %(doc_security_limit)s 1280 @param security_limit: %(doc_security_limit)s
1281 @param chained(bool): True if the Deferred result must be returned to the frontend
1282 useful when backend is in a series of dialogs with an ui
1261 @return (data): a deferred which fire the data 1283 @return (data): a deferred which fire the data
1262 """ 1284 """
1263 assert xmlui.submit_id == '' 1285 xmlui_d = deferredUI(xmlui)
1264 xmlui_d = defer.Deferred()
1265
1266 def onSubmit(data, profile):
1267 xmlui_d.callback(data)
1268 return {}
1269
1270 xmlui.submit_id = host.registerCallback(onSubmit, with_data=True, one_shot=True)
1271 action_data = {'xmlui': xmlui.toXml()} 1286 action_data = {'xmlui': xmlui.toXml()}
1272 if action_extra is not None: 1287 if action_extra is not None:
1273 action_data.update(action_extra) 1288 action_data.update(action_extra)
1274 host.actionNew(action_data, security_limit=security_limit, keep_id=xmlui.submit_id, profile=profile) 1289 host.actionNew(action_data, security_limit=security_limit, keep_id=xmlui.submit_id, profile=profile)
1275 return xmlui_d 1290 return xmlui_d