Skip to content
Snippets Groups Projects
Commit 393b4111 authored by PavelBegunkov's avatar PavelBegunkov Committed by Роман Штейнберг
Browse files

Optimize rating events, refs #116

optimize rating events
optimize rating twig structure
parent 111d6478
Branches
Tags
No related merge requests found
...@@ -158,11 +158,11 @@ class GroupFilter { ...@@ -158,11 +158,11 @@ class GroupFilter {
// Скрываем все остальные группы // Скрываем все остальные группы
// 0 - показать все // 0 - показать все
filterGroups(groupID) { filterGroups(groupID) {
let groupClass = `group_${groupID}`; let $trs = this.$table.children().slice(3);
this.$table.children().slice(3).each((_, elem) => { $trs.show();
let matchGroup = groupID == 0 || $(elem).hasClass(groupClass);
matchGroup ? $(elem).show() : $(elem).hide(); if (+groupID !== 0)
}); $trs.not(`.group_${groupID}`).hide();
} }
listen($selector) { listen($selector) {
...@@ -234,7 +234,7 @@ function Rating() { ...@@ -234,7 +234,7 @@ function Rating() {
do { do {
row += dy; row += dy;
col += dx; col += dx;
currentCell = $(`#col_${col}_row_${row}`); currentCell = $(`#col_row_${col}_${row}`);
} while (currentCell.length > 0 && currentCell.children('input').attr('disabled') === 'disabled'); } while (currentCell.length > 0 && currentCell.children('input').attr('disabled') === 'disabled');
return currentCell; return currentCell;
}; };
...@@ -242,55 +242,9 @@ function Rating() { ...@@ -242,55 +242,9 @@ function Rating() {
let isFocusCell = false; // Стоит фокус на ячейке или нет let isFocusCell = false; // Стоит фокус на ячейке или нет
let oldRate = 0; let oldRate = 0;
var cancelFlag = false; var cancelFlag = false;
let initGeneralCells = function (finalize) {
var jCommonCell = $('.commonCell').not('.absenceCell').not('.autoPass');
jCommonCell.mouseenter(function () {
if (isFocusCell === false)
highlighter.focus($(this));
});
jCommonCell.mouseleave(function () {
if (isFocusCell === false)
highlighter.focusOut();
});
jCommonCell.focusin(function () {
isFocusCell = true;
highlighter.focus($(this));
rateInfo.show($(this));
var value = $(this).children('input').val();
oldRate = (value !== '') ? +value : -1;
});
jCommonCell.focusout(function () {
isFocusCell = false;
if (cancelFlag) {
var str = (oldRate != -1) ? oldRate : '';
$(this).children('input').val(str);
cancelFlag = false;
} else
setRate($(this), +oldRate);
highlighter.focusOut();
rateInfo.hide($(this));
finalize($(this));
});
jCommonCell.children('input').focusin(function () {
$(this).select();
});
// При нажатии на элемент commonCell дочерный input получает фокус
jCommonCell.click(function () {
$(this).children('input').focus();
});
// В inputCredit (где баллы вводить) разрешаем вводить только цифры
jCommonCell.children('input').keydown(KeyDownOnlyNumber);
let initGeneralCells = function (finalize) {
const keyDirs = { const keyDirs = {
27: Direction.Down, // esc 27: Direction.Down, // esc
13: Direction.Down, // enter 13: Direction.Down, // enter
...@@ -300,24 +254,53 @@ function Rating() { ...@@ -300,24 +254,53 @@ function Rating() {
37: Direction.Left // left arrow 37: Direction.Left // left arrow
}; };
jCommonCell.keydown(function (e) { $('.studentsRate tbody')
cancelFlag = cancelFlag || +e.keyCode === 27; // escape .on('mouseenter', '.commonCell', function() {
if (!(e.keyCode in keyDirs)) // if (isFocusCell === false)
return; highlighter.focus($(this));
})
let [col, row] = cursor.get(); .on('mouseleave', '.commonCell', function () {
let direction = keyDirs[e.keyCode]; if (isFocusCell === false)
let whereToMoveFocus = getDesiredCell(direction); highlighter.focusOut();
})
.on('focusin', '.commonCell', function () {
isFocusCell = true;
highlighter.focus($(this));
rateInfo.show($(this));
var value = $(this).children('input').val();
oldRate = (value !== '') ? +value : -1;
})
.on('focusout', '.commonCell', function () {
isFocusCell = false;
if (cancelFlag) {
var str = (oldRate != -1) ? oldRate : '';
$(this).children('input').val(str);
cancelFlag = false;
} else
setRate($(this), +oldRate);
if (whereToMoveFocus.length > 0) {
highlighter.focusOut(); highlighter.focusOut();
cursor.update(col, row); rateInfo.hide($(this));
whereToMoveFocus.children('input').focus(); finalize($(this));
} else })
$(this).children('input').blur(); .on('keydown', '.commonCell input', KeyDownOnlyNumber) // В inputCredit (где баллы вводить) разрешаем вводить только цифры
}); .on('keydown', '.commonCell', function (e) {
cancelFlag = cancelFlag || +e.keyCode === 27; // escape
if (!(e.keyCode in keyDirs)) //
return;
let [col, row] = cursor.get();
let direction = keyDirs[e.keyCode];
let whereToMoveFocus = getDesiredCell(direction);
if (whereToMoveFocus.length > 0) {
highlighter.focusOut();
cursor.update(col, row);
whereToMoveFocus.children('input').focus();
} else
$(this).children('input').blur();
});
}; };
...@@ -330,7 +313,7 @@ function Rating() { ...@@ -330,7 +313,7 @@ function Rating() {
// Открываем доступ к след. ячейке добора баллов // Открываем доступ к след. ячейке добора баллов
if ($this.hasClass('additionalCell')) { if ($this.hasClass('additionalCell')) {
let [col, row] = cursor.get(); let [col, row] = cursor.get();
let nextAdditionalCell = $(`#col_${col + 1}_row_${row}`); let nextAdditionalCell = $(`#col_row_${col + 1}_${row}`);
let placeholderMaxVal = (rateResult < 60) ? (60 - rateResult) : 0; let placeholderMaxVal = (rateResult < 60) ? (60 - rateResult) : 0;
if (nextAdditionalCell.hasClass('additionalCell')) { if (nextAdditionalCell.hasClass('additionalCell')) {
......
...@@ -150,17 +150,16 @@ ...@@ -150,17 +150,16 @@
{% if r.ModuleType == 'exam' %} {% if r.ModuleType == 'exam' %}
{% set td_class = 'commonCell attemptCell' %} {% set td_class = 'commonCell attemptCell' %}
{% endif %} {% elseif r.ModuleType == 'extra' %}
{% if r.ModuleType == 'extra' %}
{% set td_class = 'commonCell additionalCell' %} {% set td_class = 'commonCell additionalCell' %}
{% endif %} {% endif %}
{% if r.Blocked or (r.ModuleType != 'extra' and student.RateResult < 38) %} {% if r.Blocked or (r.ModuleType != 'extra' and student.RateResult < 38) %}
<td class="{{ td_class }}" id="col_{{ col }}_row_{{ row }}"> <td class="{{ td_class }}" id="col_row_{{ col }}_{{ row }}">
<input type="text" value="{{ r.Rate }}" disabled="disabled"> <input type="text" value="{{ r.Rate }}" disabled="disabled">
</td> </td>
{% else %} {% else %}
<td class="{{ td_class }}" id="col_{{ col }}_row_{{ row }}"> <td class="{{ td_class }}" id="col_row_{{ col }}_{{ row }}">
<input type="text" value="{{ r.Rate }}" <input type="text" value="{{ r.Rate }}"
{% if r.ModuleType == 'extra' %} {% if r.ModuleType == 'extra' %}
class = "extra" class = "extra"
...@@ -176,13 +175,13 @@ ...@@ -176,13 +175,13 @@
{% endif %} {% endif %}
{% if r.ModuleType == 'exam' %} {% if r.ModuleType == 'exam' %}
<td class="absenceCell {{ td_class }}" id="absence_{{col}}_{{row}}"> <td class="absenceCell" id="absence_{{col}}_{{row}}">
<input type="checkbox" class="absenceCheck" <input type="checkbox" class="absenceCheck"
{{ r.ExamPeriodOption == 'absence' ? 'checked="true"' }}> {{ r.ExamPeriodOption == 'absence' ? 'checked="true"' }}>
</td> </td>
{% if autoPassNotAdded %} {% if autoPassNotAdded %}
<td class="autoPass {{ td_class }}" id="autopass_{{col}}_{{row}}"> <td class="autoPass" id="autopass_{{col}}_{{row}}">
<input type="checkbox" class="autoPassCheck" <input type="checkbox" class="autoPassCheck"
{{ r.ExamPeriodOption == 'pass' ? 'checked="true"' }}> {{ r.ExamPeriodOption == 'pass' ? 'checked="true"' }}>
</td> </td>
......
...@@ -157,7 +157,7 @@ ...@@ -157,7 +157,7 @@
{% set j = j + 1 %} {% set j = j + 1 %}
{% if Module.Type == 'regular' or Module.Type == 'bonus' %} {% if Module.Type == 'regular' or Module.Type == 'bonus' %}
<td id="col_{{ j }}_row_{{row}}" class="{{ Discipline.Milestone ? 'staticCell' : 'commonCell' }}"> <td id="col_row_{{ j }}_{{row}}" class="{{ Discipline.Milestone ? 'staticCell' : 'commonCell' }}">
<input type="text" value="{{ rate }}"> <input type="text" value="{{ rate }}">
</td> </td>
{% else %} {% else %}
......
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