annotate libervia/pages/photos/album/_browser/__init__.py @ 1346:cda5537c71d6

browser (photos/album): videos integrations: videos can now be added to an album, the alternative media player is then used to display them. Slides options are used to remove pagination and slidebar from slideshow (they don't play well with media player), and video are reset when its slide is exited.
author Goffi <goffi@goffi.org>
date Tue, 25 Aug 2020 08:31:56 +0200
parents ce1217e3a9c0
children 2c3bc7284992
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents: 1330
diff changeset
1 from browser import document, window, bind, html, DOMNode
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
2 from javascript import JSON
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
3 from bridge import Bridge
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from template import Template
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
5 import dialog
1308
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
6 from slideshow import SlideShow
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents: 1330
diff changeset
7 from invitation import InvitationManager
1346
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
8 import alt_media_player
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
9
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents: 1330
diff changeset
10 cache_path = window.cache_path
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
11 files_service = window.files_service
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
12 files_path = window.files_path
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents: 1330
diff changeset
13 try:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents: 1330
diff changeset
14 affiliations = window.affiliations.to_dict()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents: 1330
diff changeset
15 except AttributeError:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents: 1330
diff changeset
16 pass
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
17 bridge = Bridge()
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
18
1346
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
19 alt_media_player.install_if_needed()
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
20
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
21 photo_tpl = Template('photo/item.html')
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
22 player_tpl = Template('components/media_player.html')
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
23
1320
0cbf86b1dcca browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents: 1312
diff changeset
24 # file upload
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
25
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
26 def on_progress(ev, photo_elt):
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
27 if ev.lengthComputable:
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
28 percent = int(ev.loaded/ev.total*100)
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
29 update_progress(photo_elt, percent)
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
30
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
31
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
32 def on_load(file_, photo_elt):
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
33 update_progress(photo_elt, 100)
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
34 photo_elt.classList.add("progress_finished")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
35 photo_elt.classList.remove("progress_started")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
36 photo_elt.select_one('.action_delete').bind("click", on_delete)
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
37 print(f"file {file_.name} uploaded correctly")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
38
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
39
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
40 def on_error(failure, file_, photo_elt):
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
41 dialog.notification(
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
42 f"can't upload {file_.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
43 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
44 )
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
45
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
46
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
47 def update_progress(photo_elt, new_value):
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
48 progress_elt = photo_elt.select_one("progress")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
49 progress_elt.value = new_value
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
50 progress_elt.text = f"{new_value}%"
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
51
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
52
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
53 def on_slot_cb(file_, upload_slot, photo_elt):
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
54 put_url, get_url, headers = upload_slot
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
55 xhr = window.XMLHttpRequest.new()
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
56 xhr.open("PUT", put_url, True)
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
57 xhr.upload.bind('progress', lambda ev: on_progress(ev, photo_elt))
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
58 xhr.upload.bind('load', lambda ev: on_load(file_, photo_elt))
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
59 xhr.upload.bind('error', lambda ev: on_error(xhr.response, file_, photo_elt))
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
60 xhr.setRequestHeader('Xmpp-File-Path', window.encodeURIComponent(files_path))
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
61 xhr.setRequestHeader('Xmpp-File-No-Http', "true")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
62 xhr.send(file_)
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
63
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
64
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
65 def on_slot_eb(file_, failure, photo_elt):
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
66 dialog.notification(
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
67 f"Can't get upload slot: {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
68 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
69 )
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
70
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
71
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
72 def upload_files(files):
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
73 print(f"uploading {len(files)} files")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
74 album_items = document['album_items']
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
75 for file_ in files:
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
76 url = window.URL.createObjectURL(file_)
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
77 photo_elt = photo_tpl.get_elt({
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
78 "file": {
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
79 "name": file_.name,
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
80 # we don't want to open the file on click, it's not yet the
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
81 # uploaded URL
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
82 "url": url,
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
83 # we have no thumb yet, so we use the whole image
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
84 # TODO: reduce image for preview
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
85 "thumb_url": url,
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
86 },
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
87 "uploading": True,
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
88 })
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
89 photo_elt.classList.add("progress_started")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
90 album_items <= photo_elt
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
91
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
92 bridge.fileHTTPUploadGetSlot(
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
93 file_.name,
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
94 file_.size,
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
95 file_.type or '',
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
96 files_service,
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
97 callback=lambda upload_slot, file_=file_, photo_elt=photo_elt:
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
98 on_slot_cb(file_, upload_slot, photo_elt),
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
99 errback=lambda failure, file_=file_, photo_elt=photo_elt:
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
100 on_slot_eb(file_, failure, photo_elt),
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
101 )
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
102
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
103
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
104 @bind("#file_drop", "drop")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
105 def on_file_select(evt):
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
106 evt.stopPropagation()
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
107 evt.preventDefault()
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
108 files = evt.dataTransfer.files
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
109 upload_files(files)
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
110
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
111
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
112 @bind("#file_drop", "dragover")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
113 def on_drag_over(evt):
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
114 evt.stopPropagation()
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
115 evt.preventDefault()
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
116 evt.dataTransfer.dropEffect = 'copy'
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
117
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
118
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
119 @bind("#file_input", "change")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
120 def on_file_input_change(evt):
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
121 files = evt.currentTarget.files
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
122 upload_files(files)
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
123
1320
0cbf86b1dcca browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents: 1312
diff changeset
124 # delete
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
125
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
126 def file_delete_cb(item_elt, item):
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
127 item_elt.classList.add("state_deleted")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
128 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
129 print(f"deleted {item['name']}")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
130
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
131
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
132 def file_delete_eb(failure, item_elt, item):
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
133 dialog.notification(
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
134 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
135 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
136 )
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
137
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
138
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
139 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
140 file_path = f"{files_path.rstrip('/')}/{item['name']}"
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
141 bridge.fileSharingDelete(
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
142 files_service,
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
143 file_path,
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
144 "",
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
145 callback=lambda : file_delete_cb(item_elt, item),
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
146 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
147 )
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
148
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
149
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
150 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
151 notif_elt.remove()
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
152 item_elt.classList.remove("selected_for_deletion")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
153
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
154
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
155 def on_delete(evt):
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
156 evt.stopPropagation()
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
157 target = evt.currentTarget
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
158 item_elt = DOMNode(target.elt.closest('.item'))
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
159 item_elt.classList.add("selected_for_deletion")
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
160 item = JSON.parse(item_elt.dataset.item)
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
161 dialog.Confirm(
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
162 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
163 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
164 ok_color="danger",
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
165 ).show(
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
166 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
167 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
168 )
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
169
1320
0cbf86b1dcca browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents: 1312
diff changeset
170 # slideshow
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
171
1308
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
172 @bind(".photo_thumb_click", "click")
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
173 def photo_click(evt):
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
174 evt.stopPropagation()
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
175 evt.preventDefault()
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
176 slideshow = SlideShow()
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
177 target = evt.currentTarget
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
178 clicked_item_elt = DOMNode(target.elt.closest('.item'))
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
179
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
180 slideshow.attach()
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
181 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
182 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
183 try:
b525fdcb393b browser (photos/album): used biggest thumbnails instead of original image for slideshow:
Goffi <goffi@goffi.org>
parents: 1320
diff changeset
184 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
185 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
186 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
187 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
188 thumb_url = None
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
189 if item.get("mime_type", "")[:5] == "video":
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
190 player = alt_media_player.MediaPlayer(
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
191 [item['url']],
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
192 poster = thumb_url,
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
193 reduce_click_area = True
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
194 )
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
195 elt = player.elt
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
196 elt.classList.add("slide_video", "no_fullscreen")
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
197 slideshow.add_slide(
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
198 elt,
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
199 item,
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
200 options={
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
201 "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
202 "exit_callback": player.reset,
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
203 }
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
204 )
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
205 else:
cda5537c71d6 browser (photos/album): videos integrations:
Goffi <goffi@goffi.org>
parents: 1345
diff changeset
206 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
207 if item_elt == clicked_item_elt:
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
208 slideshow.index = idx
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
209
7a4a92cf5b2b browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents: 1300
diff changeset
210
1300
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
211 for elt in document.select('.action_delete'):
6e110baa707f browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff changeset
212 elt.bind("click", on_delete)
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})
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents: 1330
diff changeset
222 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
a75d82713a02 browser (photos/album): remove hint when delete button is pressed
Goffi <goffi@goffi.org>
parents: 1331
diff changeset
224 # hint
a75d82713a02 browser (photos/album): remove hint when delete button is pressed
Goffi <goffi@goffi.org>
parents: 1331
diff changeset
225 @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
226 def remove_hint(evt):
a75d82713a02 browser (photos/album): remove hint when delete button is pressed
Goffi <goffi@goffi.org>
parents: 1331
diff changeset
227 document['hint'].remove()