Mercurial > libervia-web
annotate libervia/pages/photos/album/_browser/__init__.py @ 1316:d0575e9abf7d
pages (files/list): use new `FISAffiliationsGet` to get `directory_affiliation`
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 01 Aug 2020 16:47:24 +0200 |
parents | 39a87d9099c4 |
children | 0cbf86b1dcca |
rev | line source |
---|---|
1300
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 from browser import document, window, bind, html, DOMNode |
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 |
1300
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 files_service = window.files_service |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 files_path = window.files_path |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 bridge = Bridge() |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 def on_progress(ev, photo_elt): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 if ev.lengthComputable: |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 percent = int(ev.loaded/ev.total*100) |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 update_progress(photo_elt, percent) |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 def on_load(file_, photo_elt): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 update_progress(photo_elt, 100) |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 photo_elt.classList.add("progress_finished") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 photo_elt.classList.remove("progress_started") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 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
|
24 print(f"file {file_.name} uploaded correctly") |
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 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 def on_error(failure, file_, photo_elt): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 # TODO: cleaner error notification |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 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
|
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 update_progress(photo_elt, new_value): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 progress_elt = photo_elt.select_one("progress") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 progress_elt.value = new_value |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 progress_elt.text = f"{new_value}%" |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 |
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 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
|
39 put_url, get_url, headers = upload_slot |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 xhr = window.XMLHttpRequest.new() |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 xhr.open("PUT", put_url, True) |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 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
|
43 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
|
44 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
|
45 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
|
46 xhr.setRequestHeader('Xmpp-File-No-Http', "true") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 xhr.send(file_) |
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 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 def on_slot_eb(file_, failure, photo_elt): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 breakpoint() |
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 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 def upload_files(files): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 print(f"uploading {len(files)} files") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 photo_tpl = Template('photo/item.html') |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 album_items = document['album_items'] |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 for file_ in files: |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 url = window.URL.createObjectURL(file_) |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 photo_elt = photo_tpl.get_elt({ |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 "file": { |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 "name": file_.name, |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 # 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
|
64 # uploaded URL |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 "url": url, |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 # 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
|
67 # TODO: reduce image for preview |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 "thumb_url": url, |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 }, |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 "uploading": True, |
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 photo_elt.classList.add("progress_started") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 album_items <= photo_elt |
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 bridge.fileHTTPUploadGetSlot( |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 file_.name, |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 file_.size, |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 file_.type or '', |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 files_service, |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 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
|
81 on_slot_cb(file_, upload_slot, photo_elt), |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 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
|
83 on_slot_eb(file_, failure, photo_elt), |
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 |
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 @bind("#file_drop", "drop") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 def on_file_select(evt): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 evt.stopPropagation() |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 evt.preventDefault() |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 files = evt.dataTransfer.files |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 upload_files(files) |
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 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 @bind("#file_drop", "dragover") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 def on_drag_over(evt): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 evt.stopPropagation() |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 evt.preventDefault() |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 evt.dataTransfer.dropEffect = 'copy' |
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_input", "change") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 def on_file_input_change(evt): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 files = evt.currentTarget.files |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 upload_files(files) |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 |
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 def file_delete_cb(item_elt, item): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 item_elt.classList.add("state_deleted") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 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
|
111 print(f"deleted {item['name']}") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 def file_delete_eb(failure, item_elt, item): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 # TODO: cleaner error notification |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 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
|
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 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
|
120 file_path = f"{files_path.rstrip('/')}/{item['name']}" |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 bridge.fileSharingDelete( |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 files_service, |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 file_path, |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 "", |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 callback=lambda : file_delete_cb(item_elt, item), |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 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
|
127 ) |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 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
|
131 notif_elt.remove() |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 item_elt.classList.remove("selected_for_deletion") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 def on_delete(evt): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 evt.stopPropagation() |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 target = evt.currentTarget |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 item_elt = DOMNode(target.elt.closest('.item')) |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 item_elt.classList.add("selected_for_deletion") |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 item = JSON.parse(item_elt.dataset.item) |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 dialog.Confirm( |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 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
|
143 ok_label="delete", |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 ).show( |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 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
|
146 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
|
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 |
1308
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
150 @bind(".photo_thumb_click", "click") |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
151 def photo_click(evt): |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
152 evt.stopPropagation() |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
153 evt.preventDefault() |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
154 slideshow = SlideShow() |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
155 target = evt.currentTarget |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
156 clicked_item_elt = DOMNode(target.elt.closest('.item')) |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
157 |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
158 slideshow.attach() |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
159 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
|
160 item = JSON.parse(item_elt.dataset.item) |
1312
39a87d9099c4
browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents:
1308
diff
changeset
|
161 slideshow.add_slide(html.IMG(src=item['url'], Class="slide_img"), item) |
1308
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
162 if item_elt == clicked_item_elt: |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
163 slideshow.index = idx |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
164 |
7a4a92cf5b2b
browser (album): start slideshow on photo click
Goffi <goffi@goffi.org>
parents:
1300
diff
changeset
|
165 |
1300
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 for elt in document.select('.action_delete'): |
6e110baa707f
browser (photos/album): photo(s) upload and deletion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 elt.bind("click", on_delete) |