2022-11-21 16:32:17 +01:00
|
|
|
import { ApplicationController } from './application_controller';
|
2023-01-04 18:29:44 +01:00
|
|
|
import { disable, enable } from '@utils';
|
2022-11-21 16:32:17 +01:00
|
|
|
|
|
|
|
export class BatchOperationController extends ApplicationController {
|
2023-01-04 18:29:44 +01:00
|
|
|
static targets = ['input'];
|
2022-11-21 16:32:17 +01:00
|
|
|
|
|
|
|
declare readonly inputTargets: HTMLInputElement[];
|
|
|
|
|
2023-01-04 18:29:44 +01:00
|
|
|
onCheckOne() {
|
2022-11-21 16:32:17 +01:00
|
|
|
this.toggleSubmitButtonWhenNeeded();
|
|
|
|
}
|
|
|
|
|
|
|
|
onCheckAll(event: Event) {
|
2022-12-02 17:16:29 +01:00
|
|
|
const target = event.target as HTMLInputElement;
|
|
|
|
|
|
|
|
this.inputTargets.forEach((e) => (e.checked = target.checked));
|
2022-11-21 16:32:17 +01:00
|
|
|
this.toggleSubmitButtonWhenNeeded();
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleSubmitButtonWhenNeeded() {
|
|
|
|
const available = this.inputTargets.some((e) => e.checked);
|
2023-01-04 18:29:44 +01:00
|
|
|
const buttons = this.element.querySelectorAll<HTMLButtonElement>(
|
|
|
|
'.batch-operation button'
|
|
|
|
);
|
|
|
|
for (const button of buttons) {
|
|
|
|
if (available) {
|
|
|
|
enable(button);
|
|
|
|
} else {
|
|
|
|
disable(button);
|
2022-12-15 17:35:50 +01:00
|
|
|
}
|
2022-11-21 16:32:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|