-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'production' into frf/plages-ouverture-meilleur-libelle-…
…par-defaut
- Loading branch information
Showing
19 changed files
with
468 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
document.addEventListener("turbolinks:load", function () { | ||
batchEditCheckboxes().forEach(e => e.addEventListener("change", refreshButtonState)) | ||
|
||
const trigger = triggerCheckbox() | ||
if(trigger) { | ||
trigger.addEventListener("change", event => { | ||
batchEditCheckboxes().forEach(input => input.checked = trigger.checked) | ||
refreshButtonState() | ||
}) | ||
} | ||
}); | ||
|
||
function refreshButtonState() { | ||
const disabled = Array.from(batchEditCheckboxes()).filter(c => c.checked).length < 2; | ||
batchEditButton().disabled = disabled; | ||
batchEditButton().classList.toggle("btn-outline-primary", !disabled) | ||
} | ||
|
||
function batchEditCheckboxes() { | ||
return document.querySelectorAll(".js-batch-edit-checkbox") | ||
} | ||
|
||
function batchEditButton() { | ||
return document.querySelector(".js-batch-edit-button") | ||
} | ||
|
||
function triggerCheckbox() { | ||
return document.querySelector(".js-trigger-checkbox") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
app/views/admin/territories/motifs/_motifs_table.html.slim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/ # locals: (motifs:, display_actions: false, display_checkboxes: false) | ||
table.table.table-centered.table-bordered.table-sm.mb-0[class=(display_checkboxes ? "table-hover" : "")] | ||
thead.thead-light | ||
tr | ||
- if display_checkboxes | ||
th[scope="col"] | ||
input.js-trigger-checkbox[type="checkbox"] | ||
|
||
th[scope="col"] | ||
/ Color columns | ||
th[scope="col"] | ||
| Nom | ||
th[scope="col"] | ||
| Service | ||
th[scope="col"] | ||
| Organisation | ||
th[scope="col"] | ||
| Type | ||
th[scope="col"] | ||
| Durée | ||
|
||
- if display_actions | ||
th[scope="col"] | ||
tbody | ||
- motifs.each do |motif| | ||
- motif_policy = Agent::MotifPolicy.new(current_agent, motif) | ||
tr | ||
- if display_checkboxes | ||
td | ||
input.js-batch-edit-checkbox[id="edit_checkbox#{motif.id}" type="checkbox" form="batch_edit_form" name="motif_ids[]" value=motif.id] | ||
td | ||
span.badge.badge-pill style="background: #{motif.color};" | ||
td | ||
label.mb-0[for="edit_checkbox#{motif.id}"] | ||
= motif.name | ||
= motif_badges(motif) | ||
td | ||
label.mb-0[for="edit_checkbox#{motif.id}"] | ||
= motif.service.short_name | ||
td | ||
- if motif_policy.show? && display_actions | ||
= link_to(motif.organisation.name, admin_organisation_motifs_path(organisation_id: motif.organisation.id)) | ||
- else | ||
= motif.organisation.name | ||
td | ||
label.mb-0[for="edit_checkbox#{motif.id}"] | ||
= Motif.human_attribute_value(:location_type, motif.location_type) | ||
td | ||
label.mb-0[for="edit_checkbox#{motif.id}"] | ||
= "#{motif.default_duration_in_min}" | ||
- if display_actions | ||
td.p-0 | ||
.d-flex | ||
- if @current_tab != :archived | ||
= link_to edit_admin_organisation_motif_path(motif.organisation, motif), class: "btn btn-link", title: t("admin.motifs.actions.edit"), target: :_blank do | ||
i.fa.fa-edit | ||
- if motif.archived? | ||
- if motif_policy.unarchive? | ||
= link_to unarchive_admin_territory_motif_path(current_territory, motif), class: "btn btn-link", method: :post, title: t("admin.motifs.actions.unarchive") do | ||
i.fa.fa-arrow-up-from-bracket | ||
- if motif_policy.destroy? | ||
- if motif.destroyable? | ||
= link_to admin_territory_motif_path(current_territory, motif), class: "btn btn-link", method: :delete, title: t("admin.motifs.actions.destroy"), data: { confirm: t("admin.motifs.actions.destroy_confirm") } do | ||
i.fa.fa-trash-alt | ||
- else | ||
button.btn.btn-link [disabled="disabled" title=t("admin.motifs.actions.not_destroyable_explanation")] | ||
i.fa.fa-trash-alt | ||
- else | ||
- if motif_policy.archive? | ||
= link_to archive_admin_territory_motif_path(current_territory, motif), class: "btn btn-link", method: :post, title: t("admin.motifs.actions.archive"), data: { confirm: t("admin.motifs.actions.archive_confirm") } do | ||
i.fa.fa-box-archive |
115 changes: 115 additions & 0 deletions
115
app/views/admin/territories/motifs/batch_edit.html.slim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
= territory_navigation(t("admin.territories.motifs.batch_edit.title"), [link_to(t("admin.territories.motifs.index.title"), admin_territory_motifs_path)]) | ||
|
||
h1 Modification en masse de #{@motifs.size} motifs | ||
|
||
= render partial: "admin/territories/motifs/motifs_table", locals: { motifs: @motifs } | ||
|
||
.card.mt-4.mb-4.p-3 | ||
= form_with(url: batch_update_admin_territory_motifs_path, method: :post, html: { id: "name_form" }) do |f| | ||
- @motifs.each do |motif| | ||
= f.hidden_field "motif_ids[]", value: motif.id | ||
|
||
.form-group | ||
- unique_values = @motifs.map(&:name).tally | ||
= f.label "Nom du motif", for: :name, class: "text-bold" | ||
- if unique_values.size > 1 | ||
p Ces motifs ont des noms différents : | ||
ul.mt-0 | ||
- unique_values.sort_by(&:last).reverse.each do |value, nb_of_occurrences| | ||
li #{value} (#{nb_of_occurrences}) | ||
- else | ||
small.form-text.text-muted.mb-2 Ces #{@motifs.size} motifs ont le même nom | ||
.input-group | ||
= f.text_field :name, value: (unique_values.size > 1 ? "" : unique_values.keys.first), class: "form-control", required: true | ||
.input-group-append | ||
= f.submit "Appliquer à ces #{@motifs.size} motifs", class: "btn btn-primary" | ||
|
||
.card.p-3.mb-4 | ||
= form_with(url: batch_update_admin_territory_motifs_path, method: :post, html: { id: "service_form" }) do |f| | ||
- @motifs.each do |motif| | ||
= f.hidden_field "motif_ids[]", value: motif.id | ||
|
||
.form-group | ||
- unique_values = @motifs.map(&:service).tally | ||
= f.label "Service associé", for: :service_id, class: "text-bold" | ||
- if unique_values.size > 1 | ||
p.mb-1 Ces motifs sont associés à des services différents : | ||
ul.mt-0 | ||
- unique_values.sort_by(&:last).reverse.each do |value, nb_of_occurrences| | ||
li #{value.name} (#{nb_of_occurrences}) | ||
- else | ||
small.form-text.text-muted.mb-2 Ces #{@motifs.size} motifs sont associés au même service | ||
.input-group | ||
= f.select :service_id, current_territory.services.reject(&:secretariat?).map { [_1.name, _1.id] }, { selected: (unique_values.size > 1 ? "" : unique_values.keys.first.id), include_blank: true, required: true }, { class: "custom-select" } | ||
.input-group-append | ||
= f.submit "Appliquer à ces #{@motifs.size} motifs", class: "btn btn-primary" | ||
|
||
.card.p-3.mb-4 | ||
= form_with(url: batch_update_admin_territory_motifs_path, method: :post, html: { id: "duration_form" }) do |f| | ||
- @motifs.each do |motif| | ||
= f.hidden_field "motif_ids[]", value: motif.id | ||
|
||
.form-group | ||
- unique_values = @motifs.map(&:default_duration_in_min).tally | ||
= f.label "Durée par défaut en minutes", for: :default_duration_in_min, class: "text-bold" | ||
- if unique_values.size > 1 | ||
p.mb-1 Ces motifs on des durées par défaut différentes : | ||
ul.mt-0 | ||
- unique_values.sort_by(&:last).reverse.each do |value, nb_of_occurrences| | ||
li #{value} (#{nb_of_occurrences}) | ||
- else | ||
small.form-text.text-muted.mb-2 Ces #{@motifs.size} motifs ont la même durée par défaut | ||
.input-group | ||
= f.number_field :default_duration_in_min, value: (unique_values.keys.size > 1 ? nil : unique_values.keys.first), class: "form-control", required: true | ||
.input-group-append | ||
= f.submit "Appliquer à ces #{@motifs.size} motifs", class: "btn btn-primary" | ||
|
||
.card.p-3.mb-4 | ||
= form_with(url: batch_update_admin_territory_motifs_path, method: :post, html: { id: "color_form" }) do |f| | ||
- @motifs.each do |motif| | ||
= f.hidden_field "motif_ids[]", value: motif.id | ||
|
||
.form-group | ||
- current_colors = @motifs.map(&:color).uniq | ||
/ Cette datalist permet au color picker natif de suggérer les couleurs existantes dans sa palette ! | ||
datalist#current_colors | ||
- current_colors.each do |color| | ||
option[value=color] | ||
= f.label "Couleur associée", for: :color, class: "text-bold" | ||
.input-group | ||
= f.color_field :color, value: current_colors.first, class: "form-control", list: "current_colors", required: true | ||
.input-group-append | ||
= f.submit "Appliquer à ces #{@motifs.size} motifs", class: "btn btn-primary" | ||
|
||
- %i[restriction_for_rdv instruction_for_rdv custom_cancel_warning_message].each do |instruction_attr_name| | ||
.card.p-3.mb-4 | ||
= form_with(url: batch_update_admin_territory_motifs_path, method: :post, html: { id: "#{instruction_attr_name}_form" }) do |f| | ||
- @motifs.each do |motif| | ||
= f.hidden_field "motif_ids[]", value: motif.id | ||
|
||
.form-group | ||
- unique_values = @motifs.map(&instruction_attr_name).tally | ||
= f.label t("activerecord.attributes.motif.#{instruction_attr_name}"), for: instruction_attr_name, class: "text-bold" | ||
- if unique_values.size > 1 | ||
p.mb-1 Ces motifs ont des textes différents : | ||
ul.mt-0 | ||
- unique_values.sort_by(&:last).reverse.each do |value, nb_of_occurrences| | ||
li | ||
- if value.present? | ||
= "#{value}" | ||
- else | ||
em pas de texte | ||
= " (#{nb_of_occurrences})" | ||
- else | ||
small.form-text.text-muted.mb-2 Ces #{@motifs.size} motifs ont le même texte | ||
= f.text_area instruction_attr_name, value: (unique_values.size > 1 ? nil : unique_values.keys.first), class: "form-control" | ||
.mt-1 | ||
= link_to image_path("motif_form/#{instruction_attr_name}.png"), target: "_blank" do | ||
span> Voir un exemple | ||
i.fa.fa-external-link-alt> | ||
|
||
.float-right | ||
= f.submit "Appliquer à ces #{@motifs.size} motifs", class: "btn btn-primary" | ||
|
||
.rdv-text-align-center.mb-4 | ||
= link_to("Retour", admin_territory_motifs_path, class: "btn btn-outline-primary") |
Oops, something went wrong.