From 9b16f836937a2099b00e27504667faf52691a235 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 18 Apr 2020 12:04:49 +0200 Subject: [PATCH] Can delete movie --- assets/js/components/movies/interface.js | 13 +++++++++ assets/js/components/movies/picker.js | 35 ++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/assets/js/components/movies/interface.js b/assets/js/components/movies/interface.js index aaf9c134..429ccb7c 100644 --- a/assets/js/components/movies/interface.js +++ b/assets/js/components/movies/interface.js @@ -18,6 +18,19 @@ ComunicWeb.components.movies.interface = { ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); + }, + + + /** + * Delete a movie + * + * @param {number} movieID The ID of the movie to delete + * @return {Promise} + */ + delete: function(movieID) { + return api("movies/delete", { + movieID: movieID + }, true); } } \ No newline at end of file diff --git a/assets/js/components/movies/picker.js b/assets/js/components/movies/picker.js index bbe944a2..ab223be5 100644 --- a/assets/js/components/movies/picker.js +++ b/assets/js/components/movies/picker.js @@ -147,10 +147,12 @@ ComunicWeb.components.movies.picker = { //Process the list of movies var i; - for(i in list){ + for(i in list) { + + const movie = list[i]; //Create a line - var line = createElem2({ + const line = createElem2({ appendTo: tableBody, type: "tr", }); @@ -187,7 +189,7 @@ ComunicWeb.components.movies.picker = { type: "td", }); - var chooseButton = createElem2({ + const chooseButton = createElem2({ appendTo: actionCell, type: "button", class: "btn btn-primary", @@ -203,6 +205,33 @@ ComunicWeb.components.movies.picker = { //Call callback callback(list[this.getAttribute("data-movie-num")]); } + + + // Add delete button + createElem2({ + appendTo: actionCell, + type: "button", + class: "btn btn-danger", + innerHTML: "Delete", + onclick: () => { + + if(!ComunicWeb.common.messages.confirm("Do you really want to delete this movie ?", async res => { + + if(!res) + return; + + try { + await ComunicWeb.components.movies.interface.delete(movie.id) + line.remove(); + } catch(e) { + console.error(e); + notify("Could not delete movie!", "danger"); + } + + })); + + } + }) } }, } \ No newline at end of file