Cosmetics
Some checks failed
/ Run tests (push) Failing after 1m13s
/ Run system tests (push) Failing after 1m15s
/ Build, push and deploy image (push) Has been skipped

This commit is contained in:
david 2024-11-01 00:50:15 +01:00
parent 729ed13521
commit 6db0b64f4c
7 changed files with 27 additions and 13 deletions

View file

@ -57,6 +57,7 @@ class ChecklistsController < ApplicationController
# Only allow a list of trusted parameters through.
def checklist_params
params.require(:checklist).permit(:code, :name, :description, :description_html,
check_ids: [],
checklist_entries_attributes: %i[id check_id position _destroy])
end
end

View file

@ -11,22 +11,30 @@ export default class extends Controller {
window.addEventListener("beforeunload", (event) => this.leavingPage(event))
document.addEventListener('turbo:before-visit', (e) => this.leavingPage(e))
this.element.addEventListener("submit", (_) => this.initialState = this.formState())
this.element.addEventListener("submit", (_) => this.initialState = null)
}
formState() {
return JSON.stringify(Array.from(new FormData(this.element).entries())
.filter(x => x[1] != "")
.sort(x => x[0]))
.filter(x => x[1] != "")
.sort(x => x[0]))
}
leavingPage(event) {
if(this.initialState == this.formState()) {
console.log(event.type)
if (this.initialState == null || this.initialState == this.formState()) {
return
}
if (!window.confirm(LEAVE_ALERT)) {
event.preventDefault()
if (event.type == "turbo:before-visit") {
if (!window.confirm(LEAVE_ALERT)) {
event.preventDefault()
} else {
this.initialState = null
}
} else {
this.initialState = null
event.returnValue = LEAVE_ALERT;
return event.returnValue;
}
}
}

View file

@ -1,6 +1,6 @@
class Page < ApplicationRecord
belongs_to :report
has_many :elements
has_many :elements, dependent: :destroy
has_rich_text :comment
end

View file

@ -1,4 +1,4 @@
<%= bootstrap_form_with(model: checklist) do |form| %>
<%= bootstrap_form_with(model: checklist, data: { controller: "unsaved-changes" }) do |form| %>
<%= form.text_field :name %>
<%= form.rich_text_area :description_html, rows: 12 %>
<%= form.submit %>

View file

@ -0,0 +1,5 @@
= bootstrap_form_with(model: checklist, data: { controller: "unsaved-changes" }) do |form|
= form.text_field :name
= form.rich_text_area :description_html, rows: 12
= form.collection_check_boxes :check_ids, Check.all.order(:external_number), :id, :display_label
= form.submit

View file

@ -1,4 +1,4 @@
<%= bootstrap_form_with(model: link) do |form| %>
<%= bootstrap_form_with(model: link, data: { controller: "unsaved-changes" }) do |form| %>
<div data-controller="check-link">
<%= form.text_field :url, placeholder: "https://wikipedia.org", data: { "check-link-target": "input" } %>

View file

@ -4,7 +4,7 @@
<div class="collapse show" id="collapseSuccessCriterion_<%= success_criterion.id %>">
<div class="card-body">
<%= bootstrap_form_with(model: success_criterion.persisted? ? success_criterion : [:element, success_criterion]) do |form| %>
<%= bootstrap_form_with(model: success_criterion.persisted? ? success_criterion : [:element, success_criterion], data: { controller: "unsaved-changes" }) do |form| %>
<div class="row">
<div class="col">
<div class="btn-group" role="group" aria-label="Resultat">