Files
lucent-laravel/front/js/entry/FieldEditEntry/FieldEditEntry.svelte
T

161 lines
4.6 KiB
Svelte
Raw Normal View History

2026-01-08 15:19:08 +02:00
<script>
2026-01-08 18:50:32 +02:00
import SchemaLayout from "../../layouts/SchemaLayout.svelte";
2026-01-08 15:19:08 +02:00
import TextFieldProps from "./TextFieldProps.svelte";
2026-01-10 02:09:50 +02:00
import RelationFieldProps from "./RelationFieldProps.svelte";
2026-01-13 17:51:19 +02:00
import FileFieldProps from "./FileFieldProps.svelte";
2026-01-08 15:19:08 +02:00
import DeleteButton from "../../common/DeleteButton.svelte";
import { post } from "../../modules/remote";
import { getApp } from "../../app";
let { channel, user, data } = $props();
const app = getApp();
function handleUpdate(e) {
e.preventDefault();
post(
app.url("fields/update"),
{
field: data.field,
},
(data, err) => {
if (err.isEmpty()) {
Turbo.visit(app.url("schemas"));
} else {
console.log(err);
}
},
);
}
function handleDelete() {
post(
app.url("fields/delete"),
{
fieldId: data.field.id,
},
(data, err) => {
if (err.isEmpty()) {
Turbo.visit(app.url("schemas"));
} else {
console.log(err);
}
},
);
}
</script>
2026-01-08 18:50:32 +02:00
<SchemaLayout {body} {channel} {user}></SchemaLayout>
2026-01-08 15:19:08 +02:00
{#snippet body()}
<h3 class="header-small mb-4 mt-5">
Edit <em>{data.field.type}</em> field {data.field.name}
</h3>
2026-01-08 23:23:48 +02:00
{#if data.field.alias == "_title"}
{@render titleField()}
{:else}
{@render normalfield()}
{/if}
{/snippet}
{#snippet normalfield()}
2026-01-08 15:19:08 +02:00
<form onsubmit={handleUpdate}>
<fieldset>
<label>
Name
<input
bind:value={data.field.name}
placeholder="ex. Description"
minlength="2"
maxlength="30"
required
/>
</label>
<label>
Alias
<input
bind:value={data.field.alias}
placeholder="ex. description"
minlength="2"
maxlength="30"
required
aria-describedby="alias-helper"
/>
<small id="alias-helper">
Developers will use this to reference the field
</small>
</label>
2026-01-09 16:54:42 +02:00
<label>
Help text
<input bind:value={data.field.help} />
</label>
2026-01-08 23:23:48 +02:00
<label>
<input
bind:checked={data.field.translatable}
type="checkbox"
role="switch"
/>
Is Translatable
</label>
2026-01-09 16:54:42 +02:00
<fieldset>
<label>
<input
bind:checked={data.field.required}
type="checkbox"
role="switch"
/>
Required
</label>
<label>
<input
bind:checked={data.field.readonly}
type="checkbox"
role="switch"
/>
Readonly
</label>
<label>
<input
bind:checked={data.field.hidden}
type="checkbox"
role="switch"
/>
Hidden
</label>
</fieldset>
2026-01-08 15:19:08 +02:00
</fieldset>
{#if data.field.type === "text"}
<TextFieldProps field={data.field}></TextFieldProps>
2026-01-10 02:09:50 +02:00
{:else if data.field.type === "relation"}
<RelationFieldProps field={data.field} schemas={data.schemas}
></RelationFieldProps>
2026-01-13 17:51:19 +02:00
{:else if data.field.type === "file"}
<FileFieldProps field={data.field}></FileFieldProps>
2026-01-08 15:19:08 +02:00
{/if}
<button type="submit">Update</button>
</form>
<DeleteButton onDelete={handleDelete}>
{#snippet text()}
Delete field
{/snippet}
</DeleteButton>
{/snippet}
2026-01-08 23:23:48 +02:00
{#snippet titleField()}
<form onsubmit={handleUpdate}>
<fieldset>
<label>
<input
bind:checked={data.field.translatable}
type="checkbox"
role="switch"
/>
Is Translatable
</label>
</fieldset>
<button type="submit">Update</button>
</form>
{/snippet}