| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import {formState} from '~/types/interfaces'
- import {FORM_FUNCTION} from "~/types/enum/enums";
- import {defineStore} from "pinia";
- import {AnyJson} from "~/types/enum/data";
- export const useFormStore = defineStore('form', {
- state: (): formState => {
- return {
- formFunction: FORM_FUNCTION.EDIT,
- violations: {},
- readonly: false,
- dirty: false,
- showConfirmToLeave: false,
- goAfterLeave: null
- }
- },
- actions: {
- setViolations (violations: Array<string>) {
- this.violations = violations
- },
- addViolations(invalidFields: AnyJson){
- this.violations = invalidFields
- },
- setReadOnly (readonly: boolean) {
- this.readonly = readonly
- },
- setFormFunction (formFunction: FORM_FUNCTION) {
- this.formFunction = formFunction
- },
- setDirty (dirty: boolean) {
- this.dirty = dirty
- },
- setShowConfirmToLeave (showConfirmToLeave: boolean) {
- this.showConfirmToLeave = showConfirmToLeave
- },
- setGoAfterLeave (goAfterLeave: string) {
- this.goAfterLeave = goAfterLeave
- },
- /**
- * Actions devant être gérées si on souhaite quitter une page
- * @param to
- */
- handleActionsAfterLeavePage(to: any){
- if (this.dirty) {
- this.showConfirmToLeave = true
- this.goAfterLeave = to
- } else {
- this.formFunction = FORM_FUNCTION.EDIT
- this.violations = []
- }
- }
- }
- })
|