Add 'refuser' and 'classer sans suite' buttons

This commit is contained in:
Guillaume Lazzara 2016-08-25 17:46:26 +02:00
parent 0120ce2a32
commit 09236f32aa
7 changed files with 104 additions and 11 deletions

View file

@ -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 }});
}

View file

@ -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]

View file

@ -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

View file

@ -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

View file

@ -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'

View file

@ -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!

View file

@ -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