annotate libervia/pages/lists/_browser/__init__.py @ 1394:72f9639594b2

browser (lists): code is now async + item removal for non creator: when user is creator of item, it is removed from list of interests and node is deleted, otherwise it is only removed from list of interests.
author Goffi <goffi@goffi.org>
date Sat, 27 Feb 2021 21:06:45 +0100
parents a84383c659b4
children 106bae41f5c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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)))