var $ = jQuery; $(function() { var g_col; var g_row; var g_isFocusCell = false; // Стоит фокус или нет var g_oldRateCell = null; var g_submoduleID = null; var g_studentID = null; var g_submoduleTitle = ""; var g_submoduleMaxRate = 0; var g_stdName = ""; var jTdInfo_wrap = $("#tdInfo_wrap"); var jTdInfo = jTdInfo_wrap.children('#tdInfo'); var g_URL = (window.location.href).split("/"); var g_disciplineID = g_URL[g_URL.length - 1]; // studyGroupID для фильтра var json_settings = $.parseJSON($("#hidden_div").html()); $("#hidden_div").remove(); filterGroups(json_settings.studyGroupID); $(".groupSelector [value='"+ json_settings.studyGroupID +"']").attr("selected", "selected"); // Скрываем все остальные группы // 0 - показать все function filterGroups(groupID) { if (groupID == 0) { $(".studentsRate tbody") .children() .each( function() { $(this).show(); }); } else { $(".studentsRate tbody") .children(":gt(2)") .each( function() { if ($(this).hasClass(groupID)) $(this).show(); else $(this).hide(); }); } } // Ставим подстветку function TdFocus(jThis){ g_col = parseInt(jThis.attr('id')); g_row = parseInt(jThis.parent('tr').attr('id')); g_oldRateCell = jThis.children("input").val(); $(".RatingTableSubmodulesHeadMaxRate .col_" + g_col).css("background-color", "#f1f1f1"); $("td#" + g_col + ".rateCell").each(function(){ $(this).children('input').css("background-color", "#f1f1f1"); }); $("tr#" + g_row + " .rateCell").each(function(){ $(this).children('input').css("background-color", "#f1f1f1"); }); $("tr#" + g_row + " .staticCell").each(function(){ $(this).css("background-color", "#f1f1f1"); }); jThis.children('input').css("background-color", "#fff"); } // Убираем подстветку function TdUnFocus(){ $(".RatingTableSubmodulesHeadMaxRate .col_" + g_col).css("background-color", "#fff"); $("td#" + g_col + ".rateCell").each(function(){ $(this).children('input').css("background-color", "#fff"); }); $("tr#" + g_row + " .rateCell").each(function(){ $(this).children('input').css("background-color", "#fff"); }); $("tr#" + g_row + " .staticCell").each(function(){ $(this).css("background-color", "#fff"); }); } function TdInfo(jThis) { // Получаем подмодуль g_submoduleID = parseInt($(".RatingTableSubmodulesHeadMaxRate .col_"+g_col+":first").attr("id")); g_submoduleTitle = $(".RatingTableSubmodulesHead .col_"+g_col+":first").text(); if ($(".RatingTableSubmodulesHead .col_"+g_col+":first").length < 1 && $(".RatingTableModulesHead .bonus").length > 0 ) g_submoduleTitle = 'Бонусные баллы'; g_submoduleMaxRate = parseInt($(".RatingTableSubmodulesHeadMaxRate #"+g_submoduleID).children("input").val()); // Получаем студента g_studentID = parseInt(jThis.siblings('.student').attr("id")); g_stdName = jThis.siblings('.student').text(); jTdInfo_wrap.show(); jTdInfo.children("#student").children("b").html(g_stdName); jTdInfo.children("#submodule").children("b").html(g_submoduleTitle); jTdInfo.children("#maxRate").children("b").html(g_submoduleMaxRate); //if (jThis.children('.tdInfo').length <= 0) // jThis.append("<div class='tdInfo'>"+g_submoduleTitle+"<br>"+g_stdName+"</div>"); } function UnsetTdInfo(jThis){ //jThis.children(".tdInfo").remove(); jTdInfo_wrap.hide(); g_submoduleID = null; g_studentID = null; g_submoduleMaxRate = 0; } function Rating(jThis, oldRate) { 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 maxRate = parseInt($(".RatingTableSubmodulesHeadMaxRate #"+g_submoduleID).children("input").val()); var rateResult = parseInt(jThis.siblings(".RateResult").text()) - oldRate + newRate; if (rateResult > 100) { jThis.children("input").val(oldRate); EventInspector_ShowMsg("Сумма баллов не может привышать 100", "error"); jThis.children("input").removeAttr("disabled"); } else { 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) { jThis.siblings(".RateResult").text(rateResult); 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"); } } } $(".rateCell").mouseenter(function(){ if (g_isFocusCell === false) TdFocus($(this)); }); $(".rateCell").mouseleave(function(){ if (g_isFocusCell === false) TdUnFocus(); }); var oldRate = 0; $(".rateCell").focusin(function(){ g_isFocusCell = true; TdFocus($(this)); TdInfo($(this)); if ($(this).children("input").val() !== "") oldRate = $(this).children("input").val(); else oldRate = 0; }); $(".rateCell").focusout(function(){ g_isFocusCell = false; var newRate = 0; if ($(this).children("input").val() !== "") newRate = $(this).children("input").val(); if (newRate != oldRate) Rating($(this), oldRate); TdUnFocus(); UnsetTdInfo($(this)); }); $(".rateCell").keyup(function(e){ var jThis = $(this); var row = g_row; var col = g_col; // При нажатие Enter (переход к оцениванию след. студента, т.е. ниже) if(e.keyCode==13) row = row + 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) col = col - 1; if ((e.keyCode >= 37 && e.keyCode <= 40) || e.keyCode == 13 ) { var jTempObj = $("tr#" + row + " td#" + col + ".rateCell"); if (jTempObj.length > 0) { TdUnFocus(); g_row = row; g_col = col; jTempObj.children("input").focus(); } } }); $(".rateCell input").focusin(function(){ $(this).select(); }); // При нажатие на элемент rateCell дочерный input получает фокус $(".rateCell ").click(function(){ $(this).children("input").focus(); } ); // В inputCredit (где баллы вводить) разрешаем вводить только цифры $(".rateCell").children("input").keydown(function(event) { KeyDownOnlyNumber(event); }); // Фильтр по группе $(".groupSelector").change(function() { var val = parseInt($(this).val()); // StudyGroupID if (val >= 0) { filterGroups(val); $.post( URLdir + "handler/rating/SelectGroup", { "disciplineID": g_disciplineID, "groupSelected": val }, function(data){ data = $.parseJSON(data); if(data.success === true) { } } ); } }); $(".downloadExcel").click(function(){ $.fileDownload(URLdir + 'handler/rating/GetExcelRateTable', { httpMethod: "POST", data: { 'disciplineID': g_disciplineID }, successCallback: function (url) { // $('#downloadStudentPDF').removeAttr('disabled'); } // failCallback: function (html, url) { // $('#downloadStudentPDF').removeAttr('disabled'); // alert(html); // } }); }); });