annotate libervia/pages/lists/_browser/__init__.py @ 1388:68ffd60a58a5

pages (lists): specify when item is coming from config
author Goffi <goffi@goffi.org>
date Sat, 27 Feb 2021 20:55:35 +0100
parents a84383c659b4
children 72f9639594b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 from browser import bind, DOMNode
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 from javascript import JSON
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 from bridge import Bridge
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
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 def list_delete_cb(item_elt, item):
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 dialog.notification.show(f"{item['name']!r} has been deleted")
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
12
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 def list_delete_eb(failure_, item_elt, item):
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 dialog.notification.show(
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 f"Error while deleting {item['name']!r}: {failure_['message']}",
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 "error"
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 )
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 def interest_retract_cb(item_elt, item):
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 print(f"{item['name']!r} removed successfuly from list of interests")
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 item_elt.classList.add("state_deleted")
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 item_elt.bind("transitionend", lambda evt: item_elt.remove())
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 bridge.psNodeDelete(
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 item['service'],
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 item['node'],
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 callback=lambda: list_delete_cb(item_elt, item),
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 errback=lambda failure: list_delete_eb(failure, item_elt, item),
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 )
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
30
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 def interest_retract_eb(failure_, item_elt, item):
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 dialog.notification.show(
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 f"Can't remove list {item['name']!r} from personal interests: "
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 f"{failure_['message']}",
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 "error"
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 )
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
38
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
39
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 def delete_ok(evt, notif_elt, item_elt, item):
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 bridge.interestRetract(
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 "", item['id'],
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 callback=lambda: interest_retract_cb(item_elt, item),
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 errback=lambda failure:interest_retract_eb(failure, item_elt, item))
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
45
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
46
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 def delete_cancel(evt, notif_elt, item_elt, item):
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 notif_elt.remove()
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 item_elt.classList.remove("selected_for_deletion")
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
50
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
51
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 @bind(".action_delete", "click")
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 def on_delete(evt):
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 evt.stopPropagation()
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 evt.preventDefault()
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 target = evt.currentTarget
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 item_elt = DOMNode(target.closest('.item'))
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 item_elt.classList.add("selected_for_deletion")
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 item = JSON.parse(item_elt.dataset.item)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 dialog.Confirm(
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 f"List {item['name']!r} will be deleted, are you sure?",
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 ok_label="delete",
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 ).show(
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 ok_cb=lambda evt, notif_elt: delete_ok(evt, notif_elt, item_elt, item),
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 cancel_cb=lambda evt, notif_elt: delete_cancel(evt, notif_elt, item_elt, item),
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 )