attendances.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <LayoutContainer>
  3. <div v-if="organizationProfile.isSchool">
  4. <UiLoadingPanel v-if="pending" />
  5. <UiForm
  6. v-else-if="parameters !== null"
  7. :model="Parameters"
  8. :entity="parameters"
  9. action-position="bottom"
  10. >
  11. <v-row>
  12. <v-col cols="12">
  13. <UiInputCheckbox
  14. v-model="parameters.sendAttendanceEmail"
  15. field="sendAttendanceEmail"
  16. label="sendAttendanceEmail"
  17. />
  18. <UiInputCheckbox
  19. v-model="parameters.sendAttendanceSms"
  20. field="sendAttendanceSms"
  21. />
  22. <UiInputCheckbox
  23. v-model="parameters.notifyAdministrationAbsence"
  24. field="notifyAdministrationAbsence"
  25. />
  26. <UiInputNumber
  27. v-model="parameters.numberConsecutiveAbsences"
  28. field="notifyAdministrationAbsence"
  29. :rules="rules()"
  30. />
  31. </v-col>
  32. </v-row>
  33. </UiForm>
  34. <v-divider class="my-10" />
  35. </div>
  36. <UiLoadingPanel v-if="attendanceBookingReasonsPending" />
  37. <div v-else>
  38. <v-table>
  39. <thead>
  40. <tr>
  41. <td>{{ $t('attendanceBookingReasons') }}</td>
  42. <td></td>
  43. </tr>
  44. </thead>
  45. <tbody v-if="attendanceBookingReasons!.items.length > 0">
  46. <tr
  47. v-for="reason in attendanceBookingReasons!.items"
  48. :key="reason.id"
  49. >
  50. <td class="cycle-editable-cell">
  51. {{ reason.reason }}
  52. </td>
  53. <td class="d-flex flex-row">
  54. <v-btn
  55. :flat="true"
  56. icon="fa fa-pen"
  57. class="cycle-edit-icon mr-3"
  58. @click="goToEditPage(reason.id as number)"
  59. />
  60. <UiButtonDelete
  61. :entity="reason"
  62. :flat="true"
  63. class="cycle-edit-icon"
  64. />
  65. </td>
  66. </tr>
  67. </tbody>
  68. <tbody v-else>
  69. <tr class="theme-neutral">
  70. <td>
  71. <i>{{ $t('nothing_to_show') }}</i>
  72. </td>
  73. <td></td>
  74. </tr>
  75. </tbody>
  76. </v-table>
  77. <v-btn
  78. :flat="true"
  79. prepend-icon="fa fa-plus"
  80. class="theme-primary mt-4"
  81. @click="goToCreatePage"
  82. >
  83. {{ $t('add') }}
  84. </v-btn>
  85. </div>
  86. </LayoutContainer>
  87. </template>
  88. <script setup lang="ts">
  89. import type { AsyncData } from '#app'
  90. import Parameters from '~/models/Organization/Parameters'
  91. import { useEntityFetch } from '~/composables/data/useEntityFetch'
  92. import { useOrganizationProfileStore } from '~/stores/organizationProfile'
  93. import UrlUtils from '~/services/utils/urlUtils'
  94. import AttendanceBookingReason from '~/models/Booking/AttendanceBookingReason'
  95. definePageMeta({
  96. name: 'parameters_attendances_page',
  97. })
  98. const { fetch } = useEntityFetch()
  99. const i18n = useI18n()
  100. const organizationProfile = useOrganizationProfileStore()
  101. if (organizationProfile.parametersId === null) {
  102. throw new Error('Missing organization parameters id')
  103. }
  104. const { data: parameters, pending } = fetch(
  105. Parameters,
  106. organizationProfile.parametersId,
  107. ) as AsyncData<Parameters | null, Error | null>
  108. const { fetchCollection } = useEntityFetch()
  109. const {
  110. data: attendanceBookingReasons,
  111. pending: attendanceBookingReasonsPending,
  112. } = fetchCollection(AttendanceBookingReason)
  113. const rules = () => [
  114. (numberConsecutiveAbsences: string | null) =>
  115. (numberConsecutiveAbsences !== null &&
  116. parseInt(numberConsecutiveAbsences) > 0) ||
  117. i18n.t('please_enter_a_value'),
  118. ]
  119. const goToEditPage = (id: number) => {
  120. navigateTo(UrlUtils.join('/parameters/attendance_booking_reasons', id))
  121. }
  122. const goToCreatePage = () => {
  123. navigateTo('/parameters/attendance_booking_reasons/new')
  124. }
  125. </script>