Commit 5fd0ddad by Félicie

now possible to change shifts for some attached people

parent 3f50b24f
...@@ -6,10 +6,12 @@ var calendar = null, ...@@ -6,10 +6,12 @@ var calendar = null,
* A partner can exchange shifts if: * A partner can exchange shifts if:
* - s.he doesn't have to choose a makeup shift * - s.he doesn't have to choose a makeup shift
* - s.he's not an associated partner * - s.he's not an associated partner
* - s.he's is an associated partner who is not blocked in his actions
* @returns boolean * @returns boolean
*/ */
function can_exchange_shifts() { function can_exchange_shifts() {
return partner_data.makeups_to_do == 0 && partner_data.is_associated_people === "False"; console.log(partner_data)
return partner_data.makeups_to_do == 0 && (partner_data.is_associated_people === "False" || (partner_data.is_associated_people === "True" && block_actions_for_attached_people === "False"));
} }
/** /**
...@@ -30,10 +32,19 @@ function add_or_change_shift(new_shift_id) { ...@@ -30,10 +32,19 @@ function add_or_change_shift(new_shift_id) {
if (is_time_to('change_shift')) { if (is_time_to('change_shift')) {
setTimeout(openModal, 100); // loading on setTimeout(openModal, 100); // loading on
tData = 'idNewShift=' + new_shift_id if (partner_data.is_associated_people === "False") {
+'&idPartner=' + partner_data.partner_id tData = 'idNewShift=' + new_shift_id
+ '&shift_type=' + partner_data.shift_type +'&idPartner=' + partner_data.partner_id
+ '&verif_token=' + partner_data.verif_token; + '&shift_type=' + partner_data.shift_type
+ '&verif_token=' + partner_data.verif_token;
} else if(partner_data.is_associated_people === "True" && block_actions_for_attached_people === "False") {
tData = 'idNewShift=' + new_shift_id
+'&idPartner=' + partner_data.parent_id
+ '&shift_type=' + partner_data.shift_type
+ '&verif_token=' + partner_data.parent_verif_token;
} else {
return false;
}
if (selected_shift === null) { if (selected_shift === null) {
tUrl = '/shifts/add_shift'; tUrl = '/shifts/add_shift';
...@@ -84,17 +95,37 @@ function add_or_change_shift(new_shift_id) { ...@@ -84,17 +95,37 @@ function add_or_change_shift(new_shift_id) {
// Redraw calendar // Redraw calendar
calendar.refetchEvents(); calendar.refetchEvents();
} else {
closeModal();
selected_shift = null;
alert(`Une erreur est survenue. ` +
`Il est néanmoins possible que la requête ait abouti, ` +
`veuillez patienter quelques secondes puis vérifier vos services enregistrés.`);
// Refectch shifts anyway, if registration/exchange was still succesful
setTimeout(() => {
load_partner_shifts(partner_data.concerned_partner_id)
.then(init_shifts_list);
}, 300);
} }
}, },
error: function(error) { error: function(error) {
closeModal(); closeModal();
selected_shift = null; selected_shift = null;
if (error.status === 400) { if (error.status === 400 && error.msg === "Old service in less than 24hours.") {
alert(`Désolé ! Le service que tu souhaites échanger démarre dans moins de 24h. ` + alert(`Désolé ! Le service que tu souhaites échanger démarre dans moins de 24h. ` +
`Afin de faciliter la logistique des services, il n'est plus possible de l'échanger. ` + `Afin de faciliter la logistique des services, il n'est plus possible de l'échanger. ` +
`Si tu ne peux vraiment pas venir, tu seras noté.e absent.e à ton service. ` + `Si tu ne peux vraiment pas venir, tu seras noté.e absent.e à ton service. ` +
`Tu devras alors sélectionner un service de rattrapage sur ton espace membre.`); `Tu devras alors sélectionner un service de rattrapage sur ton espace membre.`);
} else if (error.status === 500 && error.msg === "Fail to create shift") {
alert(`Une erreur est survenue. ` +
`Il est néanmoins possible que la requête ait abouti, ` +
`veuillez patienter quelques secondes puis vérifier vos services enregistrés.`);
} else if (error.status === 400 && error.msg === "Bad arguments") {
alert(`Une erreur est survenue. ` +
`Il est néanmoins possible que la requête ait abouti, ` +
`veuillez patienter quelques secondes puis vérifier vos services enregistrés.`);
} else { } else {
alert(`Une erreur est survenue. ` + alert(`Une erreur est survenue. ` +
`Il est néanmoins possible que la requête ait abouti, ` + `Il est néanmoins possible que la requête ait abouti, ` +
...@@ -131,7 +162,7 @@ function init_shifts_list() { ...@@ -131,7 +162,7 @@ function init_shifts_list() {
shift_line_template.find(".shift_line_date").text(f_date_shift_start); shift_line_template.find(".shift_line_date").text(f_date_shift_start);
shift_line_template.find(".shift_line_time").text(datetime_shift_start.toLocaleTimeString("fr-fr", time_options)); shift_line_template.find(".shift_line_time").text(datetime_shift_start.toLocaleTimeString("fr-fr", time_options));
if (!can_exchange_shifts()) { if (!can_exchange_shifts() && block_actions_for_attached_people === "True") {
shift_line_template.find(".selectable_shift_line").removeClass("btn--primary"); shift_line_template.find(".selectable_shift_line").removeClass("btn--primary");
shift_line_template.find(".selectable_shift_line").addClass("btn"); shift_line_template.find(".selectable_shift_line").addClass("btn");
shift_line_template.find(".checkbox").prop("disabled", "disabled"); shift_line_template.find(".checkbox").prop("disabled", "disabled");
......
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