annotate libervia/web/pages/photos/album/_browser/__init__.py @ 1595:7941444c1671

pages: set `own_local_jid` to avoid confusion with `own_jid`: - `own_jid` is the real JID of the user. - `own_local_jid` is the JID used in chat, which can be real JID, or a room JID.
author Goffi <goffi@goffi.org>
date Wed, 13 Dec 2023 22:05:48 +0100
parents 106945841fbc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1532
106945841fbc _browser (album): moved code to upload file to a separate `file_uploader` module:
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
1 import alt_media_player
106945841fbc _browser (album): moved code to upload file to a separate `file_uploader` module:
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
2 from bridge import AsyncBridge, Bridge
106945841fbc _browser (album): moved code to upload file to a separate `file_uploader` module:
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
3 from browser import DOMNode, aio, bind, document, html, window
106945841fbc _browser (album): moved code to upload file to a separate `file_uploader` module:
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
4 import dialog
106945841fbc _browser (album): moved code to upload file to a separate `file_uploader` module:
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
5 from file_uploader import FileUploader
106945841fbc _browser (album): moved code to upload file to a separate `file_uploader` module:
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
6 from invitation import InvitationManager
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
7 from javascript import JSON
1532
106945841fbc _browser (album): moved code to upload file to a separate `file_uploader` module:
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
8 import loading
1308
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
9 from slideshow import SlideShow
1532
106945841fbc _browser (album): moved code to upload file to a separate `file_uploader` module:
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
10 from template import Template
1352
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
11 import tmp_aio
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
12
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
13
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents: 1330
diff changeset
14 cache_path = window.cache_path
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
15 files_service = window.files_service
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
16 files_path = window.files_path
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents: 1330
diff changeset
17 try:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents: 1330
diff changeset
18 affiliations = window.affiliations.to_dict()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents: 1330
diff changeset
19 except AttributeError:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents: 1330
diff changeset
20 pass
1510
5ea06e8b06ed browser: make bridge API closer to the one use with other frontends:
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
21 bridge = Bridge()
5ea06e8b06ed browser: make bridge API closer to the one use with other frontends:
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
22 async_bridge = AsyncBridge()
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
23
1346
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
24 alt_media_player.install_if_needed()
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
25
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
26 photo_tpl = Template('photo/item.html')
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
27 player_tpl = Template('components/media_player.html')
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
28
1320
0cbf86b1dcca browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents: 1312
diff changeset
29 # file upload
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
30
1532
106945841fbc _browser (album): moved code to upload file to a separate `file_uploader` module:
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
31 file_uploader = FileUploader(files_service, "photo/item.html", files_path)
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
32
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
33
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
34 @bind("#file_drop", "drop")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
35 def on_file_select(evt):
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
36 evt.stopPropagation()
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
37 evt.preventDefault()
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
38 files = evt.dataTransfer.files
1532
106945841fbc _browser (album): moved code to upload file to a separate `file_uploader` module:
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
39 file_uploader.upload_files(files, document["album_items"])
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
40
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
41
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
42 @bind("#file_drop", "dragover")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
43 def on_drag_over(evt):
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
44 evt.stopPropagation()
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
45 evt.preventDefault()
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
46 evt.dataTransfer.dropEffect = 'copy'
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
47
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
48
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
49 @bind("#file_input", "change")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
50 def on_file_input_change(evt):
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
51 files = evt.currentTarget.files
1532
106945841fbc _browser (album): moved code to upload file to a separate `file_uploader` module:
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
52 file_uploader.upload_files(files, document["album_items"])
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
53
1320
0cbf86b1dcca browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents: 1312
diff changeset
54 # delete
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
55
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
56 def file_delete_cb(item_elt, item):
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
57 item_elt.classList.add("state_deleted")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
58 item_elt.bind("transitionend", lambda evt: item_elt.remove())
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
59 print(f"deleted {item['name']}")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
60
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
61
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
62 def file_delete_eb(failure, item_elt, item):
1351
2c3bc7284992 browser (photos/album): fixed notifications
Goffi <goffi@goffi.org>
parents: 1346
diff changeset
63 dialog.notification.show(
1345
ce1217e3a9c0 browser (photos/album): use notifications to show error messages + use `ok_color` argument for delete confirmation
Goffi <goffi@goffi.org>
parents: 1332
diff changeset
64 f"error while deleting {item['name']}: failure",
ce1217e3a9c0 browser (photos/album): use notifications to show error messages + use `ok_color` argument for delete confirmation
Goffi <goffi@goffi.org>
parents: 1332
diff changeset
65 level="error"
ce1217e3a9c0 browser (photos/album): use notifications to show error messages + use `ok_color` argument for delete confirmation
Goffi <goffi@goffi.org>
parents: 1332
diff changeset
66 )
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
67
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
68
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
69 def delete_ok(evt, notif_elt, item_elt, item):
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
70 file_path = f"{files_path.rstrip('/')}/{item['name']}"
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1428
diff changeset
71 bridge.file_sharing_delete(
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
72 files_service,
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
73 file_path,
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
74 "",
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
75 callback=lambda : file_delete_cb(item_elt, item),
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
76 errback=lambda failure: file_delete_eb(failure, item_elt, item),
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
77 )
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
78
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
79
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
80 def delete_cancel(evt, notif_elt, item_elt, item):
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
81 notif_elt.remove()
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
82 item_elt.classList.remove("selected_for_deletion")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
83
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
84
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
85 def on_delete(evt):
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
86 evt.stopPropagation()
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
87 target = evt.currentTarget
1357
dbd573b0bc9c browser: updated code to work with new Brython 3.8.10:
Goffi <goffi@goffi.org>
parents: 1352
diff changeset
88 item_elt = DOMNode(target.closest('.item'))
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
89 item_elt.classList.add("selected_for_deletion")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
90 item = JSON.parse(item_elt.dataset.item)
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
91 dialog.Confirm(
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
92 f"{item['name']!r} will be deleted, are you sure?",
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
93 ok_label="delete",
1345
ce1217e3a9c0 browser (photos/album): use notifications to show error messages + use `ok_color` argument for delete confirmation
Goffi <goffi@goffi.org>
parents: 1332
diff changeset
94 ok_color="danger",
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
95 ).show(
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
96 ok_cb=lambda evt, notif_elt: delete_ok(evt, notif_elt, item_elt, item),
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
97 cancel_cb=lambda evt, notif_elt: delete_cancel(evt, notif_elt, item_elt, item),
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
98 )
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
99
1532
106945841fbc _browser (album): moved code to upload file to a separate `file_uploader` module:
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
100 file_uploader.on_delete_cb = on_delete
106945841fbc _browser (album): moved code to upload file to a separate `file_uploader` module:
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
101
1352
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
102 # cover
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
103
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
104 async def cover_ok(evt, notif_elt, item_elt, item):
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
105 # we first need to get a blob of the image
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
106 img_elt = item_elt.select_one("img")
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
107 # the simplest way is to download it
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
108 r = await tmp_aio.ajax("GET", img_elt.src, "blob")
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
109 if r.status != 200:
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
110 dialog.notification.show(
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
111 f"can't retrieve cover: {r.status}: {r.statusText}",
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
112 level="error"
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
113 )
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
114 return
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
115 img_blob = r.response
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
116 # now we'll upload it via HTTP Upload, we need a slow
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
117 img_name = img_elt.src.rsplit('/', 1)[-1]
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
118 img_size = img_blob.size
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
119
1510
5ea06e8b06ed browser: make bridge API closer to the one use with other frontends:
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
120 slot = await async_bridge.file_http_upload_get_slot(
1352
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
121 img_name,
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
122 img_size,
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
123 '',
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
124 files_service
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
125 )
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
126 get_url, put_url, headers = slot
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
127 # we have the slot, we can upload image
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
128 r = await tmp_aio.ajax("PUT", put_url, "", img_blob)
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
129 if r.status != 201:
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
130 dialog.notification.show(
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
131 f"can't upload cover: {r.status}: {r.statusText}",
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
132 level="error"
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
133 )
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
134 return
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
135 extra = {"thumb_url": get_url}
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
136 album_name = files_path.rsplit('/', 1)[-1]
1510
5ea06e8b06ed browser: make bridge API closer to the one use with other frontends:
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
137 await async_bridge.interests_file_sharing_register(
1352
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
138 files_service,
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
139 "photos",
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
140 "",
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
141 files_path,
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
142 album_name,
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
143 JSON.stringify(extra),
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
144 )
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
145 dialog.notification.show("Album cover has been changed")
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
146
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
147
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
148 def cover_cancel(evt, notif_elt, item_elt, item):
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
149 notif_elt.remove()
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
150 item_elt.classList.remove("selected_for_action")
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
151
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
152
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
153 def on_cover(evt):
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
154 evt.stopPropagation()
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
155 target = evt.currentTarget
1357
dbd573b0bc9c browser: updated code to work with new Brython 3.8.10:
Goffi <goffi@goffi.org>
parents: 1352
diff changeset
156 item_elt = DOMNode(target.closest('.item'))
1352
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
157 item_elt.classList.add("selected_for_action")
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
158 item = JSON.parse(item_elt.dataset.item)
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
159 dialog.Confirm(
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
160 f"use {item['name']!r} for this album cover?",
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
161 ok_label="use as cover",
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
162 ).show(
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
163 ok_cb=lambda evt, notif_elt: aio.run(cover_ok(evt, notif_elt, item_elt, item)),
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
164 cancel_cb=lambda evt, notif_elt: cover_cancel(evt, notif_elt, item_elt, item),
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
165 )
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
166
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
167
1320
0cbf86b1dcca browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents: 1312
diff changeset
168 # slideshow
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
169
1308
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
170 @bind(".photo_thumb_click", "click")
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
171 def photo_click(evt):
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
172 evt.stopPropagation()
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
173 evt.preventDefault()
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
174 slideshow = SlideShow()
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
175 target = evt.currentTarget
1357
dbd573b0bc9c browser: updated code to work with new Brython 3.8.10:
Goffi <goffi@goffi.org>
parents: 1352
diff changeset
176 clicked_item_elt = DOMNode(target.closest('.item'))
1308
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
177
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
178 slideshow.attach()
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
179 for idx, item_elt in enumerate(document.select('.item')):
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
180 item = JSON.parse(item_elt.dataset.item)
1330
b525fdcb393b browser (photos/album): used biggest thumbnails instead of original image for slideshow:
Goffi <goffi@goffi.org>
parents: 1320
diff changeset
181 try:
b525fdcb393b browser (photos/album): used biggest thumbnails instead of original image for slideshow:
Goffi <goffi@goffi.org>
parents: 1320
diff changeset
182 biggest_thumb = item['extra']['thumbnails'][-1]
b525fdcb393b browser (photos/album): used biggest thumbnails instead of original image for slideshow:
Goffi <goffi@goffi.org>
parents: 1320
diff changeset
183 thumb_url = f"{cache_path}{biggest_thumb['filename']}"
b525fdcb393b browser (photos/album): used biggest thumbnails instead of original image for slideshow:
Goffi <goffi@goffi.org>
parents: 1320
diff changeset
184 except (KeyError, IndexError) as e:
b525fdcb393b browser (photos/album): used biggest thumbnails instead of original image for slideshow:
Goffi <goffi@goffi.org>
parents: 1320
diff changeset
185 print(f"Can't get full screen thumbnail URL: {e}")
1346
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
186 thumb_url = None
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
187 if item.get("mime_type", "")[:5] == "video":
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
188 player = alt_media_player.MediaPlayer(
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
189 [item['url']],
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
190 poster = thumb_url,
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
191 reduce_click_area = True
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
192 )
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
193 elt = player.elt
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
194 elt.classList.add("slide_video", "no_fullscreen")
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
195 slideshow.add_slide(
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
196 elt,
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
197 item,
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
198 options={
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
199 "flags": (alt_media_player.NO_PAGINATION, alt_media_player.NO_SCROLLBAR),
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
200 "exit_callback": player.reset,
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
201 }
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
202 )
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
203 else:
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
204 slideshow.add_slide(html.IMG(src=thumb_url or item['url'], Class="slide_img"), item)
1308
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
205 if item_elt == clicked_item_elt:
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
206 slideshow.index = idx
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
207
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
208
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
209 for elt in document.select('.action_delete'):
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
210 elt.bind("click", on_delete)
1352
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
211 for elt in document.select('.action_cover'):
d100d3a07dd7 browser (photos/album): change cover on "cover" button click:
Goffi <goffi@goffi.org>
parents: 1351
diff changeset
212 elt.bind("click", on_cover)
1320
0cbf86b1dcca browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents: 1312
diff changeset
213
0cbf86b1dcca browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents: 1312
diff changeset
214 # manage
0cbf86b1dcca browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents: 1312
diff changeset
215
0cbf86b1dcca browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents: 1312
diff changeset
216
0cbf86b1dcca browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents: 1312
diff changeset
217 @bind("#button_manage", "click")
0cbf86b1dcca browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents: 1312
diff changeset
218 def manage_click(evt):
0cbf86b1dcca browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents: 1312
diff changeset
219 evt.stopPropagation()
0cbf86b1dcca browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents: 1312
diff changeset
220 evt.preventDefault()
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents: 1330
diff changeset
221 manager = InvitationManager("photos", {"service": files_service, "path": files_path})
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
222 aio.run(manager.attach(affiliations=affiliations))
1332
a75d82713a02 browser (photos/album): remove hint when delete button is pressed
Goffi <goffi@goffi.org>
parents: 1331
diff changeset
223
1372
19eb8b6c02d4 browser (album): remove loading screen at the end of the script
Goffi <goffi@goffi.org>
parents: 1357
diff changeset
224
1332
a75d82713a02 browser (photos/album): remove hint when delete button is pressed
Goffi <goffi@goffi.org>
parents: 1331
diff changeset
225 # hint
a75d82713a02 browser (photos/album): remove hint when delete button is pressed
Goffi <goffi@goffi.org>
parents: 1331
diff changeset
226 @bind("#hint .click_to_delete", "click")
a75d82713a02 browser (photos/album): remove hint when delete button is pressed
Goffi <goffi@goffi.org>
parents: 1331
diff changeset
227 def remove_hint(evt):
a75d82713a02 browser (photos/album): remove hint when delete button is pressed
Goffi <goffi@goffi.org>
parents: 1331
diff changeset
228 document['hint'].remove()
1372
19eb8b6c02d4 browser (album): remove loading screen at the end of the script
Goffi <goffi@goffi.org>
parents: 1357
diff changeset
229
19eb8b6c02d4 browser (album): remove loading screen at the end of the script
Goffi <goffi@goffi.org>
parents: 1357
diff changeset
230
19eb8b6c02d4 browser (album): remove loading screen at the end of the script
Goffi <goffi@goffi.org>
parents: 1357
diff changeset
231 loading.remove_loading_screen()