File size: 1,575 Bytes
3d330e9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
<script lang="ts">
import type { Page } from '$lib/types/Page';
import type { PageData } from './$types';
export let data: PageData;
function updatePicture(page: Page, key: string, value: string) {
fetch('/admin/pages/' + encodeURIComponent(page._id), {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ type: 'picture', key, value })
});
}
function updateText(page: Page, key: string, value: string) {
fetch('/admin/pages/' + encodeURIComponent(page._id), {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ type: 'text', key, value })
});
}
</script>
{#each data.pages as page}
<section class="mb-6">
<h1>{page.name} ({page._id})</h1>
<h2 class="mt-4">Textes</h2>
{#each Object.keys(page.text) as key}
<label class="block w-full mt-4">
<h3>{key}</h3>
<textarea
name="{page._id}_text_{key}"
cols="30"
rows="10"
class="block w-full"
value={page.text[key]}
on:blur={(event) => updateText(page, key, event.currentTarget.value)}
/>
</label>
{/each}
<h2 class="mt-4">Images</h2>
{#each Object.keys(page.pictures) as key}
<label class="block w-full mt-4">
<h3>{key}</h3>
<select
name="{page._id}_picture_{key}"
value={page.pictures[key]}
on:change={(event) => updatePicture(page, key, event.currentTarget.value)}
>
{#each data.photos as photo}
<option value={photo._id}>{photo.name}</option>
{/each}
</select>
</label>
{/each}
</section>
{/each}
|