Cost units can be edited

This commit is contained in:
2026-02-08 20:06:38 +01:00
parent 6fc65e195c
commit bccfc11687
53 changed files with 2021 additions and 29 deletions

View File

@@ -0,0 +1,46 @@
<script setup>
const model = defineModel({ type: String, default: '' })
function onInput(e) {
let val = e.target.value
// nur Ziffern und Komma erlauben
val = val.replace(/[^0-9,]/g, '')
// nur das erste Komma behalten
const parts = val.split(',')
if (parts.length > 2) {
val = parts[0] + ',' + parts.slice(1).join('')
}
// Nachkommastellen auf 2 begrenzen
if (parts.length === 2) {
val = parts[0] + ',' + parts[1].slice(0, 2)
}
model.value = val
}
function onKeypress(e) {
const key = e.key
// Ziffern sind immer erlaubt
if (/[0-9]/.test(key)) return
// Komma nur wenn noch keines im Wert enthalten ist
if (key === ',' && !model.value.includes(',')) return
// alles andere blocken (inkl. Minuszeichen, Punkte, Buchstaben)
e.preventDefault()
}
</script>
<template>
<input
type="text"
:value="model"
inputmode="decimal"
@input="onInput"
@keypress="onKeypress"
/>
</template>

View File

@@ -0,0 +1,139 @@
<template>
<teleport to="body">
<transition name="fade">
<div
v-if="show"
class="modal-overlay"
@click.self="close"
>
<transition name="scale">
<div
v-if="show"
ref="modalRef"
class="modal-content"
tabindex="-1"
>
<div class="modal-header">
<div class="title"><label>{{ title }}</label>
<span @click="close" class="dashicons dashicons-dismiss modal-close"></span>
</div>
</div>
<div class="modal-body">
<slot />
</div>
</div>
</transition>
</div>
</transition>
</teleport>
</template>
<script setup>
import { ref, watch, onMounted, onUnmounted, nextTick } from 'vue'
const props = defineProps({
show: Boolean,
title: { type: String, default: 'Modal' }
})
const emit = defineEmits(['close'])
const modalRef = ref(null)
function close() {
emit('close')
}
/**
* 1. ESC-Key schließt Modal
*/
function handleKeyDown(e) {
if (e.key === 'Escape') {
close()
}
// 2. Focus-Trap
if (e.key === 'Tab' && modalRef.value) {
const focusable = modalRef.value.querySelectorAll(
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
)
if (focusable.length === 0) return
const first = focusable[0]
const last = focusable[focusable.length - 1]
if (e.shiftKey && document.activeElement === first) {
e.preventDefault()
last.focus()
} else if (!e.shiftKey && document.activeElement === last) {
e.preventDefault()
first.focus()
}
}
}
/**
* 3. Body-Scroll sperren wenn Modal offen
*/
watch(
() => props.show,
async (newVal) => {
if (newVal) {
document.body.style.overflow = 'hidden'
await nextTick()
modalRef.value?.focus() // Setzt Focus ins Modal
} else {
document.body.style.overflow = ''
}
}
)
onMounted(() => {
window.addEventListener('keydown', handleKeyDown)
})
onUnmounted(() => {
window.removeEventListener('keydown', handleKeyDown)
document.body.style.overflow = '' // fallback cleanup
})
</script>
<style scoped>
.modal-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
}
.modal-content {
background: white;
border-radius: 12px;
max-width: 600px;
width: 90%;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
outline: none;
}
/* Animation */
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.3s ease;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}
.scale-enter-active,
.scale-leave-active {
transition: transform 0.25s ease, opacity 0.25s ease;
}
.scale-enter-from,
.scale-leave-to {
transform: scale(0.95);
opacity: 0;
}
</style>

View File

@@ -3,8 +3,6 @@
style: { type: String},
class: { type: String},
})
console.log(props.style)
</script>
<template>

View File

@@ -0,0 +1,115 @@
<script setup>
import { ref, shallowRef, onMounted } from "vue"
const props = defineProps({
tabs: {
type: Array,
required: true,
// [{ title: "Titel", component: Component, endpoint: "/wp-json/..." }]
}
})
const activeTab = ref(null) // aktuell ausgewählter Tab
const tabData = ref({}) // Daten für jeden Tab
const tabComponent = shallowRef(null) // Komponente für aktuellen Tab
const loading = ref(false)
const error = ref(null)
async function selectTab(index) {
const tab = props.tabs[index]
activeTab.value = index
tabComponent.value = null
error.value = null
loading.value = true
try {
const csrfToken = document
.querySelector('meta[name="csrf-token"]')
?.getAttribute('content')
const response = await fetch(tab.endpoint, {
method: 'GET', // oder POST, PUT, DELETE …
headers: {
'Accept': 'application/json',
'X-CSRF-TOKEN': csrfToken,
'X-Requested-With': 'XMLHttpRequest',
},
credentials: 'same-origin', // wichtig für Session/Auth
})
if (!response.ok) throw new Error("Fehler: " + response.status)
const json = await response.json()
tabData.value[index] = json
tabComponent.value = tab.component
} catch (err) {
error.value = err.message
} finally {
loading.value = false
}
}
// ersten Tab automatisch laden
onMounted(() => {
if (props.tabs.length > 0) {
selectTab(0)
}
})
</script>
<template>
<div class="tabs">
<!-- Tab Header -->
<div class="tab-header">
<button
v-for="(tab, index) in tabs"
:key="index"
:class="['tab-button', { active: activeTab === index }]"
@click="selectTab(index)"
>
{{ tab.title }}
</button>
</div>
<!-- Tab Content -->
<div class="tab-content" id="tab-content">
<div v-if="loading"> Lädt...</div>
<div v-else-if="error"> {{ error }}</div>
<component
v-else-if="tabComponent"
:is="tabComponent"
:data="tabData[activeTab]"
:deep_jump_id="tabs[activeTab].deep_jump_id"
:deep_jump_id_sub="tabs[activeTab].deep_jump_id_sub"
/>
</div>
</div>
</template>
<style scoped>
.tabs {
border: 1px solid #ddd;
border-radius: 8px;
}
.tab-header {
display: flex;
border-bottom: 1px solid #ddd;
}
.tab-button {
padding: 0.5rem 1rem;
cursor: pointer;
border: none;
background: #f8f8f8;
}
.tab-button.active {
font-weight: bold;
background: white;
border-bottom: 2px solid #0073aa;
}
.tab-content {
padding: 1rem;
width: 100%;
}
</style>