adjust conditions modal
This commit is contained in:
@@ -29,21 +29,38 @@
|
||||
>Available in Pro</a>
|
||||
</div>
|
||||
<form @submit.prevent="validateSaveAndClose">
|
||||
<div class="my-4">
|
||||
<div class="space-y-4">
|
||||
<div class="my-4 space-y-5">
|
||||
<div
|
||||
v-for="(condition, cindex) in conditions"
|
||||
:key="cindex"
|
||||
class="space-y-4 relative"
|
||||
>
|
||||
<div
|
||||
v-if="conditions.length > 1"
|
||||
class="flex justify-between border-b mx-1 -mb-1 pb-1"
|
||||
>
|
||||
<span class="text-sm">
|
||||
{{ t('condition') }} {{ cindex + 1 }}
|
||||
</span>
|
||||
<a
|
||||
href="#"
|
||||
class="link text-sm"
|
||||
@click.prevent="conditions.splice(cindex, 1)"
|
||||
> {{ t('remove') }}</a>
|
||||
</div>
|
||||
<select
|
||||
class="select select-bordered select-sm w-full bg-white h-11 pl-4 text-base font-normal"
|
||||
required
|
||||
@change="[
|
||||
newCondition.field_uuid = $event.target.value,
|
||||
delete newCondition.value,
|
||||
(conditionActions.includes(newCondition.action) ? '' : newCondition.action = conditionActions[0])
|
||||
condition.field_uuid = $event.target.value,
|
||||
delete condition.value,
|
||||
(conditionActions(condition).includes(condition.action) ? '' : condition.action = conditionActions(condition)[0])
|
||||
]"
|
||||
>
|
||||
<option
|
||||
value=""
|
||||
disabled
|
||||
:selected="!newCondition.field_uuid"
|
||||
:selected="!condition.field_uuid"
|
||||
>
|
||||
{{ t('select_field_') }}
|
||||
</option>
|
||||
@@ -51,19 +68,19 @@
|
||||
v-for="f in fields"
|
||||
:key="f.uuid"
|
||||
:value="f.uuid"
|
||||
:selected="newCondition.field_uuid === f.uuid"
|
||||
:selected="condition.field_uuid === f.uuid"
|
||||
>
|
||||
{{ f.name || buildDefaultName(f, template.fields) }}
|
||||
</option>
|
||||
</select>
|
||||
<select
|
||||
v-model="newCondition.action"
|
||||
v-model="condition.action"
|
||||
class="select select-bordered select-sm w-full h-11 pl-4 text-base font-normal"
|
||||
:class="{ 'bg-white': newCondition.field_uuid, 'bg-base-300': !newCondition.field_uuid }"
|
||||
:required="newCondition.field_uuid"
|
||||
:class="{ 'bg-white': condition.field_uuid, 'bg-base-300': !condition.field_uuid }"
|
||||
:required="condition.field_uuid"
|
||||
>
|
||||
<option
|
||||
v-for="action in conditionActions"
|
||||
v-for="action in conditionActions(condition)"
|
||||
:key="action"
|
||||
:value="action"
|
||||
>
|
||||
@@ -71,10 +88,10 @@
|
||||
</option>
|
||||
</select>
|
||||
<select
|
||||
v-if="conditionField?.options?.length"
|
||||
v-if="conditionField(condition)?.options?.length"
|
||||
class="select select-bordered select-sm w-full bg-white h-11 pl-4 text-base font-normal"
|
||||
required
|
||||
@change="newCondition.value = $event.target.value"
|
||||
@change="condition.value = $event.target.value"
|
||||
>
|
||||
<option
|
||||
value=""
|
||||
@@ -84,16 +101,21 @@
|
||||
{{ t('select_value_') }}
|
||||
</option>
|
||||
<option
|
||||
v-for="(option, index) in conditionField.options"
|
||||
v-for="(option, index) in conditionField(condition).options"
|
||||
:key="option.uuid"
|
||||
:value="option.uuid"
|
||||
:selected="newCondition.value === option.uuid"
|
||||
:selected="condition.value === option.uuid"
|
||||
>
|
||||
{{ option.value || `${t('option')} ${index + 1}` }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<a
|
||||
href="#"
|
||||
class="inline float-right link text-right mb-3 px-2"
|
||||
@click.prevent="conditions.push({})"
|
||||
> + {{ t('add_condition') }}</a>
|
||||
<button
|
||||
class="base-button w-full mt-2"
|
||||
>
|
||||
@@ -106,7 +128,7 @@
|
||||
>
|
||||
<button
|
||||
class="link"
|
||||
@click="[newCondition.field_uuid = null, delete field.conditions, validateSaveAndClose()]"
|
||||
@click="[conditions = [], delete field.conditions, validateSaveAndClose()]"
|
||||
>
|
||||
{{ t('remove_condition') }}
|
||||
</button>
|
||||
@@ -133,16 +155,10 @@ export default {
|
||||
emits: ['close'],
|
||||
data () {
|
||||
return {
|
||||
newCondition: this.field.conditions?.[0] || {}
|
||||
conditions: this.field.conditions?.[0] ? JSON.parse(JSON.stringify(this.field.conditions)) : [{}]
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
conditionField () {
|
||||
return this.fields.find((f) => f.uuid === this.newCondition.field_uuid)
|
||||
},
|
||||
conditionActions () {
|
||||
return this.fieldActions(this.conditionField)
|
||||
},
|
||||
fields () {
|
||||
return this.template.fields.reduce((acc, f) => {
|
||||
if (f !== this.field && f.submitter_uuid === this.field.submitter_uuid) {
|
||||
@@ -157,6 +173,12 @@ export default {
|
||||
this.field.conditions ||= []
|
||||
},
|
||||
methods: {
|
||||
conditionField (condition) {
|
||||
return this.fields.find((f) => f.uuid === condition.field_uuid)
|
||||
},
|
||||
conditionActions (condition) {
|
||||
return this.fieldActions(this.conditionField(condition))
|
||||
},
|
||||
fieldActions (field) {
|
||||
const actions = []
|
||||
|
||||
@@ -181,8 +203,8 @@ export default {
|
||||
return alert('Available only in Pro')
|
||||
}
|
||||
|
||||
if (this.newCondition.field_uuid) {
|
||||
this.field.conditions = [this.newCondition]
|
||||
if (this.conditions.find((f) => f.field_uuid)) {
|
||||
this.field.conditions = this.conditions
|
||||
} else {
|
||||
delete this.field.conditions
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ const en = {
|
||||
select_field_: 'Select field...',
|
||||
select_value_: 'Select value...',
|
||||
remove_condition: 'Remove condition',
|
||||
add_condition: 'Add condition',
|
||||
are_you_sure: 'Are you sure?',
|
||||
sign_yourself: 'Sign Yourself',
|
||||
set_signing_date: 'Set signing date',
|
||||
|
||||
Reference in New Issue
Block a user