diff --git a/app/Form/Models/Form.php b/app/Form/Models/Form.php index 2a7eadcd..136b1864 100644 --- a/app/Form/Models/Form.php +++ b/app/Form/Models/Form.php @@ -66,13 +66,17 @@ class Form extends Model implements HasMedia }); $this->addMediaCollection('mailattachments') ->withDefaultProperties(fn () => [ - 'conditions' => [], + 'conditions' => [ + 'mode' => 'all', + 'ifs' => [] + ], ]) ->withPropertyValidation(fn () => [ - 'conditions' => 'array', - 'conditions.*.field' => 'required', - 'conditions.*.comparator' => 'required', - 'conditions.*.value' => 'present', + 'conditions.mode' => 'required|string|in:all,any', + 'conditions.ifs' => 'array', + 'conditions.ifs.*.field' => 'required', + 'conditions.ifs.*.comparator' => 'required', + 'conditions.ifs.*.value' => 'present', ]); } diff --git a/resources/js/components/form/Editor.vue b/resources/js/components/form/Editor.vue index a7726451..5dc100d7 100644 --- a/resources/js/components/form/Editor.vue +++ b/resources/js/components/form/Editor.vue @@ -74,13 +74,13 @@ const props = defineProps({ const editor = ref(null); const condition = ref(null); -async function openPopup(conditions) { +async function openPopup(data) { return new Promise((resolve, reject) => { new Promise((innerResolve, innerReject) => { condition.value = { resolve: innerResolve, reject: innerReject, - data: conditions, + data: data, }; }).then((data) => { resolve(data); @@ -93,7 +93,8 @@ class ConditionTune { constructor({api, data, config, block}) { this.api = api; this.data = data || { - conditions: [], + mode: 'all', + ifs: [], }; this.config = config; this.block = block; @@ -111,8 +112,12 @@ class ConditionTune { return this.wrapper; } + hasData() { + return this.data.ifs.length > 0; + } + styleWrapper() { - if (this.data.conditions.length > 0) { + if (this.hasData()) { this.wrapper.className = 'relative mt-6 mb-6 p-1 border border-blue-200 rounded'; if (!this.wrapper.querySelector('.condition-description')) { var tooltip = document.createElement('div'); @@ -134,7 +139,7 @@ class ConditionTune { closeOnActivate: true, toggle: true, onActivate: async () => { - this.data.conditions = await openPopup(this.data.conditions); + this.data = await openPopup(this.data); this.styleWrapper(); this.block.dispatchChange(); }, diff --git a/resources/js/views/form/Conditions.vue b/resources/js/views/form/Conditions.vue index 00d3d12a..0c3095e4 100644 --- a/resources/js/views/form/Conditions.vue +++ b/resources/js/views/form/Conditions.vue @@ -7,7 +7,7 @@
Bedingung einfügen -
+
- +
Speichern @@ -95,12 +95,12 @@ const fieldOptions = computed(() => }) ); -const conditions = ref(JSON.parse(JSON.stringify(props.value))); +const inner = ref(JSON.parse(JSON.stringify(props.value))); const locked = ref(false); function addCondition() { - conditions.value.push({ + inner.value.ifs.push({ field: null, comparator: null, value: null, @@ -108,7 +108,7 @@ function addCondition() { } async function save() { - emit('save', conditions.value); + emit('save', inner.value); } async function checkIfDirty() { diff --git a/resources/js/views/form/Index.vue b/resources/js/views/form/Index.vue index 72fb1623..6fdf5bff 100644 --- a/resources/js/views/form/Index.vue +++ b/resources/js/views/form/Index.vue @@ -99,7 +99,7 @@ >