// SPDX-FileCopyrightText: 2020 IN COMMON Collective // // SPDX-License-Identifier: AGPL-3.0-or-later // Visit The Stimulus Handbook for more details // https://stimulusjs.org/handbook/introduction // import { Controller } from "stimulus" export default class extends Controller { static targets = [ "category", "deploy", "filter", "section", "toggle" ] initialize() { console.log("Taxonomy controller initialized.") } connect() { console.log("Taxonomy controller connected.") if (this.hasFilterTarget) { let url = `/taxonomies/${this.data.get('uuid')}/filter.js` console.log(`loading url = ${url}`) fetch(url, { headers: { accept: 'application/json'} }) .then(response => response.text()) .then(html => this.filterTarget.innerHTML = html) } else { console.log("Taxonomy filter is missing") } } deploy() { console.log(`deploying taxonomy ${this.data.get('uuid')}`); fetch(`/taxonomies/${this.data.get('uuid')}.js`) .then(response => response.text()) .then(html => this.deployTarget.innerHTML = html); } toggle() { var cssClass = 'on'; this.toggleTarget.classList.toggle(cssClass) this.filterTarget.parentNode.classList.toggle(cssClass) } category(event) { let catId = event.target.dataset.taxonomyCategoryId event.target.classList.toggle('active') } section(event) { let catId = event.target.dataset.taxonomySectionId event.target.classList.toggle('active') } }