Mercurial > libervia-web
annotate src/browser/sat_browser/contact_group.py @ 608:ea27925ef2a8 frontends_multi_profiles
merges souliane changes
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 09 Feb 2015 21:58:49 +0100 |
parents | 32dbbc941123 |
children | e0021d571eef |
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 | 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 import dialog |
467 | 30 import list_manager |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
31 import contact_list |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
32 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
33 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
34 unicode = str # FIXME: pyjamas workaround |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
35 |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
36 |
467 | 37 class ContactGroupManager(list_manager.ListManager): |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
38 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
39 def __init__(self, container, keys, contacts, offsets, style): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
40 """ |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
41 @param container (FlexTable): FlexTable parent widget |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
42 @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
|
43 keys to their display config data. |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
44 @param contacts (list): list of contacts |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
45 @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
|
46 - "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
|
47 - "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
|
48 - "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
|
49 @param style (dict): define CSS styles |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
50 """ |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
51 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
|
52 self.registerPopupMenuPanel(entries={"Remove group": {}}, |
422
20c508f9b32a
browser side: fixed bad use of Timer
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
53 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
|
54 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
55 def removeContactKey(self, sender, key): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
56 key = sender.getText() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
57 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
58 def confirm_cb(answer): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
59 if answer: |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
60 list_manager.ListManager.removeItemKey(self, key) |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
61 self.container.removeKeyFromAddGroupPanel(key) |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
62 |
467 | 63 _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
|
64 _dialog.show() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
65 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
66 def removeFromRemainingList(self, contacts): |
467 | 67 list_manager.ListManager.removeFromRemainingList(self, contacts) |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
68 self.container.updateContactList(contacts) |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
69 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
70 def addToRemainingList(self, contacts, ignore_key=None): |
467 | 71 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
|
72 self.container.updateContactList(contacts) |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
73 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
74 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
75 class ContactGroupEditor(DockPanel): |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
76 """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
|
77 |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
78 def __init__(self, host, container=None, onCloseCallback=None): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
79 """ |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
80 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
81 @param host (SatWebFrontend) |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
82 @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
|
83 @param onCloseCallback (callable) |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
84 """ |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
85 DockPanel.__init__(self) |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
86 self.host = host |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
87 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
88 # eventually display in a popup |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
89 if container is None: |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
90 container = DialogBox(autoHide=False, centered=True) |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
91 container.setHTML("Manage contact groups") |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
92 self.container = container |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
93 self._on_close_callback = onCloseCallback |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
94 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 roster_groups = roster_entities_by_group.keys() |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
99 roster_groups.sort() |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
100 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
101 self.add_group_panel = self.initAddGroupPanel(roster_groups) |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
102 south_panel = self.initCloseSaveButtons() |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
103 center_panel = self.initContactGroupManager(roster_groups) |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
104 east_panel = self.initContactList() |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
105 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
106 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
|
107 self.add(east_panel, DockPanel.EAST) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
108 self.add(center_panel, DockPanel.NORTH) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
109 self.add(south_panel, DockPanel.SOUTH) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
110 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
120 # 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
|
121 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
|
122 self.toggleContacts(showAll=True) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
123 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
124 # 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
|
125 self.restore_contact_panel = False |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
126 clist = self.host.contact_list |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
127 if clist.getVisible(): |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
128 self.restore_contact_panel = True |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
129 self.host.panel._contactsSwitch() |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
130 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
131 container.add(self) |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
132 container.setVisible(True) |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
133 if isinstance(container, DialogBox): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
134 container.center() |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
135 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
136 def initContactGroupManager(self, groups): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
137 """Initialise the contact group manager. |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
138 |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
139 @param groups (list[unicode]): contact groups |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
140 """ |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
141 flex_table = FlexTable() |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
142 flex_table.addStyleName('contactGroupEditor') |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
143 |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
144 # 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
|
145 style = {"keyItem": "group", |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
146 "popupMenuItem": "popupMenuItem", |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
147 "removeButton": "contactGroupRemoveButton", |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
148 "buttonCell": "contactGroupButtonCell", |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
149 "keyPanel": "contactGroupPanel" |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
150 } |
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 groups = {group: {} for group in groups} |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
153 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
|
154 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
|
155 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
156 # 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
|
157 flex_table.updateContactList = self.updateContactList |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
158 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
|
159 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
160 return flex_table |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
161 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
162 def initAddGroupPanel(self, groups): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
163 """Initialise the 'Add group' panel. |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
164 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
165 @param groups (list[unicode]): contact groups |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
166 """ |
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 def add_group_cb(key): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
169 self.groups.addItemKey(key) |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
170 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
|
171 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
172 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
|
173 add_group_panel.addStyleName("addContactGroupPanel") |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
174 return add_group_panel |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
175 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
176 def initCloseSaveButtons(self): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
177 """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
|
178 buttons = HorizontalPanel() |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
179 buttons.addStyleName("marginAuto") |
392
f539f6f8ee9c
browser_side: standardize the dialogs size and buttons display:
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
180 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
|
181 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
|
182 return buttons |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
183 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
184 def initContactList(self): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
185 """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
|
186 self.toggle = Button("", self.toggleContacts) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
187 self.toggle.addStyleName("toggleAssignedContacts") |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
188 self.contacts = contact_list.BaseContactsPanel(self.host) |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
189 for contact in self.all_contacts: |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
190 self.contacts.add(contact) |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
191 contact_panel = VerticalPanel() |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
192 contact_panel.add(self.toggle) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
193 contact_panel.add(self.contacts) |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
194 return contact_panel |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
195 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
196 def toggleContacts(self, sender=None, showAll=None): |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
197 """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
|
198 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
199 @param sender (Button) |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
200 @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
|
201 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
|
202 """ |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
203 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
|
204 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
|
205 self.updateContactList() |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
206 |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
207 def updateContactList(self, contacts=None): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
208 """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
|
209 button and the "contacts" attribute. |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
210 |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
211 @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
|
212 """ |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
213 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
|
214 return |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
215 if contacts is not None: |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
216 to_remove = set() |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
217 for contact in contacts: |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
218 if contact not in self.all_contacts: |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
219 to_remove.add(contact) |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
220 for contact in to_remove: |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
221 contacts.remove(contact) |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
222 else: |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
223 contacts = self.all_contacts |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
224 for contact in contacts: |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
225 if self.toggle.showAll: |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
226 self.contacts.getContactBox(contact).setVisible(True) |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
227 else: |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
228 if contact in self.groups.items_remaining: |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
229 self.contacts.getContactBox(contact).setVisible(True) |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
230 else: |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
231 self.contacts.getContactBox(contact).setVisible(False) |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
232 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
233 def __close(self): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
234 """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
|
235 if isinstance(self.container, DialogBox): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
236 self.container.hide() |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
237 self.container.remove(self) |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
238 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
|
239 self._on_close_callback() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
240 if self.restore_contact_panel: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
241 self.host.panel._contactsSwitch() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
242 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
243 def cancelWithoutSaving(self): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
244 """Ask for confirmation before closing the dialog.""" |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
245 def confirm_cb(answer): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
246 if answer: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
247 self.__close() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
248 |
467 | 249 _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
|
250 _dialog.show() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
251 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
252 def closeAndSave(self): |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
253 """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
|
254 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
|
255 old_entities = old_groups_by_entity.keys() |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
256 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
|
257 entities = groups_by_entity.keys() |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
258 |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
259 for invalid in entities.difference(self.all_contacts): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
260 dialog.InfoDialog("Invalid contact(s)", |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
261 "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
|
262 "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
|
263 return |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
264 |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
265 for entity in old_entities.difference(entities): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
266 self.host.bridge.call('updateContact', None, unicode(entity), '', []) |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
267 |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
268 for entity, groups in groups_by_entity.iteritems(): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
269 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
|
270 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
|
271 self.__close() |