Fix drag-drop behavior when dropping onto root.

This commit is contained in:
voussoir 2020-09-20 12:20:36 -07:00
parent 00bc7e6eac
commit 169fd4945d
2 changed files with 20 additions and 5 deletions

View file

@ -424,14 +424,29 @@ function on_album_drag_drop(event)
return; return;
} }
const child_title = child.querySelector('.album_card_title').textContent.trim(); let prompt;
const parent_title = parent.querySelector('.album_card_title').textContent.trim(); if (parent_id === "root")
const prompt = `Move\n${child_title}\ninto\n${parent_title}?`; {
const child_title = child.querySelector('.album_card_title').textContent.trim();
prompt = `Remove child\n${child_title}?`;
}
else
{
const child_title = child.querySelector('.album_card_title').textContent.trim();
const parent_title = parent.querySelector('.album_card_title').textContent.trim();
prompt = `Move\n${child_title}\ninto\n${parent_title}?`;
}
if (! confirm(prompt)) if (! confirm(prompt))
{ {
return; return;
} }
if (ALBUM_ID)
if (parent_id === "root")
{
api.albums.remove_child(ALBUM_ID, child_id, common.refresh);
}
else if (ALBUM_ID)
{ {
api.albums.add_child(parent_id, child_id, null); api.albums.add_child(parent_id, child_id, null);
api.albums.remove_child(ALBUM_ID, child_id, common.refresh); api.albums.remove_child(ALBUM_ID, child_id, common.refresh);

View file

@ -5,7 +5,7 @@
<div <div
id="{{id}}" id="{{id}}"
class="album_card album_card_{{view}}" class="album_card album_card_{{view}}"
data-id="{{album.id}}" data-id="{{'root' if album == 'root' else album.id}}"
ondragstart="return on_album_drag_start(event);" ondragstart="return on_album_drag_start(event);"
ondragend="return on_album_drag_end(event);" ondragend="return on_album_drag_end(event);"
ondragover="return on_album_drag_over(event);" ondragover="return on_album_drag_over(event);"