diff --git a/app/assets/javascripts/description.js b/app/assets/javascripts/description.js index fab66068a..0948b9164 100644 --- a/app/assets/javascripts/description.js +++ b/app/assets/javascripts/description.js @@ -23,6 +23,7 @@ function action_type_de_champs() { }); address_type_init(); + toggle_header_section_composents(); } function toggleErrorClass(node, boolean) { @@ -45,3 +46,21 @@ function validateEmail(email) { function validateInput(input, regex) { return regex.test(input); } + +function toggle_header_section_composents() { + $("a.mask_section_button").on('click', function (e) { + target = e.currentTarget; + + header_section_id = target.id.split('mask_button_')[1]; + header_section_composents = $(".header_section_" + header_section_id); + + header_section_composents.slideToggle(200, function(){ + if (header_section_composents.css('display') == 'none') { + $(target).html('Afficher la section ') + } + else { + $(target).html('Masquer la section ') + } + }); + }); +} \ No newline at end of file diff --git a/app/views/users/description/_champs.html.haml b/app/views/users/description/_champs.html.haml index cb78dbd3b..f7eef0953 100644 --- a/app/views/users/description/_champs.html.haml +++ b/app/views/users/description/_champs.html.haml @@ -1,26 +1,25 @@ +-actual_header_section = nil -@champs.each do |champ| - .row + .row{class: (actual_header_section.nil? || champ.type_champ == 'header_section' ? '' : "header_section_"+actual_header_section.to_s)} %div{class: "type_champ-#{champ.type_champ}"} - -if champ.type_champ == 'checkbox' - %h4{style:'margin-left:15px;'} - = champ.libelle - - if champ.mandatory? - = '*' - %input{type: 'hidden', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", value: ''} - %input{type: 'checkbox', style:'margin-left: 15px;', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", checked: ('checked' if champ.value == 'on')} - - elsif champ.type_champ == 'header_section' + - if champ.type_champ == 'header_section' =render partial: 'users/description/champs/header_section', locals: {champ: champ} + -actual_header_section = champ.id -else - %h4 - = champ.libelle - - if champ.mandatory? - = '*' + - unless champ.type_champ == 'checkbox' + %h4 + = champ.libelle + - if champ.mandatory? + = '*' -if champ.type_champ == 'textarea' =render partial: 'users/description/champs/textarea', locals: {champ: champ} + -elsif champ.type_champ == 'checkbox' + = render partial: 'users/description/champs/checkbox', locals: {champ: champ} + -elsif champ.type_champ == 'civilite' =render partial: 'users/description/champs/civilite', locals: {champ: champ} diff --git a/app/views/users/description/champs/_checkbox.html.haml b/app/views/users/description/champs/_checkbox.html.haml new file mode 100644 index 000000000..8f2727f9d --- /dev/null +++ b/app/views/users/description/champs/_checkbox.html.haml @@ -0,0 +1,6 @@ +%h4{style:'margin-left:15px;'} + = champ.libelle + - if champ.mandatory? + = '*' + %input{type: 'hidden', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", value: ''} + %input{type: 'checkbox', style:'margin-left: 15px;', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", checked: ('checked' if champ.value == 'on')} diff --git a/app/views/users/description/champs/_header_section.html.haml b/app/views/users/description/champs/_header_section.html.haml index 5ff3eae62..18b34e181 100644 --- a/app/views/users/description/champs/_header_section.html.haml +++ b/app/views/users/description/champs/_header_section.html.haml @@ -1,2 +1,6 @@ %h3.text-primary.page-header - =champ.libelle \ No newline at end of file + =champ.libelle + %span.mask_section{style:'float: right'} + %a.mask_section_button.btn.btn-xs.btn-default{id: "mask_button_"+champ.id.to_s} + Masquer la section + %i.fa.fa-chevron-up \ No newline at end of file