documents
This commit is contained in:
@@ -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