mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
36 lines
846 B
JavaScript
36 lines
846 B
JavaScript
import ApplicationController from "./application_controller";
|
|
|
|
export default class extends ApplicationController {
|
|
static targets = ["extraParams"]
|
|
static values = { reflex: String }
|
|
|
|
connect() {
|
|
super.connect();
|
|
}
|
|
|
|
perform() {
|
|
let params = { bulk_ids: this.getSelectedIds() };
|
|
|
|
if (this.hasExtraParamsTarget) {
|
|
Object.assign(params, this.extraFormData())
|
|
}
|
|
|
|
this.stimulate(this.reflexValue, params);
|
|
}
|
|
|
|
// private
|
|
|
|
getSelectedIds() {
|
|
const checkboxes = document.querySelectorAll(
|
|
"table input[name='bulk_ids[]']:checked"
|
|
);
|
|
return Array.from(checkboxes).map((checkbox) => checkbox.value);
|
|
}
|
|
|
|
extraFormData() {
|
|
if (this.extraParamsTarget.constructor.name !== "HTMLFormElement") { return {} }
|
|
|
|
return Object.fromEntries(new FormData(this.extraParamsTarget).entries())
|
|
}
|
|
}
|