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. # Only allow a list of trusted parameters through.
def checklist_params def checklist_params
params.require(:checklist).permit(:code, :name, :description, :description_html, params.require(:checklist).permit(:code, :name, :description, :description_html,
check_ids: [],
checklist_entries_attributes: %i[id check_id position _destroy]) checklist_entries_attributes: %i[id check_id position _destroy])
end end
end end

View file

@ -11,7 +11,7 @@ export default class extends Controller {
window.addEventListener("beforeunload", (event) => this.leavingPage(event)) window.addEventListener("beforeunload", (event) => this.leavingPage(event))
document.addEventListener('turbo:before-visit', (e) => this.leavingPage(e)) 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() { formState() {
@ -21,12 +21,20 @@ export default class extends Controller {
} }
leavingPage(event) { leavingPage(event) {
if(this.initialState == this.formState()) { console.log(event.type)
if (this.initialState == null || this.initialState == this.formState()) {
return return
} }
if (event.type == "turbo:before-visit") {
if (!window.confirm(LEAVE_ALERT)) { if (!window.confirm(LEAVE_ALERT)) {
event.preventDefault() 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 class Page < ApplicationRecord
belongs_to :report belongs_to :report
has_many :elements has_many :elements, dependent: :destroy
has_rich_text :comment has_rich_text :comment
end 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.text_field :name %>
<%= form.rich_text_area :description_html, rows: 12 %> <%= form.rich_text_area :description_html, rows: 12 %>
<%= form.submit %> <%= 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"> <div data-controller="check-link">
<%= form.text_field :url, placeholder: "https://wikipedia.org", data: { "check-link-target": "input" } %> <%= 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="collapse show" id="collapseSuccessCriterion_<%= success_criterion.id %>">
<div class="card-body"> <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="row">
<div class="col"> <div class="col">
<div class="btn-group" role="group" aria-label="Resultat"> <div class="btn-group" role="group" aria-label="Resultat">