changeset 431:4fcf9bac109c

browser_side: roster management menus are now imported from the backend
author souliane <souliane@mailoo.org>
date Mon, 07 Apr 2014 23:31:21 +0200
parents a927a98b398d
children 8ecc5a7062e4
files browser_side/menu.py
diffstat 1 files changed, 6 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/menu.py	Thu Apr 03 15:49:01 2014 +0200
+++ b/browser_side/menu.py	Mon Apr 07 23:31:21 2014 +0200
@@ -106,14 +106,12 @@
             except KeyError:
                 menu_bar = menus_dict[menu_name] = MenuBar(vertical=True)
                 menus_order.append((menu_name, menu_name_i18n, icon))
-            menu_bar.addItem(item_name_i18n, menu_cmd)
+            if item_name_i18n and menu_cmd:
+                menu_bar.addItem(item_name_i18n, menu_cmd)
 
         addMenu("General", _("General"), _("Web widget"), 'home', MenuCmd(self, "onWebWidget"))
         addMenu("General", _("General"), _("Disconnect"), 'home', MenuCmd(self, "onDisconnect"))
-        addMenu("Contacts", _("Contacts"), _("Add contact"), 'social', MenuCmd(self, "onAddContact"))
-        addMenu("Contacts", _("Contacts"), _("Update contact"), 'social', MenuCmd(self, "onUpdateContact"))
-        addMenu("Contacts", _("Contacts"), _("Remove contact"), 'social', MenuCmd(self, "onRemoveContact"))
-        addMenu("Contacts", _("Contacts"), _("Manage groups"), 'social', MenuCmd(self, "onManageContactGroups"))
+        addMenu("Contacts", _("Contacts"), None, 'social', None)
         addMenu("Groups", _("Groups"), _("Discussion"), 'social', MenuCmd(self, "onJoinRoom"))
         addMenu("Groups", _("Groups"), _("Collective radio"), 'social', MenuCmd(self, "onCollectiveRadio"))
         addMenu("Games", _("Games"), _("Tarot"), 'games', MenuCmd(self, "onTarotGame"))
@@ -136,6 +134,9 @@
             item_name_i18n = ' | '.join(path_i18n[1:])
             addMenu(menu_name, menu_name_i18n, item_name_i18n, 'plugins', PluginMenuCmd(self.host, action_id))
 
+        # menu items that should be displayed after the automatically added ones
+        addMenu("Contacts", _("Contacts"), _("Manage groups"), 'social', MenuCmd(self, "onManageContactGroups"))
+
         menus_order.append(None)  # we add separator
 
         addMenu("Help", _("Help"), _("Social contract"), 'help', MenuCmd(self, "onSocialContract"))
@@ -194,72 +195,6 @@
         _dialog.show()
 
     #Contact menu
-    def onAddContact(self):
-        """Q&D contact addition"""
-        _dialog = None
-        edit = TextBox()
-
-        def addContactCb(sender):
-            if not re.match(r'^.+@.+\..+', edit.getText(), re.IGNORECASE):
-                Window.alert('You must enter a valid contact JID (like "contact@%s")' % self.host._defaultDomain)
-                _dialog.show()
-            else:
-                self.host.bridge.call('addContact', None, edit.getText(), '', _dialog.getSelectedGroups())
-
-        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(), [],
-                                       "Add", addContactCb)
-        _dialog.setHTML('Adding contact')
-        _dialog.show()
-
-    def onUpdateContact(self):
-        _dialog = None
-        _contacts_list = ListBox()
-
-        def updateContactCb(sender):
-            _jid = _contacts_list.getValue(_contacts_list.getSelectedIndex())
-            self.host.bridge.call('updateContact', None, _jid, '', _dialog.getSelectedGroups())
-
-        def onContactChange(_list):
-            _jid = _contacts_list.getValue(_contacts_list.getSelectedIndex())
-            groups = self.host.contact_panel.getContactGroups(_jid)
-            _dialog.setGroupsSelected(groups)
-
-        for contact in self.host.contact_panel.getContacts():
-            _contacts_list.addItem(contact)
-        _contacts_list.addChangeListener(onContactChange)
-        _jid = _contacts_list.getValue(_contacts_list.getSelectedIndex())
-        _selected_groups = self.host.contact_panel.getContactGroups(_jid)
-        _dialog = dialog.GroupSelector([Label('Which contact do you want to update ?'), _contacts_list],
-                                       self.host.contact_panel.getGroups(), _selected_groups,
-                                       "Update", updateContactCb)
-        _dialog.setHTML('Updating contact')
-        _dialog.show()
-
-    def onRemoveContact(self):
-        _dialog = None
-        _contacts_list = ListBox()
-
-        def secondConfirmCb(confirm):
-            if confirm:
-                for contact in _contacts_list.getSelectedValues():
-                    self.host.bridge.call('delContact', None, contact)
-            else:
-                _dialog.show()
-
-        def dialogCb(confirm):
-            if confirm:
-                html_list = ''.join(['<li>%s</li>' % html_sanitize(contact) for contact in _contacts_list.getSelectedValues()])
-                html_body = "Are you sure to remove the following contacts from your contact list ?<ul>%s</ul>" % html_list
-                dialog.ConfirmDialog(secondConfirmCb, html_body).show()
-
-        for contact in self.host.contact_panel.getContacts():
-            _contacts_list.addItem(contact)
-        _dialog = dialog.GenericConfirmDialog([_contacts_list], dialogCb, "Who do you want to remove from your contacts ?")
-        _dialog.show()
-
     def onManageContactGroups(self):
         """Open the contact groups manager."""