Things
All checks were successful
Build and Deploy Nuxt / build (push) Successful in 1m6s

This commit is contained in:
2026-10-13 22:50:51 +02:00
parent 50828af674
commit af76cf1050
18 changed files with 847 additions and 86 deletions

View File

@@ -11,13 +11,27 @@ const id = data.id;
const handle = ref(null);
const wrapper = ref(null);
const saving = ref(false);
const form = ref({
name: '', type: 'character', species: '', className: '', level: '', background: '', challengeRating: '',
category: 'adventuring-gear', rarity: 'common', quantity: 1, weight: '', properties: '', description: ''
});
// The window edits items when the sidebar passes one in; actors have their sheet.
const editing = data.entry || null;
const isActor = data.entityType === 'actor';
const endpoint = isActor ? '/actor/create' : '/item/create';
const endpoint = isActor ? '/actor/create' : (editing ? '/item/update' : '/item/create');
function initialForm() {
if (!editing) {
return {
name: '', type: 'character', species: '', className: '', level: '', background: '', challengeRating: '',
category: 'adventuring-gear', rarity: 'common', quantity: 1, weight: '', properties: '', description: ''
};
}
return {
name: editing.name ?? '', type: 'character', species: '', className: '', level: '', background: '', challengeRating: '',
category: editing.category ?? 'adventuring-gear', rarity: editing.rarity ?? 'common',
quantity: editing.quantity ?? 1, weight: editing.weight ?? '', properties: editing.properties ?? '',
description: editing.description ?? ''
};
}
const form = ref(initialForm());
onMounted(() => {
SetupHandle(id, handle);
@@ -31,7 +45,9 @@ async function saveEntry() {
if (!form.value.name.trim() || saving.value) return;
saving.value = true;
try {
const payload = { name: form.value.name.trim(), campaign: data.campaign };
const payload = isActor
? { name: form.value.name.trim(), campaign: data.campaign }
: { name: form.value.name.trim(), ...(editing ? { id: editing._id } : { campaign: data.campaign }) };
if (!isActor) {
for (const field of ['category', 'rarity', 'quantity', 'weight', 'properties', 'description']) {
payload[field] = form.value[field];
@@ -39,7 +55,7 @@ async function saveEntry() {
}
const response = await Server().post(endpoint, payload);
if (response.data.status === 'ok') {
emitter.emit('campaign-entry-created', { entityType: data.entityType, entry: response.data[isActor ? 'actor' : 'item'] });
emitter.emit(editing ? 'campaign-entry-updated' : 'campaign-entry-created', { entityType: data.entityType, entry: response.data[isActor ? 'actor' : 'item'] });
ClearWindow({ id });
}
} catch (error) {
@@ -54,7 +70,8 @@ async function saveEntry() {
<div class="window-wrapper" :id="'window-wrapper-' + id" ref="wrapper">
<WindowHandle :window="id" ref="handle" />
<div class="body">
<h3>{{ $t(isActor ? 'campaigns.actor.new' : 'campaigns.item.new') }}</h3>
<h3>{{ $t(editing ? 'campaigns.item.edit' : (isActor ? 'campaigns.actor.new' : 'campaigns.item.new')) }}</h3>
<p v-if="!isActor && editing?.foundryItemId" class="sync-note">{{ $t('campaigns.item.foundry-sync-note') }}</p>
<form @submit.prevent="saveEntry">
<label class="form-field">
<span>{{ $t('campaigns.fields.name') }}</span>
@@ -109,7 +126,7 @@ async function saveEntry() {
</label>
<div class="form-actions">
<button class="btn-primary sound-click" type="submit" :disabled="saving">
{{ saving ? $t('campaigns.actions.saving') : $t('campaigns.actions.submit') }}
{{ saving ? $t('campaigns.actions.saving') : $t(editing ? 'campaigns.actions.save' : 'campaigns.actions.submit') }}
</button>
</div>
</form>
@@ -121,6 +138,7 @@ async function saveEntry() {
.window-wrapper { display: flex; align-items: center; flex-direction: column; }
.body { width: 100%; padding: 10px 18px 16px; overflow-y: auto; }
h3 { margin: 0 0 12px; font-family: MrEavesRemake; }
.sync-note { margin: -8px 0 12px; font-size: 12px; opacity: 0.72; }
form { display: flex; flex-direction: column; gap: 10px; }
.form-field { min-width: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }