EditeurBenevole.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <div class="editor-panel">
  3. <h3>Modifier les informations sur les bénévoles</h3>
  4. <div class="actions">
  5. <button class="btn small primary" v-on:click="emitCreationOrder">
  6. <i class="material-icons">create</i>Nouveau
  7. </button>
  8. <button
  9. class="btn small error"
  10. :disabled="benevole === undefined"
  11. v-on:click="emitDeleteOrder"
  12. >
  13. <i class="material-icons">delete_forever</i>Supprimer
  14. </button>
  15. </div>
  16. <div class="empty" v-if="benevole === undefined">
  17. Veuillez selectioner une ligne du tableau.
  18. </div>
  19. <div class="editor-body" v-else>
  20. <styled-input
  21. class="s3"
  22. label="Identifiant"
  23. id="competence_id"
  24. type="text"
  25. :modelValue="benevole.id"
  26. disabled
  27. v-show="false"
  28. />
  29. <styled-input
  30. class="s6"
  31. label="Prénom"
  32. id="last_name"
  33. type="text"
  34. :modelValue="benevole.name"
  35. @input="inputListener($event, 'name')"
  36. />
  37. <styled-input
  38. class="s6"
  39. label="Nom"
  40. id="family_name"
  41. type="text"
  42. :modelValue="benevole.surname"
  43. @input="inputListener($event, 'surname')"
  44. />
  45. <styled-input
  46. class="s6"
  47. label="Email"
  48. id="email"
  49. type="email"
  50. :modelValue="benevole.email"
  51. @input="inputListener($event, 'email')"
  52. />
  53. <styled-input
  54. label="Telephone"
  55. class="s6"
  56. id="phone"
  57. type="text"
  58. :modelValue="benevole.phone"
  59. @input="inputListener($event, 'phone')"
  60. />
  61. <styled-input
  62. label="Commentaire"
  63. id="comment"
  64. type="textarea"
  65. :modelValue="benevole.comment"
  66. @input="inputListener($event, 'comment')"
  67. />
  68. <checkbox
  69. label="Ne pas ajouter de créneau"
  70. :modelValue="benevole.isFixed"
  71. help="Indique au solveur de ne pas changer les affectations de ce bénévole"
  72. @input="checkboxListener($event, 'isFixed')"
  73. />
  74. <h3 style="padding-bottom: 0.8rem">Propriétés</h3>
  75. <chips-input
  76. label="Préference & compétences"
  77. id="preference_selection"
  78. placeholder="Choisir un élément"
  79. secondary-placeholder="+ élément"
  80. :autocompleteList="autocompleteList"
  81. :strict-autocomplete="true"
  82. v-model="competenceIdList"
  83. ></chips-input>
  84. </div>
  85. </div>
  86. </template>
  87. <script lang="ts">
  88. import Benevole from "@/models/Benevole";
  89. import Competence from "@/models/Competence";
  90. import styledInput from "@/components/Form/Input.vue";
  91. import chipsInput from "@/components/Form/SelectChipInput.vue";
  92. import checkbox from "@/components/Form/checkBox.vue";
  93. import { defineComponent, PropType } from "vue";
  94. import { MutationTypes } from "@/store/Mutations";
  95. import AutocompleteOptions from "@/models/AutocompleteOptions";
  96. export default defineComponent({
  97. name: "EditeurBenevole",
  98. components: { styledInput, chipsInput, checkbox },
  99. props: { benevole: { type: Object as PropType<Benevole> } },
  100. data: function () {
  101. return {
  102. refreshFrom: null,
  103. competenceIdList: [] as Array<string>,
  104. };
  105. },
  106. watch: {
  107. benevole(b: Benevole) {
  108. this.competenceIdList = b.competenceIdList.map((s) => s.toString());
  109. },
  110. competenceIdList(val: Array<string>) {
  111. const new_arr = val.map((s) => parseInt(s));
  112. const old_arr = this.benevole?.competenceIdList;
  113. if (
  114. new_arr.length !== old_arr?.length ||
  115. new_arr.reduce((acc: boolean, n: number) => acc && old_arr.includes(n), true)
  116. ) {
  117. this.updateBenevole("competenceIdList", new_arr);
  118. }
  119. },
  120. },
  121. computed: {
  122. autocompleteList(): Array<AutocompleteOptions> {
  123. return this.competenceList.map((contraint) => {
  124. return { id: contraint.id.toString(), name: contraint.fullname };
  125. });
  126. },
  127. competenceList(): Array<Competence> {
  128. return this.$store.state.competenceList;
  129. },
  130. },
  131. methods: {
  132. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  133. inputListener(event: any, field: keyof Benevole) {
  134. this.updateBenevole(field, event.target.value);
  135. },
  136. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  137. checkboxListener(event: any, field: keyof Benevole) {
  138. this.updateBenevole(field, event.target.checked);
  139. },
  140. updateBenevole<K extends keyof Benevole>(k: K, value: Benevole[K]) {
  141. if (this.benevole) {
  142. this.$store.commit(MutationTypes.editBenevole, {
  143. id: this.benevole.id,
  144. field: k,
  145. value: value,
  146. });
  147. }
  148. },
  149. emitCreationOrder: function () {
  150. this.$emit("create");
  151. },
  152. emitDeleteOrder: function () {
  153. this.$emit("delete", this.benevole);
  154. },
  155. },
  156. });
  157. </script>
  158. <style scoped></style>