2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function compute_moyenne() {
|
2022-09-03 20:48:56 +02:00
|
|
|
var notes = $(".tf_field_note input").map(
|
|
|
|
function () { return parseFloat($(this).val()); }
|
2020-09-26 16:19:37 +02:00
|
|
|
).get();
|
2022-09-03 20:48:56 +02:00
|
|
|
// les coefs sont donnes (ECTS en BUT)
|
|
|
|
let coefs = $("form.tf_ext_edit_ue_validations").data("ue_coefs");
|
|
|
|
// ou saisis (formations classiques)
|
|
|
|
if (coefs == 'undefined') {
|
|
|
|
coefs = $(".tf_field_coef input").map(
|
|
|
|
function () { return parseFloat($(this).val()); }
|
|
|
|
).get();
|
|
|
|
}
|
2020-09-26 16:19:37 +02:00
|
|
|
var N = notes.length;
|
|
|
|
var dp = 0.;
|
|
|
|
var sum_coefs = 0.;
|
2022-09-03 20:48:56 +02:00
|
|
|
for (var i = 0; i < N; i++) {
|
2020-09-26 16:19:37 +02:00
|
|
|
if (!(isNaN(notes[i]) || isNaN(coefs[i]))) {
|
|
|
|
dp += notes[i] * coefs[i];
|
|
|
|
sum_coefs += coefs[i];
|
|
|
|
}
|
|
|
|
}
|
2022-09-03 20:48:56 +02:00
|
|
|
let moy = dp / sum_coefs;
|
|
|
|
if (isNaN(moy)) {
|
|
|
|
moy = "-";
|
|
|
|
}
|
|
|
|
if (typeof moy == "number") {
|
|
|
|
moy = moy.toFixed(2);
|
|
|
|
}
|
|
|
|
return moy;
|
2020-09-26 16:19:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Callback select menu (UE code)
|
|
|
|
function enable_disable_fields_cb() {
|
|
|
|
enable_disable_fields(this);
|
|
|
|
}
|
2022-09-03 20:48:56 +02:00
|
|
|
function enable_disable_fields(select_elt) {
|
2020-09-26 16:19:37 +02:00
|
|
|
// input fields controled by this menu
|
2022-09-03 20:48:56 +02:00
|
|
|
var input_fields = $(select_elt).parent().parent().find('input:not(.ext_coef_disabled)');
|
2020-09-26 16:19:37 +02:00
|
|
|
var disabled = false;
|
|
|
|
if ($(select_elt).val() === "None") {
|
|
|
|
disabled = true;
|
|
|
|
}
|
2022-09-03 20:48:56 +02:00
|
|
|
input_fields.each(function () {
|
|
|
|
if (disabled) {
|
|
|
|
let cur_value = $(this).val();
|
|
|
|
$(this).data('saved-value', cur_value);
|
|
|
|
$(this).val("");
|
|
|
|
} else {
|
|
|
|
let saved_value = $(this).data('saved-value');
|
|
|
|
if (typeof saved_value == 'undefined') {
|
|
|
|
saved_value = '';
|
|
|
|
}
|
|
|
|
if (saved_value) {
|
|
|
|
$(this).val(saved_value);
|
|
|
|
}
|
2020-09-26 16:19:37 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
input_fields.prop('disabled', disabled);
|
|
|
|
}
|
|
|
|
function setup_text_fields() {
|
|
|
|
$(".ueext_valid_select").each(
|
2022-09-03 20:48:56 +02:00
|
|
|
function () {
|
2020-09-26 16:19:37 +02:00
|
|
|
enable_disable_fields(this);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-03 20:48:56 +02:00
|
|
|
$().ready(function () {
|
|
|
|
$(".tf_ext_edit_ue_validations").change(function () {
|
|
|
|
$(".ext_sem_moy_val")[0].innerHTML = compute_moyenne();
|
|
|
|
});
|
|
|
|
$("form.tf_ext_edit_ue_validations input").blur(function () {
|
|
|
|
$(".ext_sem_moy_val")[0].innerHTML = compute_moyenne();
|
2020-09-26 16:19:37 +02:00
|
|
|
});
|
2022-09-03 20:48:56 +02:00
|
|
|
$(".ueext_valid_select").change(enable_disable_fields_cb);
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
setup_text_fields();
|
|
|
|
});
|