Mercurial > libervia-web
annotate src/browser/sat_browser/contact_group.py @ 982:a78169c1bf77
pages (tickets/new): added reporter_jid in ignore list (if needed, it is filled in backend)
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 15 Nov 2017 09:00:00 +0100 |
parents | 5d9f6d25c586 |
children |
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 |
818 | 5 # Copyright (C) 2013-2016 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.Button import Button |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
21 from pyjamas.ui.CheckBox import CheckBox |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
22 from pyjamas.ui.Label import Label |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
23 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
24 from pyjamas.ui.VerticalPanel import VerticalPanel |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
25 from pyjamas.ui.DialogBox import DialogBox |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
26 from pyjamas.ui.ScrollPanel import ScrollPanel |
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 |
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 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
33 from sat_frontends.tools import jid |
256
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 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
36 unicode = str # FIXME: pyjamas workaround |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
37 |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
38 |
467 | 39 class ContactGroupManager(list_manager.ListManager): |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
40 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
41 def __init__(self, editor, data, contacts, offsets): |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
42 """ |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
43 @param container (FlexTable): FlexTable parent widget |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
44 @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
|
45 keys to their display config data. |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
46 @param contacts (list): list of contacts |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
47 """ |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
48 self.editor = editor |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
49 list_manager.ListManager.__init__(self, data, contacts) |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
50 self.registerPopupMenuPanel(entries={"Remove group": {}}, |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
51 callback=lambda sender, key: self.removeGroup(sender)) |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
52 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
53 def removeGroup(self, sender): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
54 group = sender.getHTML() |
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 confirm_cb(answer): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
57 if answer: |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
58 list_manager.ListManager.removeList(self, group) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
59 self.editor.add_group_panel.groups.remove(group) |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
60 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
61 _dialog = dialog.ConfirmDialog(confirm_cb, text="Do you really want to delete the group '%s'?" % group) |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
62 _dialog.show() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
63 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
64 def tag(self, contacts): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
65 list_manager.ListManager.tag(self, contacts) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
66 self.editor.updateContactList(contacts) |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
67 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
68 def untag(self, contacts, ignore_key=None): |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
69 list_manager.ListManager.untag(self, contacts, ignore_key) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
70 self.editor.updateContactList(contacts) |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
71 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
72 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
73 class ContactGroupEditor(VerticalPanel): |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
74 """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
|
75 |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
76 def __init__(self, host, container=None, onCloseCallback=None): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
77 """ |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
78 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
79 @param host (SatWebFrontend) |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
80 @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
|
81 @param onCloseCallback (callable) |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
82 """ |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
83 VerticalPanel.__init__(self, StyleName="contactGroupEditor") |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
84 self.host = host |
263
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 # eventually display in a popup |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
87 if container is None: |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
88 container = DialogBox(autoHide=False, centered=True) |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
89 container.setHTML("Manage contact groups") |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
90 self.container = container |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
91 self._on_close_callback = onCloseCallback |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
92 |
944 | 93 self.all_contacts = contact_list.JIDList(self.host.contact_list.roster) |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
94 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
|
95 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
|
96 roster_groups = roster_entities_by_group.keys() |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
97 roster_groups.sort() |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
98 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
99 # groups on the left |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
100 manager = self.initContactGroupManager(roster_entities_by_group) |
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) |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
102 left_container = VerticalPanel(Width="100%") |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
103 left_container.add(manager) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
104 left_container.add(self.add_group_panel) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
105 left_container.setCellHorizontalAlignment(self.add_group_panel, HasAlignment.ALIGN_CENTER) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
106 left_panel = ScrollPanel(left_container, StyleName="contactGroupManager") |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
107 left_panel.setAlwaysShowScrollBars(True) |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
108 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
109 # contact list on the right |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
110 east_panel = ScrollPanel(self.initContactList(), StyleName="contactGroupRoster") |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
111 east_panel.setAlwaysShowScrollBars(True) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
112 |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
113 south_panel = self.initCloseSaveButtons() |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
114 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
115 main_panel = HorizontalPanel() |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
116 main_panel.add(left_panel) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
117 main_panel.add(east_panel) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
118 self.add(Label("You get here an over whole view of your contact groups. There are two ways to assign your contacts to an existing group: write them into auto-completed textboxes or use the right panel to drag and drop them into the group.")) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
119 self.add(main_panel) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
120 self.add(south_panel) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
121 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
122 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
|
123 |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
124 # need to be done after the contact list has been initialized |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
125 self.updateContactList() |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
126 |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
127 # 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
|
128 self.restore_contact_panel = False |
944 | 129 clist = self.host.contact_list_widget |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
130 if clist.getVisible(): |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
131 self.restore_contact_panel = True |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
132 self.host.panel._contactsSwitch() |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
133 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
134 container.add(self) |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
135 container.setVisible(True) |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
136 if isinstance(container, DialogBox): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
137 container.center() |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
138 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
139 def initContactGroupManager(self, data): |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
140 """Initialise the contact group manager. |
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 @param groups (list[unicode]): contact groups |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
143 """ |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
144 self.groups = ContactGroupManager(self, data, self.all_contacts) |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
145 return self.groups |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
146 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
147 def initAddGroupPanel(self, groups): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
148 """Initialise the 'Add group' panel. |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
149 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
150 @param groups (list[unicode]): contact groups |
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 def add_group_cb(key): |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
154 self.groups.addList(key) |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
155 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
|
156 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
157 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
|
158 add_group_panel.addStyleName("addContactGroupPanel") |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
159 return add_group_panel |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
160 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
161 def initCloseSaveButtons(self): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
162 """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
|
163 buttons = HorizontalPanel() |
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
164 buttons.addStyleName("marginAuto") |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
165 buttons.add(Button("Cancel", listener=self.cancelWithoutSaving)) |
392
f539f6f8ee9c
browser_side: standardize the dialogs size and buttons display:
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
166 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
|
167 return buttons |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
168 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
169 def initContactList(self): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
170 """Add the contact list to the DockPanel.""" |
944 | 171 |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
172 self.toggle = CheckBox("Hide assigned contacts") |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
173 self.toggle.addClickListener(lambda dummy: self.updateContactList()) |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
174 self.toggle.addStyleName("toggleAssignedContacts") |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
175 self.contacts = contact_panel.ContactsPanel(self.host) |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
176 for contact in self.all_contacts: |
691
16079280a39e
browser_side: minor fixes for ContactMenuBar and ContactGroupManager
souliane <souliane@mailoo.org>
parents:
687
diff
changeset
|
177 self.contacts.updateContactBox(contact) |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
178 panel = VerticalPanel() |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
179 panel.add(self.toggle) |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
180 panel.add(self.contacts) |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
181 return panel |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
182 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
183 def updateContactList(self, contacts=None): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
184 """Update the contact list's items visibility, depending of the toggle |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
185 checkbox and the "contacts" attribute. |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
186 |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
187 @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
|
188 """ |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
189 if not hasattr(self, "toggle"): |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
190 return |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
191 if contacts is not None: |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
192 contacts = [jid.JID(contact) for contact in contacts] |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
193 contacts = set(contacts).intersection(self.all_contacts) |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
194 else: |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
195 contacts = self.all_contacts |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
196 |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
197 for contact in contacts: |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
198 if not self.toggle.getChecked(): # show all contacts |
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
|
199 self.contacts.updateContactBox(contact).setVisible(True) |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
200 else: # show only non-assigned contacts |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
201 if contact in self.groups.untagged: |
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
|
202 self.contacts.updateContactBox(contact).setVisible(True) |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
203 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
|
204 self.contacts.updateContactBox(contact).setVisible(False) |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
205 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
206 def __close(self): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
207 """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
|
208 if isinstance(self.container, DialogBox): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
209 self.container.hide() |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
210 self.container.remove(self) |
256
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
211 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
|
212 self._on_close_callback() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
213 if self.restore_contact_panel: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
214 self.host.panel._contactsSwitch() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
215 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
216 def cancelWithoutSaving(self): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
217 """Ask for confirmation before closing the dialog.""" |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
218 def confirm_cb(answer): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
219 if answer: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
220 self.__close() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
221 |
467 | 222 _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
|
223 _dialog.show() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
224 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
225 def closeAndSave(self): |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
256
diff
changeset
|
226 """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
|
227 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
|
228 old_entities = old_groups_by_entity.keys() |
736
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
229 result = {jid.JID(item): keys for item, keys in self.groups.getKeysByItem().iteritems()} |
fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
691
diff
changeset
|
230 groups_by_entity = contact_list.JIDDict(result) |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
231 entities = groups_by_entity.keys() |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
232 |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
233 for invalid in entities.difference(self.all_contacts): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
234 dialog.InfoDialog("Invalid contact(s)", |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
235 "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
|
236 "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
|
237 return |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
238 |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
239 for entity in old_entities.difference(entities): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
240 self.host.bridge.call('updateContact', None, unicode(entity), '', []) |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
241 |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
242 for entity, groups in groups_by_entity.iteritems(): |
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
243 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
|
244 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
|
245 self.__close() |