annotate src/browser/sat_browser/list_manager.py @ 703:1a19ee7d8d8a

server_side: add default theme
author souliane <souliane@mailoo.org>
date Thu, 04 Jun 2015 11:56:34 +0200
parents 9877607c719a
children fe3c2357a8c9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
1 #!/usr/bin/python
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
3
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 323
diff changeset
4 # Libervia: a Salut à Toi frontend
685
9877607c719a 2015 copyright dates update
Goffi <goffi@goffi.org>
parents: 648
diff changeset
5 # Copyright (C) 2013, 2014, 2015 Adrien Cossa <souliane@mailoo.org>
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
6
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 323
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: 323
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: 323
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: 323
diff changeset
10 # (at your option) any later version.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
11
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 323
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: 323
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: 323
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: 323
diff changeset
15 # GNU Affero General Public License for more details.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
16
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 323
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: 323
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
19
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 422
diff changeset
20 from sat.core.log import getLogger
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 422
diff changeset
21 log = getLogger(__name__)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
22 from pyjamas.ui.Button import Button
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
23 from pyjamas.ui.FlowPanel import FlowPanel
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
24 from pyjamas.ui.AutoComplete import AutoCompleteTextBox
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
25 from pyjamas.ui.KeyboardListener import KEY_ENTER
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
26 from pyjamas.ui.DragWidget import DragWidget
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
27 from pyjamas.Timer import Timer
323
0b7934e75e76 misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents: 279
diff changeset
28
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 604
diff changeset
29 import base_panel
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
30 import base_widget
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 604
diff changeset
31 import libervia_widget
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
32
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
33 from sat_frontends.tools import jid
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
34
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
35
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
36 unicode = str # FIXME: pyjamas workaround
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
37
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
38 # HTML content for the removal button (image or text)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
39 REMOVE_BUTTON = '<span class="itemRemoveIcon">x</span>'
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
40
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
41
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
42 # FIXME: dirty method and magic string to fix ASAP
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
43 def tryJID(obj):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
44 return jid.JID(obj) if (isinstance(obj, unicode) and not obj.startswith('@')) else obj
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
45
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
46
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
47 class ListManager(object):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
48 """A base class to manage one or several lists of items."""
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
49
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
50 def __init__(self, container, keys=None, items=None, offsets=None, style=None):
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
51 """
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
52 @param container (FlexTable): FlexTable parent widget
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
53 @param keys (dict{unicode: dict{unicode: unicode}}): dict binding items
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
54 keys to their display config data.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
55 @param items (list): list of items
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
56 @param offsets (dict): define widgets positions offsets within container:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
57 - "x_first": the x offset for the first widget's row on the grid
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
58 - "x": the x offset for all widgets rows, except the first one if "x_first" is defined
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
59 - "y": the y offset for all widgets columns on the grid
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
60 @param style (dict): define CSS styles
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
61 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
62 self.container = container
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
63 self.keys = {} if keys is None else keys
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
64 self.items = [] if items is None else items
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
65 self.items.sort()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
66
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
67 # store the list of items that are not assigned yet
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
68 self.items_remaining = [item for item in self.items]
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
69 self.items_remaining_sorted = True
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
70
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
71 self.offsets = {"x_first": 0, "x": 0, "y": 0}
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
72 if offsets is not None:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
73 if "x" in offsets and "x_first" not in offsets:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
74 offsets["x_first"] = offsets["x"]
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
75 self.offsets.update(offsets)
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 232
diff changeset
76
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
77 self.style = {"keyItem": "itemKey",
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
78 "popupMenuItem": "itemKey",
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
79 "buttonCell": "itemButtonCell",
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
80 "keyPanel": "itemPanel",
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
81 "textBox": "itemTextBox",
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
82 "textBox-invalid": "itemTextBox-invalid",
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
83 "removeButton": "itemRemoveButton",
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
84 }
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
85 if style is not None:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
86 self.style.update(style)
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
87
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
88 def createWidgets(self, title_format="%s"):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
89 """Fill the container widget with one ListPanel per item key (some may be
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
90 hidden during the initialization).
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
91
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
92 @param title_format (unicode): format string for the title
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
93 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
94 self.children = {}
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
95 for key in self.keys:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
96 self.addItemKey(key, title_format=title_format)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
97
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
98 def addItemKey(self, key, data=None, title_format="%s"):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
99 """Add to the container a Button and ListPanel for a new item key.
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
100
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
101 @param key (unicode): item key
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
102 @param data (dict{unicode: unicode}): config data
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
103 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
104 key_data = self.keys.setdefault(key, {})
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
105 if data is not None:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
106 key_data.update(data)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
107 key_data["title"] = key # copy the key to its associated sub-map
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
108
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
109 button = Button(title_format % key)
256
0e7f3944bd27 browser_side: added contact group manager based on ListManager
souliane <souliane@mailoo.org>
parents: 254
diff changeset
110 button.setStyleName(self.style["keyItem"])
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
111 if hasattr(key_data, "desc"):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
112 button.setTitle(key_data["desc"])
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
113 if "optional" not in key_data:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
114 key_data["optional"] = False
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
115 button.setVisible(not key_data["optional"])
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
116 y = len(self.children) + self.offsets["y"]
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
117 x = self.offsets["x_first"] if y == self.offsets["y"] else self.offsets["x"]
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
118
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
119 self.container.insertRow(y)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
120 self.container.setWidget(y, x, button)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
121 self.container.getCellFormatter().setStyleName(y, x, self.style["buttonCell"])
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
122
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
123 _child = ListPanel(self, key_data, self.style)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
124 self.container.setWidget(y, x + 1, _child)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
125
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
126 self.children[key] = {}
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
127 self.children[key]["button"] = button
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
128 self.children[key]["panel"] = _child
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
129
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
130 if hasattr(self, "popup_menu"):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
131 # self.registerPopupMenuPanel has been called yet
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
132 self.popup_menu.registerClickSender(button)
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
133
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
134 def removeItemKey(self, key):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
135 """Remove from the container a ListPanel representing an item key, and all
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
136 its associated data.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
137
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
138 @param key (unicode): item key
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
139 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
140 items = self.children[key]["panel"].getItems()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
141 (y, x) = self.container.getIndex(self.children[key]["button"])
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
142 self.container.removeRow(y)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
143 del self.children[key]
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
144 del self.keys[key]
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
145 self.addToRemainingList(items)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
146
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
147 def refresh(self, hide_everything=False):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
148 """Set visible the sub-panels that are non optional or non empty, hide
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
149 the rest. Setting the attribute "hide_everything" to True you can also
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
150 hide everything.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
151
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
152 @param hide_everything (boolean): set to True to hide everything
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
153 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
154 for key in self.children:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
155 self.setItemPanelVisible(key, False)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
156 if hide_everything:
348
83454ba70a9c browser_side: added a method setVisible to ListManager
souliane <souliane@mailoo.org>
parents: 340
diff changeset
157 return
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
158 for key, items in self.getItemsByKey().iteritems():
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
159 if len(items) > 0 or not self.keys[key]["optional"]:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
160 self.setItemPanelVisible(key, True)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
161
348
83454ba70a9c browser_side: added a method setVisible to ListManager
souliane <souliane@mailoo.org>
parents: 340
diff changeset
162 def setVisible(self, visible):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
163 self.refresh(not visible)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
164
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
165 def setItemPanelVisible(self, key, visible=True, sender=None):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
166 """Set the item key's widgets visibility.
348
83454ba70a9c browser_side: added a method setVisible to ListManager
souliane <souliane@mailoo.org>
parents: 340
diff changeset
167
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
168 @param key (unicode): item key
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
169 @param visible (bool): set to True to display the widgets
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
170 @param sender
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
171 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
172 self.children[key]["button"].setVisible(visible)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
173 self.children[key]["panel"].setVisible(visible)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
174
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
175 @property
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
176 def items_remaining(self):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
177 """Return the unused items."""
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
178 if not self.items_remaining_sorted:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
179 self.items_remaining.sort()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
180 self.items_remaining_sorted = True
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
181 return self.items_remaining
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
182
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
183 def setRemainingListUnsorted(self):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
184 """Mark the list of unused items as being unsorted."""
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
185 self.items_remaining_sorted = False
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
186
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
187 def removeFromRemainingList(self, items):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
188 """Remove some items from the list of unused items.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
189
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
190 @param items (list): items to be removed
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
191 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
192 for item in items:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
193 if item in self.items_remaining:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
194 self.items_remaining.remove(item)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
195
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
196 def addToRemainingList(self, items, ignore_key=None):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
197 """Add some items to the list of unused items. Check first if the
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
198 items are really not used in any ListPanel.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
199
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
200 @param items (list): items to be removed
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
201 @param ignore_key (unicode): item key to be ignored while checking
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
202 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
203 items_assigned = set()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
204 for key, current_items in self.getItemsByKey().iteritems():
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
205 if ignore_key is not None and key == ignore_key:
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
206 continue
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
207 items_assigned.update(current_items)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
208 for item in items:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
209 if item not in self.items or item in self.items_remaining or item in items_assigned:
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
210 continue
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
211 self.items_remaining.append(item)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
212 self.setRemainingListUnsorted()
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
213
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
214 def resetItems(self, data={}):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
215 """Repopulate all the lists (one per item key) with the given items.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
216
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
217 @param data (dict{unicode: list}): dict binding items keys to items.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
218 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
219 for key in self.keys:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
220 if key in data:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
221 self.children[key]["panel"].resetItems(data[key])
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
222 else:
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
223 self.children[key]["panel"].resetItems([])
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
224 self.refresh()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
225
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
226 def getItemsByKey(self):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
227 """Get all the items by key.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
228
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
229 @return: dict{unicode: set}
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
230 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
231 return {key: self.children[key]["panel"].getItems() for key in self.children}
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
232
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
233 def getKeysByItem(self):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
234 """Get all the keys by item.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
235
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
236 @return: dict{object: set(unicode)}
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
237 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
238 result = {}
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
239 for key in self.children:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
240 for item in self.children[key]["panel"].getItems():
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
241 result.setdefault(item, set()).add(key)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
242 return result
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
243
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
244 def registerPopupMenuPanel(self, entries, hide, callback):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
245 """Register a popup menu panel for the item keys buttons.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
246
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
247 @param entries (dict{unicode: dict{unicode: unicode}}): menu entries
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
248 @param hide (callable): method to call in order to know if a menu item
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
249 should be hidden from the menu. Takes in the button widget and the
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
250 item key and returns a boolean.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
251 @param callback (callable): common callback for all menu items, takes in
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
252 the button widget and the item key.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
253 """
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 604
diff changeset
254 self.popup_menu = base_panel.PopupMenuPanel(entries, hide, callback, style={"item": self.style["popupMenuItem"]})
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
255
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
256
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
257 class DragAutoCompleteTextBox(AutoCompleteTextBox, DragWidget):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
258 """A draggable AutoCompleteTextBox which is used for representing an item."""
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
259
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
260 def __init__(self, list_panel, event_cbs, style):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
261 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
262
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
263 @param list_panel (ListPanel)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
264 @param event_cbs (list[callable])
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
265 @param style (dict)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
266 """
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
267 AutoCompleteTextBox.__init__(self)
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
268 DragWidget.__init__(self)
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
269 self.list_panel = list_panel
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
270 self.event_cbs = event_cbs
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
271 self.style = style
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
272 self.addStyleName(style["textBox"])
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
273 self.reset()
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
274
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
275 # Parent classes already init self as an handler for these events
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
276 self.addMouseListener(self)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
277 self.addFocusListener(self)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
278 self.addChangeListener(self)
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
279
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
280 def onDragStart(self, event):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
281 """The user starts dragging the text box."""
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
282 self.list_panel.manager.target_drop_cell = None
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
283 self.setSelectionRange(len(self.getText()), 0)
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
284
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
285 dt = event.dataTransfer
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
286 dt.setData('text/plain', "%s\n%s" % (self.getText(), "CONTACT_TEXTBOX"))
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
287 dt.setDragImage(self.getElement(), 15, 15)
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
288
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
289 def onDragEnd(self, event):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
290 """The user dropped the text box."""
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
291 target = self.list_panel.manager.target_drop_cell # parent or another ListPanel
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
292 if self.getText() == "" or target is None:
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
293 return
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
294 self.event_cbs["drop"](self, target)
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
295
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
296 def onClick(self, sender):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
297 """The choices list is clicked"""
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
298 assert sender == self.choices
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
299 AutoCompleteTextBox.onClick(self, sender)
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
300 self.validate()
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
301
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
302 def onChange(self, sender):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
303 """The list selection or the text has been changed"""
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
304 assert sender == self.choices or sender == self
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
305 if sender == self.choices:
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
306 AutoCompleteTextBox.onChange(self, sender)
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
307 self.validate()
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
308
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
309 def onKeyUp(self, sender, keycode, modifiers):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
310 """Listen for key stroke"""
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
311 assert sender == self
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
312 AutoCompleteTextBox.onKeyUp(self, sender, keycode, modifiers)
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
313 if keycode == KEY_ENTER:
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
314 self.validate()
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
315
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
316 def onMouseMove(self, sender):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
317 """Mouse enters the area of a DragAutoCompleteTextBox."""
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
318 assert sender == self
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
319 if hasattr(sender, "remove_btn"):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
320 sender.remove_btn.setVisible(True)
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
321
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
322 def onMouseLeave(self, sender):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
323 """Mouse leaves the area of a DragAutoCompleteTextBox."""
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
324 assert sender == self
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
325 if hasattr(sender, "remove_btn"):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
326 Timer(1500, lambda timer: sender.remove_btn.setVisible(False))
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
327
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
328 def onFocus(self, sender):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
329 """The DragAutoCompleteTextBox has the focus."""
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
330 assert sender == self
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
331 # FIXME: this raises runtime JS error "Permission denied to access property..." when you drag the object
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
332 #sender.setSelectionRange(0, len(sender.getText()))
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
333 sender.event_cbs["focus"](sender)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
334
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
335 def reset(self):
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
336 """Reset the text box"""
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
337 self.setText("")
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
338 self.setValid()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
339
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
340 def setValid(self, valid=True):
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
341 """Change the style according to the text validity."""
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
342 if self.getText() == "":
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
343 valid = True
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
344 if valid:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
345 self.removeStyleName(self.style["textBox-invalid"])
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
346 else:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
347 self.addStyleName(self.style["textBox-invalid"])
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
348 self.valid = valid
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
349
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
350 def validate(self):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
351 """Check if the text is valid, update the style."""
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
352 self.setSelectionRange(len(self.getText()), 0)
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
353 self.event_cbs["validate"](self)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
354
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
355 def setRemoveButton(self):
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
356 """Add the remove button after the text box."""
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
357
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
358 def remove_cb(sender):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
359 """Callback for the button to remove this item."""
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
360 self.list_panel.remove(self)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
361 self.list_panel.remove(self.remove_btn)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
362 self.event_cbs["remove"](self)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
363
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
364 self.remove_btn = Button(REMOVE_BUTTON, remove_cb, Visible=False)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
365 self.remove_btn.setStyleName(self.style["removeButton"])
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
366 self.list_panel.add(self.remove_btn)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
367
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
368 def removeOrReset(self):
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
369 """Remove the text box if the remove button exists, or reset the text box."""
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
370 if hasattr(self, "remove_btn"):
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
371 self.remove_btn.click()
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
372 else:
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
373 self.reset()
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
374
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
375
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
376 VALID = 1
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
377 INVALID = 2
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
378 DELETE = 3
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
379
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
380
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 604
diff changeset
381 class ListPanel(FlowPanel, libervia_widget.DropCell):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
382 """Panel used for listing items sharing the same key. The key is showed as
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
383 a Button to which you can bind a popup menu and the items are represented
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
384 with a sequence of DragAutoCompleteTextBox."""
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
385 # XXX: beware that pyjamas.ui.FlowPanel is not fully implemented yet and can not be used with pyjamas.ui.Label
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
386
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
387 def __init__(self, manager, data, style={}):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
388 """Initialization with a button and a DragAutoCompleteTextBox.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
389
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
390 @param manager (ListManager)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
391 @param data (dict{unicode: unicode})
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
392 @param style (dict{unicode: unicode})
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
393 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
394 FlowPanel.__init__(self, Visible=(False if data["optional"] else True))
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
395
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
396 def setTargetDropCell(host, item):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
397 self.manager.target_drop_cell = self
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
398
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
399 # FIXME: dirty magic strings '@' and '@@'
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
400 drop_cbs = {"GROUP": lambda host, item: self.addItem("@%s" % item),
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
401 "CONTACT": lambda host, item: self.addItem(tryJID(item)),
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
402 "CONTACT_TITLE": lambda host, item: self.addItem('@@'),
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
403 "CONTACT_TEXTBOX": setTargetDropCell
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
404 }
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 604
diff changeset
405 libervia_widget.DropCell.__init__(self, None)
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
406 self.drop_keys = drop_cbs
254
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
407 self.style = style
28d3315a8003 browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
408 self.addStyleName(self.style["keyPanel"])
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
409 self.manager = manager
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
410 self.key = data["title"]
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
411 self._addTextBox()
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
412
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
413 def onDrop(self, event):
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
414 try:
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 604
diff changeset
415 libervia_widget.DropCell.onDrop(self, event)
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
416 except base_widget.NoLiberviaWidgetException:
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
417 pass
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
418
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
419 def _addTextBox(self, switchPrevious=False):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
420 """Add an empty text box to the last position.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
421
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
422 @param switchPrevious (bool): if True, simulate an insertion before the
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
423 current last textbox by switching the texts and valid states
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
424 @return: an DragAutoCompleteTextBox, the created text box or the
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
425 previous one if switchPrevious is True.
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
426 """
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
427 if hasattr(self, "_last_textbox"):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
428 if self._last_textbox.getText() == "":
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
429 return
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
430 self._last_textbox.setRemoveButton()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
431 else:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
432 switchPrevious = False
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
433
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
434 def focus_cb(sender):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
435 if sender != self._last_textbox:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
436 # save the current value before it's being modified
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
437 self.manager.addToRemainingList([tryJID(sender.getText())], ignore_key=self.key)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
438
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
439 items = [unicode(item) for item in self.manager.items_remaining]
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
440 sender.setCompletionItems(items)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
441
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
442 def add_cb(sender):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
443 self.addItem(tryJID(sender.getText()), sender)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
444
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
445 def remove_cb(sender):
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
446 """Callback for the button to remove this item."""
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
447 self.manager.addToRemainingList([tryJID(sender.getText())])
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
448 self.manager.setRemainingListUnsorted()
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
449 self._last_textbox.setFocus(True)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
450
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
451 def drop_cb(sender, target):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
452 """Callback when the textbox is drag-n-dropped."""
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
453 list_panel = sender.list_panel
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
454 if target != list_panel and target.addItem(tryJID(sender.getText())):
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
455 sender.removeOrReset()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
456 else:
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
457 list_panel.manager.removeFromRemainingList([tryJID(sender.getText())])
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
458
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
459 events_cbs = {"focus": focus_cb, "validate": add_cb, "remove": remove_cb, "drop": drop_cb}
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
460 textbox = DragAutoCompleteTextBox(self, events_cbs, self.style)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
461 self.add(textbox)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
462 if switchPrevious:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
463 textbox.setText(self._last_textbox.getText())
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
464 textbox.setValid(self._last_textbox.valid)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
465 self._last_textbox.reset()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
466 previous = self._last_textbox
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
467 self._last_textbox = textbox
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
468 return previous if switchPrevious else textbox
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
469
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
470 def _checkItem(self, item, modify):
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
471 """
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
472 @param item (object): the item to check
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
473 @param modify (bool): True if the item is being modified
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
474 @return: int value defined by one of these constants:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
475 - VALID if the item is valid
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
476 - INVALID if the item is not valid but can be displayed
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
477 - DELETE if the item should not be displayed at all
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
478 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
479 def count(list_, item):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
480 # XXX: list.count in not implemented by pyjamas
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
481 return len([elt for elt in list_ if elt == item])
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
482
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
483 if not item:
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
484 return DELETE
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
485 if count(self.getItems(), item) > (1 if modify else 0):
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
486 return DELETE
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
487 return VALID if item in self.manager.items else INVALID
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
488
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
489 def addItem(self, item, sender=None):
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
490 """Try to add an item. It will be added if it's a valid one.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
491
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
492 @param item (object): item to be added
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
493 @param (DragAutoCompleteTextBox): widget triggering the event
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
494 @param sender: if True, the item will be "written" to the last textbox
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
495 and a new text box will be added afterward.
604
c22b47d63fe2 browser_side: fixed DragAutoCompleteTextBox for the list manager
souliane <souliane@mailoo.org>
parents: 600
diff changeset
496 @return: True if the item has been added.
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
497 """
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
498 valid = self._checkItem(item, sender is not None)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
499 item_s = unicode(item)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
500 if sender is None:
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
501 # method has been called not to modify but to add an item
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
502 if valid == VALID:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
503 # eventually insert before the last textbox if it's not empty
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
504 sender = self._addTextBox(True) if self._last_textbox.getText() != "" else self._last_textbox
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
505 sender.setText(item_s)
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
506 else:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
507 sender.setValid(valid == VALID)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
508 if valid != VALID:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
509 if sender is not None and valid == DELETE:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
510 sender.removeOrReset()
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
511 return False
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
512 if sender == self._last_textbox:
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
513 self._addTextBox()
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
514 sender.setVisibleLength(len(item_s))
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
515 self.manager.removeFromRemainingList([item])
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
516 self._last_textbox.setFocus(True)
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
517 return True
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
518
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
519 def emptyItems(self):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
520 """Empty the list of items."""
263
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
521 for child in self.getChildren():
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
522 if hasattr(child, "remove_btn"):
d3c734669577 browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents: 256
diff changeset
523 child.remove_btn.click()
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
524
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
525 def resetItems(self, items):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
526 """Repopulate the items.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
527
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
528 @param items (list): the items to be listed.
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
529 """
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
530 self.emptyItems()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
531 if isinstance(items, set):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
532 items = list(items)
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
533 items.sort()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
534 for item in items:
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
535 self.addItem(item)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
536
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
537 def getItems(self):
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
538 """Get the listed items.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
539
600
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
540 @return: set"""
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
541 items = set()
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
542 for widget in self.getChildren():
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
543 if isinstance(widget, DragAutoCompleteTextBox) and widget.getText() != "":
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
544 items.add(tryJID(widget.getText()))
32dbbc941123 browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents: 467
diff changeset
545 return items