helpers: allow dossier_display_state to take a state as input

This allow to use either:

- `dossier_display_state(dossier)`
- `dossier_display_state(:en_construction)`
This commit is contained in:
Pierre de La Morinerie 2019-12-19 13:22:40 +01:00
parent 0b54af822f
commit c7a307553c
2 changed files with 11 additions and 27 deletions

View file

@ -47,9 +47,10 @@ module DossierHelper
dossier.brouillon? && dossier.procedure.close?
end
def dossier_display_state(dossier, lower: false)
state = I18n.t(dossier.state, scope: [:activerecord, :attributes, :dossier, :state])
lower ? state.downcase : state
def dossier_display_state(dossier_or_state, lower: false)
state = dossier_or_state.is_a?(Dossier) ? dossier_or_state.state : dossier_or_state
display_state = I18n.t(state, scope: [:activerecord, :attributes, :dossier, :state])
lower ? display_state.downcase : display_state
end
def dossier_legacy_state(dossier)