113 lines
2.6 KiB
JavaScript
113 lines
2.6 KiB
JavaScript
// assets/controllers/toolbar_controller.js
|
|
import { Controller } from "@hotwired/stimulus"
|
|
|
|
export default class extends Controller {
|
|
static targets = ["dropdown"]
|
|
static values = {
|
|
currentSort: String,
|
|
currentOrder: String,
|
|
currentStatus: String
|
|
}
|
|
|
|
refreshMetadata(event) {
|
|
const mangaId = event.currentTarget.dataset.mangaid;
|
|
const url = `/refresh_metadata`;
|
|
|
|
fetch(url, {
|
|
method: 'POST',
|
|
headers: {
|
|
'X-Requested-With': 'XMLHttpRequest',
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({ mangaId: mangaId })
|
|
})
|
|
.then(response => {
|
|
if (!response.ok) {
|
|
throw new Error('Network response was not ok');
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(data => {
|
|
console.log('Metadata refreshed:', data);
|
|
// Traitez la réponse ici, par exemple en mettant à jour l'interface utilisateur
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
// Gérez l'erreur ici, par exemple en affichant un message à l'utilisateur
|
|
});
|
|
}
|
|
|
|
searchLastChapter() {
|
|
console.log("Searching last chapter...");
|
|
}
|
|
|
|
import() {
|
|
console.log("Importing...");
|
|
}
|
|
|
|
editMangas() {
|
|
console.log("Editing mangas...");
|
|
}
|
|
|
|
editManga() {
|
|
const event = new CustomEvent('openEditModal');
|
|
document.dispatchEvent(event);
|
|
}
|
|
|
|
deleteMangas() {
|
|
console.log("Deleting mangas...");
|
|
}
|
|
|
|
deleteManga() {
|
|
const event = new CustomEvent('openDeleteModal');
|
|
document.dispatchEvent(event);
|
|
}
|
|
|
|
showOptions() {
|
|
console.log("Showing options...");
|
|
}
|
|
|
|
expandAll() {
|
|
console.log("Expanding all...");
|
|
}
|
|
changeView(event) {
|
|
event.preventDefault();
|
|
const viewOption = event.currentTarget.dataset.view;
|
|
|
|
const url = new URL(window.location);
|
|
url.searchParams.set('view', viewOption);
|
|
|
|
window.location = url.toString();
|
|
}
|
|
|
|
sort(event) {
|
|
event.preventDefault()
|
|
const sortOption = event.currentTarget.dataset.sort;
|
|
let order = 'asc';
|
|
|
|
if (sortOption === this.currentSortValue && this.currentOrderValue === 'asc') {
|
|
order = 'desc';
|
|
}
|
|
|
|
const url = new URL(window.location);
|
|
url.searchParams.set('sort', sortOption);
|
|
url.searchParams.set('order', order);
|
|
|
|
window.location = url.toString();
|
|
}
|
|
|
|
filter(event) {
|
|
event.preventDefault();
|
|
const filterOption = event.currentTarget.dataset.filter;
|
|
|
|
const url = new URL(window.location);
|
|
url.searchParams.set('status', filterOption);
|
|
|
|
// Réinitialiser la page à 1 si on utilise la pagination
|
|
// url.searchParams.set('page', '1');
|
|
|
|
window.location = url.toString();
|
|
}
|
|
|
|
}
|