|
|
@@ -10,8 +10,8 @@ de quitter si des données ont été modifiées.
|
|
|
<template>
|
|
|
<LayoutContainer>
|
|
|
<v-form
|
|
|
- v-model="isValid"
|
|
|
ref="form"
|
|
|
+ v-model="isValid"
|
|
|
:readonly="readonly"
|
|
|
@submit.prevent=""
|
|
|
>
|
|
|
@@ -27,9 +27,9 @@ de quitter si des données ont été modifiées.
|
|
|
|
|
|
<UiButtonSubmit
|
|
|
v-if="!readonly"
|
|
|
- @submit="submit"
|
|
|
:actions="actions"
|
|
|
:validation-pending="validationPending || !isValid"
|
|
|
+ @submit="submit"
|
|
|
></UiButtonSubmit>
|
|
|
</v-col>
|
|
|
</v-row>
|
|
|
@@ -49,9 +49,9 @@ de quitter si des données ont été modifiées.
|
|
|
<slot name="form.button" />
|
|
|
|
|
|
<UiButtonSubmit
|
|
|
- @submit="submit"
|
|
|
- :actions="actions"
|
|
|
:validation-pending="validationPending || !isValid"
|
|
|
+ :actions="actions"
|
|
|
+ @submit="submit"
|
|
|
></UiButtonSubmit>
|
|
|
</v-col>
|
|
|
</v-row>
|
|
|
@@ -59,10 +59,7 @@ de quitter si des données ont été modifiées.
|
|
|
</v-form>
|
|
|
|
|
|
<!-- Confirmation dialog -->
|
|
|
- <LazyLayoutDialog
|
|
|
- :show="isConfirmationDialogShowing"
|
|
|
- :maxWidth="1000"
|
|
|
- >
|
|
|
+ <LazyLayoutDialog :show="isConfirmationDialogShowing" :max-width="1000">
|
|
|
<template #dialogText>
|
|
|
<v-card-title class="text-h5 theme-neutral">
|
|
|
{{ $t('caution') }}
|
|
|
@@ -93,18 +90,20 @@ de quitter si des données ont été modifiées.
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import {computed, ref} from "@vue/reactivity";
|
|
|
-import type {ComputedRef, Ref} from "@vue/reactivity";
|
|
|
-import {FORM_FUNCTION, SUBMIT_TYPE, TYPE_ALERT} from "~/types/enum/enums";
|
|
|
-import { useFormStore } from "~/stores/form";
|
|
|
-import type {Route, RouteLocationNormalized, RouteLocationRaw} from "@intlify/vue-router-bridge";
|
|
|
-import {useEntityManager} from "~/composables/data/useEntityManager";
|
|
|
-import ApiModel from "~/models/ApiModel";
|
|
|
-import {usePageStore} from "~/stores/page";
|
|
|
-import {watch} from "@vue/runtime-core";
|
|
|
-import type {PropType} from "@vue/runtime-core";
|
|
|
-import type {AnyJson} from "~/types/data";
|
|
|
+import { computed, ref, watch } from 'vue'
|
|
|
+import type { ComputedRef, Ref, PropType } from 'vue'
|
|
|
+import type {
|
|
|
+ Route,
|
|
|
+ RouteLocationNormalized,
|
|
|
+ RouteLocationRaw,
|
|
|
+} from '@intlify/vue-router-bridge'
|
|
|
import * as _ from 'lodash-es'
|
|
|
+import { FORM_FUNCTION, SUBMIT_TYPE, TYPE_ALERT } from '~/types/enum/enums'
|
|
|
+import { useFormStore } from '~/stores/form'
|
|
|
+import { useEntityManager } from '~/composables/data/useEntityManager'
|
|
|
+import ApiModel from '~/models/ApiModel'
|
|
|
+import { usePageStore } from '~/stores/page'
|
|
|
+import type { AnyJson } from '~/types/data'
|
|
|
import { useRefreshProfile } from '~/composables/data/useRefreshProfile'
|
|
|
|
|
|
const props = defineProps({
|
|
|
@@ -128,6 +127,7 @@ const props = defineProps({
|
|
|
onChanged: {
|
|
|
type: Function,
|
|
|
required: false,
|
|
|
+ default: null,
|
|
|
},
|
|
|
goBackRoute: {
|
|
|
type: Object as PropType<RouteLocationRaw>,
|
|
|
@@ -141,7 +141,7 @@ const props = defineProps({
|
|
|
type: Object,
|
|
|
required: false,
|
|
|
default: () => {
|
|
|
- let actions: AnyJson = {}
|
|
|
+ const actions: AnyJson = {}
|
|
|
actions[SUBMIT_TYPE.SAVE] = {}
|
|
|
return actions
|
|
|
},
|
|
|
@@ -175,7 +175,7 @@ const i18n = useI18n()
|
|
|
const router = useRouter()
|
|
|
const { em } = useEntityManager()
|
|
|
const { refreshProfile } = useRefreshProfile()
|
|
|
-const route = useRoute();
|
|
|
+const route = useRoute()
|
|
|
|
|
|
// Le formulaire est-il valide
|
|
|
const isValid: Ref<boolean> = ref(true)
|
|
|
@@ -258,16 +258,16 @@ const submit = async (next: string | null = null) => {
|
|
|
if (
|
|
|
error.response &&
|
|
|
error.response.status === 422 &&
|
|
|
- error.response.data['violations']
|
|
|
+ error.response.data.violations
|
|
|
) {
|
|
|
// TODO: à revoir
|
|
|
const violations: Array<string> = []
|
|
|
let fields: AnyJson = {}
|
|
|
|
|
|
- for (const violation of error.response.data['violations']) {
|
|
|
- violations.push(i18n.t(violation['message']) as string)
|
|
|
+ for (const violation of error.response.data.violations) {
|
|
|
+ violations.push(i18n.t(violation.message) as string)
|
|
|
fields = Object.assign(fields, {
|
|
|
- [violation['propertyPath']]: violation['message'],
|
|
|
+ [violation.propertyPath]: violation.message,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -320,14 +320,16 @@ function onSaveAndQuitAction(route: Route) {
|
|
|
/**
|
|
|
* Avant de quitter le formulaire, si le formulaire a été modifié, on demande confirmation
|
|
|
*/
|
|
|
-onBeforeRouteLeave((to: RouteLocationNormalized, from: RouteLocationNormalized) => {
|
|
|
- if (formStore.dirty === true) {
|
|
|
- requestedLeavingRoute.value = to
|
|
|
- formStore.setShowConfirmToLeave(true)
|
|
|
- return false
|
|
|
- }
|
|
|
- return true
|
|
|
-});
|
|
|
+onBeforeRouteLeave(
|
|
|
+ (to: RouteLocationNormalized, from: RouteLocationNormalized) => {
|
|
|
+ if (formStore.dirty === true) {
|
|
|
+ requestedLeavingRoute.value = to
|
|
|
+ formStore.setShowConfirmToLeave(true)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ },
|
|
|
+)
|
|
|
|
|
|
onMounted(() => {
|
|
|
window.addEventListener('beforeunload', (event) => {
|
|
|
@@ -442,5 +444,4 @@ defineExpose({ validate })
|
|
|
margin: 6px 0 !important;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
</style>
|