Mercurial > libervia-backend
comparison src/stdui/ui_contact_list.py @ 2071:c2fdee1bd908
core (stdui): fixed cancellation of ContactList forms
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 11 Sep 2016 23:17:31 +0200 |
parents | 2daf7b4c6756 |
children | 90189f312fd3 |
comparison
equal
deleted
inserted
replaced
2070:58f0c96d60e5 | 2071:c2fdee1bd908 |
---|---|
20 from sat.core.i18n import _, D_ | 20 from sat.core.i18n import _, D_ |
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from sat.tools import xml_tools | 22 from sat.tools import xml_tools |
23 from twisted.words.protocols.jabber import jid | 23 from twisted.words.protocols.jabber import jid |
24 from xml.dom.minidom import Element | 24 from xml.dom.minidom import Element |
25 import re | |
26 | 25 |
27 | 26 |
28 class ContactList(object): | 27 class ContactList(object): |
29 """Add, update and remove contacts.""" | 28 """Add, update and remove contacts.""" |
30 | 29 |
207 | 206 |
208 @param data (dict) | 207 @param data (dict) |
209 @param profile: %(doc_profile)s | 208 @param profile: %(doc_profile)s |
210 @return dict | 209 @return dict |
211 """ | 210 """ |
211 if C.bool(data.get('cancelled', 'false')): | |
212 return {} | |
212 contact = data[xml_tools.formEscape('contact_jid')] | 213 contact = data[xml_tools.formEscape('contact_jid')] |
213 cb = lambda data, profile: self._deleteContact(jid.JID(contact), profile) | 214 def delete_cb(data, profile): |
214 delete_id = self.host.registerCallback(cb, with_data=True, one_shot=True) | 215 if not C.bool(data.get('cancelled', 'false')): |
216 self._deleteContact(jid.JID(contact), profile) | |
217 return {} | |
218 delete_id = self.host.registerCallback(delete_cb, with_data=True, one_shot=True) | |
215 form_ui = xml_tools.XMLUI("form", title=D_("Delete contact"), submit_id=delete_id) | 219 form_ui = xml_tools.XMLUI("form", title=D_("Delete contact"), submit_id=delete_id) |
216 form_ui.addText(D_("Are you sure you want to remove %s from your contact list?") % contact) | 220 form_ui.addText(D_("Are you sure you want to remove %s from your contact list?") % contact) |
217 return {'xmlui': form_ui.toXml()} | 221 return {'xmlui': form_ui.toXml()} |
218 | 222 |
219 def _addContact(self, data, profile): | 223 def _addContact(self, data, profile): |
221 | 225 |
222 @param data (dict) | 226 @param data (dict) |
223 @param profile: %(doc_profile)s | 227 @param profile: %(doc_profile)s |
224 @return dict | 228 @return dict |
225 """ | 229 """ |
230 if C.bool(data.get('cancelled', 'false')): | |
231 return {} | |
226 contact_jid_s = data[xml_tools.formEscape('contact_jid')] | 232 contact_jid_s = data[xml_tools.formEscape('contact_jid')] |
227 try: | 233 try: |
228 contact_jid = jid.JID(contact_jid_s) | 234 contact_jid = jid.JID(contact_jid_s) |
229 except (RuntimeError, jid.InvalidFormat, AttributeError): | 235 except (RuntimeError, jid.InvalidFormat, AttributeError): |
230 # TODO: replace '\t' by a constant (see tools.xmlui.XMLUI.onFormSubmitted) | 236 # TODO: replace '\t' by a constant (see tools.xmlui.XMLUI.onFormSubmitted) |
242 | 248 |
243 @param data (dict) | 249 @param data (dict) |
244 @param profile: %(doc_profile)s | 250 @param profile: %(doc_profile)s |
245 @return dict | 251 @return dict |
246 """ | 252 """ |
253 if C.bool(data.get('cancelled', 'false')): | |
254 return {} | |
247 contact_jid = jid.JID(data[xml_tools.formEscape('contact_jid')]) | 255 contact_jid = jid.JID(data[xml_tools.formEscape('contact_jid')]) |
248 # TODO: replace '\t' by a constant (see tools.xmlui.XMLUI.onFormSubmitted) | 256 # TODO: replace '\t' by a constant (see tools.xmlui.XMLUI.onFormSubmitted) |
249 groups = data[xml_tools.formEscape('groups_list')].split('\t') | 257 groups = data[xml_tools.formEscape('groups_list')].split('\t') |
250 self.host.updateContact(contact_jid, name='', groups=groups, profile_key=profile) | 258 self.host.updateContact(contact_jid, name='', groups=groups, profile_key=profile) |
251 return {} | 259 return {} |