2023-10-02 23:10:49 +03:00
|
|
|
<script>
|
2026-05-06 18:11:42 +03:00
|
|
|
import { array_move } from "../../edges/sortEdges";
|
2023-10-02 23:10:49 +03:00
|
|
|
import Sortable from "../../libs/Sortable.svelte";
|
2024-08-15 22:11:26 +03:00
|
|
|
import PreviewFile from "../previews/PreviewFile.svelte";
|
2026-04-29 19:40:37 +03:00
|
|
|
import FileDialog from "../../dialog/FileDialog.svelte";
|
|
|
|
|
import Uploader from "../../files/Uploader.svelte";
|
2026-05-14 22:49:47 +03:00
|
|
|
import Icon from "../../common/Icon.svelte";
|
2023-10-02 23:10:49 +03:00
|
|
|
|
|
|
|
|
export let field;
|
|
|
|
|
export let record;
|
2026-05-06 18:11:42 +03:00
|
|
|
export let value = [];
|
2023-10-02 23:10:49 +03:00
|
|
|
let browseModal;
|
|
|
|
|
|
2026-05-06 18:11:42 +03:00
|
|
|
function removeFile(e) {
|
2023-10-02 23:10:49 +03:00
|
|
|
e.preventDefault();
|
2026-05-06 18:11:42 +03:00
|
|
|
value = value.filter((f) => !(f.id === e.detail));
|
2023-10-02 23:10:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function reorder(e) {
|
2026-05-06 18:11:42 +03:00
|
|
|
value = await array_move(value, e.detail.source, e.detail.target);
|
2023-10-02 23:10:49 +03:00
|
|
|
}
|
|
|
|
|
|
2026-05-06 18:11:42 +03:00
|
|
|
function insertFiles(e) {
|
2023-10-02 23:10:49 +03:00
|
|
|
e.preventDefault();
|
|
|
|
|
browseModal.close();
|
2026-05-14 22:49:47 +03:00
|
|
|
value = [...(value ?? []), ...(e.detail.files ?? [])];
|
2026-05-06 18:11:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function replaceFiles(e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
browseModal.close();
|
|
|
|
|
value = e.detail ?? [];
|
2026-04-29 19:40:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function uploadComplete(e) {
|
2026-05-13 19:33:27 +03:00
|
|
|
value = [...value, ...e.detail];
|
2023-10-02 23:10:49 +03:00
|
|
|
}
|
2026-05-05 19:21:59 +03:00
|
|
|
|
|
|
|
|
function openBrowseModal(e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
browseModal.open(record.id);
|
|
|
|
|
}
|
2023-10-02 23:10:49 +03:00
|
|
|
</script>
|
|
|
|
|
|
2026-05-14 22:49:47 +03:00
|
|
|
<div
|
|
|
|
|
class="mb-0"
|
|
|
|
|
style="display: flex; align-items: start; justify-content: start; gap:6px"
|
|
|
|
|
>
|
|
|
|
|
<button class="button" on:click={openBrowseModal}>
|
|
|
|
|
<Icon icon="photo-film"></Icon> Browse
|
|
|
|
|
</button>
|
2026-04-29 19:40:37 +03:00
|
|
|
|
2026-05-14 22:49:47 +03:00
|
|
|
<Uploader recordId={record.id} on:uploadComplete={uploadComplete} />
|
2023-10-02 23:10:49 +03:00
|
|
|
</div>
|
2026-05-06 18:11:42 +03:00
|
|
|
{#if value.length > 0}
|
2024-08-16 14:34:39 +03:00
|
|
|
<Sortable sortableClass="mt-3" on:update={reorder}>
|
2026-05-06 18:11:42 +03:00
|
|
|
{#each value ?? [] as aFile (aFile.id)}
|
2024-08-16 16:00:48 +03:00
|
|
|
<!--This div helps the sorting thing-->
|
2026-05-06 18:11:42 +03:00
|
|
|
<div>
|
2026-04-29 19:40:37 +03:00
|
|
|
<PreviewFile
|
2026-05-06 18:11:42 +03:00
|
|
|
file={aFile}
|
2026-04-29 19:40:37 +03:00
|
|
|
hasDelete={true}
|
2026-05-06 18:11:42 +03:00
|
|
|
on:remove_file={removeFile}
|
2026-04-29 19:40:37 +03:00
|
|
|
></PreviewFile>
|
2024-08-16 16:00:48 +03:00
|
|
|
</div>
|
2023-10-02 23:10:49 +03:00
|
|
|
{/each}
|
|
|
|
|
</Sortable>
|
2026-05-06 18:11:42 +03:00
|
|
|
{/if}
|
|
|
|
|
<FileDialog
|
|
|
|
|
bind:this={browseModal}
|
|
|
|
|
on:insert_files={insertFiles}
|
|
|
|
|
on:replace_files={replaceFiles}
|
|
|
|
|
></FileDialog>
|