Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 24 additions & 34 deletions app/static/js/volunteerDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,45 @@ $(document).ready(function () {
$(".displayCheckbox").on('change', function () {
getCheckBoxes()
})
$.fn.dataTable.ext.search.push(function (settings, data, dataIndex) {
if (settings.nTable.id !== 'volunteerInformationTableToPrint') {
return true;
}
const status = data[3].toLowerCase();
if (status === 'attended' && !$('#attendedSelect').is(':checked')) return false;
if (status === 'rsvp' && !$('#rsvpSelect').is(':checked')) return false;
if (status === 'waitlist' && !$('#waitlistSelect').is(':checked')) return false;
return true;
});
function hideDuplicateVolunteers() {
let allEntries = $(".volunteerInfoEntries")
let shownUsers = []
for (let i = 0; i < allEntries.length; i++) {
let currentEntry = $(allEntries[i])
let allEntries = $("#volunteerInformationCardToPrint .volunteerInfoEntries");
let shownUsers = [];
allEntries.each(function () {
let currentEntry = $(this);
let user = currentEntry.data("user");
if (currentEntry.is(":visible")) {
if (shownUsers.includes(currentEntry.data("user"))) {
if (shownUsers.includes(user)) {
currentEntry.hide()
} else {
shownUsers.push(currentEntry.data("user"))
shownUsers.push(user);
}
}
}
stripeVolunteerInfoTable()
});
}
function getCheckBoxes() {
$(".displayCheckbox").each(function () {
let checkboxId = this.id;
if ($('#' + checkboxId).is(':checked')) {
$("." + checkboxId).show()
$("#volunteerInformationCardToPrint ." + checkboxId).show();
} else {
$("." + checkboxId).hide()
$("#volunteerInformationCardToPrint ." + checkboxId).hide();
}
})
});
hideDuplicateVolunteers()
volunteerInfoTable.page('first').draw(false);

}

function sortVolunteers() {
let sortedTable = $("#volunteerInformationTableToPrint_wrapper");
let entriesTable = sortedTable.find(".volunteerInfoEntries");
Expand All @@ -58,35 +70,13 @@ $(document).ready(function () {
return textA.localeCompare(textB);
});

entriesTable.appendTo(sortedTable);

let sortedCards = $("#volunteerInformationCardToPrint .sort-here");
let entriesCards = sortedCards.find(".volunteerInfoEntries");

entriesCards.sort(function (a, b) {
let textA = a.getElementsByClassName('nameSelect')[0].innerText
let textB = b.getElementsByClassName('nameSelect')[0].innerText
return textA.localeCompare(textB);
});

entriesCards.appendTo(sortedCards);
};

function stripeVolunteerInfoTable() {
$('#volunteerInformationTableToPrint .volunteerInfoEntries').removeClass('custom-odd custom-even')
$('#volunteerInformationTableToPrint .volunteerInfoEntries:visible').each(function (i,e) {
$(e).addClass(i % 2 ? 'custom-odd' : 'custom-even')
})
}
var volunteerInfoTable = $('#volunteerInformationTableToPrint').DataTable({pageLength: 10,order: [[0, 'asc']]});
getCheckBoxes()
hideDuplicateVolunteers()
sortVolunteers()
var volunteerInfoTable= $('#volunteerInformationTableToPrint').DataTable({ stripeClasses: []});
volunteerInfoTable.on('draw.dt', function (){
getCheckBoxes()
stripeVolunteerInfoTable()
});
stripeVolunteerInfoTable()
for(let i = 0; i < users.length; i++){
$('#volunteerUsernames').append(`<input type="hidden" name="username" value=${users[i]}>`)
}
Expand Down
23 changes: 13 additions & 10 deletions app/templates/events/volunteerDetails.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,20 @@ <h4 class="nameSelect" nowrap><b>{{ participant.user.firstName }} {{ participant
{% endmacro %}

{% macro printParticipants(type, attended, rsvp, waitlist) %}
{% set seen = [] %}
{% set combinedParticipants = attended + rsvp + waitlist %}
{% for p in combinedParticipants | unique %}
{% if p in rsvp %}
{{createTable(p, 'rsvp') if type == 'table' else createCard(p, 'rsvp') }}
{% endif %}
{% if p in attended%}
{{createTable(p, 'attended') if type == 'table' else createCard(p, 'attended') }}
{% endif %}
{% if p in waitlist %}
{{createTable(p, 'waitlist') if type == 'table' else createCard(p, 'waitlist') }}
{% endif %}
{% for p in combinedParticipants %}
{% set username = p.user.username %}
{% if username not in seen %}
{% set _ = seen.append(username) %}
{% if p in attended %}
{{ createTable(p, 'attended') if type == 'table' else createCard(p, 'attended') }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of using create table 3 times, create a new variable called 'status', for example, and set that variable to be 'attended', 'rsvp', and 'waitlist within the if statements. Then after the if statements create the table, ex:

{% set status = None %}
{% if p in attended %}
    {% set status = 'attended' %}
{% elif p in rsvp %}
    {% set status = 'rsvp' %}
{% elif p in waitlist%}
    {% set status = 'waitlist' %}
{% endif %}

{% if status %}
    {{ createTable(p, status) if type == 'table' else createCard(p, status) }}
{% endif %}

This would make general code maintenance in the future easier.

{% elif p in rsvp %}
{{ createTable(p, 'rsvp') if type == 'table' else createCard(p, 'rsvp') }}
{% elif p in waitlist %}
{{ createTable(p, 'waitlist') if type == 'table' else createCard(p, 'waitlist') }}
{% endif %}
{% endif %}
{% endfor %}
{% endmacro %}

Expand Down