annotate libervia/pages/events/_browser/__init__.py @ 1499:134ff560d67e

pages (merge-requests/view): serialise extra following backend change
author Goffi <goffi@goffi.org>
date Sun, 02 Oct 2022 18:25:01 +0200
parents e35151a2cec1
children 106bae41f5c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1482
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
1 from browser import DOMNode, document, aio
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
2 from javascript import JSON
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
3 from aio_bridge import Bridge, BridgeException
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
4 import dialog
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
5
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
6 bridge = Bridge()
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
7
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
8
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
9 async def on_delete(evt):
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
10 evt.stopPropagation()
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
11 evt.preventDefault()
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
12 target = evt.currentTarget
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
13 item_elt = DOMNode(target.closest('.item'))
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
14 item_elt.classList.add("selected_for_deletion")
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
15 item = JSON.parse(item_elt.dataset.item)
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
16 confirmed = await dialog.Confirm(
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
17 f"Event {item['name']!r} will be deleted, are you sure?",
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
18 ok_label="delete",
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
19 ).ashow()
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
20
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
21 if not confirmed:
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
22 item_elt.classList.remove("selected_for_deletion")
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
23 return
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
24
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
25 try:
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
26 await bridge.interestRetract("", item['interest_id'])
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
27 except BridgeException as e:
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
28 dialog.notification.show(
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
29 f"Can't remove list {item['name']!r} from personal interests: {e}",
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
30 "error"
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
31 )
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
32 else:
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
33 print(f"{item['name']!r} removed successfuly from list of interests")
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
34 item_elt.classList.add("state_deleted")
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
35 item_elt.bind("transitionend", lambda evt: item_elt.remove())
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
36 if item.get("creator", False):
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
37 try:
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
38 await bridge.psNodeDelete(
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
39 item['service'],
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
40 item['node'],
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
41 )
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
42 except BridgeException as e:
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
43 dialog.notification.show(
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
44 f"Error while deleting {item['name']!r}: {e}",
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
45 "error"
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
46 )
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
47 else:
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
48 dialog.notification.show(f"{item['name']!r} has been deleted")
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
49
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
50
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
51 for elt in document.select('.action_delete'):
e35151a2cec1 browser (events): delete implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
52 elt.bind("click", lambda evt: aio.run(on_delete(evt)))