Mercurial > libervia-web
changeset 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 | b911f2b43fd4 |
children | 86055ccf69c3 |
files | browser_side/dialog.py |
diffstat | 1 files changed, 17 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/browser_side/dialog.py Mon Oct 14 20:54:13 2013 +0200 +++ b/browser_side/dialog.py Tue Oct 15 13:39:21 2013 +0200 @@ -38,6 +38,7 @@ # List here the patterns that are not allowed in contact group names FORBIDDEN_PATTERNS_IN_GROUP = () + class ContactsChooser(DialogBox): def __init__(self, host, callback, nb_contact=None, text='Please select contacts'): @@ -46,12 +47,24 @@ @param host: SatWebFrontend instance @param callback: method to call when contacts have been choosed @param nb_contact: number of contacts that have to be selected, None for no limit + If a tuple is given instead of an integer, nb_contact[0] is the minimal and + nb_contact[1] is the maximal number of contacts to be chosen. """ self.host = host self.callback = callback + if isinstance(nb_contact, tuple): + if len(nb_contact) == 0: + nb_contact = None + elif len(nb_contact) == 1: + nb_contact = (nb_contact[0], nb_contact[0]) + elif nb_contact is not None: + nb_contact = (nb_contact, nb_contact) + if nb_contact is None: + print "Need to select as many contacts as you want" + else: + print "Need to select between %d and %d contacts" % nb_contact self.nb_contact = nb_contact DialogBox.__init__(self, centered=True) - content = VerticalPanel() content.setWidth('100%') self.contacts_list = ListBox() @@ -64,7 +77,7 @@ button_panel = HorizontalPanel() button_panel.addStyleName("marginAuto") self.choose_button = Button("Choose", self.onChoose) - if (nb_contact): + if nb_contact and nb_contact[0] > 0: self.choose_button.setEnabled(False) button_panel.add(self.choose_button) button_panel.add(Button("Cancel", self.onCancel)) @@ -74,7 +87,8 @@ def onChange(self, sender): if self.nb_contact: - if len(self.contacts_list.getSelectedValues()) == self.nb_contact: + selected = len(self.contacts_list.getSelectedValues()) + if selected >= self.nb_contact[0] and selected <= self.nb_contact[1]: self.choose_button.setEnabled(True) else: self.choose_button.setEnabled(False)