changeset 1482:e35151a2cec1

browser (events): delete implementation
author Goffi <goffi@goffi.org>
date Thu, 11 Nov 2021 18:10:43 +0100
parents 7c776c9d7c75
children 595e7fef41f3 0181867dd0c5
files libervia/pages/events/_browser/__init__.py
diffstat 1 files changed, 52 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libervia/pages/events/_browser/__init__.py	Thu Nov 11 18:10:43 2021 +0100
@@ -0,0 +1,52 @@
+from browser import DOMNode, document, aio
+from javascript import JSON
+from aio_bridge import Bridge, BridgeException
+import dialog
+
+bridge = Bridge()
+
+
+async def on_delete(evt):
+    evt.stopPropagation()
+    evt.preventDefault()
+    target = evt.currentTarget
+    item_elt = DOMNode(target.closest('.item'))
+    item_elt.classList.add("selected_for_deletion")
+    item = JSON.parse(item_elt.dataset.item)
+    confirmed = await dialog.Confirm(
+        f"Event {item['name']!r} will be deleted, are you sure?",
+        ok_label="delete",
+    ).ashow()
+
+    if not confirmed:
+        item_elt.classList.remove("selected_for_deletion")
+        return
+
+    try:
+        await bridge.interestRetract("", item['interest_id'])
+    except BridgeException as e:
+        dialog.notification.show(
+            f"Can't remove list {item['name']!r} from personal interests: {e}",
+            "error"
+        )
+    else:
+        print(f"{item['name']!r} removed successfuly from list of interests")
+        item_elt.classList.add("state_deleted")
+        item_elt.bind("transitionend", lambda evt: item_elt.remove())
+        if item.get("creator", False):
+            try:
+                await bridge.psNodeDelete(
+                    item['service'],
+                    item['node'],
+                )
+            except BridgeException as e:
+                dialog.notification.show(
+                    f"Error while deleting {item['name']!r}: {e}",
+                    "error"
+                )
+            else:
+                dialog.notification.show(f"{item['name']!r} has been deleted")
+
+
+for elt in document.select('.action_delete'):
+    elt.bind("click", lambda evt: aio.run(on_delete(evt)))