|
@@ -1,26 +1,32 @@
|
|
|
import { AnyJson, AnyStore } from '~/types/interfaces'
|
|
import { AnyJson, AnyStore } from '~/types/interfaces'
|
|
|
|
|
+import {computed, ComputedRef, useStore} from "@nuxtjs/composition-api";
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @category Use/form
|
|
* @category Use/form
|
|
|
* @class UseDirtyForm
|
|
* @class UseDirtyForm
|
|
|
* Use Classe pour gérer l'apparition de message si le formulaire est dirty
|
|
* Use Classe pour gérer l'apparition de message si le formulaire est dirty
|
|
|
*/
|
|
*/
|
|
|
-export class UseDirtyForm {
|
|
|
|
|
|
|
+export class UseForm {
|
|
|
private store: AnyStore
|
|
private store: AnyStore
|
|
|
private readonly handler: any
|
|
private readonly handler: any
|
|
|
|
|
|
|
|
- constructor (handler: any, store: AnyStore) {
|
|
|
|
|
- this.store = store
|
|
|
|
|
- this.handler = handler
|
|
|
|
|
|
|
+ constructor () {
|
|
|
|
|
+ this.store = useStore()
|
|
|
|
|
+ this.handler = getEventHandler()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Composition function
|
|
* Composition function
|
|
|
*/
|
|
*/
|
|
|
public invoke (): AnyJson {
|
|
public invoke (): AnyJson {
|
|
|
|
|
+ const readonly: ComputedRef<boolean> = computed(() => {
|
|
|
|
|
+ return this.store.state.form.readonly
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
return {
|
|
return {
|
|
|
markFormAsDirty: () => this.markAsDirty(),
|
|
markFormAsDirty: () => this.markAsDirty(),
|
|
|
- markFormAsNotDirty: () => this.markAsNotDirty()
|
|
|
|
|
|
|
+ markFormAsNotDirty: () => this.markAsNotDirty(),
|
|
|
|
|
+ readonly
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -67,5 +73,4 @@ function getEventHandler () {
|
|
|
e.returnValue = ''
|
|
e.returnValue = ''
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-const handler = getEventHandler()
|
|
|
|
|
-export const $useDirtyForm = (store: AnyStore) => new UseDirtyForm(handler, store).invoke()
|
|
|
|
|
|
|
+export const $useForm = () => new UseForm().invoke()
|