annotate src/browser/sat_browser/contact_group.py @ 704:5319110a862c

server_side: static blog uses the default template
author souliane <souliane@mailoo.org>
date Thu, 04 Jun 2015 12:39:27 +0200
parents 16079280a39e
children fe3c2357a8c9
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
685
9877607c719a 2015 copyright dates update
Goffi <goffi@goffi.org>
parents: 648
diff changeset
5 # Copyright (C) 2013, 2014, 2015 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 import dialog
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
30 import list_manager
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
31 import contact_panel
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
32 import contact_list
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
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
35 unicode = str # FIXME: pyjamas workaround
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
36
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
37
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
38 class ContactGroupManager(list_manager.ListManager):
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
39
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
40 def __init__(self, container, keys, contacts, offsets, style):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
41 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
42 @param container (FlexTable): FlexTable parent widget
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
43 @param keys (dict{unicode: dict{unicode: unicode}}): dict binding items
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
44 keys to their display config data.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
45 @param contacts (list): list of contacts
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
46 @param offsets (dict): define widgets positions offsets within container:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
47 - "x_first": the x offset for the first widget's row on the grid
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
48 - "x": the x offset for all widgets rows, except the first one if "x_first" is defined
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
49 - "y": the y offset for all widgets columns on the grid
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
50 @param style (dict): define CSS styles
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
51 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
52 list_manager.ListManager.__init__(self, container, keys, contacts, offsets, style)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
53 self.registerPopupMenuPanel(entries={"Remove group": {}},
422
20c508f9b32a browser side: fixed bad use of Timer
Goffi <goffi@goffi.org>
parents: 392
diff changeset
54 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
55
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
56 def removeContactKey(self, sender, key):
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
57 key = sender.getText()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
58
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
59 def confirm_cb(answer):
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
60 if answer:
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
61 list_manager.ListManager.removeItemKey(self, key)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
62 self.container.removeKeyFromAddGroupPanel(key)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
63
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
64 _dialog = dialog.ConfirmDialog(confirm_cb, text="Do you really want to delete the group '%s'?" % key)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
65 _dialog.show()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
66
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
67 def removeFromRemainingList(self, contacts):
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
68 list_manager.ListManager.removeFromRemainingList(self, contacts)
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
69 self.container.updateContactList(contacts)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
70
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
71 def addToRemainingList(self, contacts, ignore_key=None):
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
72 list_manager.ListManager.addToRemainingList(self, contacts, ignore_key)
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
73 self.container.updateContactList(contacts)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
74
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
75
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
76 class ContactGroupEditor(DockPanel):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
77 """A big panel including a ContactGroupManager and other UI stuff."""
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
78
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
79 def __init__(self, host, container=None, onCloseCallback=None):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
80 """
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
81
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
82 @param host (SatWebFrontend)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
83 @param container (PanelBase): parent panel or None to display in a popup
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
84 @param onCloseCallback (callable)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
85 """
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
86 DockPanel.__init__(self)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
87 self.host = host
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
88
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
89 # eventually display in a popup
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
90 if container is None:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
91 container = DialogBox(autoHide=False, centered=True)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
92 container.setHTML("Manage contact groups")
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
93 self.container = container
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
94 self._on_close_callback = onCloseCallback
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
95
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
96 self.all_contacts = contact_list.JIDList(self.host.contact_list.roster_entities)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
97 roster_entities_by_group = self.host.contact_list.roster_entities_by_group
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
98 del roster_entities_by_group[None] # remove the empty group
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
99 roster_groups = roster_entities_by_group.keys()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
100 roster_groups.sort()
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
101
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
102 self.add_group_panel = self.initAddGroupPanel(roster_groups)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
103 south_panel = self.initCloseSaveButtons()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
104 center_panel = self.initContactGroupManager(roster_groups)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
105 east_panel = self.initContactList()
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
106
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
107 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
108 self.add(east_panel, DockPanel.EAST)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
109 self.add(center_panel, DockPanel.NORTH)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
110 self.add(south_panel, DockPanel.SOUTH)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
111
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
112 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
113 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
114 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
115 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
116 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
117 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
118 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
119 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
120
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
121 # need to be done after the contact list has been initialized
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
122 self.groups.resetItems(roster_entities_by_group)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
123 self.toggleContacts(showAll=True)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
124
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
125 # 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
126 self.restore_contact_panel = False
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
127 clist = self.host.contact_list
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
128 if clist.getVisible():
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
129 self.restore_contact_panel = True
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
130 self.host.panel._contactsSwitch()
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
131
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
132 container.add(self)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
133 container.setVisible(True)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
134 if isinstance(container, DialogBox):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
135 container.center()
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
136
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
137 def initContactGroupManager(self, groups):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
138 """Initialise the contact group manager.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
139
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
140 @param groups (list[unicode]): contact groups
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
141 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
142 flex_table = FlexTable()
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
143 flex_table.addStyleName('contactGroupEditor')
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
144
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
145 # overwrite the default style which has been set for rich text editor
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
146 style = {"keyItem": "group",
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
147 "popupMenuItem": "popupMenuItem",
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
148 "removeButton": "contactGroupRemoveButton",
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
149 "buttonCell": "contactGroupButtonCell",
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
150 "keyPanel": "contactGroupPanel"
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
151 }
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
152
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
153 groups = {group: {} for group in groups}
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
154 self.groups = ContactGroupManager(flex_table, groups, self.all_contacts, style=style)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
155 self.groups.createWidgets() # widgets are automatically added to the FlexTable
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
156
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
157 # 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
158 flex_table.updateContactList = self.updateContactList
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
159 flex_table.removeKeyFromAddGroupPanel = self.add_group_panel.groups.remove
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
160
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
161 return flex_table
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
162
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
163 def initAddGroupPanel(self, groups):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
164 """Initialise the 'Add group' panel.
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
165
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
166 @param groups (list[unicode]): contact groups
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
167 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
168
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
169 def add_group_cb(key):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
170 self.groups.addItemKey(key)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
171 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
172
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
173 add_group_panel = dialog.AddGroupPanel(groups, add_group_cb)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
174 add_group_panel.addStyleName("addContactGroupPanel")
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
175 return add_group_panel
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
176
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
177 def initCloseSaveButtons(self):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
178 """Add the buttons to close the dialog and save the groups."""
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
179 buttons = HorizontalPanel()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
180 buttons.addStyleName("marginAuto")
392
f539f6f8ee9c browser_side: standardize the dialogs size and buttons display:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
181 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
182 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
183 return buttons
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
184
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
185 def initContactList(self):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
186 """Add the contact list to the DockPanel."""
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
187 self.toggle = Button("", self.toggleContacts)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
188 self.toggle.addStyleName("toggleAssignedContacts")
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
189 self.contacts = contact_panel.ContactsPanel(self.host)
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
190 for contact in self.all_contacts:
691
16079280a39e browser_side: minor fixes for ContactMenuBar and ContactGroupManager
souliane <souliane@mailoo.org>
parents: 687
diff changeset
191 self.contacts.updateContactBox(contact)
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
192 panel = VerticalPanel()
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
193 panel.add(self.toggle)
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
194 panel.add(self.contacts)
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
195 return panel
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
196
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
197 def toggleContacts(self, sender=None, showAll=None):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
198 """Toggle the button to show contacts and the contact list.
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
199
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
200 @param sender (Button)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
201 @param showAll (bool): if set, initialise with True to show all contacts
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
202 or with False to show only the ones that are not assigned yet.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
203 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
204 self.toggle.showAll = (not self.toggle.showAll) if showAll is None else showAll
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
205 self.toggle.setText("Hide assigned" if self.toggle.showAll else "Show assigned")
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
206 self.updateContactList()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
207
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
208 def updateContactList(self, contacts=None):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
209 """Update the contact list's items visibility, depending of the toggle
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
210 button and the "contacts" attribute.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
211
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
212 @param contacts (list): contacts to be updated, or None to update all.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
213 """
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
214 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
215 return
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
216 if contacts is not None:
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
217 to_remove = set()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
218 for contact in contacts:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
219 if contact not in self.all_contacts:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
220 to_remove.add(contact)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
221 for contact in to_remove:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
222 contacts.remove(contact)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
223 else:
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
224 contacts = self.all_contacts
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
225 for contact in contacts:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
226 if self.toggle.showAll:
687
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
227 self.contacts.updateContactBox(contact).setVisible(True)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
228 else:
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
229 if contact in self.groups.items_remaining:
687
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
230 self.contacts.updateContactBox(contact).setVisible(True)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
231 else:
687
3845a086f0b3 browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents: 685
diff changeset
232 self.contacts.updateContactBox(contact).setVisible(False)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
233
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
234 def __close(self):
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
235 """Remove the widget from parent or close the popup."""
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
236 if isinstance(self.container, DialogBox):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
237 self.container.hide()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
238 self.container.remove(self)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
239 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
240 self._on_close_callback()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
241 if self.restore_contact_panel:
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
242 self.host.panel._contactsSwitch()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
243
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
244 def cancelWithoutSaving(self):
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
245 """Ask for confirmation before closing the dialog."""
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
246 def confirm_cb(answer):
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
247 if answer:
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
248 self.__close()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
249
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
250 _dialog = dialog.ConfirmDialog(confirm_cb, text="Do you really want to cancel without saving?")
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
251 _dialog.show()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
252
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
253 def closeAndSave(self):
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
254 """Call bridge methods to save the changes and close the dialog"""
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
255 old_groups_by_entity = contact_list.JIDDict(self.host.contact_list.roster_groups_by_entity)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
256 old_entities = old_groups_by_entity.keys()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
257 groups_by_entity = contact_list.JIDDict(self.groups.getKeysByItem())
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
258 entities = groups_by_entity.keys()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
259
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
260 for invalid in entities.difference(self.all_contacts):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
261 dialog.InfoDialog("Invalid contact(s)",
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
262 "The contact '%s' is not in your contact list but has been assigned to: '%s'." % (invalid, "', '".join(groups_by_entity[invalid])) +
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
263 "Your changes could not be saved: please check your assignments and save again.", Width="400px").center()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
264 return
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
265
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
266 for entity in old_entities.difference(entities):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
267 self.host.bridge.call('updateContact', None, unicode(entity), '', [])
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
268
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
269 for entity, groups in groups_by_entity.iteritems():
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
270 if entity not in old_groups_by_entity or groups != old_groups_by_entity[entity]:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 589
diff changeset
271 self.host.bridge.call('updateContact', None, unicode(entity), '', list(groups))
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
272 self.__close()