Extract common behavior to BulkActionsController

This commit is contained in:
Jean-Baptiste Bellet
2023-01-27 14:45:28 +01:00
parent 27630a4304
commit ffaf4a837f
2 changed files with 26 additions and 10 deletions

View File

@@ -0,0 +1,23 @@
import ApplicationController from "./application_controller";
export default class extends ApplicationController {
connect() {
super.connect();
}
// abstract
confirm(action) {
this.stimulate(action, this.getOrdersIds());
}
// private
getOrdersIds() {
const order_ids = [];
document
.querySelectorAll("#listing_orders input[name='order_ids[]']:checked")
.forEach((checkbox) => {
order_ids.push(checkbox.value);
});
return order_ids;
}
}

View File

@@ -1,18 +1,11 @@
import ApplicationController from "./application_controller";
import BulkActionsController from "./bulk_actions_controller";
export default class extends ApplicationController {
export default class extends BulkActionsController {
connect() {
super.connect();
}
confirm() {
const order_ids = [];
document
.querySelectorAll("#listing_orders input[name='order_ids[]']:checked")
.forEach((checkbox) => {
order_ids.push(checkbox.value);
});
this.stimulate("ResendConfirmationEmailReflex#confirm", order_ids);
super.confirm("ResendConfirmationEmailReflex#confirm");
}
}