Mercurial > libervia-web
annotate libervia/pages/lists/_browser/__init__.py @ 1470:837ae0c4b858
pages (lists/view_item): use uppercase for firt letter of Item breadcrumb
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 01 Oct 2021 16:30:05 +0200 |
parents | 72f9639594b2 |
children | 106bae41f5c8 |
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 |
1394
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
3 from aio_bridge import 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 |
a84383c659b4
lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 bridge = Bridge() |
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: |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
26 await bridge.interestRetract("", item['id']) |
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: |
72f9639594b2
browser (lists): code is now async + item removal for non creator:
Goffi <goffi@goffi.org>
parents:
1387
diff
changeset
|
38 await bridge.psNodeDelete( |
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))) |