Add auto champs objects at a dossier (same as PJ)

Add dynamic of Champs on the description page
Rename model 'Champs' to 'Champ'
This commit is contained in:
Xavier J 2015-11-03 15:27:49 +01:00
parent 56eccf55df
commit 27dbd3a878
14 changed files with 103 additions and 81 deletions

View file

@ -0,0 +1,44 @@
@import "bootstrap";
@import "bootstrap-datepicker3";
#description_page #liste_champs{
h4{
padding-top: 10px;
}
}
.type_champs-text {
@extend .col-md-6;
@extend .col-lg-6;
input[type='text'] {
width: 100%;
}
}
.type_champs-textarea {
@extend .col-md-9;
@extend .col-lg-9;
textarea.form-control {
width:100%;
}
}
.type_champs-number {
@extend .col-md-3;
@extend .col-lg-3;
input[type='number']{
width: 100%;
}
}
.type_champs-datetime {
@extend .col-md-2;
@extend .col-lg-2;
input[type='number']{
width: 100%;
}
}

View file

@ -1,73 +1,3 @@
class DossiersController < ApplicationController
# def show
# @dossier = Dossier.find(params[:id])
# @etablissement = @dossier.etablissement
# @entreprise = @dossier.entreprise.decorate
# rescue ActiveRecord::RecordNotFound
# flash.alert = t('errors.messages.dossier_not_found')
# redirect_to url_for(controller: :siret)
# end
# def create
# procedure = Procedure.find(params['procedure_id'])
# @etablissement = Etablissement.new(SIADE::EtablissementAdapter.new(siret).to_params)
# @entreprise = Entreprise.new(SIADE::EntrepriseAdapter.new(siren).to_params)
# @dossier = Dossier.create
# @dossier.draft!
# @dossier.procedure = procedure
# @dossier.save
# @entreprise.dossier = @dossier
# @entreprise.save
# @etablissement.dossier = @dossier
# @etablissement.entreprise = @entreprise
# @etablissement.save
# redirect_to url_for(controller: :dossiers, action: :show, id: @dossier.id)
# rescue RestClient::ResourceNotFound
# flash.alert = t('errors.messages.invalid_siret')
# redirect_to url_for(controller: :siret, procedure_id: params['procedure_id'])
# rescue ActiveRecord::RecordNotFound
# flash.alert = t('errors.messages.dossier_not_found')
# redirect_to url_for(controller: :siret)
# end
# def update
# @dossier = Dossier.find(params[:id])
# if checked_autorisation_donnees?
# @dossier.update_attributes(update_params)
# redirect_to url_for(controller: :description, action: :show, dossier_id: @dossier.id)
# else
# @etablissement = @dossier.etablissement
# @entreprise = @dossier.entreprise.decorate
# flash.now.alert = 'Les conditions sont obligatoires.'
# render 'show'
# end
# end
# private
# def update_params
# params.require(:dossier).permit(:autorisation_donnees)
# end
# def dossier_id_is_present?
# @dossier_id != ''
# end
# def checked_autorisation_donnees?
# update_params[:autorisation_donnees] == '1'
# end
# def siret
# params[:siret]
# end
# def siren
# siret[0..8]
# end
end

View file

@ -50,7 +50,6 @@ class Users::DescriptionController < UsersController
flash.notice = 'Félicitation, votre demande a bien été enregistrée.'
redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: @dossier.id)
end
private

View file

@ -1,5 +1,6 @@
class Users::DossiersController < UsersController
before_action :authenticate_user!
def index
@dossiers = current_user.dossiers.order(updated_at: 'DESC').decorate
end

View file

@ -1,6 +1,5 @@
class Champs < ActiveRecord::Base
class Champ < ActiveRecord::Base
belongs_to :dossier
belongs_to :type_de_champs
delegate :libelle, :type_champs, :order_place, to: :type_de_champs
end

View file

@ -19,10 +19,12 @@ class Dossier < ActiveRecord::Base
delegate :siren, to: :entreprise
delegate :siret, to: :etablissement
delegate :types_de_piece_justificative, to: :procedure
delegate :types_de_champs, to: :procedure
before_create :build_default_cerfa
after_save :build_default_pieces_justificatives, if: Proc.new { procedure_id_changed? }
after_save :build_default_champs, if: Proc.new { procedure_id_changed? }
validates :nom_projet, presence: true, allow_blank: false, allow_nil: true
validates :description, presence: true, allow_blank: false, allow_nil: true
@ -33,11 +35,18 @@ class Dossier < ActiveRecord::Base
end
def build_default_pieces_justificatives
procedure.types_de_piece_justificative.each do |type_de_piece_justificative|
PieceJustificative.create(type_de_piece_justificative_id: type_de_piece_justificative.id, dossier_id: id)
end
end
def build_default_champs
procedure.types_de_champs.each do |type_de_champs|
Champ.create(type_de_champs_id: type_de_champs.id, dossier_id: id)
end
end
def sous_domaine
if Rails.env.production?
'tps'

View file

@ -6,5 +6,4 @@ class Procedure < ActiveRecord::Base
validates :libelle, presence: true, allow_blank: false, allow_nil: false
validates :description, presence: true, allow_blank: false, allow_nil: false
#validates :lien_demarche, presence: true, allow_blank: false, allow_nil: false
end

View file

@ -6,7 +6,7 @@ class TypeDeChamps < ActiveRecord::Base
}
belongs_to :procedure
has_many :champs
has_many :champ
validates :libelle, presence: true, allow_blank: false, allow_nil: false
validates :type_champs, presence: true, allow_blank: false, allow_nil: false

View file

@ -3,7 +3,6 @@
%br
= form_tag(url_for({controller: :description, action: :create, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST', multipart: true) do
%div
.row
.col-md-12
@ -15,6 +14,27 @@
%h4 Description de votre projet *
= text_area_tag :description, @dossier.description, rows: '6', placeholder: 'Description du projet', class: 'form-control'
%br
#liste_champs.row
-@dossier.champs.each do |champ|
%div{class: "type_champs-#{champ.type_champs}"}
%h4
= champ.libelle
-if champ.type_champs == 'textarea'
%textarea.form-control{name:"champs[#{champ.id}]",
placeholder: champ.libelle,
id: "champs_#{champ.id}"}
=champ.value
-else
%input.form-control{name:"champs[#{champ.id}]",
value: champ.value,
placeholder: champ.libelle,
id: "champs_#{champ.id}",
type:"#{champ.type_champs}",
'data-provide' => ('datepicker' if champ.type_champs == 'datetime'),
'data-date-format' => ('dd/mm/yyyy' if champ.type_champs == 'datetime')}
%h3 Documents administratifs
%br