Can delete movie

This commit is contained in:
Pierre HUBERT 2020-04-18 12:04:49 +02:00
parent a34d10619c
commit 9b16f83693
2 changed files with 45 additions and 3 deletions

View File

@ -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);
}
}

View File

@ -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");
}
}));
}
})
}
},
}