Mercurial > libervia-web
comparison libervia/web/pages/photos/_browser/__init__.py @ 1518:eb00d593801d
refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 02 Jun 2023 16:49:28 +0200 |
parents | libervia/pages/photos/_browser/__init__.py@5ea06e8b06ed |
children |
comparison
equal
deleted
inserted
replaced
1517:b8ed9726525b | 1518:eb00d593801d |
---|---|
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.file_sharing_delete( | |
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.interest_retract( | |
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.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 ) |