diff libervia/pages/lists/_browser/__init__.py @ 1387:a84383c659b4

lists: creation, invitation, item deletion: this big patch includes: - reorganisation of pages for consistency, discovery is now the main list page, and list overview is now in `view` while item view is moved to `view_item` - lists from lists of interest are now shown in discovery page - list deletion from discory page - list can now be created, using templates now available from backend - invitation manager can now be used from list overview - list item can now be deleted from `view_item`
author Goffi <goffi@goffi.org>
date Sat, 20 Feb 2021 14:07:22 +0100
parents
children 72f9639594b2
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libervia/pages/lists/_browser/__init__.py	Sat Feb 20 14:07:22 2021 +0100
@@ -0,0 +1,66 @@
+from browser import bind, DOMNode
+from javascript import JSON
+from bridge import Bridge
+import dialog
+
+bridge = Bridge()
+
+
+def list_delete_cb(item_elt, item):
+    dialog.notification.show(f"{item['name']!r} has been deleted")
+
+
+def list_delete_eb(failure_, item_elt, item):
+    dialog.notification.show(
+        f"Error while deleting {item['name']!r}: {failure_['message']}",
+        "error"
+    )
+
+
+def interest_retract_cb(item_elt, item):
+    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())
+    bridge.psNodeDelete(
+        item['service'],
+        item['node'],
+        callback=lambda: list_delete_cb(item_elt, item),
+        errback=lambda failure: list_delete_eb(failure, item_elt, item),
+    )
+
+
+def interest_retract_eb(failure_, item_elt, item):
+    dialog.notification.show(
+        f"Can't remove list {item['name']!r} from personal interests: "
+        f"{failure_['message']}",
+        "error"
+    )
+
+
+def delete_ok(evt, notif_elt, item_elt, item):
+    bridge.interestRetract(
+        "", item['id'],
+        callback=lambda: interest_retract_cb(item_elt, item),
+        errback=lambda failure:interest_retract_eb(failure, item_elt, item))
+
+
+def delete_cancel(evt, notif_elt, item_elt, item):
+    notif_elt.remove()
+    item_elt.classList.remove("selected_for_deletion")
+
+
+@bind(".action_delete", "click")
+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)
+    dialog.Confirm(
+        f"List {item['name']!r} will be deleted, are you sure?",
+        ok_label="delete",
+    ).show(
+        ok_cb=lambda evt, notif_elt: delete_ok(evt, notif_elt, item_elt, item),
+        cancel_cb=lambda evt, notif_elt: delete_cancel(evt, notif_elt, item_elt, item),
+    )