Mercurial > libervia-web
annotate libervia/web/pages/lists/_browser/__init__.py @ 1596:52098b5bab8d
browser (chat): add data for reactions
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 13 Dec 2023 22:06:05 +0100 |
parents | eb00d593801d |
children | c1c1d68d063e |
rev | line source |
---|---|
1394
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
1 from browser import DOMNode, document, aio |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 from javascript import JSON |
1510
5ea06e8b06ed
browser: make bridge API closer to the one use with other frontends:
Goffi <goffi@goffi.org>
parents:
1509
diff
changeset
|
3 from bridge import AsyncBridge as Bridge, BridgeException |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 import dialog |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
1510
5ea06e8b06ed
browser: make bridge API closer to the one use with other frontends:
Goffi <goffi@goffi.org>
parents:
1509
diff
changeset
|
6 bridge = Bridge() |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 |
1394
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
9 async def on_delete(evt): |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 evt.stopPropagation() |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 evt.preventDefault() |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 target = evt.currentTarget |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 item_elt = DOMNode(target.closest('.item')) |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 item_elt.classList.add("selected_for_deletion") |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 item = JSON.parse(item_elt.dataset.item) |
1394
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
16 confirmed = await dialog.Confirm( |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 f"List {item['name']!r} will be deleted, are you sure?", |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 ok_label="delete", |
1394
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
19 ).ashow() |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
20 |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
21 if not confirmed: |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
22 item_elt.classList.remove("selected_for_deletion") |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
23 return |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
24 |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
25 try: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1394
diff
changeset
|
26 await bridge.interest_retract("", item['id']) |
1394
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
27 except BridgeException as e: |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
28 dialog.notification.show( |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
29 f"Can't remove list {item['name']!r} from personal interests: {e}", |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
30 "error" |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
31 ) |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
32 else: |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
33 print(f"{item['name']!r} removed successfuly from list of interests") |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
34 item_elt.classList.add("state_deleted") |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
35 item_elt.bind("transitionend", lambda evt: item_elt.remove()) |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
36 if item.get("creator", False): |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
37 try: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1394
diff
changeset
|
38 await bridge.ps_node_delete( |
1394
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
39 item['service'], |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
40 item['node'], |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
41 ) |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
42 except BridgeException as e: |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
43 dialog.notification.show( |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
44 f"Error while deleting {item['name']!r}: {e}", |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
45 "error" |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
46 ) |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
47 else: |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
48 dialog.notification.show(f"{item['name']!r} has been deleted") |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
49 |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
50 |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
51 for elt in document.select('.action_delete'): |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
52 elt.bind("click", lambda evt: aio.run(on_delete(evt))) |