form.ts 843 B

123456789101112131415161718192021222324252627282930313233
  1. import {Store} from "vuex";
  2. import {FORM_STATUS} from "~/types/enums";
  3. import {Route} from "vue-router";
  4. export default class FormStorage {
  5. private store:Store<any>
  6. constructor(store:Store<any>) {
  7. this.store = store
  8. }
  9. /**
  10. * Actions devant être gérées si on souhaite quitter une page
  11. * @param to
  12. */
  13. handleActionsAfterLeavePage(to: Route){
  14. if (this.store.state.form.dirty) {
  15. this.store.commit('form/setShowConfirmToLeave', true)
  16. this.store.commit('form/setGoAfterLeave', to)
  17. } else {
  18. this.store.commit('form/setFormStatus', FORM_STATUS.EDIT)
  19. this.store.commit('form/setViolations', [])
  20. }
  21. }
  22. /**
  23. * Ajout des violations dans le store
  24. * @param invalidFields
  25. */
  26. addViolations(invalidFields: Array<any>){
  27. this.store.commit('form/setViolations', invalidFields)
  28. }
  29. }