Mercurial > libervia-web
annotate browser_side/contact_group.py @ 261:3df0c3634c29
browser side: management of extra data for sendMblogComment, allowing to send rich text for comments
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 15 Nov 2013 15:34:57 +0100 |
parents | 0e7f3944bd27 |
children | d3c734669577 |
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 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
4 """ |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
5 Libervia: a Salut à Toi frontend |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
6 Copyright (C) 2013 Adrien Cossa <souliane@mailoo.org> |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
7 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
8 This program is free software: you can redistribute it and/or modify |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
11 (at your option) any later version. |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
12 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
13 This program is distributed in the hope that it will be useful, |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
16 GNU Affero General Public License for more details. |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
17 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
20 """ |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
21 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
22 from pyjamas.ui.FlexTable import FlexTable |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
23 from browser_side.dialog import ConfirmDialog |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
24 from list_manager import ListManager |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
25 import contact |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
26 from pyjamas.Timer import Timer |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
27 from pyjamas.ui.Button import Button |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
28 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
29 from pyjamas.ui.VerticalPanel import VerticalPanel |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
30 from pyjamas.ui.DialogBox import DialogBox |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
31 import dialog |
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 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
34 class ContactGroupManager(ListManager): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
35 """A manager for sub-panels to assign contacts to each group.""" |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
36 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
37 def __init__(self, parent, keys_dict, contact_list, offsets, style): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
38 ListManager.__init__(self, parent, keys_dict, contact_list, offsets, style) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
39 self.registerPopupMenuPanel(entries={"Remove group": {}}, |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
40 callback=lambda sender, key: Timer(5, lambda: self.removeContactKey(sender, key))) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
41 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
42 def removeContactKey(self, sender, key): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
43 key = sender.getText() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
44 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
45 def confirm_cb(answer): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
46 if answer: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
47 (y, x) = self._parent.getIndex(self.__children[key]["button"]) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
48 self._parent.removeCell(y, x + 1) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
49 self._parent.removeCell(y, x) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
50 del self.__keys_dict[key] |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
51 del self.__children[key] |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
52 self._parent.add_group_panel.groups.remove(key) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
53 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
54 _dialog = ConfirmDialog(confirm_cb, text="Do you really want to delete the group '%s'?" % key) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
55 _dialog.show() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
56 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
57 def removeFromRemainingList(self, contact_): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
58 ListManager.removeFromRemainingList(self, contact_) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
59 self._parent.updateContactList(contact_=contact_) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
60 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
61 def addToRemainingList(self, contact_): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
62 ListManager.addToRemainingList(self, contact_) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
63 self._parent.updateContactList(contact_=contact_) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
64 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
65 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
66 class ContactGroupEditor(FlexTable): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
67 """Panel for the contact groups manager.""" |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
68 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
69 def __init__(self, host, parent=None, onCloseCallback=None): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
70 # This must be done before FlexTable.__init__ because it is used by setVisible |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
71 self.host = host |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
72 if parent is None: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
73 parent = DialogBox(autoHide=False, centered=True) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
74 parent.setHTML("Manage contact groups") |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
75 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
76 self._parent = parent |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
77 self._on_close_callback = onCloseCallback |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
78 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
79 groups_list = self.host.contact_panel.groups.keys() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
80 groups_list.sort() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
81 FlexTable.__init__(self, len(groups_list) + 2, 3) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
82 self.addStyleName('contactGroupEditor') |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
83 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
84 def cb(text): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
85 nb_keys = len(self.groups.keys) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
86 self.getFlexCellFormatter().setColSpan(nb_keys + 1, 0, 1) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
87 self.getFlexCellFormatter().setColSpan(nb_keys + 2, 0, 1) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
88 self.remove(self.add_group_panel) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
89 self.remove(self.command) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
90 self.groups.addContactKey(text) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
91 refresh() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
92 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
93 # overwrite the default style which has been set for rich text editor |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
94 style = { |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
95 "keyItem": "group", |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
96 "popupMenuItem": "popupMenuItem", |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
97 "removeButton": "contactGroupRemoveButton", |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
98 "buttonCell": "contactGroupButtonCell", |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
99 "keyPanel": "contactGroupPanel" |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
100 } |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
101 self.all_contacts = self.host.contact_panel.getContacts() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
102 self.groups = ContactGroupManager(self, groups_list, self.all_contacts, style=style) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
103 self.groups.createWidgets() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
104 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
105 self.add_group_panel = dialog.AddGroupPanel(groups_list, cb) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
106 self.add_group_panel.addStyleName("addContactGroupPanel") |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
107 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
108 self.command = HorizontalPanel() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
109 self.command.addStyleName("marginAuto") |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
110 self.command.add(Button("Cancel", listener=self.cancelWithoutSaving)) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
111 self.command.add(Button("Save", listener=self.closeAndSave)) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
112 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
113 contact_panel = VerticalPanel() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
114 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
115 # checkbox has been replaced by a button |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
116 self.checkbox = Button("", self.toggleContacts) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
117 self.checkbox.getChecked = lambda: self.checkbox.checked if hasattr(self.checkbox, "checked") else None |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
118 self.checkbox.addStyleName("toggleAssignedContacts") |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
119 contact_panel.add(self.checkbox) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
120 self.contacts = contact.GenericContactList(host) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
121 contact_panel.add(self.contacts) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
122 for contact in self.all_contacts: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
123 self.contacts.add(contact) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
124 self.setWidget(0, 2, contact_panel) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
125 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
126 def refresh(): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
127 nb_keys = len(self.groups.keys) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
128 self.getFlexCellFormatter().setColSpan(nb_keys + 1, 0, 2) # add group panel |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
129 self.setWidget(nb_keys + 1, 0, self.add_group_panel) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
130 self.getFlexCellFormatter().setColSpan(nb_keys + 2, 0, 3) # buttons panel |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
131 self.setWidget(nb_keys + 2, 0, self.command) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
132 self.getFlexCellFormatter().setRowSpan(0, 2, nb_keys + 2) # contact list |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
133 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
134 self.groups.setContacts(self.host.contact_panel.groups) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
135 refresh() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
136 self.restore_contact_panel = False |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
137 if self.host.contact_panel.getVisible(): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
138 self.restore_contact_panel = True |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
139 self.host.panel._contactsSwitch() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
140 self.toggleContacts() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
141 parent.add(self) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
142 parent.setVisible(True) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
143 if isinstance(parent, DialogBox): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
144 parent.center() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
145 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
146 def toggleContacts(self, sender=None): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
147 if sender is None: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
148 sender = self.checkbox |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
149 if sender.getChecked(): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
150 sender.checked = False |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
151 sender.setText("Hide assigned") |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
152 else: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
153 sender.checked = True |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
154 sender.setText("Show assigned") |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
155 self.updateContactList(sender) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
156 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
157 def updateContactList(self, sender=None, contact_=None): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
158 sender = self.checkbox |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
159 if sender.getChecked() is None: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
160 # do not update during initialization |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
161 return |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
162 if contact_ is not None: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
163 if contact_ not in self.all_contacts or not sender.getChecked(): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
164 return |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
165 all_contacts = [contact_] |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
166 else: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
167 all_contacts = self.all_contacts |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
168 for contact_ in all_contacts: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
169 if sender.getChecked(): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
170 if contact_ in self.groups.remaining_list: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
171 self.contacts.getContactLabel(contact_).setVisible(True) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
172 else: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
173 self.contacts.getContactLabel(contact_).setVisible(False) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
174 else: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
175 self.contacts.getContactLabel(contact_).setVisible(True) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
176 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
177 def __close(self): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
178 """Remove the widget from parent or close the popup.""" |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
179 if isinstance(self._parent, DialogBox): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
180 self._parent.hide() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
181 self._parent.remove(self) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
182 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
|
183 self._on_close_callback() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
184 if self.restore_contact_panel: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
185 self.host.panel._contactsSwitch() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
186 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
187 def cancelWithoutSaving(self): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
188 """Ask for confirmation before closing the dialog.""" |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
189 def confirm_cb(answer): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
190 if answer: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
191 self.__close() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
192 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
193 _dialog = ConfirmDialog(confirm_cb, text="Do you really want to cancel without saving?") |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
194 _dialog.show() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
195 |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
196 def closeAndSave(self): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
197 map_ = {} |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
198 for contact_ in self.all_contacts: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
199 map_[contact_] = set() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
200 contacts = self.groups.getContacts() |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
201 for group in contacts.keys(): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
202 for contact_ in contacts[group]: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
203 map_[contact_].add(group) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
204 for contact_ in map_.keys(): |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
205 groups = map_[contact_] |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
206 current_groups = self.host.contact_panel.getContactGroups(contact_) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
207 if groups != current_groups: |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
208 self.host.bridge.call('updateContact', None, contact_, '', list(groups)) |
0e7f3944bd27
browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
209 self.__close() |