Add button in manager to transition démarche in brouillon state

fix #2565
This commit is contained in:
Paul Chavard 2018-10-09 12:11:13 +02:00
parent acacfebd92
commit bcbfc370b2
4 changed files with 24 additions and 0 deletions

View file

@ -6,5 +6,16 @@ module Manager
flash[:notice] = "Démarche whitelistée."
redirect_to manager_procedure_path(procedure)
end
def draft
procedure = Procedure.find(params[:id])
if procedure.dossiers.empty?
procedure.draft!
flash[:notice] = "La démarche a bien été passée en brouillon."
else
flash[:alert] = "Impossible de repasser en brouillon une démarche à laquelle sont rattachés des dossiers."
end
redirect_to manager_procedure_path(procedure)
end
end
end

View file

@ -86,6 +86,10 @@ class Procedure < ApplicationRecord
transitions from: :publiee, to: :hidden
transitions from: :archivee, to: :hidden
end
event :draft, after: :after_draft do
transitions from: :publiee, to: :brouillon
end
end
def publish_or_reopen!(path)
@ -372,6 +376,10 @@ class Procedure < ApplicationRecord
publish_with_path!(path)
end
def after_draft
update!(published_at: nil)
end
def update_juridique_required
self.juridique_required ||= (cadre_juridique.present? || deliberation.attached?)
true

View file

@ -36,6 +36,10 @@ as well as a link to its edit page.
<% if !procedure.whitelisted? %>
<%= link_to 'whitelister', whitelist_manager_procedure_path(procedure), method: :post, class: 'button' %>
<% end %>
<% if procedure.publiee? && procedure.dossiers.empty? %>
<%= link_to 'passer en brouillon', draft_manager_procedure_path(procedure), method: :post, class: 'button' %>
<% end %>
<div>
</header>

View file

@ -8,6 +8,7 @@ Rails.application.routes.draw do
namespace :manager do
resources :procedures, only: [:index, :show] do
post 'whitelist', on: :member
post 'draft', on: :member
end
resources :dossiers, only: [:index, :show] do