Commit a58dde81 by Damien Moulard

members admin: batch remove makeups to members

parent c325b191
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
position: relative; position: relative;
} }
.header {
margin: 1.5rem 0;
}
.login_area { .login_area {
position: absolute; position: absolute;
top: 0; top: 0;
...@@ -52,6 +56,15 @@ ...@@ -52,6 +56,15 @@
padding: 2rem 0; padding: 2rem 0;
} }
#table_top_area {
display: flex;
justify-content: space-between;
}
#decrement_selected_members_makeups {
display: none;
}
.table_area { .table_area {
margin-top: 20px; margin-top: 20px;
} }
...@@ -60,3 +73,7 @@ ...@@ -60,3 +73,7 @@
padding: 0.4rem 1.25rem; padding: 0.4rem 1.25rem;
margin-left: 10px; margin-left: 10px;
} }
.select_member_cb {
cursor: pointer;
}
\ No newline at end of file
var makeups_members_table = null, var makeups_members_table = null,
makeups_members = null; makeups_members = null,
selected_rows = []; // Contain members id
function switch_active_tab() { function switch_active_tab() {
// Set tabs // Set tabs
...@@ -10,23 +11,26 @@ function switch_active_tab() { ...@@ -10,23 +11,26 @@ function switch_active_tab() {
$('.tab_content').hide(); $('.tab_content').hide();
let tab = $(this).attr('id'); let tab = $(this).attr('id');
if (tab == 'tab_settings') { if (tab == 'tab_makeups') {
$('#tab_settings_content').show();
} else {
// Default
$('#tab_makeups_content').show(); $('#tab_makeups_content').show();
} }
load_tab_data(); load_tab_data();
} }
/**
* Load data for the current tab
*/
function load_tab_data() { function load_tab_data() {
let current_tab = $('.tab .active').attr('id'); let current_tab = $('.tab .active').attr('id');
if (current_tab === 'tab_makeups') { if (current_tab === 'tab_makeups' && makeups_members === null) {
load_makeups_members(); load_makeups_members();
} }
} }
/**
* Load partners who have makeups to do
*/
function load_makeups_members() { function load_makeups_members() {
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
...@@ -51,6 +55,9 @@ function load_makeups_members() { ...@@ -51,6 +55,9 @@ function load_makeups_members() {
}); });
} }
/**
* (Re)Display table of makeup members
*/
function display_makeups_members() { function display_makeups_members() {
if (makeups_members_table) { if (makeups_members_table) {
$('#makeups_members_table').off(); $('#makeups_members_table').off();
...@@ -60,9 +67,9 @@ function display_makeups_members() { ...@@ -60,9 +67,9 @@ function display_makeups_members() {
// Remove members with 0 makeups to do // Remove members with 0 makeups to do
ids_to_remove = [] ids_to_remove = []
for (of in makeups_members) { for (member_item of makeups_members) {
if (makeups_members[i].makeups_to_do == 0) { if (member_item.makeups_to_do == 0) {
ids_to_remove.push(makeups_members[i].id) ids_to_remove.push(member_item.id)
} }
} }
makeups_members = makeups_members.filter(m => !ids_to_remove.includes(m.id)) makeups_members = makeups_members.filter(m => !ids_to_remove.includes(m.id))
...@@ -129,8 +136,46 @@ function display_makeups_members() { ...@@ -129,8 +136,46 @@ function display_makeups_members() {
false false
) )
}); });
$('#makeups_members_table').on('click', 'tbody td .select_member_cb', function () {
$(this).closest('tr')
.toggleClass('selected');
// Save / unsave selected row
const m_id = makeups_members_table.row($(this).closest('tr')).data().id;
const first_select = selected_rows.length === 0;
if (this.checked) {
selected_rows.push(m_id);
} else {
const i = selected_rows.findIndex(id => id == m_id);
selected_rows.splice(i, 1);
}
if (selected_rows.length > 0) {
$("#decrement_selected_members_makeups").show();
if (first_select) {
$("#decrement_selected_members_makeups").on("click", () => {
openModal(
`Enlever un rattrapage aux membres sélectionnés ?`,
() => {
decrement_makeups(selected_rows);
},
"Confirmer",
false
)
});
}
} else {
$("#decrement_selected_members_makeups").off().hide();
}
});
} }
/**
* Send request to update members nb of makeups to do
* @param {Array} member_ids
*/
function decrement_makeups(member_ids) { function decrement_makeups(member_ids) {
openModal(); openModal();
...@@ -153,6 +198,7 @@ function decrement_makeups(member_ids) { ...@@ -153,6 +198,7 @@ function decrement_makeups(member_ids) {
traditional: true, traditional: true,
contentType: "application/json; charset=utf-8", contentType: "application/json; charset=utf-8",
success: function(data) { success: function(data) {
selected_rows = [];
display_makeups_members(); display_makeups_members();
closeModal() closeModal()
}, },
...@@ -170,9 +216,14 @@ function decrement_makeups(member_ids) { ...@@ -170,9 +216,14 @@ function decrement_makeups(member_ids) {
} }
$(document).ready(function() { $(document).ready(function() {
if (coop_is_connected()) {
$.ajaxSetup({ headers: { "X-CSRFToken": getCookie('csrftoken') } }); $.ajaxSetup({ headers: { "X-CSRFToken": getCookie('csrftoken') } });
$(".page_content").show();
load_makeups_members(); load_makeups_members();
$(".tabs .tab").on('click', switch_active_tab); $(".tabs .tab").on('click', switch_active_tab);
} else {
$(".page_content").hide();
}
}); });
...@@ -106,12 +106,6 @@ function init_history() { ...@@ -106,12 +106,6 @@ function init_history() {
responsivePriority: 1 responsivePriority: 1
}, },
{ {
data: "created_by",
title: "Créé par",
responsivePriority: 20000,
className: "desktop tablet-l"
},
{
data: "shift_name", data: "shift_name",
title: "Service" title: "Service"
}, },
...@@ -120,13 +114,6 @@ function init_history() { ...@@ -120,13 +114,6 @@ function init_history() {
title: "Détails", title: "Détails",
responsivePriority: 3 responsivePriority: 3
}, },
{
data: "point_qty",
title: (viewportWidth <= 768) ? "Mvmt de points" : "Mouvement de points",
responsivePriority: 2,
width: "10%",
className: (viewportWidth <= 768) ? "dt-body-center" : ''
}
], ],
iDisplayLength: -1, iDisplayLength: -1,
ordering: false, ordering: false,
......
...@@ -22,22 +22,27 @@ ...@@ -22,22 +22,27 @@
<h1>Bureau des membres</h1> <h1>Bureau des membres</h1>
</div> </div>
<div class="page_content">
<section class="tabs autogrid"> <section class="tabs autogrid">
<div class="button tab active" id="tab_makeups"><h5>Rattrapages</h5></div> <div class="button tab active" id="tab_makeups"><h5>Rattrapages</h5></div>
<div class="button tab" id="tab_settings"><h5>Réglages</h5></div>
</section> </section>
<div id="tab_makeups_content" class="tab_content"> <div id="tab_makeups_content" class="tab_content">
<div id="table_top_area">
<h3>Liste des membres devant effectuer un rattrapage</h3> <h3>Liste des membres devant effectuer un rattrapage</h3>
<div class="table_grouped_action">
<button type="button" class="btn--primary" id="decrement_selected_members_makeups">
-1 rattrapage pour les membres sélectionnés
</button>
</div>
</div>
<div class="table_area"> <div class="table_area">
<table id="makeups_members_table" class="display" cellspacing="0" width="100%"></table> <table id="makeups_members_table" class="display" cellspacing="0" width="100%"></table>
</div> </div>
</div> </div>
<div id="tab_settings_content" class="tab_content" style="display:none;">
...
</div> </div>
<div id="templates" style="display:none;"></div> <div id="templates" style="display:none;"></div>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment