comparison 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
comparison
equal deleted inserted replaced
1386:83be300d17e3 1387:a84383c659b4
1 from browser import bind, DOMNode
2 from javascript import JSON
3 from bridge import Bridge
4 import dialog
5
6 bridge = Bridge()
7
8
9 def list_delete_cb(item_elt, item):
10 dialog.notification.show(f"{item['name']!r} has been deleted")
11
12
13 def list_delete_eb(failure_, item_elt, item):
14 dialog.notification.show(
15 f"Error while deleting {item['name']!r}: {failure_['message']}",
16 "error"
17 )
18
19
20 def interest_retract_cb(item_elt, item):
21 print(f"{item['name']!r} removed successfuly from list of interests")
22 item_elt.classList.add("state_deleted")
23 item_elt.bind("transitionend", lambda evt: item_elt.remove())
24 bridge.psNodeDelete(
25 item['service'],
26 item['node'],
27 callback=lambda: list_delete_cb(item_elt, item),
28 errback=lambda failure: list_delete_eb(failure, item_elt, item),
29 )
30
31
32 def interest_retract_eb(failure_, item_elt, item):
33 dialog.notification.show(
34 f"Can't remove list {item['name']!r} from personal interests: "
35 f"{failure_['message']}",
36 "error"
37 )
38
39
40 def delete_ok(evt, notif_elt, item_elt, item):
41 bridge.interestRetract(
42 "", item['id'],
43 callback=lambda: interest_retract_cb(item_elt, item),
44 errback=lambda failure:interest_retract_eb(failure, item_elt, item))
45
46
47 def delete_cancel(evt, notif_elt, item_elt, item):
48 notif_elt.remove()
49 item_elt.classList.remove("selected_for_deletion")
50
51
52 @bind(".action_delete", "click")
53 def on_delete(evt):
54 evt.stopPropagation()
55 evt.preventDefault()
56 target = evt.currentTarget
57 item_elt = DOMNode(target.closest('.item'))
58 item_elt.classList.add("selected_for_deletion")
59 item = JSON.parse(item_elt.dataset.item)
60 dialog.Confirm(
61 f"List {item['name']!r} will be deleted, are you sure?",
62 ok_label="delete",
63 ).show(
64 ok_cb=lambda evt, notif_elt: delete_ok(evt, notif_elt, item_elt, item),
65 cancel_cb=lambda evt, notif_elt: delete_cancel(evt, notif_elt, item_elt, item),
66 )