diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index c34b8a448..8ea0febde 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -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' diff --git a/app/views/admin/procedures/_modal_publish.html.haml b/app/views/admin/procedures/_modal_publish.html.haml index 31d5bbe17..88f9d58eb 100644 --- a/app/views/admin/procedures/_modal_publish.html.haml +++ b/app/views/admin/procedures/_modal_publish.html.haml @@ -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' } diff --git a/app/views/admin/procedures/publish.js.erb b/app/views/admin/procedures/publish.js.erb new file mode 100644 index 000000000..04a6b2229 --- /dev/null +++ b/app/views/admin/procedures/publish.js.erb @@ -0,0 +1 @@ +<%= "togglePathMessage(true, #{@mine})" %> \ No newline at end of file diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index 51c9628d9..50a253e80 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -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