From ec0092fb3c39334a56ed96f50e79304aab3b01e7 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Mon, 13 Mar 2017 15:01:41 +0100 Subject: [PATCH 1/6] Cleaning --- .../description/champs/_header_section.html.haml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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} From 176092c256c3f4bf9373ff90c93ba227a97de9ce Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Mon, 13 Mar 2017 15:02:05 +0100 Subject: [PATCH 2/6] Explication: add field and template --- app/models/type_de_champ.rb | 3 ++- .../users/description/champs/_render_list_champs.html.haml | 2 ++ config/locales/models/type_de_champ/fr.yml | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 9d1b2e693..19f263860 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -16,7 +16,8 @@ class TypeDeChamp < ActiveRecord::Base regions: 'regions', departements: 'departements', engagement: 'engagement', - header_section: 'header_section' + header_section: 'header_section', + explication: 'explication' } belongs_to :procedure 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..d219efa78 100644 --- a/app/views/users/description/champs/_render_list_champs.html.haml +++ b/app/views/users/description/champs/_render_list_champs.html.haml @@ -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/config/locales/models/type_de_champ/fr.yml b/config/locales/models/type_de_champ/fr.yml index 83d87828b..0e42fa98f 100644 --- a/config/locales/models/type_de_champ/fr.yml +++ b/config/locales/models/type_de_champ/fr.yml @@ -21,4 +21,5 @@ 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' From fcca0bb247347e88ca9c986e66fae93637956f63 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Tue, 14 Mar 2017 13:54:31 +0100 Subject: [PATCH 3/6] Cleaning --- app/views/dossiers/_infos_dossier.html.haml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index afe71a442..085d0b991 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,19 +7,19 @@ %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 From d250cafccc7ed53c9243ced2a911d6fa60e74158 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Tue, 14 Mar 2017 13:58:21 +0100 Subject: [PATCH 4/6] Explication: add champ in edit formulaire --- app/assets/javascripts/admin.js | 8 +++++--- app/models/type_de_champ.rb | 6 +++--- .../admin/types_de_champ/_fields.html.haml | 20 ++++++++++--------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/admin.js b/app/assets/javascripts/admin.js index 6c2e63536..4b381dbe7 100644 --- a/app/assets/javascripts/admin.js +++ b/app/assets/javascripts/admin.js @@ -23,13 +23,13 @@ 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': @@ -38,7 +38,9 @@ function on_change_type_de_champ_select (){ case 'drop_down_list': parent.children(".drop_down_list").addClass('show_inline'); break; - + case 'explication': + $('.mandatory', parent).hide(); + break; } - }) + }); } diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 19f263860..64277d606 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -30,7 +30,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] } @@ -40,8 +40,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/views/admin/types_de_champ/_fields.html.haml b/app/views/admin/types_de_champ/_fields.html.haml index 649be960e..37da7585b 100644 --- a/app/views/admin/types_de_champ/_fields.html.haml +++ b/app/views/admin/types_de_champ/_fields.html.haml @@ -1,27 +1,29 @@ = 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' : ''}"} + .form-inline{ class: (ff.object.object.type_champ == 'header_section' ? 'header_section' : '') } .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: (ff.object.object.type_champ == 'drop_down_list' ? 'show_inline' : ''), 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.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 || ff.object.object.type_champ == 'explication') + .form-group.mandatory{ style: hide_mandatory ? 'visibility: hidden;' : '' } + %h4 Obligatoire ? + .center + = ff.check_box :mandatory, placeholder: 'Obligatoire ?' .form-group = ff.hidden_field :order_place, value: ff.index From fb2aef1810135f56f774d69df714ff0bf6189ef9 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Tue, 14 Mar 2017 13:58:59 +0100 Subject: [PATCH 5/6] Explication: style in edit page --- .../stylesheets/admin_type_de_champ.scss | 18 +++++++++++++++++- app/decorators/type_de_champ_decorator.rb | 12 ++++++++++-- .../decorators/type_de_champ_decorator_spec.rb | 11 ++++++----- .../types_de_champ/show.html.haml_spec.rb | 10 +++++----- .../show.html.haml_spec.rb | 12 ++++++------ 5 files changed, 44 insertions(+), 19 deletions(-) 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/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/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/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 From 7596c2424e639f906fad6ef9d3e839fe318a8ec3 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Tue, 14 Mar 2017 13:59:37 +0100 Subject: [PATCH 6/6] Explication: do not show explication in _infos_dossier --- app/views/dossiers/_infos_dossier.html.haml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index 085d0b991..4c381e2ee 100644 --- a/app/views/dossiers/_infos_dossier.html.haml +++ b/app/views/dossiers/_infos_dossier.html.haml @@ -25,6 +25,7 @@ - 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