ActivityYear.vue 2.6 KB

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