ArenMg/src/main/webapp/assets/js/views/agenda.vue

280 lines
7 KiB
Vue
Raw Normal View History

2021-04-16 08:34:24 +00:00
<template>
<div class="box-container">
<base-layout id="testfunc">
<template v-slot:title>
<h1>Agenda</h1>
2021-05-03 07:52:48 +00:00
<div v-if="user.is('ADMIN') || user.is('SUPERADMIN')">
<button
class="edit-btn space-top"
v-if="!isEditMode"
@click="
() => {
isEditMode = true;
copyAgendaInfo();
}
"
title="Modifier l'agenda"
>
<img alt="edit" src="assets/img/edit.png" />
</button>
<button
class="edit-btn space-top"
v-if="isEditMode"
@click="
() => {
isEditMode = false;
}
"
title="Annuler la modification"
>
<img alt="edit" src="assets/img/cancel.png" />
</button>
<button
title="Supprimer l'agenda"
class="delete-btn space-top"
v-if="!isEditMode"
@click="
() => {
2021-05-05 09:40:40 +00:00
deleteCurrentAgenda();
2021-05-03 07:52:48 +00:00
}
"
>
<img alt="edit" src="assets/img/delete.png" />
</button>
</div>
2021-04-16 08:34:24 +00:00
</template>
<div class="space-top block">
<label>
<span>Titre</span>
</label>
2021-05-03 07:52:48 +00:00
<span v-if="!isEditMode" class="block">{{ program.title }}</span>
<input
v-if="isEditMode"
class="block"
type="text"
v-model="editionProgram.title"
/>
2021-04-16 08:34:24 +00:00
<label class="block space-top">
<span>Description</span>
</label>
2021-05-03 07:52:48 +00:00
<span v-if="!isEditMode" class="block">{{ program.description }}</span>
<textarea
v-if="isEditMode"
class="block"
v-model="editionProgram.description"
></textarea>
2021-04-16 08:34:24 +00:00
<label class="block space-top">
<span class="block">Date</span>
2021-05-03 07:52:48 +00:00
<v-date-picker
v-if="isEditMode"
v-model="editionProgram.date"
mode="dateTime"
:timezone="timezone"
:min-date="new Date()"
color="red"
/>
2021-04-16 08:34:24 +00:00
</label>
2021-05-03 07:52:48 +00:00
<span v-if="!isEditMode" class="block">{{
2021-04-16 08:34:24 +00:00
new Date(program.date).toLocaleString()
}}</span>
2021-05-03 07:52:48 +00:00
<span v-if="isEditMode" class="block">{{
editionProgram.date.toISOString()
}}</span>
2021-04-16 08:34:24 +00:00
<label class="block space-top">
<span>URL</span>
</label>
2021-05-03 07:52:48 +00:00
<span v-if="!isEditMode" class="block">
<a :href="program.url" target="_blank">{{ program.url }}</a>
</span>
<input v-if="isEditMode" type="text" v-model="editionProgram.url" />
2021-04-16 08:34:24 +00:00
</div>
<div class="space-top"></div>
2021-05-03 07:52:48 +00:00
<div v-if="isEditMode" class="space-top">
2021-05-05 09:40:40 +00:00
<button
id="modifySondage"
@click="
() => {
modifyAgenda();
}
"
>
2021-05-03 07:52:48 +00:00
Modifier l' agenda
</button>
</div>
2021-04-16 08:34:24 +00:00
</base-layout>
</div>
</template>
<style scoped>
.box-container {
border: 1px solid #a1a3a1;
border-radius: 10px;
padding-top: 2em;
width: 50%;
margin: 2em auto;
}
.space-top {
margin-top: 4em;
}
.block {
display: block;
}
2021-05-03 07:52:48 +00:00
#modifySondage {
background-color: #b84000;
padding: 1rem;
border-radius: 0.5rem;
color: white;
border-color: transparent;
box-shadow: 0.1rem 0.1rem 1rem #b84000;
margin-bottom: 2rem;
cursor: pointer;
}
.edit-btn {
background-color: #808080;
padding: 1rem;
border-radius: 0.5rem;
color: white;
border-color: transparent;
box-shadow: 0.1rem 0.1rem 1rem #808080;
margin-bottom: 2rem;
cursor: pointer;
width: 50px;
height: 50px;
}
.delete-btn {
background-color: #dd2034;
padding: 1rem;
border-radius: 0.5rem;
color: white;
border-color: transparent;
box-shadow: 0.1rem 0.1rem 1rem #dd2034;
margin-bottom: 2rem;
cursor: pointer;
width: 50px;
height: 50px;
}
.cancel-btn {
background-color: #b84000;
padding: 1rem;
border-radius: 0.5rem;
color: white;
border-color: transparent;
box-shadow: 0.1rem 0.1rem 1rem #b84000;
margin-bottom: 2rem;
cursor: pointer;
}
2021-04-16 08:34:24 +00:00
</style>
<script>
const getUrl = window.location;
2021-05-10 11:49:52 +00:00
// let baseUrl = getUrl.protocol + "//" + getUrl.host + "/" + getUrl.pathname.split("/")[1];
// if (baseUrl.endsWith("/")) {
// baseUrl = baseUrl.slice(0, -1);
// }
let baseUrl = getUrl.protocol + "//" + getUrl.host
2021-04-16 08:34:24 +00:00
module.exports = {
data() {
return {
2021-05-03 07:52:48 +00:00
isEditMode: false,
2021-04-16 08:34:24 +00:00
program: false,
2021-05-03 07:52:48 +00:00
editionProgram: false,
user: false,
2021-05-05 11:50:48 +00:00
timezone: "",
2021-04-16 08:34:24 +00:00
};
},
created() {
this.fetchProgram();
2021-05-03 07:52:48 +00:00
this.getCurrentUser();
2021-04-16 08:34:24 +00:00
},
methods: {
fetchProgram: async function () {
try {
let program = await axios.get(
`${baseUrl}/ws/agenda/calendars/${this.$route.query.id}`
);
this.program = program.data;
2021-05-03 07:52:48 +00:00
this.editionProgram = { ...program.data };
2021-04-16 08:34:24 +00:00
} catch (expetion) {
console.error(expetion);
}
},
2021-05-03 07:52:48 +00:00
copyAgendaInfo() {
this.editionProgram = {
...this.program,
date: new Date(this.program.date),
};
},
getCurrentUser: async function () {
ArenService.Users.getLoged({
onSuccess: (logedUser) => {
this.user = logedUser;
ArenService.NotificationListener.listen({
onMessage: (notif) => {
this.user.notifications.push(notif);
let message = this.$t(
"notification." + notif.content.message,
notif.content.details
);
this.$toast(message);
new BrowserNotification("AREN", {
body: message,
});
},
});
},
onError: (e) => {
this.logout();
},
});
},
2021-05-05 11:28:48 +00:00
modifyAgenda: async function () {
try {
let success = await axios({
method: "put",
url: `${baseUrl}/ws/agenda/calendars/${this.$route.query.id}`,
data: this.editionProgram,
});
2021-05-08 08:08:21 +00:00
console.log(success);
2021-05-05 11:28:48 +00:00
swal("Succès!", "L'agenda a été modifié", "success").then((value) => {
2021-05-08 08:08:21 +00:00
this.program = { ...this.editionProgram };
2021-05-05 11:28:48 +00:00
this.isEditMode = false;
});
} catch (error) {
swal("Erreur", `Une erreur s'est produite`, "error");
console.log(error);
}
2021-05-03 07:52:48 +00:00
},
2021-05-05 09:40:40 +00:00
deleteCurrentAgenda: function () {
2021-05-03 07:52:48 +00:00
try {
2021-05-05 09:40:40 +00:00
swal({
title: "Êtes-vous sûr?",
2021-05-05 11:28:48 +00:00
text: "L'agenda sera supprimé",
2021-05-05 09:40:40 +00:00
icon: "warning",
buttons: ["Annuler", true],
dangerMode: true,
2021-05-05 11:28:48 +00:00
}).then(async (willDelete) => {
2021-05-05 09:40:40 +00:00
if (willDelete) {
2021-05-05 11:28:48 +00:00
let _ = await axios.delete(
`${baseUrl}/ws/agenda/calendars/${this.$route.query.id}`
);
swal("Succès!", "L'agenda a été supprimé", "success").then(
(value) => {
location.href = baseUrl;
}
);
2021-05-05 09:40:40 +00:00
}
});
2021-05-03 07:52:48 +00:00
} catch (error) {
2021-05-05 09:40:40 +00:00
swal("Erreur!", `${error}`, "error");
console.log(error);
2021-05-03 07:52:48 +00:00
}
},
2021-04-16 08:34:24 +00:00
},
};
2021-05-03 07:52:48 +00:00
</script>