comparison libervia/pages/photos/_browser/__init__.py @ 1301:ff44f822bfdd

browser (photos): albums can now be deleted: when albums are deleted, there are removed from list of interest, and all photos inside are also deleted. Doesn't check permissions before deletion yet, so the button is always present even when it may fail.
author Goffi <goffi@goffi.org>
date Fri, 19 Jun 2020 16:47:51 +0200
parents
children dbd573b0bc9c
comparison
equal deleted inserted replaced
1300:6e110baa707f 1301:ff44f822bfdd
1 from browser import window, bind, DOMNode
2 from javascript import JSON
3 from bridge import Bridge
4 import dialog
5
6 bridge = Bridge()
7
8
9 def album_delete_cb(item_elt, item):
10 print(f"deleted {item['name']}")
11
12
13 def album_delete_eb(failure, item_elt, item):
14 # TODO: cleaner error notification
15 window.alert(f"error while deleting {item['name']}: failure")
16
17
18 def interest_retract_cb(item_elt, item):
19 print(f"{item['name']} removed successfuly from list of interests")
20 item_elt.classList.add("state_deleted")
21 item_elt.bind("transitionend", lambda evt: item_elt.remove())
22 bridge.fileSharingDelete(
23 item['service'],
24 item.get('path', ''),
25 item.get('files_namespace', ''),
26 callback=lambda __: album_delete_cb(item_elt, item),
27 errback=lambda failure: album_delete_eb(failure, item_elt, item),
28 )
29
30
31 def interest_retract_eb(failure_, item_elt, item):
32 # TODO: cleaner error notification
33 window.alert(f"Can't delete album {item['name']}: {failure_['message']}")
34
35
36 def delete_ok(evt, notif_elt, item_elt, item):
37 bridge.interestRetract(
38 "", item['id'],
39 callback=lambda: interest_retract_cb(item_elt, item),
40 errback=lambda failure:interest_retract_eb(failure, item_elt, item))
41
42
43 def delete_cancel(evt, notif_elt, item_elt, item):
44 notif_elt.remove()
45 item_elt.classList.remove("selected_for_deletion")
46
47
48 @bind(".action_delete", "click")
49 def on_delete(evt):
50 evt.stopPropagation()
51 target = evt.currentTarget
52 item_elt = DOMNode(target.elt.closest('.item'))
53 item_elt.classList.add("selected_for_deletion")
54 item = JSON.parse(item_elt.dataset.item)
55 dialog.Confirm(
56 f"album {item['name']!r} will be deleted (inluding all its photos), "
57 f"are you sure?",
58 ok_label="delete",
59 ).show(
60 ok_cb=lambda evt, notif_elt: delete_ok(evt, notif_elt, item_elt, item),
61 cancel_cb=lambda evt, notif_elt: delete_cancel(evt, notif_elt, item_elt, item),
62 )