63 lines
1.7 KiB
JavaScript
63 lines
1.7 KiB
JavaScript
import { Controller } from '@hotwired/stimulus';
|
|
|
|
/*
|
|
* The following line makes this controller "lazy": it won't be downloaded until needed
|
|
* See https://github.com/symfony/stimulus-bridge#lazy-controllers
|
|
*/
|
|
/* stimulusFetch: 'lazy' */
|
|
export default class extends Controller {
|
|
static values = {
|
|
title: String,
|
|
tmdbId: String,
|
|
imdbId: String,
|
|
season: String,
|
|
episode: String,
|
|
active: Boolean,
|
|
};
|
|
|
|
static targets = ['list', 'count']
|
|
static outlets = ['loading-icon']
|
|
|
|
options = []
|
|
optionsLoaded = false
|
|
|
|
async connect() {
|
|
await this.setOptions();
|
|
}
|
|
|
|
async setOptions() {
|
|
if (true === this.activeValue) {
|
|
await fetch(`/torrentio/tvshows/${this.tmdbIdValue}/${this.imdbIdValue}/${this.seasonValue}/${this.episodeValue}`)
|
|
.then(res => res.text())
|
|
.then(response => {
|
|
this.element.innerHTML = response;
|
|
this.options = this.element.querySelectorAll('tbody tr');
|
|
this.options.forEach((option) => option.querySelector('.download-btn').dataset['title'] = this.titleValue);
|
|
this.optionsLoaded = true;
|
|
this.loadingIconOutlet.increaseCount();
|
|
});
|
|
}
|
|
}
|
|
|
|
async setActive() {
|
|
this.activeValue = true;
|
|
this.element.classList.remove('hidden');
|
|
if (false === this.optionsLoaded) {
|
|
await this.setOptions();
|
|
}
|
|
}
|
|
|
|
setInActive() {
|
|
this.activeValue = false;
|
|
this.element.classList.add('hidden');
|
|
}
|
|
|
|
isActive() {
|
|
return this.activeValue;
|
|
}
|
|
|
|
toggleList() {
|
|
this.listTarget.classList.toggle('hidden');
|
|
}
|
|
}
|