ActivityYear.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <main class="d-flex">
  3. <span class="mr-2 font-weight-bold">{{ $t(label) }} : </span>
  4. <UiXeditableText
  5. class="activity-year-input bg-ot-light-grey"
  6. type="number"
  7. :data="currentActivityYear"
  8. @update="setActivityYear"
  9. >
  10. <template #xeditable.read="{inputValue}">
  11. <v-icon aria-hidden="false" size="x-small" class="text-ot-green mr-1" icon="fas fa-edit" />
  12. <strong class="text-ot-green">
  13. {{ inputValue }}
  14. <span v-if="yearPlusOne">
  15. / {{ parseInt(inputValue) + 1 }}
  16. </span>
  17. </strong>
  18. </template>
  19. </UiXeditableText>
  20. </main>
  21. </template>
  22. <script setup lang="ts">
  23. import {useEntityManager} from "~/composables/data/useEntityManager";
  24. import {useFormStore} from "~/stores/form";
  25. import {useOrganizationProfileStore} from "~/stores/organizationProfile";
  26. import {useAccessProfileStore} from "~/stores/accessProfile";
  27. import {Access} from "~/models/Access/Access";
  28. import {Ref, ref} from "@vue/reactivity";
  29. const { em } = useEntityManager()
  30. const accessProfileStore = useAccessProfileStore()
  31. const organizationProfileStore = useOrganizationProfileStore()
  32. const formStore = useFormStore()
  33. const currentActivityYear: Ref<number | null> = ref(accessProfileStore.activityYear)
  34. const yearPlusOne: boolean = !organizationProfileStore.isManagerProduct
  35. const label: string = organizationProfileStore.isSchool ? 'schooling_year' : organizationProfileStore.isArtist ? 'season_year' : 'cotisation_year'
  36. /**
  37. * Persist a new activityYear
  38. * @param activityYear
  39. */
  40. const setActivityYear = async (activityYear: number) => {
  41. if (!(1900 < activityYear) || !(activityYear <= 2100)) {
  42. throw new Error("Error: 'year' shall be a valid year")
  43. }
  44. if (accessProfileStore.id === null) {
  45. throw new Error("Error: invalide access id")
  46. }
  47. formStore.setDirty(false)
  48. const access = await em.fetch(Access, accessProfileStore.id)
  49. access.activityYear = activityYear
  50. await em.persist(Access, access)
  51. accessProfileStore.$patch({ activityYear: activityYear }) // TODO: est-ce nécessaire, sachant que l'EM met déjà à jour le profil?
  52. window.location.reload() // TODO: est-ce vraiment nécessaire?
  53. }
  54. </script>
  55. <style lang="scss">
  56. .activity-year-input {
  57. width: 120px;
  58. max-height: 20px;
  59. .v-input {
  60. min-width: 70px;
  61. }
  62. input{
  63. font-size: 14px;
  64. width: 55px !important;
  65. padding: 0 !important;
  66. margin-top: 0 !important;
  67. min-height: 24px;
  68. height: 24px;
  69. }
  70. }
  71. </style>