Mercurial > libervia-web
comparison libervia/pages/events/_browser/__init__.py @ 1482:e35151a2cec1
browser (events): delete implementation
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 11 Nov 2021 18:10:43 +0100 |
parents | |
children | 106bae41f5c8 |
comparison
equal
deleted
inserted
replaced
1481:7c776c9d7c75 | 1482:e35151a2cec1 |
---|---|
1 from browser import DOMNode, document, aio | |
2 from javascript import JSON | |
3 from aio_bridge import Bridge, BridgeException | |
4 import dialog | |
5 | |
6 bridge = Bridge() | |
7 | |
8 | |
9 async def on_delete(evt): | |
10 evt.stopPropagation() | |
11 evt.preventDefault() | |
12 target = evt.currentTarget | |
13 item_elt = DOMNode(target.closest('.item')) | |
14 item_elt.classList.add("selected_for_deletion") | |
15 item = JSON.parse(item_elt.dataset.item) | |
16 confirmed = await dialog.Confirm( | |
17 f"Event {item['name']!r} will be deleted, are you sure?", | |
18 ok_label="delete", | |
19 ).ashow() | |
20 | |
21 if not confirmed: | |
22 item_elt.classList.remove("selected_for_deletion") | |
23 return | |
24 | |
25 try: | |
26 await bridge.interestRetract("", item['interest_id']) | |
27 except BridgeException as e: | |
28 dialog.notification.show( | |
29 f"Can't remove list {item['name']!r} from personal interests: {e}", | |
30 "error" | |
31 ) | |
32 else: | |
33 print(f"{item['name']!r} removed successfuly from list of interests") | |
34 item_elt.classList.add("state_deleted") | |
35 item_elt.bind("transitionend", lambda evt: item_elt.remove()) | |
36 if item.get("creator", False): | |
37 try: | |
38 await bridge.psNodeDelete( | |
39 item['service'], | |
40 item['node'], | |
41 ) | |
42 except BridgeException as e: | |
43 dialog.notification.show( | |
44 f"Error while deleting {item['name']!r}: {e}", | |
45 "error" | |
46 ) | |
47 else: | |
48 dialog.notification.show(f"{item['name']!r} has been deleted") | |
49 | |
50 | |
51 for elt in document.select('.action_delete'): | |
52 elt.bind("click", lambda evt: aio.run(on_delete(evt))) |