diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 8c2de3421..e9049908b 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -42,6 +42,7 @@ function application_init(){ } function tooltip_init() { + $('.action_button[data-toggle="tooltip"]').tooltip({delay: { "show": 100, "hide": 100 }}); $('[data-toggle="tooltip"]').tooltip({delay: { "show": 800, "hide": 100 }}); } diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index 2c19239f0..826794e2d 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -57,6 +57,24 @@ class Backoffice::DossiersController < ApplicationController render 'show' end + def refuse + create_dossier_facade params[:dossier_id] + + @facade.dossier.next_step! 'gestionnaire', 'refuse' + flash.notice = 'Dossier considéré comme refusé.' + + render 'show' + end + + def without_continuation + create_dossier_facade params[:dossier_id] + + @facade.dossier.next_step! 'gestionnaire', 'without_continuation' + flash.notice = 'Dossier considéré comme sans suite.' + + render 'show' + end + def close create_dossier_facade params[:dossier_id] diff --git a/app/models/dossier.rb b/app/models/dossier.rb index c8f9c454a..ccae17f45 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -87,7 +87,7 @@ class Dossier < ActiveRecord::Base end def next_step! role, action - unless %w(initiate update comment valid submit receive close).include?(action) + unless %w(initiate update comment valid submit receive refuse without_continuation close).include?(action) fail 'action is not valid' end @@ -138,6 +138,14 @@ class Dossier < ActiveRecord::Base if received? closed! end + when 'refuse' + if received? + refused! + end + when 'without_continuation' + if received? + without_continuation! + end end end state diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index 0d51edced..3947d592e 100644 --- a/app/views/dossiers/_infos_dossier.html.haml +++ b/app/views/dossiers/_infos_dossier.html.haml @@ -71,7 +71,13 @@ = 'Notifier de la bonne réception' -elsif @facade.dossier.received? - = form_tag(url_for({controller: 'backoffice/dossiers', action: :close, dossier_id: @facade.dossier.id}), class: 'form-inline', method: 'POST') do + = form_tag(url_for({controller: 'backoffice/dossiers', action: :close, dossier_id: @facade.dossier.id}), class: 'form-inline action_button', method: 'POST', style: 'display:inline', 'data-toggle' => :tooltip, title: 'Accepter') do %button#action_button.btn.btn-success - = 'Accepter le dossier' + %i.fa.fa-check + = form_tag(url_for({controller: 'backoffice/dossiers', action: :refuse, dossier_id: @facade.dossier.id}), class: 'form-inline action_button', method: 'POST', style: 'display:inline', 'data-toggle' => :tooltip, title: 'Refuser') do + %button#action_button.btn.btn-danger + %i.fa.fa-times + = form_tag(url_for({controller: 'backoffice/dossiers', action: :without_continuation, dossier_id: @facade.dossier.id}), class: 'form-inline action_button', method: 'POST', style: 'display:inline', 'data-toggle' => :tooltip, title: 'Classer sans suite') do + %button#action_button.btn.btn-warning + %i.fa.fa-circle-o diff --git a/config/routes.rb b/config/routes.rb index 228950579..d1f05b3c1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -157,6 +157,8 @@ Rails.application.routes.draw do resources :dossiers do post 'valid' => 'dossiers#valid' post 'receive' => 'dossiers#receive' + post 'refuse' => 'dossiers#refuse' + post 'without_continuation' => 'dossiers#without_continuation' post 'close' => 'dossiers#close' post 'invites' => '/invites#create' diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 7ac092ab4..19c46a4f1 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -382,6 +382,59 @@ describe Dossier do end end + context 'when dossier is at state refused' do + before do + dossier.refused! + end + + context 'when user is connected' do + let(:role) { 'user' } + + context 'when he posts a comment' do + let(:action) { 'comment' } + + it { is_expected.to eq('refused') } + end + end + + context 'when gestionnaire is connect' do + let(:role) { 'gestionnaire' } + + context 'when he posts a comment' do + let(:action) { 'comment' } + + it { is_expected.to eq('refused') } + end + end + end + + context 'when dossier is at state without_continuation' do + before do + dossier.without_continuation! + end + + context 'when user is connected' do + let(:role) { 'user' } + + context 'when he posts a comment' do + let(:action) { 'comment' } + + it { is_expected.to eq('without_continuation') } + end + end + + context 'when gestionnaire is connect' do + let(:role) { 'gestionnaire' } + + context 'when he posts a comment' do + let(:action) { 'comment' } + + it { is_expected.to eq('without_continuation') } + end + end + end + + context 'when dossier is at state closed' do before do dossier.closed! diff --git a/spec/views/backoffice/dossiers/show.html.html_spec.rb b/spec/views/backoffice/dossiers/show.html.html_spec.rb index e02a9cea3..657baeb83 100644 --- a/spec/views/backoffice/dossiers/show.html.html_spec.rb +++ b/spec/views/backoffice/dossiers/show.html.html_spec.rb @@ -138,8 +138,10 @@ describe 'backoffice/dossiers/show.html.haml', type: :view do it { expect(rendered).to have_content('Reçu') } - it 'button accepter le dossier is present' do - expect(rendered).to have_content('Accepter le dossier') + it 'button accepter / refuser / classer sans suite are present' do + expect(rendered).to have_css('.action_button[data-toggle="tooltip"][title="Accepter"]') + expect(rendered).to have_css('.action_button[data-toggle="tooltip"][title="Classer sans suite"]') + expect(rendered).to have_css('.action_button[data-toggle="tooltip"][title="Refuser"]') end end @@ -153,8 +155,9 @@ describe 'backoffice/dossiers/show.html.haml', type: :view do it { expect(rendered).to have_content('Accepté') } it 'button Accepter le dossier is not present' do - expect(rendered).not_to have_css('#action_button') - expect(rendered).not_to have_content('Accepter le dossier') + expect(rendered).not_to have_css('.action_button[data-toggle="tooltip"][title="Accepter"]') + expect(rendered).not_to have_css('.action_button[data-toggle="tooltip"][title="Classer sans suite"]') + expect(rendered).not_to have_css('.action_button[data-toggle="tooltip"][title="Refuser"]') end end @@ -168,8 +171,9 @@ describe 'backoffice/dossiers/show.html.haml', type: :view do it { expect(rendered).to have_content('Sans suite') } it 'button Valider le dossier is not present' do - expect(rendered).not_to have_css('#action_button') - expect(rendered).not_to have_content('Valider le dossier') + expect(rendered).not_to have_css('.action_button[data-toggle="tooltip"][title="Accepter"]') + expect(rendered).not_to have_css('.action_button[data-toggle="tooltip"][title="Classer sans suite"]') + expect(rendered).not_to have_css('.action_button[data-toggle="tooltip"][title="Refuser"]') end end @@ -183,8 +187,9 @@ describe 'backoffice/dossiers/show.html.haml', type: :view do it { expect(rendered).to have_content('Refusé') } it 'button Valider le dossier is not present' do - expect(rendered).not_to have_css('#action_button') - expect(rendered).not_to have_content('Valider le dossier') + expect(rendered).not_to have_css('.action_button[data-toggle="tooltip"][title="Accepter"]') + expect(rendered).not_to have_css('.action_button[data-toggle="tooltip"][title="Classer sans suite"]') + expect(rendered).not_to have_css('.action_button[data-toggle="tooltip"][title="Refuser"]') end end end