2024-10-14 23:09:27 +02:00
|
|
|
import { Controller } from "@hotwired/stimulus";
|
2024-02-08 10:46:05 -06:00
|
|
|
|
|
|
|
// Connects to data-controller="modal"
|
|
|
|
export default class extends Controller {
|
2024-11-27 16:01:50 -05:00
|
|
|
static values = {
|
|
|
|
reloadOnClose: { type: Boolean, default: false },
|
|
|
|
};
|
|
|
|
|
2024-02-08 10:46:05 -06:00
|
|
|
connect() {
|
2024-10-14 23:09:27 +02:00
|
|
|
if (this.element.open) return;
|
|
|
|
this.element.showModal();
|
2024-02-08 10:46:05 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hide the dialog when the user clicks outside of it
|
2024-03-14 15:30:36 +01:00
|
|
|
clickOutside(e) {
|
2024-02-08 10:46:05 -06:00
|
|
|
if (e.target === this.element) {
|
2024-11-27 16:01:50 -05:00
|
|
|
this.close();
|
2024-02-08 10:46:05 -06:00
|
|
|
}
|
|
|
|
}
|
2024-02-27 22:55:36 +05:30
|
|
|
|
|
|
|
close() {
|
|
|
|
this.element.close();
|
2024-11-27 16:01:50 -05:00
|
|
|
|
|
|
|
if (this.reloadOnCloseValue) {
|
|
|
|
window.location.reload();
|
|
|
|
}
|
2024-02-27 22:55:36 +05:30
|
|
|
}
|
2024-02-08 10:46:05 -06:00
|
|
|
}
|