form.ts 884 B

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