Merge branch 'develop' into staging

This commit is contained in:
Xavier J 2016-08-09 16:21:49 +02:00
commit d14ee4abdf
17 changed files with 132 additions and 41 deletions

View file

@ -26,13 +26,19 @@ function on_change_type_de_champ_select (){
$("select.form-control.type_champ").on('change', function(e){
parent = $(this).parent().parent()
parent = $(this).parent().parent();
parent.removeClass('header_section');
parent.children(".drop_down_list").removeClass('show_inline');
switch(this.value){
case 'header_section':
parent.addClass('header_section');
break;
case 'drop_down_list':
parent.children(".drop_down_list").addClass('show_inline');
break;
if (this.value === 'header_section') {
parent.addClass('header_section')
}
else {
parent.removeClass('header_section')
}
})
}

View file

@ -44,5 +44,3 @@ function scroll_to() {
});
}

View file

@ -14,5 +14,14 @@
.form-group.mandatory {
display: none;
}
}
#liste_champ{
.show_inline {
display: inline-block !important;
}
.form-group.drop_down_list{
display: none;
}
}

View file

@ -57,6 +57,12 @@
}
}
.type_champ-drop_down_list {
@extend .col-md-4;
@extend .col-lg-4;
}
.type_champ-civilite {
@extend .col-md-3;
@extend .col-lg-3;

View file

@ -7,7 +7,7 @@ class Admin::TypesDeChampController < AdminController
create_facade
render 'show', format: :js
rescue ActiveRecord::RecordNotFound
render json: { message: 'Champ not found' }, status: 404
render json: {message: 'Champ not found'}, status: 404
end
def show
@ -15,18 +15,12 @@ class Admin::TypesDeChampController < AdminController
end
def update
@procedure.update_attributes(update_params)
@procedure.update_attributes(TypesDeChampService.create_update_procedure_params params)
create_facade
flash.now.notice = 'Modifications sauvegardées'
render 'show', format: :js
end
def update_params
params
.require(:procedure)
.permit(types_de_champ_attributes: [:libelle, :description, :order_place, :type_champ, :id, :mandatory, :type])
end
def move_up
index = params[:index].to_i - 1
if @procedure.switch_types_de_champ index

View file

@ -7,27 +7,21 @@ class Admin::TypesDeChampPrivateController < AdminController
create_facade
render 'admin/types_de_champ/show', format: :js
rescue ActiveRecord::RecordNotFound
render json: { message: 'Champ not found' }, status: 404
render json: {message: 'Champ not found'}, status: 404
end
def show
create_facade
create_facade
render 'admin/types_de_champ/show'
end
def update
@procedure.update_attributes(update_params)
@procedure.update_attributes(TypesDeChampService.create_update_procedure_params params, true)
create_facade
flash.now.notice = 'Modifications sauvegardées'
render 'admin/types_de_champ/show', format: :js
end
def update_params
params
.require(:procedure)
.permit(types_de_champ_private_attributes: [:libelle, :description, :order_place, :type_champ, :id, :mandatory, :type])
end
def move_up
index = params[:index].to_i - 1
if @procedure.switch_types_de_champ_private index

View file

@ -2,7 +2,7 @@ class Champ < ActiveRecord::Base
belongs_to :dossier
belongs_to :type_de_champ
delegate :libelle, :type_champ, :order_place, :mandatory, :description, to: :type_de_champ
delegate :libelle, :type_champ, :order_place, :mandatory, :description, :drop_down_list, to: :type_de_champ
def mandatory?
mandatory

View file

@ -0,0 +1,7 @@
class DropDownList < ActiveRecord::Base
belongs_to :type_de_champ
def options
value.split(/[\r\n]|[\r]|[\n]|[\n\r]/).reject(&:empty?)
end
end

View file

@ -11,12 +11,17 @@ class TypeDeChamp < ActiveRecord::Base
phone: 'phone',
address: 'address',
yes_no: 'yes_no',
drop_down_list: 'drop_down_list',
header_section: 'header_section'
}
belongs_to :procedure
has_many :champ, dependent: :destroy
has_one :drop_down_list
accepts_nested_attributes_for :drop_down_list
validates :libelle, presence: true, allow_blank: false, allow_nil: false
validates :type_champ, presence: true, allow_blank: false, allow_nil: false

View file

@ -0,0 +1,18 @@
class TypesDeChampService
def self.create_update_procedure_params(params, private=false)
attributes = (private ? 'types_de_champ_private_attributes' : 'types_de_champ_attributes')
parameters = params
.require(:procedure)
.permit("#{attributes}" => [:libelle, :description, :order_place, :type_champ, :id, :mandatory, :type,
drop_down_list_attributes: [:value, :id]])
parameters[attributes].each do |param|
if param.second[:libelle].empty?
parameters[attributes].delete(param.first.to_s)
end
end
parameters
end
end

View file

@ -10,8 +10,13 @@
.form-group.description
%h4 Description
= ff.text_area :description, class: 'form-control description', placeholder: 'Description'
= ff.text_area :description, class: 'form-control description', placeholder: 'Description', rows: 2
.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 ?

View file

@ -30,6 +30,9 @@
- elsif champ.type_champ == 'yes_no'
=render partial: 'users/description/champs/yes_no', locals: {champ: champ}
- elsif champ.type_champ == 'drop_down_list'
=render partial: 'users/description/champs/drop_down_list', locals: {champ: champ}
-else
%input.form-control{name:"champs['#{champ.id}']",
placeholder: champ.libelle,

View file

@ -0,0 +1,13 @@
%select{ name:"champs['#{champ.id}']",
id: "champs_#{champ.id}" }
- champ.drop_down_list.options.each do |option|
- if (option=~ /^--.*--$/).nil?
- if champ.value == option
%option{selected:''}
= option
- else
%option
= option
-else
%option{disabled:''}
= option

View file

@ -0,0 +1,8 @@
class CreateDropDownListTable < ActiveRecord::Migration
def change
create_table :drop_down_lists do |t|
t.string :value
t.belongs_to :type_de_champ
end
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160808115924) do
ActiveRecord::Schema.define(version: 20160809083606) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -130,6 +130,11 @@ ActiveRecord::Schema.define(version: 20160808115924) do
add_index "dossiers", ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree
add_index "dossiers", ["user_id"], name: "index_dossiers_on_user_id", using: :btree
create_table "drop_down_lists", force: :cascade do |t|
t.string "value"
t.integer "type_de_champ_id"
end
create_table "entreprises", force: :cascade do |t|
t.string "siren"
t.integer "capital_social"

View file

@ -41,24 +41,34 @@ describe Admin::TypesDeChampController, type: :controller do
let(:mandatory) { 'on' }
let(:procedure_params) do
{ types_de_champ_attributes:
{ '0' =>
{
libelle: libelle,
type_champ: type_champ,
description: description,
order_place: order_place,
id: types_de_champ_id,
mandatory: mandatory
}
}
{types_de_champ_attributes:
{'0' =>
{
libelle: libelle,
type_champ: type_champ,
description: description,
order_place: order_place,
id: types_de_champ_id,
mandatory: mandatory
},
'1' =>
{
libelle: '',
type_champ: 'text',
description: '',
order_place: '1',
id: '',
mandatory: false,
type: 'TypeDeChampPublic'
}
}
}
end
let(:request) { put :update, format: :js, procedure_id: procedure.id, procedure: procedure_params }
context 'when procedure is found' do
it { expect{ request }.to change(TypeDeChamp, :count).by(1) }
it { expect { request }.to change(TypeDeChamp, :count).by(1) }
describe 'created type de champ' do
before do

View file

@ -51,7 +51,17 @@ describe Admin::TypesDeChampPrivateController, type: :controller do
id: types_de_champ_id,
mandatory: mandatory,
type: 'TypeDeChampPrivate'
}
},
'1' =>
{
libelle: '',
type_champ: 'text',
description: '',
order_place: '1',
id: '',
mandatory: false,
type: 'TypeDeChampPrivate'
}
}
}
end