Commit 2e87daab by François C.

Fix some shift calendar bugs

parent e08214b3
Pipeline #2401 passed with stage
in 1 minute 25 seconds
......@@ -185,15 +185,12 @@ function display_member_info() {
* Set calendar and associated listeners.
*/
function set_subscription_area() {
retrieve_and_draw_shift_tempates();
retrieve_and_draw_shift_tempates({shift_listener: false});
$("#shifts_calendar_area").show();
// Wait for listeners to be set in common.js
// TODO use "signals" to avoid waiting an arbitrary time
setTimeout(() => {
// Cancel listeners from subscription page & set custom listeners
$("#shifts_calendar_area button[data-select='Volant']").off("click");
$("#shifts_calendar_area button[data-select='Volant']").on("click", function() {
$(document).off("click", "#shifts_calendar_area button[data-select='Volant']");
$(document).on("click", "#shifts_calendar_area button[data-select='Volant']", function() {
// Subscribe to comitee/ftop shift
msg = (has_committe_shift === "True")
? `Inscrire ${selected_member.name} au service des Comités ?`
......@@ -208,9 +205,8 @@ function set_subscription_area() {
false
);
});
$(".shift").off("click");
$(".shift").on("click", function() {
$(document).off("click", ".shift");
$(document).on("click", ".shift", function() {
// Subscribe to shift template
let shift_template_id = select_shift_among_compact(null, this, false); // method from common.js
let shift_template_data = shift_templates[shift_template_id].data;// shift_templates: var from common.js
......@@ -225,7 +221,7 @@ function set_subscription_area() {
false
);
});
}, 1000);
}
/**
......
......@@ -38,7 +38,7 @@ sync.on('change', function (info) {
});
if (need_reload == true) {
//On recharge depuis Odoo et on traite les enregistrements depuis CouchDB
retrieve_and_draw_shift_tempates('without_modal');
retrieve_and_draw_shift_tempates({without_modal: true, shift_listener: true});
}
}
......
......@@ -95,8 +95,7 @@ function process_asked_shift_template_change(shift_t_id) {
}
function edit_shift_template_registration() {
let external = true;
const calendar_params = {external: true, without_modal: true, shift_listener: true};
if (calendar == null) calendar = $('#modal-calendar-choice').clone();
if ($('#modal-calendar-choice').html().length > 0) {
$('#modal-calendar-choice').empty();
......@@ -106,9 +105,9 @@ function edit_shift_template_registration() {
displayMsg(calendar.html());
$('#week_types').find('input')
.change(() => {
filter_weeks(external);
filter_weeks(calendar_params);
});
retrieve_and_draw_shift_tempates(external);
retrieve_and_draw_shift_tempates(calendar_params);
}
......
......@@ -181,8 +181,11 @@ function draw_table(begin_hours, callback) {
}
function draw_shift_templates(external) {
if (typeof external !== "undefined" && external == true) shift_table = $('#shift_choice table');
function draw_shift_templates(params) {
if (params && typeof params.external !== "undefined" && params.external == true){
// Simplified calendar loaded in modal (members_space for ex.)
shift_table = $('#shift_choice table');
}
var existing_shifts = shift_table.find('.shift');
existing_shifts.off("click", single_shift_click);
......@@ -291,7 +294,9 @@ function draw_shift_templates(external) {
});
if (type == 1) {
shift_table.find('.shift').on("click", single_shift_click);
if (!params || (typeof params.shift_listener !== "undefined" && params.shift_listener == true)){
shift_table.find('.shift').on("click", single_shift_click);
}
}
if (type == 2) {
for (k in boxes) {
......@@ -315,13 +320,15 @@ function draw_shift_templates(external) {
}
}
shift_table.find('.shift').on("click", select_shift_among_compact);
if (!params || (typeof params.shift_listener !== "undefined" && params.shift_listener == true)){
shift_table.find('.shift').on("click", select_shift_among_compact);
}
}
sc_lat.find('.info').html(dispo + ' places disponibles<br />(/'+max+')');
if (typeof external == "undefined") {
if (!params || typeof params.without_modal === "undefined" || (typeof params.without_modal !== "undefined" && params.without_modal == false)) {
closeModal();
}
});
......@@ -329,13 +336,12 @@ function draw_shift_templates(external) {
}
function retrieve_and_draw_shift_tempates(external) {
function retrieve_and_draw_shift_tempates(params) {
if (shift_table.length == 0) shift_table = $('#shift_choice table');
if (!external) {
if (!params || typeof params.without_modal === "undefined" || (typeof params.without_modal !== "undefined" && params.without_modal == false)) {
openModal();
}
shift_table.find('.shift').remove();
$.ajax({url : st_url,
dataType :'json'
......@@ -374,10 +380,10 @@ function retrieve_and_draw_shift_tempates(external) {
}
});
draw_shift_templates(external);
draw_shift_templates(params);
});
} else {
draw_shift_templates(external);
draw_shift_templates(params);
}
......@@ -385,7 +391,7 @@ function retrieve_and_draw_shift_tempates(external) {
});
}
function filter_weeks(external) {
function filter_weeks(params) {
var clicked = $(this);
var week_types = $('#week_types');
var parent_div = clicked.closest('div');
......@@ -430,7 +436,7 @@ function filter_weeks(external) {
if (!w2.is(':checked') || !w4.is(':checked')) {
$('#odd_weeks').prop('checked', false);
}
draw_shift_templates(external);
draw_shift_templates(params);
}
function shift_loc_selection() {
......
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