Sha256: 57aa1bc284b7987696b08d27e1f6d601d3dbd85fe3b9a8af5ab0f576793dace4
Contents?: true
Size: 1.06 KB
Versions: 2
Compression:
Stored size: 1.06 KB
Contents
import { Controller } from "stimulus"; export default class extends Controller { static targets = ["filter"]; apply() { location.href = `${window.location.pathname}?${this.params}`; } post() { const token = document.head.querySelector( 'meta[name="csrf-token"]' ).content; const path = `${window.location.pathname}/destroy_all?${this.params}`; fetch(path, { method: "DELETE", redirect: "follow", headers: { "Content-Type": "application/json", credentials: "same-origin", }, body: JSON.stringify({ authenticity_token: token }), }).then((response) => { if (response.redirected) { window.location.href = response.url; } }); } get params() { return this.activeFilterTargets() .map((t) => `${t.name}=${t.value}`) .join("&"); } activeFilterTargets() { return this.filterTargets.filter(function (target) { if (target.type === "checkbox" || target.type === "radio") return target.checked; return target.value.length > 0; }); } }
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rails_mini_profiler-0.5.0 | app/javascript/js/filter_controller.js |
rails_mini_profiler-0 | app/javascript/js/filter_controller.js |