comparison browser_side/dialog.py @ 211:49920d76aa6a

browser side: added a mechanism to define forbidden patterns during new contact group creation this could serve for "Bug 32 - Check group names before adding them (edit)" but not used yet fix bug 32
author souliane <souliane@mailoo.org>
date Fri, 06 Sep 2013 15:51:40 +0200
parents 3092f6b1710c
children a05e16f4a343
comparison
equal deleted inserted replaced
210:3092f6b1710c 211:49920d76aa6a
31 from pyjamas.ui.Frame import Frame 31 from pyjamas.ui.Frame import Frame
32 from pyjamas.ui import HasAlignment 32 from pyjamas.ui import HasAlignment
33 from pyjamas.ui.KeyboardListener import KEY_ESCAPE, KEY_ENTER 33 from pyjamas.ui.KeyboardListener import KEY_ESCAPE, KEY_ENTER
34 from pyjamas.ui.MouseListener import MouseWheelHandler 34 from pyjamas.ui.MouseListener import MouseWheelHandler
35 from pyjamas import DOM 35 from pyjamas import DOM
36 from pyjamas import Window
37
38 # List here the patterns that are not allowed in contact group names
39 FORBIDDEN_PATTERNS_IN_GROUP = ()
36 40
37 class ContactsChooser(DialogBox): 41 class ContactsChooser(DialogBox):
38 42
39 def __init__(self, host, callback, nb_contact=None, text='Please select contacts'): 43 def __init__(self, host, callback, nb_contact=None, text='Please select contacts'):
40 """ 44 """
246 for group in _groups: 250 for group in _groups:
247 self.list_box.addItem(group) 251 self.list_box.addItem(group)
248 252
249 def setGroupsSelected(self, selected_groups): 253 def setGroupsSelected(self, selected_groups):
250 self.list_box.setItemTextSelection(selected_groups) 254 self.list_box.setItemTextSelection(selected_groups)
251 255
252 def onOK(self, sender): 256 def onOK(self, sender):
253 self.hide() 257 self.hide()
254 if self.ok_cb: 258 if self.ok_cb:
255 self.ok_cb(self) 259 self.ok_cb(self)
256 260
258 self.hide() 262 self.hide()
259 if self.cancel_cb: 263 if self.cancel_cb:
260 self.cancel_cb(self) 264 self.cancel_cb(self)
261 265
262 def onGroupInput(self, sender): 266 def onGroupInput(self, sender):
263 self.list_box.addItem(sender.getText()) 267 text = sender.getText()
268 for pattern in FORBIDDEN_PATTERNS_IN_GROUP:
269 if pattern in text:
270 Window.alert("The pattern '%s' is not allowed in group names." % pattern)
271 return
272 self.list_box.addItem(text)
264 sender.setText('') 273 sender.setText('')
265 self.list_box.setItemSelected(self.list_box.getItemCount()-1, "selected") 274 self.list_box.setItemSelected(self.list_box.getItemCount()-1, "selected")
266 275
267 276
268 class WheelTextBox(TextBox, MouseWheelHandler): 277 class WheelTextBox(TextBox, MouseWheelHandler):