User can save a draft dossier who does not see by the accompagnateur

This commit is contained in:
Xavier J 2016-10-05 16:45:51 +02:00
parent d78b64982b
commit 71de64e3ec
9 changed files with 80 additions and 15 deletions

View file

@ -25,6 +25,9 @@ class Users::DescriptionController < UsersController
@procedure = @dossier.procedure
@champs = @dossier.ordered_champs
mandatory = true
mandatory = !(params[:submit].keys.first == 'brouillon') unless params[:submit].nil?
unless @dossier.update_attributes(create_params)
@dossier = @dossier.decorate
@ -43,10 +46,10 @@ class Users::DescriptionController < UsersController
end
unless params[:champs].nil?
champs_service_errors = ChampsService.save_formulaire @dossier.champs, params
champs_service_errors = ChampsService.save_formulaire @dossier.champs, params, mandatory
unless champs_service_errors.empty?
flash.now.alert = (champs_service_errors.inject('') {|acc, error| acc+= error[:message]+'<br>' }).html_safe
flash.now.alert = (champs_service_errors.inject('') { |acc, error| acc+= error[:message]+'<br>' }).html_safe
return render 'show'
end
end
@ -56,12 +59,18 @@ class Users::DescriptionController < UsersController
return render 'show'
end
if @dossier.draft?
@dossier.initiated!
end
flash.notice = 'Félicitation, votre demande a bien été enregistrée.'
redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: @dossier.id)
if mandatory
if @dossier.draft?
@dossier.initiated!
end
flash.notice = 'Félicitation, votre demande a bien été enregistrée.'
redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: @dossier.id)
else
flash.notice = 'Votre brouillon a bien été sauvegardé.'
redirect_to url_for(controller: :dossiers, action: :index, liste: :brouillon)
end
end
def pieces_justificatives
@ -92,4 +101,5 @@ class Users::DescriptionController < UsersController
def create_params
params.permit()
end
end

View file

@ -35,6 +35,10 @@ class DossiersListFacades
@list_table_columns ||= @current_devise_profil.preference_list_dossiers.where(procedure: @procedure).order(:id)
end
def brouillon_class
(@liste == 'brouillon' ? 'active' : '')
end
def nouveaux_class
(@liste == 'nouveaux' ? 'active' : '')
end
@ -75,6 +79,10 @@ class DossiersListFacades
(@liste == 'invite' ? 'active' : '')
end
def brouillon_total
service.brouillon.count
end
def nouveaux_total
service.nouveaux.count
end
@ -116,7 +124,11 @@ class DossiersListFacades
def invite_total
service.invite.count
end
def brouillon_url
base_url 'brouillon'
end
def nouveaux_url
base_url 'nouveaux'
end

View file

@ -43,6 +43,7 @@ class Dossier < ActiveRecord::Base
validates :user, presence: true
BROUILLON = %w(draft)
NOUVEAUX = %w(initiated)
WAITING_FOR_GESTIONNAIRE = %w(updated)
WAITING_FOR_USER = %w(replied validated)
@ -164,6 +165,10 @@ class Dossier < ActiveRecord::Base
state
end
def brouillon?
BROUILLON.include?(state)
end
def nouveaux?
NOUVEAUX.include?(state)
end
@ -200,6 +205,10 @@ class Dossier < ActiveRecord::Base
TERMINE.include?(state)
end
def self.brouillon order = 'ASC'
where(state: BROUILLON, archived: false).order("updated_at #{order}")
end
def self.nouveaux order = 'ASC'
where(state: NOUVEAUX, archived: false).order("updated_at #{order}")
end

View file

@ -1,5 +1,5 @@
class ChampsService
def self.save_formulaire champs, params
def self.save_formulaire champs, params, check_mandatory=true
errors = Array.new
champs.each do |champ|
@ -13,8 +13,10 @@ class ChampsService
params[:time_minute]["'#{champ.id}'"]
end
if champ.mandatory? && (champ.value.nil? || champ.value.blank?)
errors.push({message: "Le champ #{champ.libelle} doit être rempli."})
if check_mandatory
if champ.mandatory? && (champ.value.nil? || champ.value.blank?)
errors.push({message: "Le champ #{champ.libelle} doit être rempli."})
end
end
champ.save

View file

@ -5,7 +5,8 @@ class DossiersListUserService
end
def dossiers_to_display
{'nouveaux' => nouveaux,
{'brouillon' => brouillon,
'nouveaux' => nouveaux,
'a_traiter' => waiting_for_user,
'en_attente' => waiting_for_gestionnaire,
'valides' => valides,
@ -14,6 +15,10 @@ class DossiersListUserService
'invite' => invite}[@liste]
end
def brouillon
@brouillon ||= @current_devise_profil.dossiers.brouillon
end
def nouveaux
@nouveaux ||= @current_devise_profil.dossiers.nouveaux
end

View file

@ -56,7 +56,8 @@
-if !@dossier.draft?
=render partial: '/layouts/modifications_terminees'
-else
= submit_tag 'Soumettre mon dossier', id: 'suivant', class: %w(btn btn btn-success), style: 'float:right', data: { disable_with: 'Soumettre votre dossier', submit: true}
= submit_tag 'Soumettre mon dossier', id: 'suivant', name: 'submit[nouveaux]', class: %w(btn btn btn-success), style: 'float:right', data: { disable_with: 'Soumettre votre dossier', submit: true}
= submit_tag 'Enregistrer un brouillon', id: 'brouillon', name: 'submit[brouillon]', class: %w(btn btn-xs btn-default), style: 'float:right; margin-right: 10px; margin-top: 6px', data: {disable_with: 'Enregistrer un brouillon', submit: true}
%br
%br

View file

@ -16,7 +16,10 @@
= dossier.id
%td
= link_to(dossier.procedure.libelle, users_dossiers_invite_path(id: invite.id)) unless invite.nil?
= link_to(dossier.procedure.libelle, users_dossier_recapitulatif_path(dossier)) if invite.nil?
- if invite.nil?
= link_to(dossier.procedure.libelle, users_dossier_recapitulatif_path(dossier)) unless dossier.brouillon?
= link_to(dossier.procedure.libelle, users_dossier_description_path(dossier)) if dossier.brouillon?
%td{id: "dossier_#{dossier.id}_state"}= dossier.display_state
%td= dossier.last_update

View file

@ -3,6 +3,13 @@
%br
#onglets
%ul.nav.nav-tabs
%li{ class: @dossiers_list_facade.brouillon_class }
%a{:href => "#{url_for users_dossiers_path(liste: 'brouillon')}", 'data-toggle' => :tooltip, title: 'Les dossiers jamais proposés à la relecture.'}
%h5.text-default
= "Brouillons"
.badge.progress-bar-default
= @dossiers_list_facade.brouillon_total
%li{ class: @dossiers_list_facade.nouveaux_class }
%a{:href => "#{url_for users_dossiers_path(liste: 'nouveaux')}", 'data-toggle' => :tooltip, title: 'Les nouveaux dossiers qui n\'ont pas encore été vus par votre accompagnateur.'}
%h5.text-info

View file

@ -43,9 +43,13 @@ shared_examples 'description_controller_spec' do
context 'Tous les attributs sont bons' do
describe 'Premier enregistrement des données' do
let(:submit) { {nouveaux: 'nouveaux'} }
subject { post :create, dossier_id: dossier_id, submit: submit }
before do
dossier.draft!
post :create, dossier_id: dossier_id
subject
dossier.reload
end
@ -56,6 +60,18 @@ shared_examples 'description_controller_spec' do
it 'etat du dossier est soumis' do
expect(dossier.state).to eq('initiated')
end
context 'when user whould like save just a draft' do
let(:submit) { {brouillon: 'brouillon'} }
it "redirection vers la page recapitulative" do
expect(response).to redirect_to("/users/dossiers?liste=brouillon")
end
it 'etat du dossier est soumis' do
expect(dossier.state).to eq('draft')
end
end
end
context 'En train de manipuler un dossier non brouillon' do