annotate src/browser/contact_group.py @ 452:7b6506372466

browser_side: fixes bug introduced with previous changeset (1a0cec9b0f1e)
author souliane <souliane@mailoo.org>
date Tue, 20 May 2014 13:00:52 +0200
parents 981ed669d3b3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
1 #!/usr/bin/python
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
3
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 263
diff changeset
4 # Libervia: a Salut à Toi frontend
340
ce5b33f499c5 dates update
Goffi <goffi@goffi.org>
parents: 339
diff changeset
5 # Copyright (C) 2013, 2014 Adrien Cossa <souliane@mailoo.org>
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
6
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 263
diff changeset
7 # This program is free software: you can redistribute it and/or modify
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 263
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 263
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 263
diff changeset
10 # (at your option) any later version.
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
11
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 263
diff changeset
12 # This program is distributed in the hope that it will be useful,
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 263
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 263
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 263
diff changeset
15 # GNU Affero General Public License for more details.
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
16
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 263
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 263
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
19
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
20 from pyjamas.ui.FlexTable import FlexTable
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
21 from pyjamas.ui.DockPanel import DockPanel
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
22 from pyjamas.Timer import Timer
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
23 from pyjamas.ui.Button import Button
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
24 from pyjamas.ui.HorizontalPanel import HorizontalPanel
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
25 from pyjamas.ui.VerticalPanel import VerticalPanel
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
26 from pyjamas.ui.DialogBox import DialogBox
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
27 from pyjamas.ui import HasAlignment
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 432
diff changeset
28
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 432
diff changeset
29 from dialog import ConfirmDialog, InfoDialog
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
30 from list_manager import ListManager
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 432
diff changeset
31 import dialog
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 432
diff changeset
32 import contact
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
33
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
34
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
35 class ContactGroupManager(ListManager):
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
36 """A manager for sub-panels to assign contacts to each group."""
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
37
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
38 def __init__(self, parent, keys_dict, contact_list, offsets, style):
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
39 ListManager.__init__(self, parent, keys_dict, contact_list, offsets, style)
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
40 self.registerPopupMenuPanel(entries={"Remove group": {}},
422
20c508f9b32a browser side: fixed bad use of Timer
Goffi <goffi@goffi.org>
parents: 392
diff changeset
41 callback=lambda sender, key: Timer(5, lambda timer: self.removeContactKey(sender, key)))
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
42
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
43 def removeContactKey(self, sender, key):
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
44 key = sender.getText()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
45
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
46 def confirm_cb(answer):
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
47 if answer:
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
48 ListManager.removeContactKey(self, key)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
49 self._parent.removeKeyFromAddGroupPanel(key)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
50
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
51 _dialog = ConfirmDialog(confirm_cb, text="Do you really want to delete the group '%s'?" % key)
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
52 _dialog.show()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
53
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
54 def removeFromRemainingList(self, contacts):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
55 ListManager.removeFromRemainingList(self, contacts)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
56 self._parent.updateContactList(contacts=contacts)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
57
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
58 def addToRemainingList(self, contacts, ignore_key=None):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
59 ListManager.addToRemainingList(self, contacts, ignore_key)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
60 self._parent.updateContactList(contacts=contacts)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
61
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
62
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
63 class ContactGroupEditor(DockPanel):
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
64 """Panel for the contact groups manager."""
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
65
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
66 def __init__(self, host, parent=None, onCloseCallback=None):
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
67 DockPanel.__init__(self)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
68 self.host = host
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
69
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
70 # eventually display in a popup
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
71 if parent is None:
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
72 parent = DialogBox(autoHide=False, centered=True)
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
73 parent.setHTML("Manage contact groups")
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
74 self._parent = parent
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
75 self._on_close_callback = onCloseCallback
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
76 self.all_contacts = self.host.contact_panel.getContacts()
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
77
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
78 groups_list = self.host.contact_panel.groups.keys()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
79 groups_list.sort()
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
80
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
81 self.add_group_panel = self.getAddGroupPanel(groups_list)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
82 south_panel = self.getCloseSaveButtons()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
83 center_panel = self.getContactGroupManager(groups_list)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
84 east_panel = self.getContactList()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
85
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
86 self.add(self.add_group_panel, DockPanel.CENTER)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
87 self.add(east_panel, DockPanel.EAST)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
88 self.add(center_panel, DockPanel.NORTH)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
89 self.add(south_panel, DockPanel.SOUTH)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
90
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
91 self.setCellHorizontalAlignment(center_panel, HasAlignment.ALIGN_LEFT)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
92 self.setCellVerticalAlignment(center_panel, HasAlignment.ALIGN_TOP)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
93 self.setCellHorizontalAlignment(east_panel, HasAlignment.ALIGN_RIGHT)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
94 self.setCellVerticalAlignment(east_panel, HasAlignment.ALIGN_TOP)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
95 self.setCellVerticalAlignment(self.add_group_panel, HasAlignment.ALIGN_BOTTOM)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
96 self.setCellHorizontalAlignment(self.add_group_panel, HasAlignment.ALIGN_LEFT)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
97 self.setCellVerticalAlignment(south_panel, HasAlignment.ALIGN_BOTTOM)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
98 self.setCellHorizontalAlignment(south_panel, HasAlignment.ALIGN_CENTER)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
99
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
100 # need to be done after the contact list has been initialized
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
101 self.groups.setContacts(self.host.contact_panel.groups)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
102 self.toggleContacts(showAll=True)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
103
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
104 # Hide the contacts list from the main panel to not confuse the user
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
105 self.restore_contact_panel = False
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
106 if self.host.contact_panel.getVisible():
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
107 self.restore_contact_panel = True
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
108 self.host.panel._contactsSwitch()
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
109
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
110 parent.add(self)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
111 parent.setVisible(True)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
112 if isinstance(parent, DialogBox):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
113 parent.center()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
114
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
115 def getContactGroupManager(self, groups_list):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
116 """Set the list manager for the groups"""
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
117 flex_table = FlexTable(len(groups_list), 2)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
118 flex_table.addStyleName('contactGroupEditor')
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
119 # overwrite the default style which has been set for rich text editor
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
120 style = {
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
121 "keyItem": "group",
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
122 "popupMenuItem": "popupMenuItem",
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
123 "removeButton": "contactGroupRemoveButton",
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
124 "buttonCell": "contactGroupButtonCell",
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
125 "keyPanel": "contactGroupPanel"
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
126 }
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
127 self.groups = ContactGroupManager(flex_table, groups_list, self.all_contacts, style=style)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
128 self.groups.createWidgets() # widgets are automatically added to FlexTable
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
129 # FIXME: clean that part which is dangerous
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
130 flex_table.updateContactList = self.updateContactList
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
131 flex_table.removeKeyFromAddGroupPanel = self.add_group_panel.groups.remove
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
132 return flex_table
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
133
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
134 def getAddGroupPanel(self, groups_list):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
135 """Add the 'Add group' panel to the FlexTable"""
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
136
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
137 def add_group_cb(text):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
138 self.groups.addContactKey(text)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
139 self.add_group_panel.textbox.setFocus(True)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
140
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
141 add_group_panel = dialog.AddGroupPanel(groups_list, add_group_cb)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
142 add_group_panel.addStyleName("addContactGroupPanel")
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
143 return add_group_panel
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
144
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
145 def getCloseSaveButtons(self):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
146 """Add the buttons to close the dialog / save the groups"""
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
147 buttons = HorizontalPanel()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
148 buttons.addStyleName("marginAuto")
392
f539f6f8ee9c browser_side: standardize the dialogs size and buttons display:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
149 buttons.add(Button("Save", listener=self.closeAndSave))
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
150 buttons.add(Button("Cancel", listener=self.cancelWithoutSaving))
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
151 return buttons
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
152
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
153 def getContactList(self):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
154 """Add the contact list to the DockPanel"""
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
155 self.toggle = Button("", self.toggleContacts)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
156 self.toggle.addStyleName("toggleAssignedContacts")
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
157 self.contacts = contact.GenericContactList(self.host)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
158 for contact_ in self.all_contacts:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
159 self.contacts.add(contact_)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
160 contact_panel = VerticalPanel()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
161 contact_panel.add(self.toggle)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
162 contact_panel.add(self.contacts)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
163 return contact_panel
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
164
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
165 def toggleContacts(self, sender=None, showAll=None):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
166 """Callback for the toggle button"""
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
167 if sender is None:
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
168 sender = self.toggle
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
169 sender.showAll = showAll if showAll is not None else not sender.showAll
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
170 if sender.showAll:
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
171 sender.setText("Hide assigned")
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
172 else:
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
173 sender.setText("Show assigned")
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
174 self.updateContactList(sender)
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
175
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
176 def updateContactList(self, sender=None, contacts=None):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
177 """Update the contact list regarding the toggle button"""
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
178 if not hasattr(self, "toggle") or not hasattr(self.toggle, "showAll"):
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
179 return
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
180 sender = self.toggle
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
181 if contacts is not None:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
182 if not isinstance(contacts, list):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
183 contacts = [contacts]
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
184 for contact_ in contacts:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
185 if contact_ not in self.all_contacts:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
186 contacts.remove(contact_)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
187 else:
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
188 contacts = self.all_contacts
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
189 for contact_ in contacts:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
190 if sender.showAll:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
191 self.contacts.getContactLabel(contact_).setVisible(True)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
192 else:
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
193 if contact_ in self.groups.remaining_list:
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
194 self.contacts.getContactLabel(contact_).setVisible(True)
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
195 else:
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
196 self.contacts.getContactLabel(contact_).setVisible(False)
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
197
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
198 def __close(self):
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
199 """Remove the widget from parent or close the popup."""
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
200 if isinstance(self._parent, DialogBox):
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
201 self._parent.hide()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
202 self._parent.remove(self)
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
203 if self._on_close_callback is not None:
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
204 self._on_close_callback()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
205 if self.restore_contact_panel:
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
206 self.host.panel._contactsSwitch()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
207
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
208 def cancelWithoutSaving(self):
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
209 """Ask for confirmation before closing the dialog."""
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
210 def confirm_cb(answer):
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
211 if answer:
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
212 self.__close()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
213
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
214 _dialog = ConfirmDialog(confirm_cb, text="Do you really want to cancel without saving?")
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
215 _dialog.show()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
216
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
217 def closeAndSave(self):
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
218 """Call bridge methods to save the changes and close the dialog"""
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
219 map_ = {}
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
220 for contact_ in self.all_contacts:
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
221 map_[contact_] = set()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
222 contacts = self.groups.getContacts()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
223 for group in contacts.keys():
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
224 for contact_ in contacts[group]:
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
225 try:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
226 map_[contact_].add(group)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
227 except KeyError:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
228 InfoDialog("Invalid contact",
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
229 "The contact '%s' is not your contact list but it has been assigned to the group '%s'." % (contact_, group) +
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
230 "Your changes could not be saved: please check your assignments and save again.", Width="400px").center()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
231 return
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
232 for contact_ in map_.keys():
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
233 groups = map_[contact_]
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
234 current_groups = self.host.contact_panel.getContactGroups(contact_)
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
235 if groups != current_groups:
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
236 self.host.bridge.call('updateContact', None, contact_, '', list(groups))
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
237 self.__close()