Add path field to procedure information form
This commit is contained in:
parent
f6a6d8f457
commit
f94a24d7ce
12 changed files with 176 additions and 32 deletions
|
@ -39,6 +39,9 @@ class Admin::ProceduresController < AdminController
|
|||
end
|
||||
|
||||
def edit
|
||||
@path = @procedure.path || @procedure.default_path
|
||||
@available = @procedure.path_available?(@path)
|
||||
@mine = @procedure.path_is_mine?(@path)
|
||||
end
|
||||
|
||||
def hide
|
||||
|
@ -63,29 +66,52 @@ class Admin::ProceduresController < AdminController
|
|||
def new
|
||||
@procedure ||= Procedure.new
|
||||
@procedure.module_api_carto ||= ModuleAPICarto.new
|
||||
@available = true
|
||||
@mine = true
|
||||
end
|
||||
|
||||
def create
|
||||
@procedure = Procedure.new(procedure_params)
|
||||
@procedure.module_api_carto = ModuleAPICarto.new(create_module_api_carto_params) if @procedure.valid?
|
||||
@path = params.require(:procedure).permit(:path)[:path]
|
||||
@available = !ProcedurePath.exists?(path: @path)
|
||||
@mine = ProcedurePath.mine?(current_administrateur, @path)
|
||||
|
||||
if !@procedure.save
|
||||
if !@procedure.validate
|
||||
flash.now.alert = @procedure.errors.full_messages
|
||||
return render 'new'
|
||||
elsif Flipflop.publish_draft? && !ProcedurePath.valid?(Procedure.last, @path)
|
||||
# FIXME: The code abow is a horrible hack that we need until we migrated path directly on procedure model
|
||||
flash.now.alert = 'Lien de la démarche invalide.'
|
||||
return render 'new'
|
||||
else
|
||||
@procedure.save!
|
||||
if Flipflop.publish_draft?
|
||||
@procedure.publish_with_path!(@path)
|
||||
end
|
||||
flash.notice = 'Démarche enregistrée.'
|
||||
end
|
||||
|
||||
flash.notice = 'Démarche enregistrée'
|
||||
redirect_to admin_procedure_types_de_champ_path(procedure_id: @procedure.id)
|
||||
end
|
||||
|
||||
def update
|
||||
@procedure = current_administrateur.procedures.find(params[:id])
|
||||
path = params.require(:procedure).permit(:path)[:path]
|
||||
|
||||
if !@procedure.update(procedure_params)
|
||||
flash.alert = @procedure.errors.full_messages
|
||||
elsif Flipflop.publish_draft? && @procedure.brouillon?
|
||||
if ProcedurePath.valid?(@procedure, path)
|
||||
@procedure.publish_with_path!(path)
|
||||
reset_procedure
|
||||
flash.notice = 'Démarche modifiée. Tous les brouillons de cette démarche ont été supprimés.'
|
||||
else
|
||||
flash.alert = 'Lien de la démarche invalide.'
|
||||
end
|
||||
else
|
||||
reset_procedure
|
||||
flash.notice = 'Démarche modifiée'
|
||||
flash.notice = 'Démarche modifiée. Tous les brouillons de cette démarche ont été supprimés.'
|
||||
end
|
||||
|
||||
redirect_to edit_admin_procedure_path(id: @procedure.id)
|
||||
|
|
|
@ -9,7 +9,7 @@ class Procedure < ApplicationRecord
|
|||
|
||||
has_one :module_api_carto, dependent: :destroy
|
||||
has_one :attestation_template, dependent: :destroy
|
||||
has_one :procedure_path
|
||||
has_one :procedure_path, dependent: :destroy
|
||||
|
||||
belongs_to :administrateur
|
||||
belongs_to :parent_procedure, class_name: 'Procedure'
|
||||
|
@ -158,7 +158,7 @@ class Procedure < ApplicationRecord
|
|||
end
|
||||
|
||||
def default_path
|
||||
libelle.parameterize.first(50)
|
||||
libelle&.parameterize&.first(50)
|
||||
end
|
||||
|
||||
def organisation_name
|
||||
|
|
|
@ -11,6 +11,14 @@
|
|||
= f.text_area :description, rows: '6', placeholder: 'Description du projet', class: 'form-control'
|
||||
|
||||
- if !@procedure.locked?
|
||||
- if Flipflop.publish_draft?
|
||||
.form-group
|
||||
%h4 Lien*
|
||||
= f.text_field :path, value: @path, class: 'form-control', data: { remote: true, debounce: true, url: admin_procedures_available_path, params: { id: @procedure.id }.to_query(:procedure) }
|
||||
.unavailable-path-message
|
||||
- if !@available
|
||||
= render partial: 'unavailable', locals: { mine: @mine }
|
||||
|
||||
.form-group
|
||||
%h4 Conservation des données
|
||||
= f.label :duree_conservation_dossiers_dans_ds, "Sur demarches-simplifiees.fr* (durée en mois après le début de l’instruction)"
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
%h4 Lien de la démarche
|
||||
%p.center
|
||||
= commencer_url(procedure_path: '')
|
||||
= text_field_tag('procedure_path', @procedure.default_path,
|
||||
= text_field_tag('procedure_path', @procedure.path || @procedure.default_path,
|
||||
id: 'procedure_path',
|
||||
placeholder: 'Chemin vers la démarche',
|
||||
data: { autocomplete: 'path' },
|
||||
|
|
|
@ -3,4 +3,7 @@
|
|||
= form_for @procedure, url: url_for({ controller: 'admin/procedures', action: :update, id: @procedure.id }), multipart: true do |f|
|
||||
= render partial: 'informations', locals: { f: f }
|
||||
.text-right
|
||||
= f.button 'Enregistrer', class: 'btn btn-success'
|
||||
- if !Flipflop.publish_draft? || (@available || @mine)
|
||||
= f.button 'Enregistrer', class: 'btn btn-success'
|
||||
- else
|
||||
= f.button 'Enregistrer', class: 'btn btn-success', disabled: true
|
||||
|
|
|
@ -5,4 +5,8 @@
|
|||
#procedure_new.section.section-label
|
||||
= form_for @procedure, url: { controller: 'admin/procedures', action: :create }, multipart: true do |f|
|
||||
= render partial: 'informations', locals: { f: f }
|
||||
= f.submit 'Valider', class: 'btn btn-info', id: 'save-procedure', style: 'float: right;'
|
||||
.text-right
|
||||
- if !Flipflop.publish_draft? || (@available || @mine)
|
||||
= f.button 'Valider', class: 'btn btn-info', id: 'save-procedure'
|
||||
- else
|
||||
= f.button 'Valider', class: 'btn btn-info', id: 'save-procedure', disabled: true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue