From a7791635aa98f012d35f97c3c5288494bbb28e38 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 13 Mar 2024 18:03:43 +0100 Subject: Initial commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- app/javascript/controllers/export_controller.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 app/javascript/controllers/export_controller.js (limited to 'app/javascript/controllers/export_controller.js') diff --git a/app/javascript/controllers/export_controller.js b/app/javascript/controllers/export_controller.js new file mode 100644 index 0000000..1807799 --- /dev/null +++ b/app/javascript/controllers/export_controller.js @@ -0,0 +1,19 @@ +import { Controller } from "@hotwired/stimulus" + +// Controller used in the exports#new page. That is, it allows us to change the +// format to be picked up by the exporter. +export default class extends Controller { + static targets = ["id"] + + connect() { + const url = `/searches/${this.idTarget.value}/exports.csv`; + document.getElementById("export-format-button").setAttribute('href', url); + } + + // Change the format to be used. + change() { + const format = document.getElementById("export-select-format").value; + const url = `/searches/${this.idTarget.value}/exports.${format}`; + document.getElementById("export-format-button").setAttribute('href', url); + } +} -- cgit v1.2.3