Mercurial > libervia-web
annotate libervia/pages/photos/album/_browser/__init__.py @ 1331:fe353fceec38
browser (invitation, photos/album): invitation manager improvments:
invitation manager has been moved to a separated module, it is generic so it can be used
with other activities.
It has been simplified, and contact to add are dynamically filtered using a text input.
Invitation are done by email using a the new modal.
New notification module is used to indicate when invitation has been done.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 14 Aug 2020 09:31:32 +0200 |
parents | b525fdcb393b |
children | a75d82713a02 |
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 |
1300
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 |
1331
fe353fceec38
browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
1330
diff
changeset
|
9 cache_path = window.cache_path |
1300
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 files_service = window.files_service |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 files_path = window.files_path |
1331
fe353fceec38
browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
1330
diff
changeset
|
12 try: |
fe353fceec38
browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
1330
diff
changeset
|
13 affiliations = window.affiliations.to_dict() |
fe353fceec38
browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
1330
diff
changeset
|
14 except AttributeError: |
fe353fceec38
browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
1330
diff
changeset
|
15 pass |
1300
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 bridge = Bridge() |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
1320
0cbf86b1dcca
browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents:
1312
diff
changeset
|
18 # file upload |
1300
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 def on_progress(ev, photo_elt): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 if ev.lengthComputable: |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 percent = int(ev.loaded/ev.total*100) |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 update_progress(photo_elt, percent) |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 |
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_load(file_, photo_elt): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 update_progress(photo_elt, 100) |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 photo_elt.classList.add("progress_finished") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 photo_elt.classList.remove("progress_started") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 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
|
31 print(f"file {file_.name} uploaded correctly") |
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 def on_error(failure, file_, photo_elt): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 # TODO: cleaner error notification |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 window.alert(f"can't upload {file_.name}: failure") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 |
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 def update_progress(photo_elt, new_value): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 progress_elt = photo_elt.select_one("progress") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 progress_elt.value = new_value |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 progress_elt.text = f"{new_value}%" |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 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
|
46 put_url, get_url, headers = upload_slot |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 xhr = window.XMLHttpRequest.new() |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 xhr.open("PUT", put_url, True) |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 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
|
50 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
|
51 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
|
52 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
|
53 xhr.setRequestHeader('Xmpp-File-No-Http', "true") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 xhr.send(file_) |
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 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 def on_slot_eb(file_, failure, photo_elt): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 breakpoint() |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 |
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 def upload_files(files): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 print(f"uploading {len(files)} files") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 photo_tpl = Template('photo/item.html') |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 album_items = document['album_items'] |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 for file_ in files: |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 url = window.URL.createObjectURL(file_) |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 photo_elt = photo_tpl.get_elt({ |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 "file": { |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 "name": file_.name, |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 # 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
|
71 # uploaded URL |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 "url": url, |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 # 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
|
74 # TODO: reduce image for preview |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 "thumb_url": url, |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 }, |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 "uploading": True, |
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 photo_elt.classList.add("progress_started") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 album_items <= photo_elt |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 bridge.fileHTTPUploadGetSlot( |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 file_.name, |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 file_.size, |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 file_.type or '', |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 files_service, |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 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
|
88 on_slot_cb(file_, upload_slot, photo_elt), |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 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
|
90 on_slot_eb(file_, failure, 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 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 @bind("#file_drop", "drop") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 def on_file_select(evt): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 evt.stopPropagation() |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 evt.preventDefault() |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 files = evt.dataTransfer.files |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 upload_files(files) |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 |
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 @bind("#file_drop", "dragover") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 def on_drag_over(evt): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 evt.stopPropagation() |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 evt.preventDefault() |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 evt.dataTransfer.dropEffect = 'copy' |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 @bind("#file_input", "change") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 def on_file_input_change(evt): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 files = evt.currentTarget.files |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 upload_files(files) |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 |
1320
0cbf86b1dcca
browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents:
1312
diff
changeset
|
114 # delete |
1300
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 def file_delete_cb(item_elt, item): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 item_elt.classList.add("state_deleted") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 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
|
119 print(f"deleted {item['name']}") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 def file_delete_eb(failure, item_elt, item): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 # TODO: cleaner error notification |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 window.alert(f"error while deleting {item['name']}: failure") |
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 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 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
|
128 file_path = f"{files_path.rstrip('/')}/{item['name']}" |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 bridge.fileSharingDelete( |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 files_service, |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 file_path, |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 "", |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 callback=lambda : file_delete_cb(item_elt, item), |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 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
|
135 ) |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 |
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 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
|
139 notif_elt.remove() |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 item_elt.classList.remove("selected_for_deletion") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 def on_delete(evt): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 evt.stopPropagation() |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 target = evt.currentTarget |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 item_elt = DOMNode(target.elt.closest('.item')) |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 item_elt.classList.add("selected_for_deletion") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 item = JSON.parse(item_elt.dataset.item) |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 dialog.Confirm( |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 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
|
151 ok_label="delete", |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 ).show( |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 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
|
154 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
|
155 ) |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 |
1320
0cbf86b1dcca
browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents:
1312
diff
changeset
|
157 # slideshow |
1300
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 |
1308
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
159 @bind(".photo_thumb_click", "click") |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
160 def photo_click(evt): |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
161 evt.stopPropagation() |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
162 evt.preventDefault() |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
163 slideshow = SlideShow() |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
164 target = evt.currentTarget |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
165 clicked_item_elt = DOMNode(target.elt.closest('.item')) |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
166 |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
167 slideshow.attach() |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
168 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
|
169 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
|
170 try: |
b525fdcb393b
browser (photos/album): used biggest thumbnails instead of original image for slideshow:
Goffi <goffi@goffi.org>
parents:
1320
diff
changeset
|
171 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
|
172 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
|
173 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
|
174 print(f"Can't get full screen thumbnail URL: {e}") |
b525fdcb393b
browser (photos/album): used biggest thumbnails instead of original image for slideshow:
Goffi <goffi@goffi.org>
parents:
1320
diff
changeset
|
175 thumb_url = item['url'] |
b525fdcb393b
browser (photos/album): used biggest thumbnails instead of original image for slideshow:
Goffi <goffi@goffi.org>
parents:
1320
diff
changeset
|
176 slideshow.add_slide(html.IMG(src=thumb_url, Class="slide_img"), item) |
1308
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
177 if item_elt == clicked_item_elt: |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
178 slideshow.index = idx |
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 |
1300
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 for elt in document.select('.action_delete'): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 elt.bind("click", on_delete) |
1320
0cbf86b1dcca
browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents:
1312
diff
changeset
|
183 |
0cbf86b1dcca
browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents:
1312
diff
changeset
|
184 # manage |
0cbf86b1dcca
browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents:
1312
diff
changeset
|
185 |
0cbf86b1dcca
browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents:
1312
diff
changeset
|
186 |
0cbf86b1dcca
browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents:
1312
diff
changeset
|
187 @bind("#button_manage", "click") |
0cbf86b1dcca
browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents:
1312
diff
changeset
|
188 def manage_click(evt): |
0cbf86b1dcca
browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents:
1312
diff
changeset
|
189 evt.stopPropagation() |
0cbf86b1dcca
browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents:
1312
diff
changeset
|
190 evt.preventDefault() |
1331
fe353fceec38
browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
1330
diff
changeset
|
191 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
|
192 manager.attach(affiliations=affiliations) |