Cosmetics
This commit is contained in:
parent
729ed13521
commit
6db0b64f4c
7 changed files with 27 additions and 13 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -11,22 +11,30 @@ 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() {
|
||||||
return JSON.stringify(Array.from(new FormData(this.element).entries())
|
return JSON.stringify(Array.from(new FormData(this.element).entries())
|
||||||
.filter(x => x[1] != "")
|
.filter(x => x[1] != "")
|
||||||
.sort(x => x[0]))
|
.sort(x => x[0]))
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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 %>
|
||||||
5
app/views/checklists/_form.html.slim
Normal file
5
app/views/checklists/_form.html.slim
Normal 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
|
||||||
|
|
@ -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" } %>
|
||||||
|
|
|
||||||
|
|
@ -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">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue