Mercurial > libervia-web
comparison browser_side/dialog.py @ 240:a565ce2facc0
browser_side: modified class ContactChooser to allow setting a min and max number of contacts to be chosen
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 15 Oct 2013 13:39:21 +0200 |
parents | dec76d4536ad |
children | 19153af4f327 |
comparison
equal
deleted
inserted
replaced
239:b911f2b43fd4 | 240:a565ce2facc0 |
---|---|
36 from pyjamas import Window | 36 from pyjamas import Window |
37 | 37 |
38 # List here the patterns that are not allowed in contact group names | 38 # List here the patterns that are not allowed in contact group names |
39 FORBIDDEN_PATTERNS_IN_GROUP = () | 39 FORBIDDEN_PATTERNS_IN_GROUP = () |
40 | 40 |
41 | |
41 class ContactsChooser(DialogBox): | 42 class ContactsChooser(DialogBox): |
42 | 43 |
43 def __init__(self, host, callback, nb_contact=None, text='Please select contacts'): | 44 def __init__(self, host, callback, nb_contact=None, text='Please select contacts'): |
44 """ | 45 """ |
45 ContactsChooser allow to select one or several connected contacts | 46 ContactsChooser allow to select one or several connected contacts |
46 @param host: SatWebFrontend instance | 47 @param host: SatWebFrontend instance |
47 @param callback: method to call when contacts have been choosed | 48 @param callback: method to call when contacts have been choosed |
48 @param nb_contact: number of contacts that have to be selected, None for no limit | 49 @param nb_contact: number of contacts that have to be selected, None for no limit |
50 If a tuple is given instead of an integer, nb_contact[0] is the minimal and | |
51 nb_contact[1] is the maximal number of contacts to be chosen. | |
49 """ | 52 """ |
50 self.host = host | 53 self.host = host |
51 self.callback = callback | 54 self.callback = callback |
55 if isinstance(nb_contact, tuple): | |
56 if len(nb_contact) == 0: | |
57 nb_contact = None | |
58 elif len(nb_contact) == 1: | |
59 nb_contact = (nb_contact[0], nb_contact[0]) | |
60 elif nb_contact is not None: | |
61 nb_contact = (nb_contact, nb_contact) | |
62 if nb_contact is None: | |
63 print "Need to select as many contacts as you want" | |
64 else: | |
65 print "Need to select between %d and %d contacts" % nb_contact | |
52 self.nb_contact = nb_contact | 66 self.nb_contact = nb_contact |
53 DialogBox.__init__(self, centered=True) | 67 DialogBox.__init__(self, centered=True) |
54 | |
55 content = VerticalPanel() | 68 content = VerticalPanel() |
56 content.setWidth('100%') | 69 content.setWidth('100%') |
57 self.contacts_list = ListBox() | 70 self.contacts_list = ListBox() |
58 self.contacts_list.setVisibleItemCount(10) | 71 self.contacts_list.setVisibleItemCount(10) |
59 self.contacts_list.setMultipleSelect(True) | 72 self.contacts_list.setMultipleSelect(True) |
62 self.contacts_list.addChangeListener(self.onChange) | 75 self.contacts_list.addChangeListener(self.onChange) |
63 content.add(self.contacts_list) | 76 content.add(self.contacts_list) |
64 button_panel = HorizontalPanel() | 77 button_panel = HorizontalPanel() |
65 button_panel.addStyleName("marginAuto") | 78 button_panel.addStyleName("marginAuto") |
66 self.choose_button = Button("Choose", self.onChoose) | 79 self.choose_button = Button("Choose", self.onChoose) |
67 if (nb_contact): | 80 if nb_contact and nb_contact[0] > 0: |
68 self.choose_button.setEnabled(False) | 81 self.choose_button.setEnabled(False) |
69 button_panel.add(self.choose_button) | 82 button_panel.add(self.choose_button) |
70 button_panel.add(Button("Cancel", self.onCancel)) | 83 button_panel.add(Button("Cancel", self.onCancel)) |
71 content.add(button_panel) | 84 content.add(button_panel) |
72 self.setHTML(text) | 85 self.setHTML(text) |
73 self.setWidget(content) | 86 self.setWidget(content) |
74 | 87 |
75 def onChange(self, sender): | 88 def onChange(self, sender): |
76 if self.nb_contact: | 89 if self.nb_contact: |
77 if len(self.contacts_list.getSelectedValues()) == self.nb_contact: | 90 selected = len(self.contacts_list.getSelectedValues()) |
91 if selected >= self.nb_contact[0] and selected <= self.nb_contact[1]: | |
78 self.choose_button.setEnabled(True) | 92 self.choose_button.setEnabled(True) |
79 else: | 93 else: |
80 self.choose_button.setEnabled(False) | 94 self.choose_button.setEnabled(False) |
81 | 95 |
82 def getContacts(self): | 96 def getContacts(self): |