comparison src/browser/libervia_main.py @ 718:5745b5e6586a

browser + server sides: actionNew signal handling
author Goffi <goffi@goffi.org>
date Tue, 18 Aug 2015 08:10:02 +0200
parents 3b91225b457a
children 108bb9d74fa2
comparison
equal deleted inserted replaced
717:29b84af2ff7b 718:5745b5e6586a
44 from pyjamas import Window, DOM 44 from pyjamas import Window, DOM
45 45
46 from sat_browser import json 46 from sat_browser import json
47 from sat_browser import register 47 from sat_browser import register
48 from sat_browser.contact_list import ContactList 48 from sat_browser.contact_list import ContactList
49 from sat_browser import widget
50 from sat_browser import main_panel 49 from sat_browser import main_panel
51 from sat_browser import blog 50 from sat_browser import blog
51 from sat_browser import xmlui
52 from sat_browser import dialog 52 from sat_browser import dialog
53 from sat_browser import xmlui
54 from sat_browser import html_tools 53 from sat_browser import html_tools
55 from sat_browser import notification 54 from sat_browser import notification
56 from sat_browser import libervia_widget 55 from sat_browser import libervia_widget
57 56
58 from sat_browser.constants import Const as C 57 from sat_browser.constants import Const as C
71 70
72 # MAX_MBLOG_CACHE = 500 # Max microblog entries kept in memories # FIXME 71 # MAX_MBLOG_CACHE = 500 # Max microblog entries kept in memories # FIXME
73 72
74 73
75 class SatWebFrontend(InputHistory, QuickApp): 74 class SatWebFrontend(InputHistory, QuickApp):
75
76 def onModuleLoad(self): 76 def onModuleLoad(self):
77 log.info("============ onModuleLoad ==============") 77 log.info("============ onModuleLoad ==============")
78 self.bridge_signals = json.BridgeSignals(self) 78 self.bridge_signals = json.BridgeSignals(self)
79 QuickApp.__init__(self, json.BridgeCall) 79 QuickApp.__init__(self, json.BridgeCall, xmlui=xmlui)
80 self._profile_plugged = False 80 self._profile_plugged = False
81 self.signals_cache[C.PROF_KEY_NONE] = [] 81 self.signals_cache[C.PROF_KEY_NONE] = []
82 self.panel = main_panel.MainPanel(self) 82 self.panel = main_panel.MainPanel(self)
83 self.tab_panel = self.panel.tab_panel 83 self.tab_panel = self.panel.tab_panel
84 self.tab_panel.addTabListener(self) 84 self.tab_panel.addTabListener(self)
434 return True 434 return True
435 else: 435 else:
436 # this would eventually set the browser saved password 436 # this would eventually set the browser saved password
437 Timer(5, lambda: self._register_box._form.login_pass_box.setFocus(True)) 437 Timer(5, lambda: self._register_box._form.login_pass_box.setFocus(True))
438 438
439 def _actionCb(self, data): 439 def _actionManagerUnknownError(self):
440 if not data:
441 # action was a one shot, nothing to do
442 pass
443 elif "xmlui" in data:
444 ui = xmlui.create(self, xml_data=data['xmlui'])
445 ui.show()
446 elif "public_blog" in data:
447 # FIXME: remove this, this is not generic !
448 # TODO: use the bare instead of node when all blogs can be retrieved
449 node = jid.JID(data['public_blog']).node
450 # FIXME: "/blog/{}" won't work with unicode nodes
451 self.displayWidget(widget.WebWidget, "/blog/{}".format(node), show_url=False, new_tab=_(u"{}'s blog").format(unicode(node)))
452 else:
453 dialog.InfoDialog("Error",
454 "Unmanaged action result", Width="400px").center()
455
456 def _actionEb(self, err_data):
457 err_code, err_obj = err_data
458 dialog.InfoDialog("Error", 440 dialog.InfoDialog("Error",
459 unicode(err_obj), Width="400px").center() 441 "Unmanaged action result", Width="400px").center()
460
461 def launchAction(self, callback_id, data=None, callback=None, profile=C.PROF_KEY_NONE):
462 """ Launch a dynamic action
463 @param callback_id: id of the action to launch
464 @param data: data needed only for certain actions
465
466 """
467 if data is None:
468 data = {}
469 self.bridge.launchAction(callback_id, data, profile=profile, callback=self._actionCb, errback=self._actionEb)
470 442
471 # def _ownBlogsFills(self, mblogs, mblog_panel=None): 443 # def _ownBlogsFills(self, mblogs, mblog_panel=None):
472 # """Put our own microblogs in cache, then fill the panels with them. 444 # """Put our own microblogs in cache, then fill the panels with them.
473 445
474 # @param mblogs (dict): dictionary mapping a publisher JID to blogs data. 446 # @param mblogs (dict): dictionary mapping a publisher JID to blogs data.
671 else: 643 else:
672 popup = dialog.InfoDialog(unicode(title), unicode(message), callback=answer_cb) 644 popup = dialog.InfoDialog(unicode(title), unicode(message), callback=answer_cb)
673 log.error(_('unmanaged dialog type: %s'), type_) 645 log.error(_('unmanaged dialog type: %s'), type_)
674 popup.show() 646 popup.show()
675 647
648 def dialogFailure(self, failure):
649 dialog.InfoDialog("Error",
650 unicode(failure), Width="400px").center()
651
676 def showFailure(self, err_data, msg=''): 652 def showFailure(self, err_data, msg=''):
677 """Show a failure that has been returned by an asynchronous bridge method. 653 """Show a failure that has been returned by an asynchronous bridge method.
678 654
679 @param failure (defer.Failure): Failure instance 655 @param failure (defer.Failure): Failure instance
680 @param msg (unicode): message to display 656 @param msg (unicode): message to display