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

View file

@ -1,6 +1,6 @@
#publishModal.modal.fade{"aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"} #publishModal.modal.fade{"aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"}
.modal-dialog.modal-lg{:role => "document"} .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-content
.modal-header .modal-header
%button.close{"aria-label" => "Close", "data-dismiss" => "modal", :type => "button"} %button.close{"aria-label" => "Close", "data-dismiss" => "modal", :type => "button"}
@ -42,8 +42,7 @@
#path_is_invalid.text-danger.center.message #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. Ce lien n'est pas valide. Seuls les caractères a-z, 0-9 et '_' sont autorisés.
.modal-footer .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), = submit_tag "#{@procedure.archived?? 'Réactiver' : 'Publier'}", class: %w(btn btn btn-success),
id: 'publish', id: 'publish',
data: { disable_with: 'Publication en cours', submit: true},
disabled: :disabled 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 it 'publish the given procedure' do
expect(procedure.published).to be_truthy expect(procedure.published).to be_truthy
expect(procedure.path).to eq(procedure_path) 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' expect(flash[:notice]).to have_content 'Procédure publiée'
end end
end end
@ -292,7 +292,7 @@ describe Admin::ProceduresController, type: :controller do
it 'publish the given procedure' do it 'publish the given procedure' do
expect(procedure.published).to be_truthy expect(procedure.published).to be_truthy
expect(procedure.path).to eq(procedure_path) 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' expect(flash[:notice]).to have_content 'Procédure publiée'
end end
@ -309,8 +309,7 @@ describe Admin::ProceduresController, type: :controller do
it 'does not publish the given procedure' do it 'does not publish the given procedure' do
expect(procedure.published).to be_falsey expect(procedure.published).to be_falsey
expect(procedure.path).to be_nil expect(procedure.path).to be_nil
expect(response).to redirect_to :admin_procedures expect(response.status).to eq 200
expect(flash[:alert]).to have_content 'Ce lien appartient à un autre administrateur et ne peut pas être utilisé.'
end end
it 'previous procedure remains published' do it 'previous procedure remains published' do
@ -372,7 +371,7 @@ describe Admin::ProceduresController, type: :controller do
end end
it { expect(procedure.archived).to be_falsey } 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' } it { expect(flash[:notice]).to have_content 'Procédure publiée' }
end end
end end