documents
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<script setup>
|
||||
import { ref, watch } from 'vue';
|
||||
import { useForm, router, usePage } from '@inertiajs/vue3';
|
||||
import DialogModal from './DialogModal.vue';
|
||||
import InputLabel from './InputLabel.vue';
|
||||
import SectionTitle from './SectionTitle.vue';
|
||||
@@ -33,47 +34,47 @@ const emit = defineEmits(['close']);
|
||||
|
||||
const close = () => {
|
||||
emit('close');
|
||||
|
||||
setTimeout(() => {
|
||||
errors.value = {};
|
||||
}, 500);
|
||||
try { form.clearErrors && form.clearErrors(); } catch {}
|
||||
}, 300);
|
||||
}
|
||||
|
||||
const form = ref({
|
||||
const form = useForm({
|
||||
address: '',
|
||||
country: '',
|
||||
type_id: props.types[0].id,
|
||||
post_code: '',
|
||||
city: '',
|
||||
type_id: props.types?.[0]?.id ?? null,
|
||||
description: ''
|
||||
});
|
||||
|
||||
const resetForm = () => {
|
||||
form.value = {
|
||||
address: '',
|
||||
country: '',
|
||||
type_id: props.types[0].id,
|
||||
description: ''
|
||||
};
|
||||
form.address = '';
|
||||
form.country = '';
|
||||
form.post_code = '';
|
||||
form.city = '';
|
||||
form.type_id = props.types?.[0]?.id ?? null;
|
||||
form.description = '';
|
||||
}
|
||||
|
||||
const create = async () => {
|
||||
processing.value = true;
|
||||
errors.value = {};
|
||||
|
||||
const data = await axios({
|
||||
method: 'post',
|
||||
url: route('person.address.create', props.person),
|
||||
data: form.value
|
||||
}).then((response) => {
|
||||
props.person.addresses.push(response.data.address);
|
||||
|
||||
processing.value = false;
|
||||
|
||||
close();
|
||||
resetForm();
|
||||
|
||||
}).catch((reason) => {
|
||||
errors.value = reason.response.data.errors;
|
||||
processing.value = false;
|
||||
form.post(route('person.address.create', props.person), {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
// Optimistically append from last created record in DB by refetch or expose via flash if needed.
|
||||
// For now, trigger a lightweight reload of person's addresses via a GET if you have an endpoint, else trust parent reactivity.
|
||||
processing.value = false;
|
||||
close();
|
||||
form.reset();
|
||||
},
|
||||
onError: (e) => {
|
||||
errors.value = e || {};
|
||||
processing.value = false;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -81,23 +82,17 @@ const update = async () => {
|
||||
processing.value = true;
|
||||
errors.value = {};
|
||||
|
||||
const data = await axios({
|
||||
method: 'put',
|
||||
url: route('person.address.update', {person: props.person, address_id: props.id}),
|
||||
data: form.value
|
||||
}).then((response) => {
|
||||
console.log(response.data.address)
|
||||
const index = props.person.addresses.findIndex( a => a.id === response.data.address.id );
|
||||
props.person.addresses[index] = response.data.address;
|
||||
|
||||
processing.value = false;
|
||||
|
||||
close();
|
||||
resetForm();
|
||||
|
||||
}).catch((reason) => {
|
||||
errors.value = reason.response.data.errors;
|
||||
processing.value = false;
|
||||
form.put(route('person.address.update', {person: props.person, address_id: props.id}), {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
processing.value = false;
|
||||
close();
|
||||
form.reset();
|
||||
},
|
||||
onError: (e) => {
|
||||
errors.value = e || {};
|
||||
processing.value = false;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -108,12 +103,12 @@ watch(
|
||||
console.log(props.edit)
|
||||
props.person.addresses.filter((a) => {
|
||||
if(a.id === props.id){
|
||||
form.value = {
|
||||
address: a.address,
|
||||
country: a.country,
|
||||
type_id: a.type_id,
|
||||
description: a.description
|
||||
};
|
||||
form.address = a.address;
|
||||
form.country = a.country;
|
||||
form.post_code = a.post_code || a.postal_code || '';
|
||||
form.city = a.city || '';
|
||||
form.type_id = a.type_id;
|
||||
form.description = a.description;
|
||||
}
|
||||
});
|
||||
return;
|
||||
@@ -175,6 +170,28 @@ const callSubmit = () => {
|
||||
|
||||
<InputError v-if="errors.address !== undefined" v-for="err in errors.address" :message="err" />
|
||||
</div>
|
||||
<div class="col-span-6 sm:col-span-4">
|
||||
<InputLabel for="cr_post_code" value="Poštna številka" />
|
||||
<TextInput
|
||||
id="cr_post_code"
|
||||
v-model="form.post_code"
|
||||
type="text"
|
||||
class="mt-1 block w-full"
|
||||
autocomplete="postal-code"
|
||||
/>
|
||||
<InputError v-if="errors.post_code !== undefined" v-for="err in errors.post_code" :message="err" />
|
||||
</div>
|
||||
<div class="col-span-6 sm:col-span-4">
|
||||
<InputLabel for="cr_city" value="Mesto" />
|
||||
<TextInput
|
||||
id="cr_city"
|
||||
v-model="form.city"
|
||||
type="text"
|
||||
class="mt-1 block w-full"
|
||||
autocomplete="address-level2"
|
||||
/>
|
||||
<InputError v-if="errors.city !== undefined" v-for="err in errors.city" :message="err" />
|
||||
</div>
|
||||
<div class="col-span-6 sm:col-span-4">
|
||||
<InputLabel for="cr_type" value="Tip"/>
|
||||
<select
|
||||
|
||||
@@ -1,17 +1,197 @@
|
||||
<template>
|
||||
<div></div>
|
||||
</template>
|
||||
<script setup>
|
||||
import { ref, watch } from "vue";
|
||||
import { useForm } from "@inertiajs/vue3";
|
||||
import DialogModal from "./DialogModal.vue";
|
||||
import InputLabel from "./InputLabel.vue";
|
||||
import SectionTitle from "./SectionTitle.vue";
|
||||
import TextInput from "./TextInput.vue";
|
||||
import InputError from "./InputError.vue";
|
||||
import PrimaryButton from "./PrimaryButton.vue";
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "Test",
|
||||
created() {},
|
||||
data() {
|
||||
return {};
|
||||
},
|
||||
props: {},
|
||||
methods: {},
|
||||
const props = defineProps({
|
||||
show: { type: Boolean, default: false },
|
||||
person: Object,
|
||||
types: Array,
|
||||
id: { type: Number, default: 0 },
|
||||
});
|
||||
|
||||
const processing = ref(false);
|
||||
const errors = ref({});
|
||||
|
||||
const emit = defineEmits(["close"]);
|
||||
const close = () => {
|
||||
emit("close");
|
||||
setTimeout(() => {
|
||||
errors.value = {};
|
||||
try {
|
||||
form.clearErrors && form.clearErrors();
|
||||
} catch {}
|
||||
}, 300);
|
||||
};
|
||||
|
||||
const form = useForm({
|
||||
address: "",
|
||||
country: "",
|
||||
post_code: "",
|
||||
city: "",
|
||||
type_id: props.types?.[0]?.id ?? null,
|
||||
description: "",
|
||||
});
|
||||
|
||||
const resetForm = () => {
|
||||
form.address = "";
|
||||
form.country = "";
|
||||
form.post_code = "";
|
||||
form.city = "";
|
||||
form.type_id = props.types?.[0]?.id ?? null;
|
||||
form.description = "";
|
||||
};
|
||||
|
||||
const hydrate = () => {
|
||||
const id = props.id;
|
||||
if (id) {
|
||||
const a = (props.person.addresses || []).find((x) => x.id === id);
|
||||
if (a) {
|
||||
form.address = a.address;
|
||||
form.country = a.country;
|
||||
form.post_code = a.post_code || a.postal_code || "";
|
||||
form.city = a.city || "";
|
||||
form.type_id = a.type_id;
|
||||
form.description = a.description || "";
|
||||
}
|
||||
} else {
|
||||
resetForm();
|
||||
}
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.id,
|
||||
() => hydrate(),
|
||||
{ immediate: true }
|
||||
);
|
||||
watch(
|
||||
() => props.show,
|
||||
(v) => {
|
||||
if (v) hydrate();
|
||||
}
|
||||
);
|
||||
|
||||
const update = async () => {
|
||||
processing.value = true;
|
||||
errors.value = {};
|
||||
|
||||
form.put(
|
||||
route("person.address.update", { person: props.person, address_id: props.id }),
|
||||
{
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
processing.value = false;
|
||||
close();
|
||||
form.reset();
|
||||
},
|
||||
onError: (e) => {
|
||||
errors.value = e || {};
|
||||
processing.value = false;
|
||||
},
|
||||
}
|
||||
);
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped></style>
|
||||
<template>
|
||||
<DialogModal :show="show" @close="close">
|
||||
<template #title>Spremeni naslov</template>
|
||||
<template #content>
|
||||
<form @submit.prevent="update">
|
||||
<SectionTitle class="border-b mb-4"
|
||||
><template #title>Naslov</template></SectionTitle
|
||||
>
|
||||
|
||||
<div class="col-span-6 sm:col-span-4">
|
||||
<InputLabel for="up_address" value="Naslov" />
|
||||
<TextInput
|
||||
id="up_address"
|
||||
v-model="form.address"
|
||||
type="text"
|
||||
class="mt-1 block w-full"
|
||||
autocomplete="address"
|
||||
/>
|
||||
<InputError
|
||||
v-if="errors.address !== undefined"
|
||||
v-for="err in errors.address"
|
||||
:message="err"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-6 sm:col-span-4">
|
||||
<InputLabel for="up_country" value="Država" />
|
||||
<TextInput
|
||||
id="up_country"
|
||||
v-model="form.country"
|
||||
type="text"
|
||||
class="mt-1 block w-full"
|
||||
autocomplete="country"
|
||||
/>
|
||||
<InputError
|
||||
v-if="errors.country !== undefined"
|
||||
v-for="err in errors.country"
|
||||
:message="err"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-6 sm:col-span-4">
|
||||
<InputLabel for="up_post_code" value="Poštna številka" />
|
||||
<TextInput
|
||||
id="up_post_code"
|
||||
v-model="form.post_code"
|
||||
type="text"
|
||||
class="mt-1 block w-full"
|
||||
autocomplete="postal-code"
|
||||
/>
|
||||
<InputError
|
||||
v-if="errors.post_code !== undefined"
|
||||
v-for="err in errors.post_code"
|
||||
:message="err"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-6 sm:col-span-4">
|
||||
<InputLabel for="up_city" value="Mesto" />
|
||||
<TextInput
|
||||
id="up_city"
|
||||
v-model="form.city"
|
||||
type="text"
|
||||
class="mt-1 block w-full"
|
||||
autocomplete="address-level2"
|
||||
/>
|
||||
<InputError
|
||||
v-if="errors.city !== undefined"
|
||||
v-for="err in errors.city"
|
||||
:message="err"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-6 sm:col-span-4">
|
||||
<InputLabel for="up_type" value="Tip" />
|
||||
<select
|
||||
id="up_type"
|
||||
v-model="form.type_id"
|
||||
class="block w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm"
|
||||
>
|
||||
<option v-for="type in types" :key="type.id" :value="type.id">
|
||||
{{ type.name }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end mt-4">
|
||||
<PrimaryButton :class="{ 'opacity-25': processing }" :disabled="processing"
|
||||
>Shrani</PrimaryButton
|
||||
>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
</DialogModal>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
|
||||
@@ -7,6 +7,7 @@ import { provide, ref, watch } from 'vue';
|
||||
import axios from 'axios';
|
||||
import PersonUpdateForm from './PersonUpdateForm.vue';
|
||||
import AddressCreateForm from './AddressCreateForm.vue';
|
||||
import AddressUpdateForm from './AddressUpdateForm.vue';
|
||||
import PhoneCreateForm from './PhoneCreateForm.vue';
|
||||
import EmailCreateForm from './EmailCreateForm.vue';
|
||||
import EmailUpdateForm from './EmailUpdateForm.vue';
|
||||
@@ -74,8 +75,9 @@ const closeConfirm = () => { confirm.value.show = false; };
|
||||
const getMainAddress = (adresses) => {
|
||||
const addr = adresses.filter( a => a.type.id === 1 )[0] ?? '';
|
||||
if( addr !== '' ){
|
||||
const tail = (addr.post_code && addr.city) ? `, ${addr.post_code} ${addr.city}` : '';
|
||||
const country = addr.country !== '' ? ` - ${addr.country}` : '';
|
||||
return addr.address !== '' ? addr.address + country : '';
|
||||
return addr.address !== '' ? (addr.address + tail + country) : '';
|
||||
}
|
||||
|
||||
return '';
|
||||
@@ -234,7 +236,9 @@ const getTRRs = (p) => {
|
||||
<button @click="openConfirm('address', address.id, address.address)"><TrashBinIcon size="md" css="text-red-600 hover:text-red-700" /></button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="text-sm md:text-base leading-7 text-gray-900">{{ address.address }}</p>
|
||||
<p class="text-sm md:text-base leading-7 text-gray-900">
|
||||
{{ (address.post_code && address.city) ? `${address.address}, ${address.post_code} ${address.city}` : address.address }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</CusTab>
|
||||
@@ -335,6 +339,13 @@ const getTRRs = (p) => {
|
||||
:id="editAddressId"
|
||||
:edit="editAddress"
|
||||
/>
|
||||
<AddressUpdateForm
|
||||
:show="drawerAddAddress && editAddress"
|
||||
@close="drawerAddAddress = false"
|
||||
:person="person"
|
||||
:types="types.address_types"
|
||||
:id="editAddressId"
|
||||
/>
|
||||
|
||||
<PhoneCreateForm
|
||||
:show="drawerAddPhone"
|
||||
|
||||
@@ -205,6 +205,49 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Custom tokens defaults -->
|
||||
<div class="bg-white border rounded-lg shadow-sm p-5 space-y-5">
|
||||
<h2 class="text-sm font-semibold tracking-wide text-gray-700 uppercase">
|
||||
Custom tokens (privzete vrednosti)
|
||||
</h2>
|
||||
<div class="space-y-3">
|
||||
<div class="flex items-center gap-2">
|
||||
<button type="button" :class="[btnBase, btnOutline]" @click="addCustomDefault">
|
||||
Dodaj vrstico
|
||||
</button>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||||
<div
|
||||
v-for="(row, idx) in customRows"
|
||||
:key="idx"
|
||||
class="grid grid-cols-12 items-center gap-2"
|
||||
>
|
||||
<input
|
||||
v-model="row.key"
|
||||
type="text"
|
||||
class="input input-bordered input-sm w-full col-span-4"
|
||||
placeholder="custom ključ (npr. order_id)"
|
||||
/>
|
||||
<input
|
||||
v-model="row.value"
|
||||
type="text"
|
||||
class="input input-bordered input-sm w-full col-span-5"
|
||||
placeholder="privzeta vrednost"
|
||||
/>
|
||||
<select v-model="row.type" class="select select-bordered select-sm w-full col-span-2">
|
||||
<option value="string">string</option>
|
||||
<option value="number">number</option>
|
||||
<option value="date">date</option>
|
||||
</select>
|
||||
<button type="button" class="btn btn-ghost btn-xs col-span-1" @click="removeCustomDefault(idx)">✕</button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="text-[11px] text-gray-500">
|
||||
Uporabite v predlogi kot <code v-pre>{{custom.your_key}}</code>. Manjkajoče vrednosti se privzeto izpraznijo.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-3 pt-2">
|
||||
<button
|
||||
type="submit"
|
||||
@@ -274,7 +317,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed } from "vue";
|
||||
import { computed, reactive } from "vue";
|
||||
import { useForm, Link, router } from "@inertiajs/vue3";
|
||||
import AdminLayout from "@/Layouts/AdminLayout.vue";
|
||||
|
||||
@@ -303,6 +346,8 @@ const form = useForm({
|
||||
action_id: props.template.action_id ?? null,
|
||||
decision_id: props.template.decision_id ?? null,
|
||||
activity_note_template: props.template.activity_note_template || "",
|
||||
// meta will include custom_defaults on submit
|
||||
meta: props.template.meta || {},
|
||||
});
|
||||
|
||||
const toggleForm = useForm({});
|
||||
@@ -322,6 +367,20 @@ function handleActionChange() {
|
||||
}
|
||||
|
||||
function submit() {
|
||||
// Build meta.custom_defaults object from rows
|
||||
const entries = customRows
|
||||
.filter((r) => (r.key || "").trim() !== "")
|
||||
.reduce((acc, r) => {
|
||||
acc[r.key.trim()] = r.value ?? "";
|
||||
return acc;
|
||||
}, {});
|
||||
const types = customRows
|
||||
.filter((r) => (r.key || "").trim() !== "")
|
||||
.reduce((acc, r) => {
|
||||
acc[r.key.trim()] = r.type || 'string';
|
||||
return acc;
|
||||
}, {});
|
||||
form.meta = Object.assign({}, form.meta || {}, { custom_defaults: entries, custom_default_types: types });
|
||||
form.put(route("admin.document-templates.settings.update", props.template.id));
|
||||
}
|
||||
|
||||
@@ -330,4 +389,22 @@ function toggleActive() {
|
||||
preserveScroll: true,
|
||||
});
|
||||
}
|
||||
|
||||
// Custom defaults rows state
|
||||
const baseDefaults = (props.template.meta && props.template.meta.custom_defaults) || {};
|
||||
const baseTypes = (props.template.meta && props.template.meta.custom_default_types) || {};
|
||||
const customRows = reactive(
|
||||
Object.keys(baseDefaults).length
|
||||
? Object.entries(baseDefaults).map(([k, v]) => ({ key: k, value: v, type: baseTypes[k] || 'string' }))
|
||||
: [{ key: "", value: "", type: 'string' }]
|
||||
);
|
||||
|
||||
function addCustomDefault() {
|
||||
customRows.push({ key: "", value: "", type: 'string' });
|
||||
}
|
||||
|
||||
function removeCustomDefault(idx) {
|
||||
customRows.splice(idx, 1);
|
||||
if (!customRows.length) customRows.push({ key: "", value: "" });
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user