Commit ad4867a3 by Damien Moulard

block shifts exchange if unsuscrubed

parent 2b5c057a
...@@ -7,13 +7,13 @@ ...@@ -7,13 +7,13 @@
/* -- Suspended screen */ /* -- Suspended screen */
#suspended_content { #suspended_content, #unsuscribed_content {
align-items: center; align-items: center;
text-align: center; text-align: center;
} }
.select_makeups { #shifts_exchange .select_makeups, #shifts_exchange .unsuscribed_form_link {
margin: 2rem 0; margin: 1.5rem 0;
} }
/* -- Calendar screen, shifts list */ /* -- Calendar screen, shifts list */
...@@ -75,7 +75,17 @@ ...@@ -75,7 +75,17 @@
#calendar { #calendar {
margin: 2rem 1rem; margin: 2rem 1rem;
}
.loading-calendar {
margin: 3rem auto;
display: none;
}
@media screen and (max-width:768px) {
#calendar {
display: none; display: none;
}
} }
.fc .fc-event { .fc .fc-event {
......
var calendar = null, var calendar = null,
selected_shift = null; selected_shift = null,
vw = null;
/** /**
* A partner can exchange shifts if: * A partner can exchange shifts if:
...@@ -61,6 +62,7 @@ function add_or_change_shift(new_shift_id) { ...@@ -61,6 +62,7 @@ function add_or_change_shift(new_shift_id) {
} }
let msg = "Parfait! "; let msg = "Parfait! ";
msg += (selected_shift === null) msg += (selected_shift === null)
? "Le service choisi a été ajouté." ? "Le service choisi a été ajouté."
: "Le service a été échangé."; : "Le service a été échangé.";
...@@ -86,7 +88,7 @@ function add_or_change_shift(new_shift_id) { ...@@ -86,7 +88,7 @@ function add_or_change_shift(new_shift_id) {
}, },
error: function(error) { error: function(error) {
closeModal(); closeModal();
selected_shift = null selected_shift = null;
if (error.status === 400) { if (error.status === 400) {
alert(`Désolé ! Le service que vous souhaitez échanger démarre dans moins de 24h. ` + alert(`Désolé ! Le service que vous souhaitez échanger démarre dans moins de 24h. ` +
...@@ -157,7 +159,8 @@ function init_shifts_list() { ...@@ -157,7 +159,8 @@ function init_shifts_list() {
} }
// Unselect other checkboxes // Unselect other checkboxes
if ($(this).find(".checkbox").prop("checked")) { if ($(this).find(".checkbox")
.prop("checked")) {
for (let cb_item of $("#shifts_list").find(".checkbox")) { for (let cb_item of $("#shifts_list").find(".checkbox")) {
if (cb.prop("value") !== $(cb_item).prop("value")) { if (cb.prop("value") !== $(cb_item).prop("value")) {
$(cb_item).prop("checked", false); $(cb_item).prop("checked", false);
...@@ -173,6 +176,10 @@ function init_shifts_list() { ...@@ -173,6 +176,10 @@ function init_shifts_list() {
* Inits the page when the calendar is displayed * Inits the page when the calendar is displayed
*/ */
function init_calendar_page() { function init_calendar_page() {
if (vw <= 768) {
$(".loading-calendar").show();
}
if (incoming_shifts !== null) { if (incoming_shifts !== null) {
init_shifts_list(); init_shifts_list();
} else { } else {
...@@ -185,7 +192,6 @@ function init_calendar_page() { ...@@ -185,7 +192,6 @@ function init_calendar_page() {
$("#need_to_select_makeups_message").show(); $("#need_to_select_makeups_message").show();
} }
const vw = window.innerWidth;
let default_initial_view = ""; let default_initial_view = "";
let header_toolbar = {}; let header_toolbar = {};
...@@ -195,19 +201,20 @@ function init_calendar_page() { ...@@ -195,19 +201,20 @@ function init_calendar_page() {
left: 'title', left: 'title',
center: 'dayGridMonth,listWeek,timeGridDay', center: 'dayGridMonth,listWeek,timeGridDay',
right: 'prev,next today' right: 'prev,next today'
} };
} else { } else {
default_initial_view = 'dayGridMonth'; default_initial_view = 'dayGridMonth';
header_toolbar = { header_toolbar = {
left: 'prev,next today', left: 'prev,next today',
center: 'title', center: 'title',
right: 'dayGridMonth,listWeek,timeGridDay' right: 'dayGridMonth,listWeek,timeGridDay'
} };
} }
const hidden_days = $.map(days_to_hide.split(", "), Number); const hidden_days = $.map(days_to_hide.split(", "), Number);
const calendarEl = document.getElementById('calendar'); const calendarEl = document.getElementById('calendar');
calendar = new FullCalendar.Calendar(calendarEl, { calendar = new FullCalendar.Calendar(calendarEl, {
locale: 'fr', locale: 'fr',
initialView: default_initial_view, initialView: default_initial_view,
...@@ -231,17 +238,18 @@ function init_calendar_page() { ...@@ -231,17 +238,18 @@ function init_calendar_page() {
// Set new shift // Set new shift
const datetime_new_shift = info.event.start; const datetime_new_shift = info.event.start;
let new_shift_date = datetime_new_shift.toLocaleDateString("fr-fr", date_options); let new_shift_date = datetime_new_shift.toLocaleDateString("fr-fr", date_options);
let new_shift_time = datetime_new_shift.toLocaleTimeString("fr-fr", time_options) let new_shift_time = datetime_new_shift.toLocaleTimeString("fr-fr", time_options);
if (selected_shift !== null && can_exchange_shifts()) { if (selected_shift !== null && can_exchange_shifts()) {
/* shift exchange */ /* shift exchange */
// Set old shift // Set old shift
let datetime_old_shift = new Date(selected_shift.date_begin); let datetime_old_shift = new Date(selected_shift.date_begin);
let old_shift_date = datetime_old_shift.toLocaleDateString("fr-fr", date_options); let old_shift_date = datetime_old_shift.toLocaleDateString("fr-fr", date_options);
let old_shift_time = datetime_old_shift.toLocaleTimeString("fr-fr", time_options) let old_shift_time = datetime_old_shift.toLocaleTimeString("fr-fr", time_options);
// Display modal // Display modal
let modal_template = $("#modal_shift_exchange_template"); let modal_template = $("#modal_shift_exchange_template");
modal_template.find(".date_old_shift").text(old_shift_date); modal_template.find(".date_old_shift").text(old_shift_date);
modal_template.find(".time_old_shift").text(old_shift_time); modal_template.find(".time_old_shift").text(old_shift_time);
modal_template.find(".date_new_shift").text(new_shift_date); modal_template.find(".date_new_shift").text(new_shift_date);
...@@ -264,6 +272,7 @@ function init_calendar_page() { ...@@ -264,6 +272,7 @@ function init_calendar_page() {
} else if (can_select_makeup()) { } else if (can_select_makeup()) {
/* choose a makeup service */ /* choose a makeup service */
let modal_template = $("#modal_add_shift_template"); let modal_template = $("#modal_add_shift_template");
modal_template.find(".date_new_shift").text(new_shift_date); modal_template.find(".date_new_shift").text(new_shift_date);
modal_template.find(".time_new_shift").text(new_shift_time); modal_template.find(".time_new_shift").text(new_shift_time);
...@@ -278,33 +287,34 @@ function init_calendar_page() { ...@@ -278,33 +287,34 @@ function init_calendar_page() {
} }
}, },
eventDidMount: function() { eventDidMount: function() {
if (vw <=768) { if (vw <= 768) {
$(".fc .fc-header-toolbar").addClass("resp-header-toolbar"); $(".fc .fc-header-toolbar").addClass("resp-header-toolbar");
}
// Calendar is hidden at first on mobile to hide header change when data is loaded
$(".loading-calendar").hide();
$("#calendar").show(); $("#calendar").show();
} }
}
}); });
calendar.render(); calendar.render();
} }
function init_shifts_exchange() { function init_shifts_exchange() {
// TODO : loading
// TODO : suspended
$(".shifts_exchange_page_content").hide(); $(".shifts_exchange_page_content").hide();
vw = window.innerWidth;
if (partner_data.cooperative_state === 'unsubscribed') { if (partner_data.cooperative_state === 'unsubscribed') {
// TODO $("#unsuscribed_content").show();
// $(".unsuscribed_form_link")
// .show() $(".unsuscribed_form_link")
// .attr('href', unsuscribe_form_link) .show()
// .on('click', function() { .attr('href', unsuscribe_form_link)
// setTimeout(500, () => { .on('click', function() {
// $(this).removeClass('active'); setTimeout(500, () => {
// }); $(this).removeClass('active');
// }); });
});
} else if (partner_data.cooperative_state === 'suspended' } else if (partner_data.cooperative_state === 'suspended'
&& partner_data.date_delay_stop === 'False') { && partner_data.date_delay_stop === 'False') {
$("#suspended_content").show(); $("#suspended_content").show();
...@@ -325,5 +335,4 @@ function init_shifts_exchange() { ...@@ -325,5 +335,4 @@ function init_shifts_exchange() {
$("#shifts_exchange_content").show(); $("#shifts_exchange_content").show();
init_calendar_page(); init_calendar_page();
} }
} }
\ No newline at end of file
<div id="shifts_exchange"> <div id="shifts_exchange">
<div id="unsuscribed_content" class="shifts_exchange_page_content">
<h3>Je suis désinscrit.e, je dois remplir un formulaire pour qu'on me réinscrive à un créneau.</h3>
<a href="#" target="_blank" class="btn--warning unsuscribed_form_link">
J'accède au formulaire
</a>
</div>
<div id="suspended_content" class="shifts_exchange_page_content"> <div id="suspended_content" class="shifts_exchange_page_content">
<h3>Je suis suspendu.e, je dois sélectionner mes rattrapages pour pouvoir refaire mes courses.</h3> <h3>Je suis suspendu.e, je dois sélectionner mes rattrapages pour pouvoir refaire mes courses.</h3>
<button type="button" class="btn--danger select_makeups"> <button type="button" class="btn--danger select_makeups">
...@@ -20,6 +26,9 @@ ...@@ -20,6 +26,9 @@
</div> </div>
<div id="shifts_list"></div> <div id="shifts_list"></div>
</div> </div>
<div class="loading-calendar">
<i class="fas fa-spinner fa-spin fa-2x"></i>
</div>
<div id="calendar"></div> <div id="calendar"></div>
</div> </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