Add button archive on procedure

This commit is contained in:
Xavier J 2015-11-26 18:41:41 +01:00
parent 02453e4cb1
commit 833752161f
9 changed files with 132 additions and 13 deletions

View file

@ -0,0 +1,14 @@
$(document).on('page:load', buttons_archived);
$(document).ready(buttons_archived);
function buttons_archived(){
$("button#archive").on('click', function(){
$("button#archive").hide();
$("#confirm").show();
});
$("#confirm #cancel").on('click', function(){
$("button#archive").show();
$("#confirm").hide();
});
}

View file

@ -22,7 +22,7 @@
@import "bootstrap";
body {
background-color:rgb(255,255,255)
background-color: rgb(255, 255, 255)
}
.logo {
@ -34,7 +34,7 @@ body {
.alert.alert-success,
.alert.alert-danger {
margin-top:-20px
margin-top: -20px
}
.navbar {
@ -54,6 +54,7 @@ body {
position: relative;
overflow: hidden;
}
.btn-file input[type=file] {
position: absolute;
top: 0;
@ -75,12 +76,13 @@ body {
}
.center {
text-align:center;
text-align: center;
}
textarea#description {
width: 100%;
}
input#nom_projet {
width: 100%;
}
@ -89,9 +91,9 @@ input#nom_projet {
max-width: 27px;
}
div.pagination{
padding-top:20px;
display:block;
div.pagination {
padding-top: 20px;
display: block;
text-align: center;
}
@ -103,4 +105,43 @@ div.pagination{
width: 100%;
margin-top: 0px;
}
.archived {
float: right;
margin-top: 10px;
.confirm {
display: none;
}
}
.btn-nav {
background-color: transparent;
margin-top: 6px;
height: 36px;
}
.btn-nav:hover {
background-color: #eeeeee;
border-color: #eeeeee #eeeeee #ddd;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
.btn-nav.text-info:hover{
color: #23527c;
}
.btn-nav.text-success:hover{
color: #3c763d;
}
.btn-nav.text-danger:hover{
color: #a94442;
}
#confirm {
display:none;
}

View file

@ -28,7 +28,7 @@ class Admin::ProceduresController < AdminController
end
flash.notice = 'Procédure enregistrée'
redirect_to admin_procedure_types_de_champ_path(procedure_id: @procedure.id)
redirect_to admin_procedure_types_de_champ_path(procedure_id: @procedure.id)
end
def update
@ -43,6 +43,18 @@ class Admin::ProceduresController < AdminController
redirect_to admin_procedures_path
end
def archive
@procedure = current_administrateur.procedures.find(params[:procedure_id])
@procedure.update_attributes({archived: true})
flash.notice = 'Procédure archivée'
redirect_to admin_procedures_path
rescue ActiveRecord::RecordNotFound
flash.alert = 'Procédure inéxistante'
redirect_to admin_procedures_path
end
private
def create_procedure_params

View file

@ -5,8 +5,18 @@
= link_to('Champs', admin_procedure_types_de_champ_path(@procedure))
%li
= link_to('Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure))
%li{style:'float:right'}
= form_tag "/admin/procedures/#{@procedure.id}/archive", action: :archive, method: :put, procedure_id: @procedure.id do
%button#archive.btn.btn-nav.text-info{type: :button}
%i.fa.fa-eraser
Archiver
#confirm
%button#valid.btn.btn-nav.text-success{type: :submit}
%i.fa.fa-check
Valider
%button#cancel.btn.btn-nav.text-danger{type: :button}
%i.fa.fa-remove
Annuler
%h2.text-info
=@procedure.libelle

View file

@ -45,11 +45,15 @@ Rails.application.routes.draw do
namespace :admin do
get 'sign_in' => '/administrateurs/sessions#new'
resources :procedures do
resource :types_de_champ, only: [:show, :update] do
post '/:index/move_up' => 'types_de_champ#move_up', as: :move_up
post '/:index/move_down' => 'types_de_champ#move_down', as: :move_down
end
put 'archive' => 'procedures#archive'
resources :types_de_champ, only: [:destroy]
resource :pieces_justificatives, only: [:show, :update]
resources :pieces_justificatives, only: :destroy

View file

@ -0,0 +1,5 @@
class AddArchivedToProcedure < ActiveRecord::Migration
def change
add_column :procedures, :archived, :boolean, default: false
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20151124085333) do
ActiveRecord::Schema.define(version: 20151126153425) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -150,6 +150,7 @@ ActiveRecord::Schema.define(version: 20151124085333) do
t.boolean "test"
t.boolean "use_api_carto", default: false
t.integer "administrateur_id"
t.boolean "archived", default: false
end
create_table "quartier_prioritaires", force: :cascade do |t|

View file

@ -166,4 +166,36 @@ describe Admin::ProceduresController, type: :controller do
end
end
end
describe 'PUT #archive' do
let(:procedure) { create(:procedure, administrateur: admin) }
context 'when admin is the owner of the procedure' do
before do
put :archive, procedure_id: procedure.id
procedure.reload
end
it { expect(procedure.archived).to be_truthy }
it { expect(response).to redirect_to :admin_procedures }
it { expect(flash[:notice]).to have_content 'Procédure archivée' }
end
context 'when admin is not the owner of the procedure' do
let(:admin_2) { create(:administrateur) }
before do
sign_out admin
sign_in admin_2
put :archive, procedure_id: procedure.id
procedure.reload
end
it { expect(response).to redirect_to :admin_procedures }
it { expect(flash[:alert]).to have_content 'Procédure inéxistante' }
end
end
end

View file

@ -12,7 +12,7 @@ feature 'on click on tabs button' do
context 'when he click on tabs a traitee' do
before do
visit backoffice_dossiers_en_attente_url
page.click_on 'À traiter (0)'
page.click_on 'À traiter 0'
end
scenario 'it redirect to backoffice dossier termine' do
@ -23,7 +23,7 @@ feature 'on click on tabs button' do
context 'when he click on tabs en attente' do
before do
visit backoffice_dossiers_termine_url
page.click_on 'En attente (0)'
page.click_on 'En attente 0'
end
scenario 'it redirect to backoffice dossier en attente' do
@ -34,7 +34,7 @@ feature 'on click on tabs button' do
context 'when he click on tabs termine' do
before do
visit backoffice_dossiers_a_traiter_url
page.click_on 'Terminé (0)'
page.click_on 'Terminé 0'
end
scenario 'it redirect to backoffice dossier termine' do