organization.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import * as _ from 'lodash'
  2. import { baseOrganizationState, organizationState } from '~/types/interfaces'
  3. export const state = () => ({
  4. id: null,
  5. parametersId: null,
  6. name: '',
  7. product: '',
  8. currentActivityYear: '',
  9. modules: [],
  10. hasChildren: false,
  11. legalStatus: '',
  12. showAdherentList: false,
  13. networks: [],
  14. website: '',
  15. parents: []
  16. })
  17. export const mutations = {
  18. setId (state: organizationState, id: number) {
  19. state.id = id
  20. },
  21. setParametersId (state: organizationState, parametersId: number) {
  22. state.parametersId = parametersId
  23. },
  24. setName (state: organizationState, name: string) {
  25. state.name = name
  26. },
  27. setProduct (state: organizationState, product: string) {
  28. state.product = product
  29. },
  30. setCurrentActivityYear (state: organizationState, currentActivityYear: number) {
  31. state.currentActivityYear = currentActivityYear
  32. },
  33. setModules (state: organizationState, modules: Array<string>) {
  34. state.modules = modules
  35. },
  36. setHasChildren (state: organizationState, hasChildren: boolean) {
  37. state.hasChildren = hasChildren
  38. },
  39. setShowAdherentList(state:organizationState, showAdherentList:boolean) {
  40. state.showAdherentList = showAdherentList
  41. },
  42. setLegalStatus(state:organizationState, legalStatus:string) {
  43. state.legalStatus = legalStatus
  44. },
  45. setNetworks(state:organizationState, networks:Array<string>) {
  46. state.networks = networks
  47. },
  48. setParents (state: organizationState, parents: Array<organizationState>) {
  49. state.parents = parents
  50. },
  51. setWebsite (state: organizationState, website: string) {
  52. state.website = website
  53. },
  54. addParent (state: organizationState, parent: organizationState) {
  55. state.parents.push(parent)
  56. }
  57. }
  58. export const actions = {
  59. setProfile (context: any, profile: any) {
  60. context.commit('setId', profile.id)
  61. context.commit('setParametersId', profile.parametersId)
  62. context.commit('setName', profile.name)
  63. context.commit('setProduct', profile.product)
  64. context.commit('setCurrentActivityYear', profile.currentYear)
  65. context.commit('setWebsite', profile.website)
  66. context.commit('setModules', profile.modules)
  67. context.commit('setHasChildren', profile.hasChildren)
  68. context.commit('setLegalStatus', profile.legalStatus)
  69. context.commit('setShowAdherentList', profile.showAdherentList)
  70. context.commit('setNetworks', profile.networks)
  71. _.each(profile.parents, (parent) => {
  72. const p: baseOrganizationState = {
  73. id: parent.id,
  74. name: parent.name,
  75. website: parent.website
  76. }
  77. context.commit('addParent', p)
  78. })
  79. }
  80. }