attendances.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. :model="AttendanceBookingReason"
  62. :entity="reason"
  63. :flat="true"
  64. class="cycle-edit-icon"
  65. />
  66. </td>
  67. </tr>
  68. </tbody>
  69. <tbody v-else>
  70. <tr class="theme-neutral">
  71. <td>
  72. <i>{{ $t('nothing_to_show') }}</i>
  73. </td>
  74. <td></td>
  75. </tr>
  76. </tbody>
  77. </v-table>
  78. <v-btn
  79. :flat="true"
  80. prepend-icon="fa fa-plus"
  81. class="theme-primary mt-4"
  82. @click="goToCreatePage"
  83. >
  84. {{ $t('add') }}
  85. </v-btn>
  86. </div>
  87. </LayoutContainer>
  88. </template>
  89. <script setup lang="ts">
  90. import type { AsyncData } from '#app'
  91. import Parameters from '~/models/Organization/Parameters'
  92. import { useEntityFetch } from '~/composables/data/useEntityFetch'
  93. import { useOrganizationProfileStore } from '~/stores/organizationProfile'
  94. import UrlUtils from '~/services/utils/urlUtils'
  95. import AttendanceBookingReason from '~/models/Booking/AttendanceBookingReason'
  96. definePageMeta({
  97. name: 'parameters_attendances_page',
  98. })
  99. const { fetch } = useEntityFetch()
  100. const i18n = useI18n()
  101. const organizationProfile = useOrganizationProfileStore()
  102. if (organizationProfile.parametersId === null) {
  103. throw new Error('Missing organization parameters id')
  104. }
  105. const { data: parameters, pending } = fetch(
  106. Parameters,
  107. organizationProfile.parametersId,
  108. ) as AsyncData<Parameters | null, Error | null>
  109. const { fetchCollection } = useEntityFetch()
  110. const {
  111. data: attendanceBookingReasons,
  112. pending: attendanceBookingReasonsPending,
  113. } = fetchCollection(AttendanceBookingReason)
  114. const rules = () => [
  115. (numberConsecutiveAbsences: string | null) =>
  116. (numberConsecutiveAbsences !== null &&
  117. parseInt(numberConsecutiveAbsences) > 0) ||
  118. i18n.t('please_enter_a_value'),
  119. ]
  120. const goToEditPage = (id: number) => {
  121. navigateTo(UrlUtils.join('/parameters/attendance_booking_reasons', id))
  122. }
  123. const goToCreatePage = () => {
  124. navigateTo('/parameters/attendance_booking_reasons/new')
  125. }
  126. </script>