255 lines
8.6 KiB
HTML
255 lines
8.6 KiB
HTML
{% if json.extra_data %}
|
|
<h2>Agenda de l'année scolaire {{ json.extra_data.school_year }}</h2>
|
|
<div class="caluire-agenda-cell caluire-agenda-cell-{{ cell.pk }}">
|
|
{% with first_monday=json.extra_data.start_date|adjust_to_week_monday %}
|
|
{% with last_day=json.extra_data.end_date|adjust_to_week_monday|add_days:6 %}
|
|
{% now 'Y-m-W' as current_week %}
|
|
{% spaceless %}
|
|
<button class="caluire-agenda-cell--previous-week">←</button>
|
|
<div class="caluire-agenda-cell--week-list">
|
|
<div class="caluire-agenda-cell--slider">
|
|
{% for day in first_monday|iterate_days_until:last_day %}
|
|
{% if day.weekday == 0 %}
|
|
{% with sunday=day|add_days:6 %}
|
|
<div class="caluire-agenda-cell--week-title {% if current_week == day|date:"Y-m-W" %}current{% endif %}"
|
|
data-edit-url="{{ eservices_url }}famille/gerer-mes-reservations/tryauth?child_id={{ child_id }}&reference_year={{ first_monday.year }}¤t={{ day|adjust_to_week_monday|date:"Y-m-d" }}">
|
|
Du {{ day|date:"d/m" }} au {{ sunday|date:"d/m" }}
|
|
</div>
|
|
{% endwith %}
|
|
{% endif %}
|
|
<div class="caluire-agenda-cell--day-item" data-weekday="{{ day.weekday }}">
|
|
<div class="caluire-agenda-cell--day-title" >
|
|
{{ day|date:"l d/m" }}
|
|
</div>
|
|
{% with day_str=day|date:"Y-m-d" %}
|
|
{% for item in json.data %}
|
|
{% if item.details.JOURDATE == day_str %}
|
|
<div class="caluire-agenda-cell--activity-item {% if item.disabled %}disabled{% endif %}">
|
|
<div class="caluire-agenda-cell--activity-status {{ item.details.status_color }}"/></div>
|
|
<div class="caluire-agenda-cell--activity-label"/>{{ item.details.activity_label }}</div>
|
|
</div>
|
|
{% endif %}
|
|
{% endfor %}
|
|
{% endwith %}
|
|
<div class="caluire-agenda-cell--day-no-activity">
|
|
Pas d'activité ce jour.
|
|
</div>
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
</div>
|
|
<button class="caluire-agenda-cell--next-week">→</button>
|
|
<a class="pk-button caluire-agenda-cell--edit-btn">
|
|
Modifier l'agenda
|
|
</a>
|
|
{% endspaceless %}
|
|
{% endwith %}
|
|
{% endwith %}
|
|
<style>
|
|
.caluire-agenda-cell {
|
|
margin-top: 1em;
|
|
display: grid;
|
|
grid-template-columns: repeat(3, auto);
|
|
grid-template-rows: repeat(2, auto);
|
|
justify-items: left;
|
|
--min-column-width: 250;
|
|
}
|
|
|
|
.caluire-agenda-cell--previous-week,
|
|
.caluire-agenda-cell--next-week {
|
|
height: 3em;
|
|
width: 3em;
|
|
}
|
|
|
|
.caluire-agenda-cell--next-week {
|
|
margin-left: 1rem;
|
|
}
|
|
|
|
.caluire-agenda-cell--edit-btn {
|
|
grid-column: 2;
|
|
grid-row: 2;
|
|
}
|
|
|
|
.caluire-agenda-cell--week-list {
|
|
overflow: hidden;
|
|
margin-bottom: 2rem;
|
|
width: 100%;
|
|
}
|
|
|
|
.caluire-agenda-cell--slider {
|
|
column-gap: 0px;
|
|
display: grid;
|
|
grid-auto-columns: 0px;
|
|
grid-auto-rows: 0px;
|
|
grid-auto-flow: column;
|
|
position: relative;
|
|
}
|
|
|
|
.caluire-agenda-cell--week-item:nth-child(even) {
|
|
background: #fafafa;
|
|
}
|
|
|
|
.caluire-agenda-cell--week-title {
|
|
border-bottom: 1px solid #888;
|
|
font-weight: bold;
|
|
margin-bottom: 1rem;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 3.2rem;
|
|
}
|
|
|
|
.caluire-agenda-cell--day-item {
|
|
margin: 0 1rem;
|
|
}
|
|
|
|
.caluire-agenda-cell--day-title {
|
|
border-bottom: 1px solid #888;
|
|
margin: 1rem 0;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.caluire-agenda-cell--day-no-activity {
|
|
color: #888;
|
|
}
|
|
|
|
.caluire-agenda-cell--activity-item + .caluire-agenda-cell--day-no-activity {
|
|
display: none;
|
|
}
|
|
|
|
.caluire-agenda-cell--activity-item {
|
|
display: flex;
|
|
align-items: baseline;
|
|
margin: 0.3rem 0;
|
|
}
|
|
|
|
.caluire-agenda-cell--activty-item.disabled {
|
|
color: #888;
|
|
}
|
|
|
|
.caluire-agenda-cell--activity-status {
|
|
min-height: calc(0.66rem + 2px);
|
|
min-width: calc(0.66rem + 2px);
|
|
background: transparent;
|
|
border: 1px solid #aaa;
|
|
border-radius: 2px;
|
|
margin-right: 1rem;
|
|
}
|
|
|
|
.caluire-agenda-cell--activity-label {
|
|
flex-grow: 1;
|
|
}
|
|
|
|
.caluire-agenda-cell--activity-status.green {
|
|
background: #3c3;
|
|
}
|
|
|
|
.caluire-agenda-cell--activity-status.grey {
|
|
background: #aaa;
|
|
}
|
|
|
|
.caluire-agenda-cell--activity-status.orange {
|
|
background: orange;
|
|
}
|
|
|
|
.caluire-agenda-cell--activity-status.red {
|
|
background: red;
|
|
}
|
|
|
|
.caluire-agenda-cell--activity-status.yellow {
|
|
background: yellow;
|
|
}
|
|
|
|
</style>
|
|
|
|
<script>
|
|
function initAgendaCell($cell) {
|
|
const $weekList = $('.caluire-agenda-cell--week-list', $cell);
|
|
const $slider = $('.caluire-agenda-cell--slider', $cell);
|
|
const $currentWeek = $('.caluire-agenda-cell--week-title.current', $cell);
|
|
const $nextWeekButton = $('.caluire-agenda-cell--next-week', $cell);
|
|
const $previousWeekButton = $('.caluire-agenda-cell--previous-week', $cell);
|
|
const $editAgendaBtn = $('.caluire-agenda-cell--edit-btn', $cell);
|
|
|
|
let $selectedWeek = $currentWeek;
|
|
|
|
function getPreviousWeek() { return $selectedWeek.prevAll('.caluire-agenda-cell--week-title:first'); }
|
|
function getNextWeek() { return $selectedWeek.nextAll('.caluire-agenda-cell--week-title:first'); }
|
|
|
|
function setCurrentWeek($week, enableTransition) {
|
|
if(!$week.length) {
|
|
return;
|
|
}
|
|
const currentOffset = $week[0].offsetLeft;
|
|
$slider.css({
|
|
'transform': `translate(-${currentOffset}px)`,
|
|
'transition': (enableTransition ? 'transform 0.5s' : '')
|
|
});
|
|
|
|
$selectedWeek = $week;
|
|
$nextWeekButton.prop('disabled', getNextWeek().length == 0);
|
|
$previousWeekButton.prop('disabled', getPreviousWeek().length == 0);
|
|
|
|
const selectedWeekIsInPast = $selectedWeek.nextAll('.caluire-agenda-cell--week-title.current').length;
|
|
$weekToEdit = selectedWeekIsInPast ? $currentWeek : $selectedWeek;
|
|
$editAgendaBtn.prop('href', $weekToEdit.attr('data-edit-url'));
|
|
}
|
|
|
|
function setPreviousWeek() { setCurrentWeek(getPreviousWeek(), true); }
|
|
function setNextWeek() { setCurrentWeek(getNextWeek(), true); }
|
|
|
|
$previousWeekButton.on('click', setPreviousWeek);
|
|
$nextWeekButton.on('click', setNextWeek);
|
|
|
|
let touchStartX = 0;
|
|
$cell.on('touchstart', (e) => {
|
|
touchStartX = e.changedTouches[0].screenX;
|
|
});
|
|
|
|
$cell.on('touchend', (e) => {
|
|
const touchEndX = e.changedTouches[0].screenX;
|
|
if (touchEndX - touchStartX < -30) {
|
|
setNextWeek();
|
|
} else if (touchEndX - touchStartX > 30) {
|
|
setPreviousWeek();
|
|
}
|
|
});
|
|
|
|
function updateColumnsWidth() {
|
|
const minWidth = $slider.css('--min-column-width');
|
|
const availableWidth = $weekList[0].offsetWidth;
|
|
let columnsWidth = availableWidth < minWidth ? availableWidth : availableWidth / Math.floor(availableWidth / minWidth);
|
|
$slider.css('grid-template-columns', `repeat(53, ${columnsWidth}px)`);
|
|
|
|
if($selectedWeek) {
|
|
// Update slider offset to bring it at the new position of the selectedWeek
|
|
setCurrentWeek($selectedWeek, false);
|
|
}
|
|
}
|
|
|
|
function hideEmptyDays() {
|
|
let nbRows = 8;
|
|
for(let i = 0; i < 7; ++i) {
|
|
const $days = $(`.caluire-agenda-cell--day-item[data-weekday=${i}]`, $cell);
|
|
const $activities = $('.caluire-agenda-cell--activity-item', $days);
|
|
if(!$activities.length) {
|
|
$days.css('display', 'none');
|
|
nbRows -= 1;
|
|
}
|
|
|
|
$slider.css('grid-template-rows', `repeat(${nbRows}, auto`);
|
|
}
|
|
}
|
|
|
|
hideEmptyDays();
|
|
new ResizeObserver(updateColumnsWidth).observe($weekList[0]);
|
|
addEventListener('resize', updateColumnsWidth);
|
|
}
|
|
|
|
|
|
initAgendaCell($('.caluire-agenda-cell-{{ cell.pk }}'));
|
|
|
|
</script>
|
|
</div>
|
|
{% endif %}
|