From e748b6883fd1454d7ffe908ecb46599881317f8f Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 12 Jul 2018 11:21:13 +0200 Subject: [PATCH 1/3] Fix comportement chelou in LinkedDropDownListChamp --- .../champs/linked_drop_down_list_champ.rb | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/app/models/champs/linked_drop_down_list_champ.rb b/app/models/champs/linked_drop_down_list_champ.rb index 0b1b68875..eb235ae7d 100644 --- a/app/models/champs/linked_drop_down_list_champ.rb +++ b/app/models/champs/linked_drop_down_list_champ.rb @@ -1,27 +1,28 @@ class Champs::LinkedDropDownListChamp < Champ - attr_reader :primary_value, :secondary_value delegate :primary_options, :secondary_options, to: :type_de_champ - after_initialize :unpack_value - - def unpack_value + def primary_value if value.present? - primary, secondary = JSON.parse(value) + JSON.parse(value)[0] else - primary = secondary = '' + '' + end + end + + def secondary_value + if value.present? + JSON.parse(value)[1] + else + '' end - @primary_value ||= primary - @secondary_value ||= secondary end def primary_value=(value) - @primary_value = value - pack_value + pack_value(value, secondary_value) end def secondary_value=(value) - @secondary_value = value - pack_value + pack_value(primary_value, value) end def main_value_name @@ -46,7 +47,7 @@ class Champs::LinkedDropDownListChamp < Champ "#{primary_value || ''};#{secondary_value || ''}" end - def pack_value - self.value = JSON.generate([ primary_value, secondary_value ]) + def pack_value(primary, secondary) + self.value = JSON.generate([ primary, secondary ]) end end From 0e8a1f16788394be28ec5ea1ded7391a1b2b3518 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 12 Jul 2018 10:37:27 +0200 Subject: [PATCH 2/3] [fix #2241] GestionnaireDossierController: allow linked drop down value in update --- .../new_gestionnaire/dossiers_controller.rb | 2 +- .../new_gestionnaire/dossiers_controller_spec.rb | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/controllers/new_gestionnaire/dossiers_controller.rb b/app/controllers/new_gestionnaire/dossiers_controller.rb index a62359a18..ee5d86cee 100644 --- a/app/controllers/new_gestionnaire/dossiers_controller.rb +++ b/app/controllers/new_gestionnaire/dossiers_controller.rb @@ -187,7 +187,7 @@ module NewGestionnaire def champs_private_params params.require(:dossier).permit(champs_private_attributes: [ - :id, :piece_justificative_file, :value, value: [], + :id, :primary_value, :secondary_value, :piece_justificative_file, :value, value: [], etablissement_attributes: Champs::SiretChamp::ETABLISSEMENT_ATTRIBUTES ]) end diff --git a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb index 960595898..acc946c70 100644 --- a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb @@ -350,12 +350,16 @@ describe NewGestionnaire::DossiersController, type: :controller do create(:type_de_champ_multiple_drop_down_list, :private, libelle: 'libelle').champ.create end + let(:champ_linked_drop_down_list) do + create(:type_de_champ_linked_drop_down_list, :private, libelle: 'libelle').champ.create + end + let(:champ_datetime) do create(:type_de_champ_datetime, :private, libelle: 'libelle').champ.create end let(:dossier) do - create(:dossier, :en_construction, procedure: procedure, champs_private: [champ_multiple_drop_down_list, champ_datetime]) + create(:dossier, :en_construction, procedure: procedure, champs_private: [champ_multiple_drop_down_list, champ_linked_drop_down_list, champ_datetime]) end before do @@ -375,16 +379,24 @@ describe NewGestionnaire::DossiersController, type: :controller do 'value(3i)': 21, 'value(4i)': 13, 'value(5i)': 17 + }, + '2': { + id: champ_linked_drop_down_list.id, + primary_value: 'primary', + secondary_value: 'secondary' } } } } champ_multiple_drop_down_list.reload + champ_linked_drop_down_list.reload champ_datetime.reload end it { expect(champ_multiple_drop_down_list.value).to eq('["un", "deux"]') } + it { expect(champ_linked_drop_down_list.primary_value).to eq('primary') } + it { expect(champ_linked_drop_down_list.secondary_value).to eq('secondary') } it { expect(champ_datetime.value).to eq('21/12/2019 13:17') } it { expect(response).to redirect_to(annotations_privees_gestionnaire_dossier_path(dossier.procedure, dossier)) } end From 106263f5e724b4abea5b0956af98270abfa8708c Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 13 Jul 2018 13:09:21 +0200 Subject: [PATCH 3/3] [fix #2247] linked drop down list: fix js scope pb --- .../new_design/champs/linked_drop_down_list.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/new_design/champs/linked_drop_down_list.js b/app/assets/javascripts/new_design/champs/linked_drop_down_list.js index d82bf438f..03e7cd692 100644 --- a/app/assets/javascripts/new_design/champs/linked_drop_down_list.js +++ b/app/assets/javascripts/new_design/champs/linked_drop_down_list.js @@ -1,14 +1,14 @@ document.addEventListener('turbolinks:load', function() { - var primaries, i, primary, secondary, secondaryOptions; + var primaries, i; primaries = document.querySelectorAll('select[data-secondary-options]'); for (i = 0; i < primaries.length; i++) { - primary = primaries[i]; - secondary = document.querySelector('select[data-secondary-id="' + primary.dataset.primaryId + '"]'); - secondaryOptions = JSON.parse(primary.dataset.secondaryOptions); + primaries[i].addEventListener('change', function(e) { + var option, options, element, primary, secondary, secondaryOptions; - primary.addEventListener('change', function(e) { - var option, options, element; + primary = e.target; + secondary = document.querySelector('select[data-secondary-id="' + primary.dataset.primaryId + '"]'); + secondaryOptions = JSON.parse(primary.dataset.secondaryOptions); while ((option = secondary.firstChild)) { secondary.removeChild(option);