Mercurial > libervia-web
annotate libervia/web/pages/lists/_browser/__init__.py @ 1608:29eb1ea35869
taks (sass): replace deprecated `node-sass` by `sass`.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 31 May 2024 11:10:02 +0200 |
parents | c1c1d68d063e |
children |
rev | line source |
---|---|
1597
c1c1d68d063e
pages (lists): uses std lib `json` and don't use anymore `DOMNODE`:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
1 import json |
c1c1d68d063e
pages (lists): uses std lib `json` and don't use anymore `DOMNODE`:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
2 |
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 |
1597
c1c1d68d063e
pages (lists): uses std lib `json` and don't use anymore `DOMNODE`:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
4 from browser import document, aio |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 import dialog |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
1510
5ea06e8b06ed
browser: make bridge API closer to the one use with other frontends:
Goffi <goffi@goffi.org>
parents:
1509
diff
changeset
|
7 bridge = Bridge() |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 |
1394
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
10 async def on_delete(evt): |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 evt.stopPropagation() |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 evt.preventDefault() |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 target = evt.currentTarget |
1597
c1c1d68d063e
pages (lists): uses std lib `json` and don't use anymore `DOMNODE`:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
14 item_elt = target.closest('.item') |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 item_elt.classList.add("selected_for_deletion") |
1597
c1c1d68d063e
pages (lists): uses std lib `json` and don't use anymore `DOMNODE`:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
16 item = json.loads(item_elt.dataset.item) |
c1c1d68d063e
pages (lists): uses std lib `json` and don't use anymore `DOMNODE`:
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
17 |
1394
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
18 confirmed = await dialog.Confirm( |
1387
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 f"List {item['name']!r} will be deleted, are you sure?", |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 ok_label="delete", |
1394
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
21 ).ashow() |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
22 |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
23 if not confirmed: |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
24 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
|
25 return |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
26 |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
27 try: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1394
diff
changeset
|
28 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
|
29 except BridgeException as e: |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
30 dialog.notification.show( |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
31 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
|
32 "error" |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
33 ) |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
34 else: |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
35 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
|
36 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
|
37 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
|
38 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
|
39 try: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1394
diff
changeset
|
40 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
|
41 item['service'], |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
42 item['node'], |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
43 ) |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
44 except BridgeException as e: |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
45 dialog.notification.show( |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
46 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
|
47 "error" |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
48 ) |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
49 else: |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
50 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
|
51 |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
52 |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
53 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
|
54 elt.bind("click", lambda evt: aio.run(on_delete(evt))) |