From ffaf4a837f9e5d4f435b1ae3b7b253bf090c101b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Fri, 27 Jan 2023 14:45:28 +0100 Subject: [PATCH] Extract common behavior to `BulkActionsController` --- .../controllers/bulk_actions_controller.js | 23 +++++++++++++++++++ .../resend_confirmation_email_controller.js | 13 +++-------- 2 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 app/webpacker/controllers/bulk_actions_controller.js diff --git a/app/webpacker/controllers/bulk_actions_controller.js b/app/webpacker/controllers/bulk_actions_controller.js new file mode 100644 index 0000000000..78401aa047 --- /dev/null +++ b/app/webpacker/controllers/bulk_actions_controller.js @@ -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; + } +} diff --git a/app/webpacker/controllers/resend_confirmation_email_controller.js b/app/webpacker/controllers/resend_confirmation_email_controller.js index d375e6a0cf..81e88ee70f 100644 --- a/app/webpacker/controllers/resend_confirmation_email_controller.js +++ b/app/webpacker/controllers/resend_confirmation_email_controller.js @@ -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"); } }