Merge branch 'develop' into staging
This commit is contained in:
commit
d14ee4abdf
17 changed files with 132 additions and 41 deletions
|
@ -26,13 +26,19 @@ function on_change_type_de_champ_select (){
|
||||||
|
|
||||||
$("select.form-control.type_champ").on('change', function(e){
|
$("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')
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
|
@ -44,5 +44,3 @@ function scroll_to() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,5 +14,14 @@
|
||||||
.form-group.mandatory {
|
.form-group.mandatory {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#liste_champ{
|
||||||
|
.show_inline {
|
||||||
|
display: inline-block !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group.drop_down_list{
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -57,6 +57,12 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.type_champ-drop_down_list {
|
||||||
|
@extend .col-md-4;
|
||||||
|
@extend .col-lg-4;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
.type_champ-civilite {
|
.type_champ-civilite {
|
||||||
@extend .col-md-3;
|
@extend .col-md-3;
|
||||||
@extend .col-lg-3;
|
@extend .col-lg-3;
|
||||||
|
|
|
@ -15,18 +15,12 @@ class Admin::TypesDeChampController < AdminController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@procedure.update_attributes(update_params)
|
@procedure.update_attributes(TypesDeChampService.create_update_procedure_params params)
|
||||||
create_facade
|
create_facade
|
||||||
flash.now.notice = 'Modifications sauvegardées'
|
flash.now.notice = 'Modifications sauvegardées'
|
||||||
render 'show', format: :js
|
render 'show', format: :js
|
||||||
end
|
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
|
def move_up
|
||||||
index = params[:index].to_i - 1
|
index = params[:index].to_i - 1
|
||||||
if @procedure.switch_types_de_champ index
|
if @procedure.switch_types_de_champ index
|
||||||
|
|
|
@ -16,18 +16,12 @@ class Admin::TypesDeChampPrivateController < AdminController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@procedure.update_attributes(update_params)
|
@procedure.update_attributes(TypesDeChampService.create_update_procedure_params params, true)
|
||||||
create_facade
|
create_facade
|
||||||
flash.now.notice = 'Modifications sauvegardées'
|
flash.now.notice = 'Modifications sauvegardées'
|
||||||
render 'admin/types_de_champ/show', format: :js
|
render 'admin/types_de_champ/show', format: :js
|
||||||
end
|
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
|
def move_up
|
||||||
index = params[:index].to_i - 1
|
index = params[:index].to_i - 1
|
||||||
if @procedure.switch_types_de_champ_private index
|
if @procedure.switch_types_de_champ_private index
|
||||||
|
|
|
@ -2,7 +2,7 @@ class Champ < ActiveRecord::Base
|
||||||
belongs_to :dossier
|
belongs_to :dossier
|
||||||
belongs_to :type_de_champ
|
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?
|
def mandatory?
|
||||||
mandatory
|
mandatory
|
||||||
|
|
7
app/models/drop_down_list.rb
Normal file
7
app/models/drop_down_list.rb
Normal 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
|
|
@ -11,12 +11,17 @@ class TypeDeChamp < ActiveRecord::Base
|
||||||
phone: 'phone',
|
phone: 'phone',
|
||||||
address: 'address',
|
address: 'address',
|
||||||
yes_no: 'yes_no',
|
yes_no: 'yes_no',
|
||||||
|
drop_down_list: 'drop_down_list',
|
||||||
header_section: 'header_section'
|
header_section: 'header_section'
|
||||||
}
|
}
|
||||||
|
|
||||||
belongs_to :procedure
|
belongs_to :procedure
|
||||||
|
|
||||||
has_many :champ, dependent: :destroy
|
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 :libelle, presence: true, allow_blank: false, allow_nil: false
|
||||||
validates :type_champ, presence: true, allow_blank: false, allow_nil: false
|
validates :type_champ, presence: true, allow_blank: false, allow_nil: false
|
||||||
|
|
18
app/services/types_de_champ_service.rb
Normal file
18
app/services/types_de_champ_service.rb
Normal 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
|
|
@ -10,8 +10,13 @@
|
||||||
|
|
||||||
.form-group.description
|
.form-group.description
|
||||||
%h4 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
|
- unless ff.object.object.class == TypeDeChampPrivate
|
||||||
.form-group.mandatory
|
.form-group.mandatory
|
||||||
%h4 Obligatoire ?
|
%h4 Obligatoire ?
|
||||||
|
|
|
@ -30,6 +30,9 @@
|
||||||
- elsif champ.type_champ == 'yes_no'
|
- elsif champ.type_champ == 'yes_no'
|
||||||
=render partial: 'users/description/champs/yes_no', locals: {champ: champ}
|
=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
|
-else
|
||||||
%input.form-control{name:"champs['#{champ.id}']",
|
%input.form-control{name:"champs['#{champ.id}']",
|
||||||
placeholder: champ.libelle,
|
placeholder: champ.libelle,
|
||||||
|
|
13
app/views/users/description/champs/_drop_down_list.html.haml
Normal file
13
app/views/users/description/champs/_drop_down_list.html.haml
Normal 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
|
8
db/migrate/20160809083606_create_drop_down_list_table.rb
Normal file
8
db/migrate/20160809083606_create_drop_down_list_table.rb
Normal 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
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
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", ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree
|
||||||
add_index "dossiers", ["user_id"], name: "index_dossiers_on_user_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|
|
create_table "entreprises", force: :cascade do |t|
|
||||||
t.string "siren"
|
t.string "siren"
|
||||||
t.integer "capital_social"
|
t.integer "capital_social"
|
||||||
|
|
|
@ -50,6 +50,16 @@ describe Admin::TypesDeChampController, type: :controller do
|
||||||
order_place: order_place,
|
order_place: order_place,
|
||||||
id: types_de_champ_id,
|
id: types_de_champ_id,
|
||||||
mandatory: mandatory
|
mandatory: mandatory
|
||||||
|
},
|
||||||
|
'1' =>
|
||||||
|
{
|
||||||
|
libelle: '',
|
||||||
|
type_champ: 'text',
|
||||||
|
description: '',
|
||||||
|
order_place: '1',
|
||||||
|
id: '',
|
||||||
|
mandatory: false,
|
||||||
|
type: 'TypeDeChampPublic'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,16 @@ describe Admin::TypesDeChampPrivateController, type: :controller do
|
||||||
id: types_de_champ_id,
|
id: types_de_champ_id,
|
||||||
mandatory: mandatory,
|
mandatory: mandatory,
|
||||||
type: 'TypeDeChampPrivate'
|
type: 'TypeDeChampPrivate'
|
||||||
|
},
|
||||||
|
'1' =>
|
||||||
|
{
|
||||||
|
libelle: '',
|
||||||
|
type_champ: 'text',
|
||||||
|
description: '',
|
||||||
|
order_place: '1',
|
||||||
|
id: '',
|
||||||
|
mandatory: false,
|
||||||
|
type: 'TypeDeChampPrivate'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue