Mercurial > libervia-web
comparison libervia/web/pages/events/_browser/__init__.py @ 1518:eb00d593801d
refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 02 Jun 2023 16:49:28 +0200 |
parents | libervia/pages/events/_browser/__init__.py@5ea06e8b06ed |
children |
comparison
equal
deleted
inserted
replaced
1517:b8ed9726525b | 1518:eb00d593801d |
---|---|
1 from browser import DOMNode, document, aio | |
2 from javascript import JSON | |
3 from bridge import AsyncBridge as 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.interest_retract("", 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.ps_node_delete( | |
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))) |