|
|
|
|
@@ -65,7 +65,7 @@ const getMediaCleanerMoviesTitle = async () => {
|
|
|
|
|
const selectedMovies = new Set();
|
|
|
|
|
const selectedTvShows = new Set();
|
|
|
|
|
|
|
|
|
|
const createCheckbox = (mediaInfo = {}, state = []) => {
|
|
|
|
|
const createCheckbox = (mediaInfo = {}, table, deleteButton) => {
|
|
|
|
|
const container = document.createElement('div');
|
|
|
|
|
container.className = 'checkboxContainer';
|
|
|
|
|
container.style.marginBottom = 0;
|
|
|
|
|
@@ -88,29 +88,48 @@ const createCheckbox = (mediaInfo = {}, state = []) => {
|
|
|
|
|
container.appendChild(label);
|
|
|
|
|
|
|
|
|
|
// Remove dependency on local state. Move to scanning for all checked checkboxes and create the array at that point.
|
|
|
|
|
// checkbox.addEventListener('change', (e) => {
|
|
|
|
|
// const mediaInfo = checkbox.dataset.mediaInfo || '(no info)';
|
|
|
|
|
// if (checkbox.checked) {
|
|
|
|
|
// state.add(mediaInfo);
|
|
|
|
|
// } else {
|
|
|
|
|
// state.delete(mediaInfo);
|
|
|
|
|
// }
|
|
|
|
|
// // Update UI or state — use console.log for debugging
|
|
|
|
|
// console.log('selected:', Array.from(state));
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
checkbox.addEventListener('change', (e) => {
|
|
|
|
|
const mediaInfo = checkbox.dataset.mediaInfo || '(no info)';
|
|
|
|
|
if (checkbox.checked) {
|
|
|
|
|
state.add(mediaInfo);
|
|
|
|
|
} else {
|
|
|
|
|
state.delete(mediaInfo);
|
|
|
|
|
if(isDeleteButtonVisible(table)){
|
|
|
|
|
console.log("Button should be visible: ", deleteButton);
|
|
|
|
|
deleteButton.style.visibility = 'visible';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
console.log("Button shouldn't be visible: ", deleteButton);
|
|
|
|
|
deleteButton.style.visibility = 'hidden';
|
|
|
|
|
}
|
|
|
|
|
// Update UI or state — use console.log for debugging
|
|
|
|
|
console.log('selected:', Array.from(state));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return container;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const isDeleteButtonVisible = (table) => {
|
|
|
|
|
const checkboxes = table.getElementsByClassName('emby-checkbox');
|
|
|
|
|
const hasChecked = Array.from(checkboxes).some(checkbox => checkbox.checked);
|
|
|
|
|
return hasChecked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const populateTables = async () => {
|
|
|
|
|
var moviesInfo = await getMediaCleanerMovieInfo();
|
|
|
|
|
var seriesInfo = await getMediaCleanerSeriesInfo();
|
|
|
|
|
|
|
|
|
|
var seriesTableBody = seriesTable.getElementsByTagName('tbody')[0];
|
|
|
|
|
seriesTableBody.replaceChildren();
|
|
|
|
|
var seriesDeleteButton = document.getElementById('seriesDeleteButton');
|
|
|
|
|
|
|
|
|
|
var moviesTableBody = moviesTable.getElementsByTagName('tbody')[0];
|
|
|
|
|
moviesTableBody.replaceChildren();
|
|
|
|
|
var moviesDeleteButton = document.getElementById('moviesDeleteButton');
|
|
|
|
|
|
|
|
|
|
if (moviesInfo.length > 0){
|
|
|
|
|
for(let i = 0; i < moviesInfo.length; i++){
|
|
|
|
|
@@ -119,7 +138,7 @@ const populateTables = async () => {
|
|
|
|
|
var cell2 = row.insertCell(1);
|
|
|
|
|
cell1.innerHTML = moviesInfo[i].Name;
|
|
|
|
|
cell1.className = "table-text";
|
|
|
|
|
cell2.appendChild(createCheckbox(moviesInfo[i], selectedMovies));
|
|
|
|
|
cell2.appendChild(createCheckbox(moviesInfo[i], moviesTable, moviesDeleteButton));
|
|
|
|
|
cell2.className = "table-checkbox"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -142,7 +161,7 @@ const populateTables = async () => {
|
|
|
|
|
cell1.className = "table-text";
|
|
|
|
|
cell2.innerHTML = seriesInfo[i].Seasons.map(season => season.replace("Season ", "")).join(", ");
|
|
|
|
|
cell2.className = "table-text";
|
|
|
|
|
cell3.appendChild(createCheckbox(seriesInfo[i], selectedTvShows));
|
|
|
|
|
cell3.appendChild(createCheckbox(seriesInfo[i], seriesTable, seriesDeleteButton));
|
|
|
|
|
cell3.className = "table-checkbox"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -157,8 +176,8 @@ const populateTables = async () => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const addClickHandlersToLinks = () => {
|
|
|
|
|
const linkbtns = document.querySelectorAll("button.links")
|
|
|
|
|
linkbtns.forEach(btn => {
|
|
|
|
|
const linkBtns = document.querySelectorAll("button.links");
|
|
|
|
|
linkBtns.forEach(btn => {
|
|
|
|
|
btn.addEventListener("click", () => {
|
|
|
|
|
const target = btn.dataset.target;
|
|
|
|
|
if (!target) return;
|
|
|
|
|
@@ -167,6 +186,17 @@ const addClickHandlersToLinks = () => {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const addClickHandlersToDeleteButtons = () => {
|
|
|
|
|
const deleteBtns = document.querySelectorAll("delete-buttons");
|
|
|
|
|
deleteBtns.forEach(btn => {
|
|
|
|
|
btn.addEventListener("click", deleteFromRadarr)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const deleteFromRadarr = () => {
|
|
|
|
|
console.log("Delete from Radarr!")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const finishLoading = () => {
|
|
|
|
|
const loadingElement = document.getElementById("loading");
|
|
|
|
|
|
|
|
|
|
|