ActivityYear.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <main class="d-flex flex-row align-center">
  3. <span v-show="mdAndUp" class="mr-2 font-weight-bold on-neutral">{{ $t(label) }} : </span>
  4. <UiXeditableText
  5. class="activity-year-input"
  6. type="number"
  7. :data="currentActivityYear"
  8. @update="setActivityYear"
  9. >
  10. <template #xeditable.read="{inputValue}">
  11. <div class="d-flex align-center on-neutral--clickable">
  12. <v-icon aria-hidden="false" size="small" class="mr-1" icon="fas fa-edit" />
  13. <strong >
  14. {{ inputValue }}
  15. <span v-if="yearPlusOne">
  16. / {{ parseInt(inputValue) + 1 }}
  17. </span>
  18. </strong>
  19. </div>
  20. </template>
  21. </UiXeditableText>
  22. </main>
  23. </template>
  24. <script setup lang="ts">
  25. import {useEntityManager} from "~/composables/data/useEntityManager";
  26. import {useFormStore} from "~/stores/form";
  27. import {useOrganizationProfileStore} from "~/stores/organizationProfile";
  28. import {useAccessProfileStore} from "~/stores/accessProfile";
  29. import Access from "~/models/Access/Access";
  30. import {Ref, ref} from "@vue/reactivity";
  31. import {useDisplay} from "vuetify";
  32. const { em } = useEntityManager()
  33. const accessProfileStore = useAccessProfileStore()
  34. const organizationProfileStore = useOrganizationProfileStore()
  35. const formStore = useFormStore()
  36. const { mdAndUp } = useDisplay()
  37. const currentActivityYear: Ref<number | null> = ref(accessProfileStore.activityYear)
  38. const yearPlusOne: boolean = !organizationProfileStore.isManagerProduct
  39. const label: string = organizationProfileStore.isSchool ? 'schooling_year' : organizationProfileStore.isArtist ? 'season_year' : 'cotisation_year'
  40. /**
  41. * Persist a new activityYear
  42. * @param activityYear
  43. */
  44. const setActivityYear = async (activityYear: number) => {
  45. if (!(1900 < activityYear) || !(activityYear <= 2100)) {
  46. throw new Error("Error: 'year' shall be a valid year")
  47. }
  48. if (accessProfileStore.id === null) {
  49. throw new Error("Error: invalide access id")
  50. }
  51. formStore.setDirty(false)
  52. const access = await em.fetch(Access, accessProfileStore.id)
  53. access.activityYear = activityYear
  54. await em.persist(Access, access)
  55. // Update the store
  56. // TODO: voir si mieux d'automatiser ces maj du profil, ou de les faire à la main au cas par cas?
  57. accessProfileStore.$patch({ activityYear: activityYear })
  58. window.location.reload()
  59. }
  60. </script>
  61. <style lang="scss">
  62. .activity-year-input {
  63. width: 120px;
  64. max-height: 20px;
  65. .v-input {
  66. min-width: 70px;
  67. }
  68. input{
  69. font-size: 14px;
  70. width: 55px !important;
  71. padding: 0 !important;
  72. margin-top: 0 !important;
  73. min-height: 24px;
  74. height: 24px;
  75. }
  76. }
  77. </style>