diff browser_side/menu.py @ 268:79970bf6af93

browser_side: added class RoomAndContactsChooser: - unified UI for all the MUC menu items callbacks to join a room, invite people and start a game
author souliane <souliane@mailoo.org>
date Sun, 17 Nov 2013 17:57:14 +0100
parents 377de26d5bc2
children 0cb9869b42b6
line wrap: on
line diff
--- a/browser_side/menu.py	Sun Nov 17 17:53:37 2013 +0100
+++ b/browser_side/menu.py	Sun Nov 17 17:57:14 2013 +0100
@@ -227,7 +227,7 @@
             else:
                 self.host.bridge.call('addContact', None, edit.getText(), '', _dialog.getSelectedGroups() )
 
-        label = Label("new contact identifier (JID):")
+        label = Label("New contact identifier (JID):")
         edit.setText('@%s' % self.host._defaultDomain)
         edit.setWidth('100%')
         _dialog = dialog.GroupSelector([label, edit], self.host.contact_panel.getGroups(), [],
@@ -291,52 +291,32 @@
 
     #Group menu
     def onJoinRoom(self):
-        _dialog = None
-        _edit = None
 
-        def onOK(sender):
-            if not _edit.getText():
-                Window.alert('You must enter a room jid in the form room@chat.%s' % self.host._defaultDomain)
+        def invite(room_jid, contacts):
+            for contact in contacts:
+                self.host.bridge.call('inviteMUC', None, contact, room_jid)
+
+        def join(room_jid, contacts):
             if self.host.whoami:
                 nick = self.host.whoami.node
-                self.host.bridge.call('joinMUC', None, _edit.getText(), nick)
-            _dialog.hide()
-
-        def onCancel(sender):
-            _dialog.hide()
+                if room_jid not in [room.bare for room in self.host.room_list]:
+                    self.host.bridge.call('joinMUC', lambda room_jid: invite(room_jid, contacts), room_jid, nick)
+                else:
+                    self.host.getOrCreateLiberviaWidget(panels.ChatPanel, (room_jid, "group"), True, JID(room_jid).bare)
+                    invite(room_jid, contacts)
 
-        _main_panel = VerticalPanel()
-        _label = Label("Discussion room:")
-        _edit = TextBox()
-        _edit.setText('sat@chat.jabberfr.org')
-        hpanel = HorizontalPanel()
-        hpanel.add(_label)
-        hpanel.add(_edit)
-        _main_panel.add(hpanel)
-        button_panel = HorizontalPanel()
-        button_panel.addStyleName("marginAuto")
-        button_panel.add(Button("Join", onOK))
-        button_panel.add(Button("Cancel", onCancel))
-        _main_panel.add(button_panel)
-        _dialog = DialogBox(centered=True)
-        _dialog.setHTML('Group discussions')
-        _dialog.setWidget(_main_panel)
-        _dialog.show()
+        dialog.RoomAndContactsChooser(self.host, join, ok_button="Join", visible=(True, False))
 
     def onCollectiveRadio(self):
-        def onContactsSelected(contacts):
-            print("let's go :)")
-            self.host.bridge.call('launchRadioCollective', None, contacts)
-        dialog.ContactsChooser(self.host, onContactsSelected, None, text="Please select contacts to invite").getContacts() 
+        def callback(room_jid, contacts):
+            self.host.bridge.call('launchRadioCollective', None, contacts, room_jid)
+        dialog.RoomAndContactsChooser(self.host, callback, ok_button="Choose", visible=(False, True))
 
     #Game menu
-
     def onTarotGame(self):
-        #Window.alert("Tarot selected")
-        #self.host.tab_panel.add(EmptyPanel(self.host), "Tarot")
-        def onPlayersSelected(other_players):
-            self.host.bridge.call('launchTarotGame', None, other_players)
-        dialog.ContactsChooser(self.host, onPlayersSelected, 3, text="Please select 3 other players").getContacts()
+        def onPlayersSelected(room_jid, other_players):
+            self.host.bridge.call('launchTarotGame', None, other_players, room_jid)
+        dialog.RoomAndContactsChooser(self.host, onPlayersSelected, 3, title_invite="Please select 3 other players", visible=(False, True))
 
     def onXiangqiGame(self):
         Window.alert("A Xiangqi game is planed, but not available yet")