Model menus, modal edit and layout improvements
Some checks failed
/ Run tests (push) Successful in 2m44s
/ Run system tests (push) Failing after 2m43s
/ Build, push and deploy image (push) Successful in 4m3s

This commit is contained in:
david 2024-11-23 19:10:09 +01:00
parent 7b0f05a448
commit 70500c49a1
35 changed files with 1079 additions and 148 deletions

View file

@ -0,0 +1,53 @@
// app/javascript/controllers/dialog_controller.js
import { Controller } from "@hotwired/stimulus"
// Connects to data-controller="dialog"
export default class extends Controller {
connect() {
this.open()
console.log("connect dialog", this.element)
this.element.addEventListener("turbo:submit-end", e => {
this.submitEnd(e)
})
this.element.addEventListener("click", e => this.clickOutside(e))
}
disconnect() {
}
// hide modal on successful form submission
// data-action="turbo:submit-end->turbo-modal#submitEnd"
submitEnd(e) {
if (e.detail.success) {
this.close()
}
}
open() {
console.log("open dialog")
this.element.showModal()
document.body.classList.add('overflow-hidden')
this.element.addEventListener("close", this.enableBodyScroll.bind(this))
}
close() {
this.element.removeEventListener("close", this.enableBodyScroll.bind(this))
this.element.close()
// clean up modal content
const frame = document.getElementById('modal')
frame.removeAttribute("src")
frame.innerHTML = ""
}
enableBodyScroll() {
document.body.classList.remove('overflow-hidden')
}
clickOutside(event) {
console.log("clickOutside", event.target, this)
if (event.target === this.element) {
this.close()
}
}
}