|
|
@@ -0,0 +1,226 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <h3 class="center-align">Modifier un créneau</h3>
|
|
|
+ <div class="row center-align">
|
|
|
+ <a class="btn-small" v-on:click="emitCreationOrder"
|
|
|
+ ><i class="material-icons right">create</i>Nouveau</a
|
|
|
+ >
|
|
|
+ <a
|
|
|
+ class="btn-small"
|
|
|
+ :class="{ disabled: creneau === undefined }"
|
|
|
+ v-on:click="emitDuplicateOrder"
|
|
|
+ ><i class="material-icons right">content_copy</i>Dupliquer</a
|
|
|
+ >
|
|
|
+ <a
|
|
|
+ class="btn-small red"
|
|
|
+ :class="{ disabled: creneau === null }"
|
|
|
+ v-on:click="emitDeleteOrder"
|
|
|
+ style="margin-top: 4px"
|
|
|
+ ><i class="material-icons right">delete_forever</i>Supprimer</a
|
|
|
+ >
|
|
|
+ </div>
|
|
|
+ <div class="center-align" v-if="creneau === undefined">Veuillez selectioner un creneau.</div>
|
|
|
+ <form v-else>
|
|
|
+ <div class="input-field col s12">
|
|
|
+ <input
|
|
|
+ id="last_name"
|
|
|
+ type="text"
|
|
|
+ class="validate"
|
|
|
+ value="creneau.title"
|
|
|
+ @input="inputListener('title')"
|
|
|
+ />
|
|
|
+ <label for="last_name">Titre</label>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="input-field col s6">
|
|
|
+ <input id="creneauDate" type="text" class="datepicker" v-model.lazy="jour" />
|
|
|
+ <label for="creneauDate">Date</label>
|
|
|
+ </div>
|
|
|
+ <div class="input-field col s3">
|
|
|
+ <input id="creneauHeure" type="text" class="timepicker" v-model.lazy="heure" />
|
|
|
+ <label for="creneauHeure">Heure</label>
|
|
|
+ </div>
|
|
|
+ <div class="input-field col s3">
|
|
|
+ <input id="creneauDuree" type="number" class="validate" v-model="duree" />
|
|
|
+ <label for="creneauDuree">Duree (min)</label>
|
|
|
+ </div>
|
|
|
+ <div class="input-field col s6">
|
|
|
+ <input
|
|
|
+ id="penibility"
|
|
|
+ type="number"
|
|
|
+ class="validate"
|
|
|
+ :value="creneau.penibility"
|
|
|
+ @input="inputListener('penibility')"
|
|
|
+ />
|
|
|
+ <label for="penibility">Pénébilité</label>
|
|
|
+ </div>
|
|
|
+ <div class="input-field col s3">
|
|
|
+ <input disabled id="disabled" type="text" class="validate" v-model="endHour" />
|
|
|
+ <label for="disabled">Heure fin</label>
|
|
|
+ </div>
|
|
|
+ <div class="input-field col s6">
|
|
|
+ <input
|
|
|
+ id="minAttendee"
|
|
|
+ type="number"
|
|
|
+ class="validate"
|
|
|
+ :value="creneau.minAttendee"
|
|
|
+ @input="inputListener('minAttendee')"
|
|
|
+ />
|
|
|
+ <label for="minAttendee">Bénévole minimum</label>
|
|
|
+ </div>
|
|
|
+ <div class="input-field col s6">
|
|
|
+ <input
|
|
|
+ id="maxAttendee"
|
|
|
+ type="number"
|
|
|
+ class="validate"
|
|
|
+ :value="creneau.maxAttendee"
|
|
|
+ @input="inputListener('maxAttendee')"
|
|
|
+ />
|
|
|
+ <label for="maxAttendee">Bénévole maximum (opt)</label>
|
|
|
+ </div>
|
|
|
+ <div class="input-field col s12">
|
|
|
+ <textarea
|
|
|
+ id="description"
|
|
|
+ type="text"
|
|
|
+ class="materialize-textarea"
|
|
|
+ v-model="creneau.description"
|
|
|
+ ></textarea>
|
|
|
+ <label for="description">Description</label>
|
|
|
+ </div>
|
|
|
+ <div class="col s12">
|
|
|
+ <chips-input
|
|
|
+ title="Compétences & préférences associées"
|
|
|
+ id="compétence_selection"
|
|
|
+ place-holder="Choisir une condition"
|
|
|
+ secondary-placeholder="+ compétence"
|
|
|
+ :autocomplete-list="autocompleteCompetencesList"
|
|
|
+ :strict-autocomplete="true"
|
|
|
+ :value="creneau.competencesIdList"
|
|
|
+ @input="inputListener('competencesIdList')"
|
|
|
+ ></chips-input>
|
|
|
+ </div>
|
|
|
+ <div class="col s12">
|
|
|
+ <chips-input
|
|
|
+ title="Bénévoles"
|
|
|
+ id="bénevole_selection"
|
|
|
+ place-holder="Choisir un bénévole"
|
|
|
+ secondary-placeholder="+ bénévole"
|
|
|
+ :autocomplete-list="autocompleteBenevolesList"
|
|
|
+ :strict-autocomplete="true"
|
|
|
+ :value="creneau.benevoleIdList"
|
|
|
+ @input="inputListener('benevoleIdList')"
|
|
|
+ ></chips-input>
|
|
|
+ </div>
|
|
|
+ </form>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script lang="ts">
|
|
|
+import { defineComponent } from "vue";
|
|
|
+import Creneau from "@/models/Creneau";
|
|
|
+import { MutationTypes } from "@/store/Mutations";
|
|
|
+import AutocompleteOptions from "@/models/AutocompleteOptions";
|
|
|
+
|
|
|
+export default defineComponent({
|
|
|
+ name: "EditeurCreneau",
|
|
|
+ props: {
|
|
|
+ creneauId: {
|
|
|
+ type: String,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ data: function () {
|
|
|
+ return {
|
|
|
+ jour: "",
|
|
|
+ heure: "",
|
|
|
+ duree: "",
|
|
|
+ };
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ creneauId() {
|
|
|
+ this.updateForm();
|
|
|
+ },
|
|
|
+ jour: function () {
|
|
|
+ this.updateDates();
|
|
|
+ },
|
|
|
+ heure: function () {
|
|
|
+ this.updateDates();
|
|
|
+ },
|
|
|
+ duree: function () {
|
|
|
+ this.updateDates();
|
|
|
+ },
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ duration(): number {
|
|
|
+ return parseFloat(this.duree) ?? 0;
|
|
|
+ },
|
|
|
+ formStartTime(): number {
|
|
|
+ const input = this.jour + "T" + this.heure;
|
|
|
+ return new Date(input).getTime();
|
|
|
+ },
|
|
|
+ endStartTime(): number {
|
|
|
+ return this.formStartTime + this.duration * 60 * 1000;
|
|
|
+ },
|
|
|
+ endHour(): string {
|
|
|
+ return new Date(this.endStartTime).toLocaleTimeString().substring(0, 5);
|
|
|
+ },
|
|
|
+ validDuree(): boolean {
|
|
|
+ return isNaN(parseInt(this.duree));
|
|
|
+ },
|
|
|
+ creneau(): Creneau | undefined {
|
|
|
+ return this.$store.getters.getCreneauById(this.creneauId || "");
|
|
|
+ },
|
|
|
+ autocompleteBenevolesList(): Array<AutocompleteOptions> {
|
|
|
+ return this.$store.state.benevoleList.map((benevole) => {
|
|
|
+ return { id: benevole.id + "", name: benevole.fullname, img: "benevole" };
|
|
|
+ });
|
|
|
+ },
|
|
|
+ autocompleteCompetencesList(): Array<AutocompleteOptions> {
|
|
|
+ return this.$store.state.competenceList.map((competence) => {
|
|
|
+ return { id: competence.id + "", name: competence.fullname };
|
|
|
+ });
|
|
|
+ },
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ updateDates: function (): void {
|
|
|
+ if (this.creneauId) {
|
|
|
+ this.updateCreneau("start", new Date(this.formStartTime));
|
|
|
+ this.updateCreneau("end", new Date(this.endStartTime));
|
|
|
+ }
|
|
|
+ },
|
|
|
+ updateCreneau<K extends keyof Creneau>(field: K, value: Creneau[K]) {
|
|
|
+ if (this.creneauId)
|
|
|
+ this.$store.commit(MutationTypes.editCreneau, {
|
|
|
+ id: this.creneauId,
|
|
|
+ field: field,
|
|
|
+ value: value,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ inputListener(field: keyof Creneau): (e: InputEvent) => void {
|
|
|
+ return (e: InputEvent) => {
|
|
|
+ this.updateCreneau(field, (e.target as HTMLInputElement).value);
|
|
|
+ };
|
|
|
+ },
|
|
|
+ updateForm: function () {
|
|
|
+ if (this.creneau) {
|
|
|
+ const startDate = this.creneau.event.start;
|
|
|
+ this.jour = startDate.toISOString().substr(0, 10);
|
|
|
+ this.heure = startDate.toTimeString().substr(0, 5);
|
|
|
+ this.duree = Math.round(
|
|
|
+ (this.creneau.event.end.getTime() - this.creneau.event.start.getTime()) / 1000 / 60
|
|
|
+ ).toString();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ emitDuplicateOrder: function () {
|
|
|
+ this.$emit("duplicate", this.creneau);
|
|
|
+ },
|
|
|
+ emitCreationOrder: function () {
|
|
|
+ this.$emit("create");
|
|
|
+ },
|
|
|
+ emitDeleteOrder: function () {
|
|
|
+ this.$emit("delete", this.creneau);
|
|
|
+ },
|
|
|
+ },
|
|
|
+});
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped></style>
|