Resolve issues in Application Form
This commit is contained in:
parent
95e803ded5
commit
b9646be0ea
|
@ -2,7 +2,7 @@
|
||||||
import type { BackendError, Application } from '~/types'
|
import type { BackendError, Application } from '~/types'
|
||||||
|
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { ref, reactive, computed } from 'vue'
|
import { ref, reactive, computed, watchEffect } from 'vue'
|
||||||
import { computedEager } from '@vueuse/core'
|
import { computedEager } from '@vueuse/core'
|
||||||
import { useGettext } from 'vue3-gettext'
|
import { useGettext } from 'vue3-gettext'
|
||||||
import { uniq } from 'lodash-es'
|
import { uniq } from 'lodash-es'
|
||||||
|
@ -59,8 +59,32 @@ const submit = async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const scopeArray = computed({
|
const scopeArray = computed({
|
||||||
get: () => fields.scopes.split(' '),
|
get: () => fields.scopes.trim().split(' '),
|
||||||
set: (scopes: string[]) => uniq(scopes).join(' ')
|
set: (scopes: string[]) => (fields.scopes = uniq(scopes).join(' '))
|
||||||
|
})
|
||||||
|
|
||||||
|
const allScopesSelected = (parent: typeof allScopes['value'][number]) => {
|
||||||
|
const scopes = new Set(scopeArray.value)
|
||||||
|
return parent.children.every(child => scopes.has(child.id))
|
||||||
|
}
|
||||||
|
|
||||||
|
const toggleAllScopes = (parent: typeof allScopes['value'][number]) => {
|
||||||
|
const scopes = new Set(scopeArray.value)
|
||||||
|
|
||||||
|
const allScopesSelected = parent.children.every(child => scopes.has(child.id))
|
||||||
|
for (const child of parent.children) {
|
||||||
|
const action = allScopesSelected
|
||||||
|
? 'delete'
|
||||||
|
: 'add'
|
||||||
|
|
||||||
|
scopes[action](child.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
scopeArray.value = [...scopes]
|
||||||
|
}
|
||||||
|
|
||||||
|
watchEffect(() => {
|
||||||
|
console.log(scopeArray.value)
|
||||||
})
|
})
|
||||||
|
|
||||||
const scopeParents = computedEager(() => [
|
const scopeParents = computedEager(() => [
|
||||||
|
@ -153,9 +177,9 @@ const allScopes = computed(() => {
|
||||||
<div class="ui parent checkbox">
|
<div class="ui parent checkbox">
|
||||||
<input
|
<input
|
||||||
:id="parent.id"
|
:id="parent.id"
|
||||||
v-model="scopeArray"
|
:checked="allScopesSelected(parent)"
|
||||||
:value="parent.id"
|
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
@input="toggleAllScopes(parent)"
|
||||||
>
|
>
|
||||||
<label :for="parent.id">
|
<label :for="parent.id">
|
||||||
{{ parent.label }}
|
{{ parent.label }}
|
||||||
|
|
Loading…
Reference in New Issue