Skip to content
Snippets Groups Projects

fix issue with appointment length computation - #78

Merged Valentin Groues requested to merge 78-issue-with-appointment-duration into master
6 files
+ 245
197
Compare changes
  • Side-by-side
  • Inline
Files
6
function appointment_type_begaviour(selectObj, outObject,api_call) {
var appointment_types_data = null;
function get_appointment_type_by_id(id) {
for (var i=0 ;i <appointment_types_data.length;i++) {
if (id == appointment_types_data[i].id) {
return appointment_types_data[i];
}
function appointment_type_behaviour(checkboxes, outObject, api_call) {
var appointment_types_data = null;
var global_sequential_time = 0;
var global_time = 0;
var global_parallel_time = 0;
function recompute_parallel_time(object) {
var result = 0;
var object_id = -1;
if (object) {
object_id = object.attr('id');
}
$.each(checkboxes, function (index, value) {
var checkbox = $(value);
var val = parseInt(checkbox.attr('value'));
if (checkbox.is(":checked") || checkbox.attr('id') == object_id) {
var appointment_type = appointment_types_data[val];
if (appointment_type.can_be_parallelized) {
result = Math.max(result, appointment_type.default_duration)
}
}
});
return result;
}
return null;
}
function compute_time(object) {
var vals = object.val();
var time = 0;
var max_paralel_time = 0;
for (var i=0;i<vals.length;i++) {
var appointment_type = get_appointment_type_by_id(vals[i]);
if (appointment_type== null) {
console.log("Cannot find appointment type with id: "+vals[i]);
} else {
if (appointment_type.can_be_parallelized) {
max_paralel_time = Math.max(max_paralel_time,appointment_type.default_duration);
} else {
time +=appointment_type.default_duration;
function recompute_sequential_time(object) {
var result = 0;
var object_id = -1;
if (object) {
object_id = object.attr('id');
}
}
$.each(checkboxes, function (index, value) {
var checkbox = $(value);
var val = parseInt(checkbox.attr('value'));
if (checkbox.is(":checked") || checkbox.attr('id') == object_id) {
var appointment_type = appointment_types_data[val];
if (!appointment_type.can_be_parallelized) {
result += appointment_type.default_duration
}
}
});
return result;
}
time = Math.max(time, max_paralel_time)
$(outObject).val(time+"");
}
$(selectObj ).change(function() {
var object = $(this)
if (appointment_types_data===null) {
$.get(api_call, function(data) {
appointment_types_data= data.appointment_types;
compute_time(object);
});
} else {
compute_time(object);
function compute_time(object) {
var val = parseInt(object.attr('value'));
var time = 0;
var appointment_type = appointment_types_data[val];
if (appointment_type == null) {
console.log("Cannot find appointment type with id: " + val);
} else {
time = appointment_type.default_duration;
if (appointment_type.can_be_parallelized) {
if (object.is(":checked")) {
global_parallel_time = Math.max(global_parallel_time, time);
} else {
global_parallel_time = recompute_parallel_time();
}
} else {
if (object.is(":checked")) {
global_sequential_time += time;
} else {
global_sequential_time -= time;
}
}
global_time = Math.max(global_parallel_time, global_sequential_time);
$(outObject).val(global_time + "");
}
}
});
$(checkboxes).change(function () {
var object = $(this);
if (appointment_types_data === null) {
$.get(api_call, function (data) {
appointment_types_data = {};
$.each(data.appointment_types, function (index, appointment_type) {
appointment_types_data[appointment_type.id] = appointment_type;
});
global_parallel_time = recompute_parallel_time(object);
global_sequential_time = recompute_sequential_time(object);
compute_time(object)
});
} else {
compute_time(object);
}
});
}
Loading