|
|
@@ -8,16 +8,13 @@ de quitter si des données ont été modifiées.
|
|
|
-->
|
|
|
|
|
|
<template>
|
|
|
- <main>
|
|
|
+ <LayoutContainer>
|
|
|
<v-form
|
|
|
- ref="form"
|
|
|
- :readonly="readonly"
|
|
|
- validate-on="lazy input"
|
|
|
- @submit.prevent=""
|
|
|
- @update:model-value="onValidationChange"
|
|
|
+ v-model="isValid"
|
|
|
+ ref="form"
|
|
|
+ :readonly="readonly"
|
|
|
+ @submit.prevent=""
|
|
|
>
|
|
|
-<!-- @update:entity="onFormChange"-->
|
|
|
-
|
|
|
<!-- Top action bar -->
|
|
|
<v-container :fluid="true" class="container btnActions">
|
|
|
<v-row>
|
|
|
@@ -73,13 +70,13 @@ de quitter si des données ont été modifiées.
|
|
|
<v-btn class="mr-4 submitBtn theme-primary" @click="saveAndQuit">
|
|
|
{{ $t('save_and_quit') }}
|
|
|
</v-btn>
|
|
|
- <v-btn class="mr-4 submitBtn theme-danger" @click="quitForm">
|
|
|
+ <v-btn class="mr-4 submitBtn theme-danger" @click="cancel">
|
|
|
{{ $t('quit_form') }}
|
|
|
</v-btn>
|
|
|
</template>
|
|
|
</LazyLayoutDialog>
|
|
|
|
|
|
- </main>
|
|
|
+ </LayoutContainer>
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
@@ -218,7 +215,13 @@ const submit = async (next: string|null = null) => {
|
|
|
// On retire l'état 'dirty'
|
|
|
setIsDirty(false)
|
|
|
|
|
|
- afterSubmissionAction(next, updatedEntity)
|
|
|
+ const actionArgs = next ? props.submitActions[next] : null
|
|
|
+
|
|
|
+ if (next === SUBMIT_TYPE.SAVE) {
|
|
|
+ onSaveAction(actionArgs, updatedEntity.id)
|
|
|
+ } else if (next === SUBMIT_TYPE.SAVE_AND_BACK) {
|
|
|
+ onSaveAndQuitAction(actionArgs)
|
|
|
+ }
|
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
|
@@ -247,26 +250,7 @@ const submit = async (next: string|null = null) => {
|
|
|
*/
|
|
|
const saveAndQuit = async () => {
|
|
|
await submit()
|
|
|
- quitForm()
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Retourne l'action à effectuer après la soumission du formulaire
|
|
|
- * @param action
|
|
|
- * @param updatedEntity
|
|
|
- */
|
|
|
-const afterSubmissionAction = (action: string | null, updatedEntity: AnyJson) => {
|
|
|
- if (action === null) {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- const actionArgs = props.submitActions[action]
|
|
|
-
|
|
|
- if (action === SUBMIT_TYPE.SAVE) {
|
|
|
- afterSaveAction(actionArgs, updatedEntity.id)
|
|
|
- } else if (action === SUBMIT_TYPE.SAVE_AND_BACK) {
|
|
|
- afterSaveAndQuitAction(actionArgs)
|
|
|
- }
|
|
|
+ cancel()
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -278,7 +262,7 @@ const afterSubmissionAction = (action: string | null, updatedEntity: AnyJson) =>
|
|
|
* @param route
|
|
|
* @param id
|
|
|
*/
|
|
|
-function afterSaveAction(route: Route, id: number){
|
|
|
+function onSaveAction(route: Route, id: number){
|
|
|
if (useFormStore().formFunction === FORM_FUNCTION.CREATE) {
|
|
|
route.path += id
|
|
|
navigateTo(route)
|
|
|
@@ -292,14 +276,14 @@ function afterSaveAction(route: Route, id: number){
|
|
|
*
|
|
|
* @param route
|
|
|
*/
|
|
|
-function afterSaveAndQuitAction(route: Route){
|
|
|
+function onSaveAndQuitAction(route: Route){
|
|
|
navigateTo(route)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Quitte le formulaire sans enregistrer
|
|
|
*/
|
|
|
-const quitForm = () => {
|
|
|
+const cancel = () => {
|
|
|
setIsDirty(false)
|
|
|
|
|
|
useFormStore().setShowConfirmToLeave(false)
|
|
|
@@ -333,10 +317,6 @@ const onFormChange = async () => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const onValidationChange = (event: boolean | null) => {
|
|
|
- isValid.value = event || false
|
|
|
-}
|
|
|
-
|
|
|
/**
|
|
|
* Utilise la méthode validate() de v-form pour valider le formulaire et mettre à jour les variables isValid et errors
|
|
|
*
|
|
|
@@ -351,7 +331,7 @@ const validate = async function () {
|
|
|
|
|
|
// #### Gestion de l'état dirty
|
|
|
watch(props.entity, async (newEntity, oldEntity) => {
|
|
|
- await onFormChange()
|
|
|
+ setIsDirty(true)
|
|
|
})
|
|
|
|
|
|
/**
|
|
|
@@ -373,8 +353,6 @@ const setIsDirty = (dirty: boolean) => {
|
|
|
useFormStore().setDirty(dirty)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
defineExpose({ validate })
|
|
|
|
|
|
</script>
|