diff --git a/Gemfile b/Gemfile index 3b1aa7926..20bc62a0a 100644 --- a/Gemfile +++ b/Gemfile @@ -102,6 +102,8 @@ gem 'simple_form' gem 'newrelic_rpm' +gem 'select2-rails' + group :test do gem 'capybara' gem 'launchy' diff --git a/Gemfile.lock b/Gemfile.lock index f0e40cf8e..353b2160a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -543,6 +543,8 @@ GEM json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) securecompare (1.0.0) + select2-rails (4.0.3) + thor (~> 0.14) selenium-webdriver (3.0.3) childprocess (~> 0.5) rubyzip (~> 1.0) @@ -709,6 +711,7 @@ DEPENDENCIES sass-rails (~> 5.0) scenic sdoc (~> 0.4.0) + select2-rails selenium-webdriver sentry-raven shoulda-matchers diff --git a/app/assets/javascripts/admin.js b/app/assets/javascripts/admin.js index 6c2e63536..967633a7b 100644 --- a/app/assets/javascripts/admin.js +++ b/app/assets/javascripts/admin.js @@ -23,22 +23,25 @@ function destroy_action(){ } function on_change_type_de_champ_select (){ - $("select.form-control.type_champ").on('change', function(e){ parent = $(this).parent().parent(); parent.removeClass('header_section'); parent.children(".drop_down_list").removeClass('show_inline'); + $('.mandatory', parent).show(); switch(this.value){ case 'header_section': parent.addClass('header_section'); break; case 'drop_down_list': + case 'multiple_drop_down_list': parent.children(".drop_down_list").addClass('show_inline'); break; - + case 'explication': + $('.mandatory', parent).hide(); + break; } - }) + }); } diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 567658f93..a7827dfc8 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -31,6 +31,7 @@ //= require bootstrap-wysihtml5/locales/fr-FR //= require handlebars //= require typeahead.bundle +//= require select2 $(document).on('page:load', application_init); $(document).ready(application_init); diff --git a/app/assets/javascripts/user/description.js b/app/assets/javascripts/user/description.js new file mode 100644 index 000000000..cdae9a4c1 --- /dev/null +++ b/app/assets/javascripts/user/description.js @@ -0,0 +1,6 @@ +$(document).on('page:load', activeSelect2); +$(document).ready(activeSelect2); + +function activeSelect2() { + $('select.select2').select2({ theme: "bootstrap", width: '100%' }); +} diff --git a/app/assets/stylesheets/admin_type_de_champ.scss b/app/assets/stylesheets/admin_type_de_champ.scss index e4a9b92e9..bc2613075 100644 --- a/app/assets/stylesheets/admin_type_de_champ.scss +++ b/app/assets/stylesheets/admin_type_de_champ.scss @@ -23,6 +23,10 @@ } #liste_champ{ + .form-inline { + margin-bottom: 30px; + } + .show_inline { display: inline-block !important; } @@ -30,4 +34,16 @@ .form-group.drop_down_list{ display: none; } -} \ No newline at end of file + + .form-group { + vertical-align: top; + margin-right: 15px; + } + + .description { + padding: 0; + textarea { + padding: 6px 12px; + } + } +} diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 5e30ef194..6d4168935 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -19,6 +19,8 @@ *= require font-awesome *= require franceconnect *= require bootstrap-wysihtml5 + *= require select2 + *= require select2-bootstrap */ @import "variables"; @import "bootstrap-sprockets"; diff --git a/app/decorators/champ_decorator.rb b/app/decorators/champ_decorator.rb index 42c9639e4..8c95b8183 100644 --- a/app/decorators/champ_decorator.rb +++ b/app/decorators/champ_decorator.rb @@ -2,9 +2,8 @@ class ChampDecorator < Draper::Decorator delegate_all def value - if type_champ == 'checkbox' - return object.value == 'on' ? 'Oui' : 'Non' - end + return object.value == 'on' ? 'Oui' : 'Non' if type_champ == 'checkbox' + return JSON.parse(object.value).join(', ') if type_champ == 'multiple_drop_down_list' && object.value.present? object.value end diff --git a/app/decorators/type_de_champ_decorator.rb b/app/decorators/type_de_champ_decorator.rb index ffe824855..d54293195 100644 --- a/app/decorators/type_de_champ_decorator.rb +++ b/app/decorators/type_de_champ_decorator.rb @@ -3,11 +3,19 @@ class TypeDeChampDecorator < Draper::Decorator delegate_all def button_up params - h.link_to '', params[:url], class: up_classes, id: "btn_up_#{params[:index]}", remote: true, method: :post if display_up_button?(params[:index], params[:private]) + h.link_to '', params[:url], class: up_classes, + id: "btn_up_#{params[:index]}", + remote: true, + method: :post, + style: display_up_button?(params[:index], params[:private]) ? '' : 'visibility: hidden;' end def button_down params - h.link_to '', params[:url], class: down_classes, id: "btn_down_#{params[:index]}", remote: true, method: :post if display_down_button?(params[:index], params[:private]) + h.link_to '', params[:url], class: down_classes, + id: "btn_down_#{params[:index]}", + remote: true, + method: :post, + style: display_down_button?(params[:index], params[:private]) ? '' : 'visibility: hidden;' end private diff --git a/app/models/drop_down_list.rb b/app/models/drop_down_list.rb index d6e2d3d02..979112f4c 100644 --- a/app/models/drop_down_list.rb +++ b/app/models/drop_down_list.rb @@ -2,6 +2,19 @@ class DropDownList < ActiveRecord::Base belongs_to :type_de_champ def options - value.split(/[\r\n]|[\r]|[\n]|[\n\r]/).reject(&:empty?) + result = value.split(/[\r\n]|[\r]|[\n]|[\n\r]/).reject(&:empty?) + result.blank? ? [] : [''] + result + end + + def disabled_options + options.select{ |v| !(v =~ /^--.*--$/).nil? } + end + + def selected_options(champ) + champ.object.value.blank? ? [] : multiple ? JSON.parse(champ.object.value) : [champ.object.value] + end + + def multiple + type_de_champ.type_champ == 'multiple_drop_down_list' end end diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 9d1b2e693..2dbfb2d90 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -12,11 +12,13 @@ class TypeDeChamp < ActiveRecord::Base address: 'address', yes_no: 'yes_no', drop_down_list: 'drop_down_list', + multiple_drop_down_list: 'multiple_drop_down_list', pays: 'pays', regions: 'regions', departements: 'departements', engagement: 'engagement', - header_section: 'header_section' + header_section: 'header_section', + explication: 'explication' } belongs_to :procedure @@ -29,7 +31,7 @@ class TypeDeChamp < ActiveRecord::Base validates :libelle, presence: true, allow_blank: false, allow_nil: false validates :type_champ, presence: true, allow_blank: false, allow_nil: false - before_validation :change_header_section_mandatory + before_validation :check_mandatory def self.type_de_champs_list_fr type_champs.map { |champ| [I18n.t("activerecord.attributes.type_de_champ.type_champs.#{champ.last}"), champ.first] } @@ -39,8 +41,8 @@ class TypeDeChamp < ActiveRecord::Base !(type_champ == 'textarea' || type_champ == 'header_section') end - def change_header_section_mandatory - self.mandatory = false if self.type_champ == 'header_section' + def check_mandatory + self.mandatory = false if %w(header_section explication).include?(self.type_champ) true end end diff --git a/app/services/types_de_champ_service.rb b/app/services/types_de_champ_service.rb index b8397d3a4..eba9a549a 100644 --- a/app/services/types_de_champ_service.rb +++ b/app/services/types_de_champ_service.rb @@ -12,8 +12,18 @@ class TypesDeChampService if param_second[:libelle].empty? parameters[attributes].delete(param_first.to_s) end + + if param_second['drop_down_list_attributes'] && param_second['drop_down_list_attributes']['value'] + param_second['drop_down_list_attributes']['value'] = self.clean_value (param_second['drop_down_list_attributes']['value']) + end end parameters end -end \ No newline at end of file + + private + + def self.clean_value value + value.split("\r\n").map{ |v| v.strip }.join("\r\n") + end +end diff --git a/app/views/admin/procedures/show.html.haml b/app/views/admin/procedures/show.html.haml index e0c945cff..7249a0ed6 100644 --- a/app/views/admin/procedures/show.html.haml +++ b/app/views/admin/procedures/show.html.haml @@ -82,7 +82,7 @@ .pieces_justificatives.col-xs-6.col-md-3 %h4.text-info - Pièces justificatives + Pièces jointes .badge.progress-bar-info = @facade.procedure.types_de_piece_justificative.size - @facade.procedure.types_de_piece_justificative.each do |piece_justificative| diff --git a/app/views/admin/profile/show.html.haml b/app/views/admin/profile/show.html.haml index 5349fd071..615d5331e 100644 --- a/app/views/admin/profile/show.html.haml +++ b/app/views/admin/profile/show.html.haml @@ -1,5 +1,5 @@ #profile_page -%h2 Profile +%h2 Profil %hr %p API TOKEN : diff --git a/app/views/admin/types_de_champ/_fields.html.haml b/app/views/admin/types_de_champ/_fields.html.haml index 649be960e..01c60cdd9 100644 --- a/app/views/admin/types_de_champ/_fields.html.haml +++ b/app/views/admin/types_de_champ/_fields.html.haml @@ -1,27 +1,31 @@ = f.fields_for @types_de_champ_facade.fields_for_var, types_de_champ, remote: true do |ff| - .form-inline{class:"#{ff.object.object.type_champ == 'header_section' ? 'header_section' : ''}"} + - type_champ = ff.object.object.type_champ + + .form-inline{ class: (type_champ == 'header_section' ? 'header_section' : nil) } .form-group.libelle %h4 Libellé = ff.text_field :libelle, class: 'form-control libelle', placeholder: 'Libellé' .form-group.type %h4 Type - = ff.select :type_champ, TypeDeChamp.type_de_champs_list_fr, {}, {class: 'form-control type_champ'} + = ff.select :type_champ, TypeDeChamp.type_de_champs_list_fr, {}, { class: 'form-control type_champ' } .form-group.description %h4 Description - = ff.text_area :description, class: 'form-control description', placeholder: 'Description', rows: 2 + = ff.text_area :description, class: 'form-control description', placeholder: 'Description', rows: 3 - .form-group.drop_down_list{class:"#{ff.object.object.type_champ == 'drop_down_list' ? 'show_inline' : ''}",style:'margin-right: 5px'} + .form-group.drop_down_list{ class: (%w(drop_down_list multiple_drop_down_list).include?(type_champ) ? 'show_inline' : nil), style: 'margin-right: 5px' } %h4 Liste déroulante = ff.fields_for :drop_down_list_attributes, ff.object.object.drop_down_list do |fff| - = fff.text_area :value, class: 'form-control drop_down_list', placeholder: "Ecrire une valeur par ligne.\nEcrire --valeur-- pour un séparateur.", rows: 3, cols: 30 + ~ fff.text_area :value, class: 'form-control drop_down_list', placeholder: "Ecrire une valeur par ligne et --valeur-- pour un séparateur.", rows: 3, cols: 30 = fff.hidden_field :id - - unless ff.object.object.class == TypeDeChampPrivate - .form-group.mandatory - %h4 Obligatoire ? - .center - = ff.check_box :mandatory, placeholder: 'Obligatoire ?' + + + - hide_mandatory = (ff.object.object.class == TypeDeChampPrivate || type_champ == 'explication') + .form-group.mandatory{ style: hide_mandatory ? 'visibility: hidden;' : nil } + %h4 Obligatoire ? + .center + = ff.check_box :mandatory, placeholder: 'Obligatoire ?' .form-group = ff.hidden_field :order_place, value: ff.index @@ -41,4 +45,6 @@ - else = link_to("", @types_de_champ_facade.delete_url(ff), method: :delete, remote: true, id: "delete_type_de_champ_#{ff.object.id}", class: %w(form-control btn btn-danger fa fa-trash-o) ) + %div{ style: 'background-color: rgb(204, 204, 204); height: 1px; margin: 30px auto;' } + diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index afe71a442..91d85a427 100644 --- a/app/views/dossiers/_infos_dossier.html.haml +++ b/app/views/dossiers/_infos_dossier.html.haml @@ -1,5 +1,5 @@ %div.row - .col-lg-12.col-md-12.col-sm-12.col-xs-12 + .col-xs-12 - if @facade.procedure.for_individual? .row.title-row %div.col-xs-4.split-hr @@ -7,24 +7,25 @@ %div.col-xs-4.split-hr .row %div.col-xs-6.depositaire-label Civilité - %div.col-md-1.col-lg-1.col-sm-1.col-xs-1.comments-off= "-" + %div.col-xs-1.comments-off= "-" %div.col-xs-5.depositaire-info= @facade.individual.gender .row %div.col-xs-6.depositaire-label Nom - %div.col-md-1.col-lg-1.col-sm-1.col-xs-1.comments-off= "-" + %div.col-xs-1.comments-off= "-" %div.col-xs-5.depositaire-info= @facade.individual.nom .row %div.col-xs-6.depositaire-label Prénom - %div.col-md-1.col-lg-1.col-sm-1.col-xs-1.comments-off= "-" + %div.col-xs-1.comments-off= "-" %div.col-xs-5.despositaire-info= @facade.individual.prenom .row %div.col-xs-6.depositaire-label Date de naissance - %div.col-md-1.col-lg-1.col-sm-1.col-xs-1.comments-off= "-" + %div.col-xs-1.comments-off= "-" %div.col-xs-5.depositaire-info= @facade.individual.birthdate .row.margin-top-20 - unless @facade.champs.nil? - @facade.champs.each do |champ| + - next if champ.type_champ == 'explication' - if champ.type_champ == 'header_section' .row.title-row.margin-top-40 %div.col-xs-3.split-hr @@ -48,19 +49,19 @@ =")" %div.row - if @facade.procedure.cerfa_flag? || @facade.dossier.types_de_piece_justificative.count > 0 - .col-lg-12.col-md-12.col-sm-12.col-xs-12 + .col-xs-12 .row.title-row %div.col-xs-4.split-hr %div.col-xs-4.dossier-title= t('utils.pieces').upcase %div.col-xs-4.split-hr - .col-lg-12.col-md-12.col-sm-12.col-xs-12#pieces_justificatives.margin-bot-40 + .col-xs-12#pieces_justificatives.margin-bot-40 .row - if @facade.procedure.cerfa_flag? .col-xs-12#piece_justificative_0 .row.piece-row .col-xs-6.depositaire-label= 'Formulaire' - .col-md-1.col-lg-1.col-sm-1.col-xs-1.comments-off= "-" + .col-xs-1.comments-off= "-" .col-xs-5.despositaire-info - if @facade.dossier.cerfa_available? %a{ href: "#{@facade.dossier.cerfa.last.content_url}", target: '_blank' } Consulter @@ -77,7 +78,7 @@ .col-xs-12{ id: "piece_justificative_#{type_de_piece_justificative.id}" } .row %div.col-xs-6.depositaire-label= type_de_piece_justificative.libelle - %div.col-md-1.col-lg-1.col-sm-1.col-xs-1.comments-off= "-" + %div.col-xs-1.comments-off= "-" %div.col-xs-5.despositaire-info - if type_de_piece_justificative.api_entreprise %span.text-success Nous l'avons récupéré pour vous. @@ -95,13 +96,13 @@ - if user_signed_in? && (@facade.dossier.owner?(current_user.email) || @facade.dossier.invite_by_user?(current_user.email)) - if @facade.procedure.cerfa_flag? || @facade.dossier.types_de_piece_justificative.size > 0 .row - .col-lg-4.col-md-4.col-sm-4.col-xs-4 + .col-xs-4 %a#maj_pj.action{"data-target" => "#UploadPJmodal", "data-toggle" => "modal", :type => "button"} - .col-lg-4.col-md-4.col-sm-4.col-xs-4.action + .col-xs-4.action Modifier les documents %br = render partial: 'users/recapitulatif/modal_upload_pj' - .col-lg-4.col-md-4.col-sm-4.col-xs-4 + .col-xs-4 - if gestionnaire_signed_in? #PJmodal.modal.fade{"aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"} diff --git a/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml b/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml index a78879adc..8a05145b8 100644 --- a/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml +++ b/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml @@ -31,7 +31,7 @@ - unless @procedure.locked? %a{:href => "#{url_for admin_procedure_pieces_justificatives_path(@procedure)}", id: 'onglet-pieces'} %div.procedure_list_element{class: ('active' if active == 'Pieces')} - Pièces justificatives + Pièces jointes - unless @procedure.locked? %a{:href => "#{url_for admin_procedure_types_de_champ_private_path(@procedure)}", id: 'onglet-private-champs'} diff --git a/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml b/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml index 9c8748b5b..12f7b4e7c 100644 --- a/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml +++ b/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml @@ -54,9 +54,9 @@ .type= "Un attribut à été changé: #{notification.liste.last}" - elsif ['piece_justificative'].include?(notification.type_notif) - if notification.liste.size > 1 - .type= "Plusieurs pièces justificatives ont été changés, dont: #{notification.liste.join(" ")}" + .type= "Plusieurs pièces jointes ont été changés, dont: #{notification.liste.join(" ")}" - else - .type= "Une pièce justificative à été changée: #{notification.liste.last}" + .type= "Une pièce jointe à été changée: #{notification.liste.last}" - else .type= notification.liste.last .split-hr diff --git a/app/views/layouts/navbars/_navbar_admin_procedurescontroller_index.html.haml b/app/views/layouts/navbars/_navbar_admin_procedurescontroller_index.html.haml index 8adfbc93d..13fdaf3c7 100644 --- a/app/views/layouts/navbars/_navbar_admin_procedurescontroller_index.html.haml +++ b/app/views/layouts/navbars/_navbar_admin_procedurescontroller_index.html.haml @@ -23,4 +23,4 @@ %li = link_to(admin_profile_path, id: :profile) do %i.fa.fa-user -  Profile +  Profil diff --git a/app/views/users/description/_show.html.haml b/app/views/users/description/_show.html.haml index 14b17b160..ac21a126e 100644 --- a/app/views/users/description/_show.html.haml +++ b/app/views/users/description/_show.html.haml @@ -4,7 +4,7 @@ .panel.panel-info{style:'margin-bottom:0'} .panel-body.center .row - .col-md-1.col-lg-1.col-sm-1.col-xs-1 + .col-xs-1 .fa.fa-info-circle.text-info{style:'font-size: 2em; margin-top: 20%'} .col-xs-10{style:'padding-right: 0px'} %b @@ -22,7 +22,7 @@ -if !@procedure.lien_demarche.blank? || @procedure.cerfa_flag || @dossier.types_de_piece_justificative.size > 0 %br - %h3 Documents administratifs + %h3 Pièces jointes //TODO a refactorer @@ -30,17 +30,6 @@ .col-lg-8 = render partial: 'users/description/pieces_justificatives', locals: { dossier: @dossier } - #state_description.row{style:'width: 50%; margin-left:20px'} - .panel.panel-info - .panel-body.center - .row - .col-md-1.col-lg-1.col-sm-1.col-xs-1 - .fa.fa-info-circle.text-info{style:'font-size: 2em; margin-top: 20%'} - .col-xs-11 - Les documents administratifs ne sont pas indispensables afin d'initier votre dossier. - Vous pourrez dans tous les cas les compléter plus tard si vous ne les possédez pas de suite. - - -route = Rails.application.routes.recognize_path(request.referrer) # WTF ? - unless route[:controller].match('admin') %div{style: 'text-align:right'} diff --git a/app/views/users/description/champs/_drop_down_list.html.haml b/app/views/users/description/champs/_drop_down_list.html.haml index e398f6519..1480aff23 100644 --- a/app/views/users/description/champs/_drop_down_list.html.haml +++ b/app/views/users/description/champs/_drop_down_list.html.haml @@ -1,2 +1,2 @@ - unless champ.drop_down_list.nil? - = render partial: 'users/description/champs/drop_down_template', locals: {values: champ.drop_down_list.options, champ: champ} + = render partial: 'users/description/champs/drop_down_template', locals: { drop_down_list: champ.drop_down_list, champ: champ } diff --git a/app/views/users/description/champs/_drop_down_template.html.haml b/app/views/users/description/champs/_drop_down_template.html.haml index e3956e3c1..5ec502745 100644 --- a/app/views/users/description/champs/_drop_down_template.html.haml +++ b/app/views/users/description/champs/_drop_down_template.html.haml @@ -1,18 +1,6 @@ -%select{ name:"champs['#{champ.id}']", - id: "champs_#{champ.id}" } - - - unless values.blank? - %option - = '' - - - values.each do |option| - - if (option=~ /^--.*--$/).nil? - - if champ.value == option - %option{selected:''} - = option - - else - %option - = option - -else - %option{disabled:''} - = option +- unless drop_down_list.options.blank? + = select_tag("champs['#{champ.id}']", + options_for_select(drop_down_list.options, selected: drop_down_list.selected_options(champ), + disabled: drop_down_list.disabled_options), + multiple: drop_down_list.multiple, + class: drop_down_list.multiple ? 'select2' : nil) diff --git a/app/views/users/description/champs/_header_section.html.haml b/app/views/users/description/champs/_header_section.html.haml index b2d4662d0..cc2c1099f 100644 --- a/app/views/users/description/champs/_header_section.html.haml +++ b/app/views/users/description/champs/_header_section.html.haml @@ -1,9 +1,9 @@ .default_data_block.default_visible - %div.row.show-block.infos - %div.header - %div.col-lg-12.col-md-12.col-sm-12.col-xs-12.title - %div.carret-right - %div.carret-down + .row.show-block.infos + .header + .col-xs-12.title + .carret-right + .carret-down =libelle - %div.body - = render partial: 'users/description/champs/render_list_champs', locals: {champs: champs, order_place: order_place} \ No newline at end of file + .body + = render partial: 'users/description/champs/render_list_champs', locals: {champs: champs, order_place: order_place} diff --git a/app/views/users/description/champs/_render_list_champs.html.haml b/app/views/users/description/champs/_render_list_champs.html.haml index 261ef88e1..1c131361e 100644 --- a/app/views/users/description/champs/_render_list_champs.html.haml +++ b/app/views/users/description/champs/_render_list_champs.html.haml @@ -26,7 +26,7 @@ - elsif champ.type_champ == 'yes_no' = render partial: 'users/description/champs/yes_no', locals: { champ: champ } - - elsif champ.type_champ == 'drop_down_list' + - elsif %w(drop_down_list multiple_drop_down_list).include?(champ.type_champ) = render partial: 'users/description/champs/drop_down_list', locals: { champ: champ } - elsif champ.type_champ == 'pays' @@ -41,6 +41,8 @@ - elsif champ.type_champ == 'departements' = render partial: 'users/description/champs/departements', locals: { champ: champ } + - elsif champ.type_champ == 'explication' + - else %input.form-control{name:"champs['#{ champ.id }']", placeholder: champ.libelle, diff --git a/app/views/users/registrations/new.html.haml b/app/views/users/registrations/new.html.haml index 12e3165cc..d8270c4a9 100644 --- a/app/views/users/registrations/new.html.haml +++ b/app/views/users/registrations/new.html.haml @@ -47,7 +47,7 @@ = f.email_field :email, class: 'form-control', placeholder: 'Email', value: params[:user_email] %br %h4 - = f.label :password + = f.label :password, 'Mot de passe' .input-group .input-group-addon %span.fa.fa-asterisk diff --git a/config/locales/models/type_de_champ/fr.yml b/config/locales/models/type_de_champ/fr.yml index 83d87828b..06206a682 100644 --- a/config/locales/models/type_de_champ/fr.yml +++ b/config/locales/models/type_de_champ/fr.yml @@ -21,4 +21,6 @@ fr: regions: 'Régions' departements: 'Départements' engagement: 'Engagement' - header_section: 'Titre de section' \ No newline at end of file + header_section: 'Titre de section' + explication: 'Explication' + multiple_drop_down_list: 'Menu déroulant à choix multiples' diff --git a/spec/decorators/champ_decorator_spec.rb b/spec/decorators/champ_decorator_spec.rb index 5d25679ca..c8b15056c 100644 --- a/spec/decorators/champ_decorator_spec.rb +++ b/spec/decorators/champ_decorator_spec.rb @@ -1,19 +1,18 @@ require 'spec_helper' describe ChampDecorator do - let(:champ) {create :champ, type_de_champ: (create :type_de_champ_public, type_champ: :checkbox)} + let(:champ) {create :champ, type_de_champ: (create :type_de_champ_public, type_champ: type_champ)} let(:decorator) { champ.decorate } + describe 'value' do subject { decorator.value } - context 'when type_champ is checkbox' do + describe 'for a checkbox' do + let(:type_champ) { :checkbox } context 'when value is on' do - before do - champ.update value: 'on' - end - + before { champ.update value: 'on' } it { is_expected.to eq 'Oui' } end @@ -21,5 +20,19 @@ describe ChampDecorator do it { is_expected.to eq 'Non' } end end + + describe 'for a multiple_drop_down_list' do + let(:type_champ) { :multiple_drop_down_list } + + context 'when value is an array' do + before { champ.update value: '["1", "2"]' } + it { is_expected.to eq '1, 2' } + end + + context 'when value is empty' do + before { champ.update value: '' } + it { is_expected.to eq '' } + end + end end end diff --git a/spec/decorators/type_de_champ_decorator_spec.rb b/spec/decorators/type_de_champ_decorator_spec.rb index 7ab455e00..dd5d75307 100644 --- a/spec/decorators/type_de_champ_decorator_spec.rb +++ b/spec/decorators/type_de_champ_decorator_spec.rb @@ -16,8 +16,8 @@ describe TypeDeChampDecorator do subject { type_de_champ_0.decorate } let(:button_up) { type_de_champ_.decorate } - it 'returns a button up' do - expect(subject.button_up(params)).to be(nil) + it 'hide a button up' do + expect(subject.button_up(params)).to include('visibility: hidden') end it 'returns a button down' do expect(subject.button_down(params)).to match(/fa-chevron-down/) @@ -45,11 +45,12 @@ describe TypeDeChampDecorator do it 'returns a button up' do expect(subject.button_up(params)).to match(/fa-chevron-up/) end - it 'returns a button down' do - expect(subject.button_down(params)).to be(nil) + + it 'hide a button down' do + expect(subject.button_down(params)).to include('visibility: hidden') end end end -end \ No newline at end of file +end diff --git a/spec/models/drop_down_list_spec.rb b/spec/models/drop_down_list_spec.rb index 523ab2ae1..be53e9dea 100644 --- a/spec/models/drop_down_list_spec.rb +++ b/spec/models/drop_down_list_spec.rb @@ -9,15 +9,16 @@ describe DropDownList do it { is_expected.to belong_to(:type_de_champ) } end + let(:dropdownlist) { create :drop_down_list, value: value } + describe '#options' do let(:value) { "Cohésion sociale Dév.Eco / Emploi Cadre de vie / Urb. Pilotage / Ingénierie " } - let(:dropdownlist) { create :drop_down_list, value: value } - it { expect(dropdownlist.options).to eq ["Cohésion sociale", "Dév.Eco / Emploi", "Cadre de vie / Urb.", "Pilotage / Ingénierie"] } + it { expect(dropdownlist.options).to eq ['', 'Cohésion sociale', 'Dév.Eco / Emploi', 'Cadre de vie / Urb.', 'Pilotage / Ingénierie'] } context 'when one value is empty' do let(:value) { "Cohésion sociale @@ -26,7 +27,36 @@ Cadre de vie / Urb. Pilotage / Ingénierie " } - it { expect(dropdownlist.options).to eq ["Cohésion sociale", "Cadre de vie / Urb.", "Pilotage / Ingénierie"] } + it { expect(dropdownlist.options).to eq ['', 'Cohésion sociale', 'Cadre de vie / Urb.', 'Pilotage / Ingénierie'] } + end + end + + describe 'disabled_options' do + let(:value) { "tip +--top-- +--troupt-- +ouaich" } + + it { expect(dropdownlist.disabled_options).to match(['--top--', '--troupt--']) } + end + + describe 'selected_options' do + let(:dropdownlist) do + create(:drop_down_list, type_de_champ: type_de_champ) + end + + context 'when multiple' do + let(:type_de_champ) { TypeDeChamp.new(type_champ: 'multiple_drop_down_list') } + + let(:champ) { Champ.new(value: '["1","2"]').decorate } + it { expect(dropdownlist.selected_options(champ)).to match(['1', '2']) } + end + + context 'when simple' do + let(:type_de_champ) { TypeDeChamp.new(type_champ: 'drop_down_list') } + + let(:champ) { Champ.new(value: '1').decorate } + it { expect(dropdownlist.selected_options(champ)).to match(['1']) } end end end diff --git a/spec/services/type_de_champ_service_spec.rb b/spec/services/type_de_champ_service_spec.rb new file mode 100644 index 000000000..e1e61ef91 --- /dev/null +++ b/spec/services/type_de_champ_service_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe TypesDeChampService do + let(:params) do + ActionController::Parameters.new({ + procedure: { + types_de_champ_attributes: { + "0" => { + libelle: 'top', + drop_down_list_attributes: { + value: "un\r\n deux\r\n -- commentaire --\r\n trois", + id: '5218' + } + } + } + } + }) + end + + let(:result) { TypesDeChampService.create_update_procedure_params(params) } + + describe 'self.create_update_procedure_params' do + describe 'the drop down list attributes' do + subject { result['types_de_champ_attributes']['0']['drop_down_list_attributes'] } + it 'has its value stripped' do + expect(subject['value']).to eq("un\r\ndeux\r\n-- commentaire --\r\ntrois") + end + end + end +end diff --git a/spec/views/admin/previsualisations/show.html.haml_spec.rb b/spec/views/admin/previsualisations/show.html.haml_spec.rb index f0983b660..cfed1dd02 100644 --- a/spec/views/admin/previsualisations/show.html.haml_spec.rb +++ b/spec/views/admin/previsualisations/show.html.haml_spec.rb @@ -129,22 +129,5 @@ describe 'admin/previsualisations/show.html.haml', type: :view do it { expect(rendered).not_to have_content 'Documents administratifs' } end - context 'when dossier have pj' do - let(:dossier) { create(:dossier) } - - it { expect(rendered).to have_content 'Documents administratifs' } - end - - context 'when procedure have demarche link' do - let(:procedure) { create :procedure } - - it { expect(rendered).to have_content 'Documents administratifs' } - end - - context 'when procedure have cerfa flag true' do - let(:procedure) {create(:procedure, cerfa_flag: true)} - - it { expect(rendered).to have_content 'Documents administratifs' } - end end end diff --git a/spec/views/admin/types_de_champ/show.html.haml_spec.rb b/spec/views/admin/types_de_champ/show.html.haml_spec.rb index bed11f3d4..acac3297a 100644 --- a/spec/views/admin/types_de_champ/show.html.haml_spec.rb +++ b/spec/views/admin/types_de_champ/show.html.haml_spec.rb @@ -33,8 +33,8 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do end context 'when there is only one field in database' do let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) } - it { expect(subject).not_to have_css('#btn_down_0') } - it { expect(subject).not_to have_css('#btn_up_0') } + it { expect(subject).to have_css('#btn_down_0[style*="visibility: hidden"]') } + it { expect(subject).to have_css('#btn_up_0[style*="visibility: hidden"]') } it { expect(subject).not_to have_css('#btn_up_1') } it { expect(subject).not_to have_css('#btn_down_1') } end @@ -42,9 +42,9 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) } let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) } it { expect(subject).to have_css('#btn_down_0') } - it { expect(subject).not_to have_css('#btn_up_0') } + it { expect(subject).to have_css('#btn_up_0[style*="visibility: hidden"]') } it { expect(subject).to have_css('#btn_up_1') } - it { expect(subject).not_to have_css('#btn_down_1') } + it { expect(subject).to have_css('#btn_down_1[style*="visibility: hidden"]') } end end -end \ No newline at end of file +end diff --git a/spec/views/admin/types_de_champ_private/show.html.haml_spec.rb b/spec/views/admin/types_de_champ_private/show.html.haml_spec.rb index 829050748..510224e9c 100644 --- a/spec/views/admin/types_de_champ_private/show.html.haml_spec.rb +++ b/spec/views/admin/types_de_champ_private/show.html.haml_spec.rb @@ -30,7 +30,7 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do describe 'mandatory checkbox' do it 'no mandatory checkbox are present' do - expect(subject).not_to have_css('.form-group.mandatory') + expect(subject).to have_css('.form-group.mandatory[style*="visibility: hidden"]') end end @@ -41,8 +41,8 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do end context 'when there is only one field in database' do let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) } - it { expect(subject).not_to have_css('#btn_down_0') } - it { expect(subject).not_to have_css('#btn_up_0') } + it { expect(subject).to have_css('#btn_down_0[style*="visibility: hidden"]') } + it { expect(subject).to have_css('#btn_up_0[style*="visibility: hidden"]') } it { expect(subject).not_to have_css('#btn_up_1') } it { expect(subject).not_to have_css('#btn_down_1') } end @@ -50,10 +50,10 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) } let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1) } it { expect(subject).to have_css('#btn_down_0') } - it { expect(subject).not_to have_css('#btn_up_0') } + it { expect(subject).to have_css('#btn_up_0[style*="visibility: hidden"]') } it { expect(subject).to have_css('#btn_up_1') } - it { expect(subject).not_to have_css('#btn_down_1') } + it { expect(subject).to have_css('#btn_down_1[style*="visibility: hidden"]') } end end end -end \ No newline at end of file +end diff --git a/spec/views/users/description/show.html.haml_spec.rb b/spec/views/users/description/show.html.haml_spec.rb index 8d4434af2..c278c09f1 100644 --- a/spec/views/users/description/show.html.haml_spec.rb +++ b/spec/views/users/description/show.html.haml_spec.rb @@ -125,22 +125,5 @@ describe 'users/description/show.html.haml', type: :view do it { expect(rendered).not_to have_content 'Documents administratifs' } end - context 'when dossier have pj' do - let(:dossier) { create(:dossier) } - - it { expect(rendered).to have_content 'Documents administratifs' } - end - - context 'when procedure have demarche link' do - let(:procedure) { create :procedure } - - it { expect(rendered).to have_content 'Documents administratifs' } - end - - context 'when procedure have cerfa flag true' do - let(:procedure) { create(:procedure, cerfa_flag: true) } - - it { expect(rendered).to have_content 'Documents administratifs' } - end end end