diff --git a/~dev_rating/media/js/rating.js b/~dev_rating/media/js/rating.js index 126ba8bd20a3ffb7c25ec0effa7b3006a804a495..2a8674c5ebc505084d7959d99d5518057f4f4bbe 100644 --- a/~dev_rating/media/js/rating.js +++ b/~dev_rating/media/js/rating.js @@ -21,28 +21,26 @@ $(function() { $("div.main_content").ready(AdjustTable); $(window).resize(AdjustTable); + function controlRowVisualization(jRow) { + var jAutoPassCheckBox = jRow.children(".autoPass").children(".autoPassCheck"); + var semesterRate = parseInt(jRow.children(".semesterRateResultCell").text()); + var absence = jRow.children(".absenceCell").children(".absenceCheck").is(":checked"); + if ((semesterRate < 60) || (absence)) + jAutoPassCheckBox.attr("disabled", true); + else + jAutoPassCheckBox.removeAttr("disabled"); + } - - function controlRowVisualization(jRow) { - var jAutoPassCheckBox = jRow.children(".autoPass").children(".autoPassCheck"); - var semesterRate = parseInt(jRow.children(".semesterRateResultCell").text()); - var absence = jRow.children(".absenceCell").children(".absenceCheck").is(":checked"); - if ((semesterRate < 60) || (absence)) - jAutoPassCheckBox.attr("disabled", true); - else - jAutoPassCheckBox.removeAttr("disabled"); - } - - function controlVisualization() { - $(".autoPassCheck") + function controlVisualization() { + $(".autoPassCheck") .each( function() { - controlRowVisualization($(this).parent().parent()); - }); - } + controlRowVisualization($(this).parent().parent()); + }); + } // on page loaded - controlVisualization(); - + //controlVisualization(); + var g_col; var g_row; var g_isFocusCell = false; // Стоит фокус РЅР° ячейки или нет @@ -62,7 +60,6 @@ $(function() { // + ID - id дисциплины // + studyGroupID_Filter - studyGroupID для фильтра (Рффект памяти) var json_settings = $.parseJSON($("#hidden_div").html()); - //console.log(json_settings); $("#hidden_div").remove(); filterGroups(json_settings.GroupID_Filter); $(".groupSelector [value='"+ json_settings.GroupID_Filter +"']").attr("selected", "selected"); @@ -72,10 +69,10 @@ $(function() { function filterGroups(groupID) { if (groupID == 0) { $(".studentsRate tbody") - .children() - .each( function() { + .children() + .each( function() { $(this).show(); - }); + }); } else { $(".studentsRate tbody") .children(":gt(2)") @@ -91,10 +88,10 @@ $(function() { // Ставим подстветку function TdFocus(jThis){ g_col = jThis.attr('id'); - g_col = parseInt(g_col.substr(4)); + g_col = parseInt(g_col.substr(4)); g_row = jThis.parent('tr').attr('id'); - g_row = parseInt(g_row.substr(4)); - + g_row = parseInt(g_row.substr(4)); + g_oldRateCell = jThis.children("input").val(); $("td#col_" + g_col + ".commonCell").each(function(){ $(this).children('input').css("background-color", "#f1f1f1"); @@ -112,7 +109,7 @@ $(function() { }); jThis.children('input').css("background-color", "#fff"); } - + // Убираем подстветку function TdUnFocus(){ $("td#col_" + g_col + ".commonCell").each(function(){ @@ -130,39 +127,38 @@ $(function() { $(this).children('input').css("background-color", "#fff"); }); } - + function TdInfo(jThis) { - var disciplineType = json_settings.ExamType; - var disciplinePassRate = 60; // credit pass rate - if (disciplineType === "exam") - disciplinePassRate = 38; + var disciplineType = json_settings.ExamType; + var disciplinePassRate = 60; // credit pass rate + if (disciplineType === "exam") + disciplinePassRate = 38; // Получаем подмодуль var jCurSubmoduleInfo = $(".RatingTableSubmodulesInfo .col_"+g_col+":first"); var jCurSubmoduleHead = $(".RatingTableSubmodulesHead .col_"+g_col+":first"); - g_submoduleID = parseInt(jCurSubmoduleInfo.attr("id")); + g_submoduleID = parseInt(jCurSubmoduleInfo.attr("id")); g_submoduleTitle = jCurSubmoduleHead.text(); if (jCurSubmoduleHead.length < 1 && $(".RatingTableModulesHead .bonus").length > 0 ) g_submoduleTitle = 'Бонусные баллы'; - g_submoduleMaxRate = parseInt($(".RatingTableSubmodulesHeadMaxRate .col_"+g_col).text()); - console.log(g_col); + g_submoduleMaxRate = parseInt($(".RatingTableSubmodulesHeadMaxRate .col_"+g_col).text()); + - - // Проверяем допустимое значение (только для РґРѕР±РѕСЂР°) + // Проверяем допустимое значение (только для РґРѕР±РѕСЂР°) if (jThis.attr("class").indexOf("additionalCell") >= 0) { - var semesterRate = parseInt(jThis.siblings(".semesterRateResultCell").text()); - if (semesterRate <= disciplinePassRate) - g_submoduleMaxRate = disciplinePassRate - semesterRate; - else - g_submoduleMaxRate = 0; + var semesterRate = parseInt(jThis.siblings(".semesterRateResultCell").text()); + if (semesterRate <= disciplinePassRate) + g_submoduleMaxRate = disciplinePassRate - semesterRate; + else + g_submoduleMaxRate = 0; } // Получаем студента g_studentID = jThis.siblings('.studentCell').attr("id"); - g_studentID = g_studentID.substr(8); - + g_studentID = g_studentID.substr(8); + g_stdName = jThis.siblings('.studentCell').text(); jTdInfo_wrap.show(); @@ -186,83 +182,83 @@ $(function() { oldRate = parseInt(oldRate); // Здесь jThis - div rateCell, Р° РЅРµ input, который является дочкой jThis.children("input").attr("disabled", true); - - var newRate = 0; - if (jThis.children("input").val() !== "") - newRate = parseInt(jThis.children("input").val()); - var rateResult = newRate; - - // считаем баллы РїРѕ строке - if ($("#pageType").val() === "exam") //(jThis.attr("class").indexOf("attemptCell") >= 0) - { - // страница сессии - rateResult += parseInt(jThis.siblings(".semesterRateResultCell").text()); - - jThis.siblings(".additionalCell").each(function(){ - if ($(this).children("input").val() !== "") - rateResult += parseInt($(this).children("input").val()); - }); - } - else if ($("#pageType").val() === "rating") - { - // страница оценивания - jThis.siblings(".commonCell").each(function(){ // добавим СЃСѓРјРјСѓ баллов РІ соседних ячейках - var rate = $(this).children("input").val(); - if (rate) - rateResult += parseInt(rate); - }); - var examRateStr = jThis.siblings(".examCell").children("p").text(); - if (examRateStr) - rateResult += parseInt(examRateStr); - } - - if (newRate <= g_submoduleMaxRate) - { - $.ajax({ - type: "POST", - url: URLdir + "handler/rating/setRate", - data: "student="+g_studentID+"&submodule="+g_submoduleID+"&rate="+newRate, - statusCode: { - 403: function() { - EventInspector_ShowMsg("Сессия истекла", "error"); - jThis.children("input").val(oldRate); - jThis.children("input").removeAttr("disabled"); - window.location.replace(URLdir); - }, - 200: function(data) { - data = $.parseJSON(data); - if(data.success === true) { - var correctRate = (rateResult > 100) ? '100+' : rateResult; - jThis.siblings(".rateResultCell").text(correctRate); - EventInspector_ShowMsg("Балл добавлен/изменен", "success"); - } - else EventInspector_ShowMsg("РќРµ удалось добавить/изменить балл", "error"); - jThis.children("input").removeAttr("disabled"); - } - } - }); - } - else { - if (oldRate <= g_submoduleMaxRate) - jThis.children("input").val(oldRate); - else - jThis.children("input").val("0"); - - EventInspector_ShowMsg("Текущий балл превышает максимальный для данного модуля", "error"); - jThis.children("input").removeAttr("disabled"); - } + + var newRate = 0; + if (jThis.children("input").val() !== "") + newRate = parseInt(jThis.children("input").val()); + var rateResult = newRate; + + // считаем баллы РїРѕ строке + if ($("#pageType").val() === "exam") //(jThis.attr("class").indexOf("attemptCell") >= 0) + { + // страница сессии + rateResult += parseInt(jThis.siblings(".semesterRateResultCell").text()); + + jThis.siblings(".additionalCell").each(function(){ + if ($(this).children("input").val() !== "") + rateResult += parseInt($(this).children("input").val()); + }); + } + else if ($("#pageType").val() === "rating") + { + // страница оценивания + jThis.siblings(".commonCell").each(function(){ // добавим СЃСѓРјРјСѓ баллов РІ соседних ячейках + var rate = $(this).children("input").val(); + if (rate) + rateResult += parseInt(rate); + }); + var examRateStr = jThis.siblings(".examCell").children("p").text(); + if (examRateStr) + rateResult += parseInt(examRateStr); + } + + if (newRate <= g_submoduleMaxRate) + { + $.ajax({ + type: "POST", + url: URLdir + "handler/rating/setRate", + data: "student="+g_studentID+"&submodule="+g_submoduleID+"&rate="+newRate, + statusCode: { + 403: function() { + EventInspector_ShowMsg("Сессия истекла", "error"); + jThis.children("input").val(oldRate); + jThis.children("input").removeAttr("disabled"); + window.location.replace(URLdir); + }, + 200: function(data) { + data = $.parseJSON(data); + if(data.success === true) { + var correctRate = (rateResult > 100) ? '100+' : rateResult; + jThis.siblings(".rateResultCell").text(correctRate); + EventInspector_ShowMsg("Балл добавлен/изменен", "success"); + } + else EventInspector_ShowMsg("РќРµ удалось добавить/изменить балл", "error"); + jThis.children("input").removeAttr("disabled"); + } + } + }); + } + else { + if (oldRate <= g_submoduleMaxRate) + jThis.children("input").val(oldRate); + else + jThis.children("input").val("0"); + + EventInspector_ShowMsg("Текущий балл превышает максимальный для данного модуля", "error"); + jThis.children("input").removeAttr("disabled"); + } } - + $(".commonCell").mouseenter(function(){ if (g_isFocusCell === false) TdFocus($(this)); }); - + $(".commonCell").mouseleave(function(){ if (g_isFocusCell === false) TdUnFocus(); }); - + var oldRate = 0; $(".commonCell").focusin(function(){ g_isFocusCell = true; @@ -272,7 +268,7 @@ $(function() { oldRate = $(this).children("input").val(); else oldRate = 0; }); - + $(".commonCell").focusout(function(){ g_isFocusCell = false; var newRate = 0; @@ -282,77 +278,122 @@ $(function() { Rating($(this), oldRate); TdUnFocus(); UnsetTdInfo($(this)); - controlRowVisualization($(this).parent()); + controlRowVisualization($(this).parent()); }); - - $(".commonCell").keydown(function(e){ - var jThis = $(this); + var Direction = { + Up: 0, + Right: 1, + Down: 2, + Left: 3 + }; + + /** + * @param direction Direction РІ каком направлении искать следующую ячейку для перемещения фокуса + * @return jQuery клетка, РІ которую надо переместиться или null, если РІ этом направлении нет подходящих ячеек + */ + function getDesiredCell(direction) { + /** Будем искать ячейку РІ направлении {@see direction} РґРѕ тех РїРѕРєР° РЅРµ найдем её Рё РїРѕРєР° РЅРµ + * кончатся ячейки РІ этом направлении */ var row = g_row; var col = g_col; + var currentCell; + switch (direction) { + case Direction.Up: + do { + row--; + currentCell = $("tr#row_" + row + " td#col_" + g_col + ".commonCell") + } while ((currentCell.length > 0) && + (currentCell.children("input").attr("disabled") == "disabled")); + return currentCell; + case Direction.Right: + do { + col++; + currentCell = $("tr#row_" + g_row + " td#col_" + col + ".commonCell") + } while ((currentCell.length > 0) && + (currentCell.children("input").attr("disabled") == "disabled")); + return currentCell; + case Direction.Down: + do { + row++; + currentCell = $("tr#row_" + row + " td#col_" + g_col + ".commonCell") + } while ((currentCell.length > 0) && + (currentCell.children("input").attr("disabled") == "disabled")); + return currentCell; + case Direction.Left: + do { + col--; + currentCell = $("tr#row_" + g_row + " td#col_" + col + ".commonCell") + } while ((currentCell.length > 0) && + (currentCell.children("input").attr("disabled") == "disabled")); + return currentCell; + } + return null; + } - // РџСЂРё нажатие Enter (переход Рє оцениванию след. студента, С‚.Рµ. ниже) - if(e.keyCode==13) - row = row + 1; - - // Стрелка влево - if(e.keyCode==37) - col = col - 1; - - // Стрелка вверх - if(e.keyCode==38) - row = row - 1; - - // Стрелка вправо - if(e.keyCode==39) - col = col + 1; - - // Стрелка РІРЅРёР· - if(e.keyCode==40) - row = row + 1; - - - if ((e.keyCode >= 37 && e.keyCode <= 40) || e.keyCode == 13 ) { - var jTempObj = $("tr#row_" + row + " td#col_" + col + ".commonCell"); - if (jTempObj.length > 0) { - TdUnFocus(); - g_row = row; - g_col = col; - jTempObj.children("input").focus(); - } + $(".commonCell").keydown(function(e){ + var row = g_row; + var col = g_col; + var direction; + switch (e.keyCode) { + case 13: // enter + direction = Direction.Down; + break; + case 38: // up arrow + direction = Direction.Up; + break; + case 39: // right arrow + direction = Direction.Right; + break; + case 40: // down arrow + direction = Direction.Down; + break; + case 37: // left arrow + direction = Direction.Left; + break; + default: + return; } + var whereToMoveFocus = getDesiredCell(direction); + if (whereToMoveFocus.length > 0) { + TdUnFocus(); + g_row = row; + g_col = col; + whereToMoveFocus.children("input").focus(); + } else + $(this).children("input").blur(); }); - + $(".commonCell input").focusin(function(){ $(this).select(); }); - + // РџСЂРё нажатии РЅР° элемент commonCell дочерный input получает фокус $(".commonCell ").click(function(){ $(this).children("input").focus(); } ); - + // Р’ inputCredit (РіРґРµ баллы вводить) разрешаем вводить только цифры $(".commonCell").children("input").keydown(function(event) { KeyDownOnlyNumber(event); }); - - // Нажатие РЅР° чекбокс "Автомат" - $(".absenceCheck").click(function(event) { - controlRowVisualization($(this).parent().parent()); + + // Нажатие РЅР° чекбокс "Автомат" + $(".absenceCheck").click(function(event) { + controlRowVisualization($(this).parent().parent()); }); // Фильтр РїРѕ РіСЂСѓРїРїРµ $(".groupSelector").change(function() { - var group = $(this).val(); + var group = $(this).val(); if (group >= 0) { filterGroups(group); $.post( URLdir + "handler/rating/SelectGroup", - { + { "disciplineID": g_disciplineID, - "groupSelected": group + "groupSelected": group }, function(data){ data = $.parseJSON(data); @@ -368,7 +409,7 @@ $(function() { $(".downloadExcel").click(function(){ $.fileDownload(URLdir + 'handler/FileCreator/GenerateExcelRatingTable', { httpMethod: "POST", - data: + data: { 'disciplineID': g_disciplineID }, @@ -382,10 +423,10 @@ $(function() { }); // Ведомость РІ формате excel - $('body').on('click', '.downloadExcelStatement', function(){ + $('body').on('click', '.downloadExcelStatement', function(){ $.fileDownload(URLdir + 'handler/FileCreator/GenerateFinalForm', { httpMethod: "POST", - data: + data: { "disciplineID": g_disciplineID, "studyGroupID": parseInt($(this).attr("id").substr(6)) @@ -399,7 +440,7 @@ $(function() { }); }); - + });