annotate browser_side/contact_group.py @ 333:c01397d18026

server side: paramsXml2xmlUI is now parasXML2XMLUI + improved lisibility in getParamsUI
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2014 16:49:20 +0100
parents d3c734669577
children 2067d6241927
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
1 #!/usr/bin/python
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
3
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
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
23 from pyjamas.ui.DockPanel import DockPanel
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
24 from pyjamas.Timer import Timer
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
25 from pyjamas.ui.Button import Button
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
26 from pyjamas.ui.HorizontalPanel import HorizontalPanel
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
27 from pyjamas.ui.VerticalPanel import VerticalPanel
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
28 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
29 from pyjamas.ui import HasAlignment
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
30 from browser_side.dialog import ConfirmDialog, InfoDialog
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
31 from list_manager import ListManager
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
32 import dialog
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
33 import contact
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
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
36 class ContactGroupManager(ListManager):
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
37 """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
38
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
39 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
40 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
41 self.registerPopupMenuPanel(entries={"Remove group": {}},
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
42 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
43
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
44 def removeContactKey(self, sender, key):
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
45 key = sender.getText()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
46
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
47 def confirm_cb(answer):
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
48 if answer:
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
49 ListManager.removeContactKey(self, key)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
50 self._parent.removeKeyFromAddGroupPanel(key)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
51
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
52 _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
53 _dialog.show()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
54
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
55 def removeFromRemainingList(self, contacts):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
56 ListManager.removeFromRemainingList(self, contacts)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
57 self._parent.updateContactList(contacts=contacts)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
58
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
59 def addToRemainingList(self, contacts, ignore_key=None):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
60 ListManager.addToRemainingList(self, contacts, ignore_key)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
61 self._parent.updateContactList(contacts=contacts)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
62
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
63
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
64 class ContactGroupEditor(DockPanel):
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
65 """Panel for the contact groups manager."""
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
66
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
67 def __init__(self, host, parent=None, onCloseCallback=None):
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
68 DockPanel.__init__(self)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
69 self.host = host
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
70
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
71 # eventually display in a popup
256
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 self._parent = parent
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
76 self._on_close_callback = onCloseCallback
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
77 self.all_contacts = self.host.contact_panel.getContacts()
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
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()
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
81
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
82 self.add_group_panel = self.getAddGroupPanel(groups_list)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
83 south_panel = self.getCloseSaveButtons()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
84 center_panel = self.getContactGroupManager(groups_list)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
85 east_panel = self.getContactList()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
86
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
87 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
88 self.add(east_panel, DockPanel.EAST)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
89 self.add(center_panel, DockPanel.NORTH)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
90 self.add(south_panel, DockPanel.SOUTH)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
91
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
92 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
93 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
94 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
95 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
96 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
97 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
98 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
99 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
100
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
101 # need to be done after the contact list has been initialized
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
102 self.groups.setContacts(self.host.contact_panel.groups)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
103 self.toggleContacts(showAll=True)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
104
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
105 # 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
106 self.restore_contact_panel = False
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
107 if self.host.contact_panel.getVisible():
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
108 self.restore_contact_panel = True
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
109 self.host.panel._contactsSwitch()
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
110
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
111 parent.add(self)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
112 parent.setVisible(True)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
113 if isinstance(parent, DialogBox):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
114 parent.center()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
115
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
116 def getContactGroupManager(self, groups_list):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
117 """Set the list manager for the groups"""
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
118 flex_table = FlexTable(len(groups_list), 2)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
119 flex_table.addStyleName('contactGroupEditor')
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
120 # 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
121 style = {
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
122 "keyItem": "group",
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
123 "popupMenuItem": "popupMenuItem",
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
124 "removeButton": "contactGroupRemoveButton",
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
125 "buttonCell": "contactGroupButtonCell",
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
126 "keyPanel": "contactGroupPanel"
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
127 }
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
128 self.groups = ContactGroupManager(flex_table, groups_list, self.all_contacts, style=style)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
129 self.groups.createWidgets() # widgets are automatically added to FlexTable
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
130 # 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
131 flex_table.updateContactList = self.updateContactList
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
132 flex_table.removeKeyFromAddGroupPanel = self.add_group_panel.groups.remove
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
133 return flex_table
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
134
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
135 def getAddGroupPanel(self, groups_list):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
136 """Add the 'Add group' panel to the FlexTable"""
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
137
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
138 def add_group_cb(text):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
139 self.groups.addContactKey(text)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
140 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
141
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
142 add_group_panel = dialog.AddGroupPanel(groups_list, add_group_cb)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
143 add_group_panel.addStyleName("addContactGroupPanel")
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
144 return add_group_panel
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
145
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
146 def getCloseSaveButtons(self):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
147 """Add the buttons to close the dialog / save the groups"""
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
148 buttons = HorizontalPanel()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
149 buttons.addStyleName("marginAuto")
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
150 buttons.add(Button("Cancel", listener=self.cancelWithoutSaving))
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
151 buttons.add(Button("Save", listener=self.closeAndSave))
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
152 return buttons
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
153
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
154 def getContactList(self):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
155 """Add the contact list to the DockPanel"""
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
156 self.toggle = Button("", self.toggleContacts)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
157 self.toggle.addStyleName("toggleAssignedContacts")
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
158 self.contacts = contact.GenericContactList(self.host)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
159 for contact_ in self.all_contacts:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
160 self.contacts.add(contact_)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
161 contact_panel = VerticalPanel()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
162 contact_panel.add(self.toggle)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
163 contact_panel.add(self.contacts)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
164 return contact_panel
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
165
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
166 def toggleContacts(self, sender=None, showAll=None):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
167 """Callback for the toggle button"""
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
168 if sender is None:
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
169 sender = self.toggle
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
170 sender.showAll = showAll if showAll is not None else not sender.showAll
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
171 if sender.showAll:
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
172 sender.setText("Hide assigned")
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
173 else:
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
174 sender.setText("Show assigned")
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
175 self.updateContactList(sender)
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
176
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
177 def updateContactList(self, sender=None, contacts=None):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
178 """Update the contact list regarding the toggle button"""
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
179 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
180 return
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
181 sender = self.toggle
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
182 if contacts is not None:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
183 if not isinstance(contacts, list):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
184 contacts = [contacts]
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
185 for contact_ in contacts:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
186 if contact_ not in self.all_contacts:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
187 contacts.remove(contact_)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
188 else:
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
189 contacts = self.all_contacts
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
190 for contact_ in contacts:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
191 if sender.showAll:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
192 self.contacts.getContactLabel(contact_).setVisible(True)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
193 else:
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
194 if contact_ in self.groups.remaining_list:
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
195 self.contacts.getContactLabel(contact_).setVisible(True)
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
196 else:
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
197 self.contacts.getContactLabel(contact_).setVisible(False)
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
198
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
199 def __close(self):
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
200 """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
201 if isinstance(self._parent, DialogBox):
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
202 self._parent.hide()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
203 self._parent.remove(self)
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
204 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
205 self._on_close_callback()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
206 if self.restore_contact_panel:
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
207 self.host.panel._contactsSwitch()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
208
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
209 def cancelWithoutSaving(self):
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
210 """Ask for confirmation before closing the dialog."""
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
211 def confirm_cb(answer):
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
212 if answer:
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
213 self.__close()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
214
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
215 _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
216 _dialog.show()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
217
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
218 def closeAndSave(self):
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
219 """Call bridge methods to save the changes and close the dialog"""
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
220 map_ = {}
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
221 for contact_ in self.all_contacts:
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
222 map_[contact_] = set()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
223 contacts = self.groups.getContacts()
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
224 for group in contacts.keys():
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
225 for contact_ in contacts[group]:
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
226 try:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
227 map_[contact_].add(group)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
228 except KeyError:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
229 InfoDialog("Invalid contact",
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
230 "The contact '%s' is not your contact list but it has been assigned to the group '%s'." % (contact_, group) +
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
231 "Your changes could not be saved: please check your assignments and save again.", Width="400px").center()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
232 return
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
233 for contact_ in map_.keys():
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
234 groups = map_[contact_]
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
235 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
236 if groups != current_groups:
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents:
diff changeset
237 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
238 self.__close()