From aca39642a1383ee68294f7a0db58d5ebfef32853 Mon Sep 17 00:00:00 2001 From: ArenMg Date: Mon, 10 May 2021 17:21:44 +0300 Subject: [PATCH] delete sondage functionnality --- src/main/webapp/assets/js/views/sondage.vue | 79 ++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/src/main/webapp/assets/js/views/sondage.vue b/src/main/webapp/assets/js/views/sondage.vue index eb18a86..ebb77de 100644 --- a/src/main/webapp/assets/js/views/sondage.vue +++ b/src/main/webapp/assets/js/views/sondage.vue @@ -3,6 +3,19 @@

@@ -128,6 +141,19 @@ max-height: 15em; } +.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; +} + .btn-vote { display: flex; justify-content: center; @@ -216,7 +242,7 @@ const getUrl = window.location; // if (baseUrl.endsWith("/")) { // baseUrl = baseUrl.slice(0, -1); // } -let baseUrl = getUrl.protocol + "//" + getUrl.host +let baseUrl = getUrl.protocol + "//" + getUrl.host; module.exports = { data() { return { @@ -224,14 +250,40 @@ module.exports = { theme: false, choices: [], votes: [], + loggedUser: false, }; }, created() { this.fetchTheme(); this.fetchUser(); this.fetchVotes(); + this.getCurrentUser(); }, methods: { + getCurrentUser: function () { + ArenService.Users.getLoged({ + onSuccess: (logedUser) => { + this.loggedUser = logedUser; + console.log(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(); + }, + }); + }, fetchUser: async function () { const _user = await axios.get(`${baseUrl}/ws/users/me`); this.user = _user.data; @@ -283,6 +335,31 @@ module.exports = { return arr.length <= 0; }, + deleteCurrentSondage: function () { + try { + swal({ + title: "Êtes-vous sûr?", + text: "Le sondage sera supprimé avec toutes ses informations", + icon: "warning", + buttons: ["Annuler", true], + dangerMode: true, + }).then(async (willDelete) => { + if (willDelete) { + let _ = await axios.delete( + `${baseUrl}/ws/themes/delete/${this.$route.query.id}` + ); + swal("Succès!", "Le sondage a été supprimé", "success").then( + (value) => { + location.href = baseUrl; + } + ); + } + }); + } catch (error) { + swal("Erreur!", `${error}`, "error"); + console.log(error); + } + }, }, };