Skip to content
Snippets Groups Projects
Commit 77318aa1 authored by PavelBegunkov's avatar PavelBegunkov
Browse files

#98, Fix incorrect result rate after exam deletion

parent 3d90733d
Branches
Tags
No related merge requests found
......@@ -15,10 +15,14 @@ $.fn.extend({
turnOn: function () {
return $(this).prop('disabled', false)
},
turnOff: function () {
return $(this).prop('disabled', true)
},
aggregate: function (foo, init = 0) {
var res = init;
this.each((_, elem) => { res = foo(res, elem); });
return res;
}
});
var Auth = (function () {
......
......@@ -143,11 +143,7 @@ $(function () {
}
// суммарный добор
var extraRate = 0;
jExtraInputs.each(function () {
extraRate += +$(this).val();
});
var extraRate = jExtraInputs.aggregate((cur, elem) => +$(elem).val() + cur);
var row = +jRow.attr('id').substr(4); // одинаковая для всех
// Определим экзамен
......@@ -349,8 +345,8 @@ $(function () {
// Открываем доступ к след. ячейке добора баллов
if (jThis.hasClass('additionalCell')) {
nextAdditionalCell = $('#col_' + (g_col + 1) + '_row_' + g_row);
placeholderMaxVal = (rateResult < 60) ? (60 - rateResult) : 0;//(60 - oldRate);
var nextAdditionalCell = $('#col_' + (g_col + 1) + '_row_' + g_row);
var placeholderMaxVal = (rateResult < 60) ? (60 - rateResult) : 0;//(60 - oldRate);
if (nextAdditionalCell.hasClass('additionalCell')) {
var placeholderMax = (placeholderMaxVal > 0) ? placeholderMax = 'макс. ' + placeholderMaxVal : '---';
......@@ -396,7 +392,7 @@ $(function () {
// блокируем ячейку пока не обработаем коллбек
jThis.children('input').attr('disabled', true);
var rateResult = newRate;
var rateResult = Math.max(0, newRate);
var bonus = parseInt(jThis.siblings('.bonus').text());
// считаем баллы по строке
......@@ -404,26 +400,19 @@ $(function () {
{
// страница сессии
rateResult += parseInt(jThis.siblings('.semesterRateResultCell').text());
jThis.siblings('.additionalCell').each(function () {
if ($(this).children('input').val() !== '')
rateResult += +$(this).children('input').val();
});
jThis.siblings('.additionalCell').aggregate((init, elem) => +$(elem).children('input').val() + init);
}
if (newRate === -1)
rateResult += jThis.siblings('.attemptCell').not('.autoPass').not('.absenceCell')
.aggregate((init, elem) => Math.max(init, +$(elem).find('input').val()));
if (newRate <= g_submoduleMaxRate) {
if (newRate <= g_submoduleMaxRate)
setRate(newRate, jThis, oldRate, rateResult, bonus);
}
else {
if (oldRate <= g_submoduleMaxRate) {
if (oldRate != -1)
jThis.children('input').val(oldRate);
else
jThis.children('input').val('');
}
else
jThis.children('input').val('0');
var cellRate = (oldRate <= g_submoduleMaxRate)
? ((oldRate != -1) ? oldRate : '')
: '0';
jThis.children('input').val(cellRate);
EventInspector.error('Текущий балл превышает максимальный для данного модуля');
}
jThis.children('input').removeAttr('disabled');
......@@ -445,10 +434,8 @@ $(function () {
TdFocus($(this));
TdInfo($(this));
if ($(this).children('input').val() !== '') {
oldRate = $(this).children('input').val();
}
else oldRate = -1;
var value = $(this).children('input').val();
oldRate = (value !== '') ? +value : -1;
});
jCommonCell.focusout(function () {
......
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