async publication procedure

This commit is contained in:
Xavier J 2016-06-30 12:33:43 +02:00
parent 575cbaa3e1
commit 09c9d5ea76
4 changed files with 10 additions and 11 deletions

View file

@ -100,15 +100,15 @@ class Admin::ProceduresController < AdminController
procedure_path.procedure.archive
@procedure.publish(params[:procedure_path])
else
flash.alert = 'Ce lien appartient à un autre administrateur et ne peut pas être utilisé.'
return redirect_to admin_procedures_path
@mine = false
return render '/admin/procedures/publish', formats: 'js'
end
else
@procedure.publish(params[:procedure_path])
end
flash.notice = "Procédure publiée"
redirect_to admin_procedures_path
render js: "window.location = '#{admin_procedures_path}'"
rescue ActiveRecord::RecordNotFound
flash.alert = 'Procédure inéxistante'

View file

@ -1,6 +1,6 @@
#publishModal.modal.fade{"aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"}
.modal-dialog.modal-lg{:role => "document"}
= form_tag admin_procedure_publish_path(procedure_id: @procedure.id), method: :put do
= form_tag admin_procedure_publish_path(procedure_id: @procedure.id), method: :put, remote: true do
.modal-content
.modal-header
%button.close{"aria-label" => "Close", "data-dismiss" => "modal", :type => "button"}
@ -42,8 +42,7 @@
#path_is_invalid.text-danger.center.message
Ce lien n'est pas valide. Seuls les caractères a-z, 0-9 et '_' sont autorisés.
.modal-footer
= submit_tag 'Annuler', class: %w(btn btn btn-default), id: 'cancel', data: { dismiss: 'modal' }
= submit_tag "#{@procedure.archived?? 'Réactiver' : 'Publier'}", class: %w(btn btn btn-success),
id: 'publish',
data: { disable_with: 'Publication en cours', submit: true},
disabled: :disabled
= button_tag 'Annuler', class: %w(btn btn btn-default), id: 'cancel', data: { dismiss: 'modal' }

View file

@ -0,0 +1 @@
<%= "togglePathMessage(true, #{@mine})" %>

View file

@ -281,7 +281,7 @@ describe Admin::ProceduresController, type: :controller do
it 'publish the given procedure' do
expect(procedure.published).to be_truthy
expect(procedure.path).to eq(procedure_path)
expect(response).to redirect_to :admin_procedures
expect(response.status).to eq 200
expect(flash[:notice]).to have_content 'Procédure publiée'
end
end
@ -292,7 +292,7 @@ describe Admin::ProceduresController, type: :controller do
it 'publish the given procedure' do
expect(procedure.published).to be_truthy
expect(procedure.path).to eq(procedure_path)
expect(response).to redirect_to :admin_procedures
expect(response.status).to eq 200
expect(flash[:notice]).to have_content 'Procédure publiée'
end
@ -309,8 +309,7 @@ describe Admin::ProceduresController, type: :controller do
it 'does not publish the given procedure' do
expect(procedure.published).to be_falsey
expect(procedure.path).to be_nil
expect(response).to redirect_to :admin_procedures
expect(flash[:alert]).to have_content 'Ce lien appartient à un autre administrateur et ne peut pas être utilisé.'
expect(response.status).to eq 200
end
it 'previous procedure remains published' do
@ -372,7 +371,7 @@ describe Admin::ProceduresController, type: :controller do
end
it { expect(procedure.archived).to be_falsey }
it { expect(response).to redirect_to :admin_procedures }
it { expect(response.status).to eq 200 }
it { expect(flash[:notice]).to have_content 'Procédure publiée' }
end
end