diff --git a/media/js/discipline/editStructure.js b/media/js/discipline/editStructure.js index 44124c6a5a2f6bf80de0f2c584370442022923a8..9b0f38a266874cb0feadeac96f30a1c2dc09c190 100644 --- a/media/js/discipline/editStructure.js +++ b/media/js/discipline/editStructure.js @@ -1,4 +1,4 @@ -var $ = jQuery; +let $ = jQuery; $(document).ready(function () { @@ -17,7 +17,7 @@ $(document).ready(function () { $.fn.extend({ sum: function (asText) { - var sum = 0; + let sum = 0; this.each(function () { sum += parseInt(0 + ( asText ? $(this).text() : $(this).val() )) }); @@ -57,7 +57,7 @@ $(document).ready(function () { )), newModule: (moduleID, submoduleID) => { - var node = templates.$module.clone().data({ id: moduleID, type: 'module' }).addClass(DATA_CLASS); + let node = templates.$module.clone().data({ id: moduleID, type: 'module' }).addClass(DATA_CLASS); node.children('div.submodules').append(templates.newSubmodule(submoduleID)); return node; }, @@ -95,7 +95,7 @@ $(document).ready(function () { }; function recountRates($submodules) { - var maxCredits = $('input.inputCurrentControl', $submodules).sum(); + let maxCredits = $('input.inputCurrentControl', $submodules).sum(); $submodules.prev().children('div.currentControl').text(maxCredits); maxCredits = $('input.inputLandmarkControl', $submodules).sum(); @@ -103,7 +103,7 @@ $(document).ready(function () { } function swapElements($lower, $upper, speed) { - var lowerRoute = $upper.offset().top - $lower.offset().top, + let lowerRoute = $upper.offset().top - $lower.offset().top, upperRoute = lowerRoute + $upper.height() - $lower.height(); $.when( @@ -120,36 +120,36 @@ $(document).ready(function () { let lower = dataOf($lower); $.postJSON(URL.discipline.map.swapModules, { type: lower.type, ID1: lower.id, ID2: dataOf($upper).id }) - .fail(_ => Popup.error(`Ошибка при изменении порядка ${lower.type == 'module' ? 'модулей' : 'мероприятий'}`)) + .fail(_ => Popup.error(`Ошибка при изменении порядка ${lower.type === 'module' ? 'модулей' : 'мероприятий'}`)) .done(_ => swapElements($lower, $upper)) } - var $modules = $('.moduleList'); + let $modules = $('.moduleList'); $modules.on('click', '.moveUp', ({ target: node }) => { - let className = (dataOf(node).type == 'module') ? '.moduleGroup' : '.submodule', + let className = (dataOf(node).type === 'module') ? '.moduleGroup' : '.submodule', $current = $(node).parents(className), $upper = $current.prev(className); - + console.log('move up'); $upper.length ? swapModules($current, $upper) : Popup.error('Переместить выше нельзя'); }); $modules.on('click', '.moveDown', ({ target: node }) => { - let className = (dataOf(node).type == 'module') ? '.moduleGroup' : '.submodule', + let className = (dataOf(node).type === 'module') ? '.moduleGroup' : '.submodule', $current = $(node).parents(className), $lower = $current.next(className); - + console.log('move down'); $lower.length ? swapModules($lower, $current) : Popup.error('Переместить ниже нельзя'); }); $('.addModule').click(function () { - var $addModule = $(this).turnOff(); + let $addModule = $(this).turnOff(); $.postJSON(API.addModule, { 'id': $addModule.data().discipline }) .done(({ module: mID, submodule: smID }) => { - var $module = templates.newModule(mID, smID), + let $module = templates.newModule(mID, smID), $place = $('.moduleList').children('.moduleGroup').last(); $place.length > 0 ? $place.after($module) : $('.moduleList').prepend($module); @@ -163,12 +163,12 @@ $(document).ready(function () { }); $modules.on('click', 'button.addSubmodule', ({ target: button }) => { - var $addSubButton = $(button).turnOff(), + let $addSubButton = $(button).turnOff(), moduleID = dataOf($addSubButton).id; $.postJSON(API.addSubmodule, { 'module': moduleID }) .done(({ submodule: id }) => { - var $submodule = templates.newSubmodule(id); + let $submodule = templates.newSubmodule(id); $addSubButton.siblings('.submodules').append($submodule); $submodule.slideDown(200); }) @@ -196,23 +196,23 @@ $(document).ready(function () { .done(_ => { $module.slideUp(200, _ => $module.remove()); - var $modulesHead = $modules.children('.moduleHead'), + let $modulesHead = $modules.children('.moduleHead'), currentCtrl = $modulesHead.children('.currentControl').sum(true), landmarkCtrl = $modulesHead.children('.landmarkControl').sum(true); - var exam = $('div.ExamModule').length ? 40 : 0; + let exam = $('div.ExamModule').length ? 40 : 0; $('span.rateIndicator').html(currentCtrl + landmarkCtrl + exam); // todo: use $.hide() / $.show() // todo: move to twig template with style "hidden" - if ($('.moduleGroup').length == 0) + if ($('.moduleGroup').length === 0) $('.moduleList').prepend('<div class="empty"><p class="notification">Модули отсутствуют</p></div>'); }) .fail(_ => Popup.error('Ошибка при удалении модуля')) }); $modules.on('click', '.confirmDeleteSubmodule ', function () { - var $submodule = $(this).parents('.submodule'); + let $submodule = $(this).parents('.submodule'); if ($submodule.siblings('.submodule').andSelf().size() <= 1) return Popup.error('Невозможно удалить единственное мероприятие в модуле.'); @@ -221,10 +221,10 @@ $(document).ready(function () { $.postJSON(API.deleteModule, { id: dataOf($submodule).id, type: 'submodule' }) .done(_ => { - var difC = parseInt($submodule.find('div.currentControl').find('input').val()), + let difC = parseInt($submodule.find('div.currentControl').find('input').val()), difL = parseInt($submodule.find('div.landmarkControl').find('input').val()); - var $moduleHead = $submodule.parents('.moduleGroup').find('.moduleHead'), + let $moduleHead = $submodule.parents('.moduleGroup').find('.moduleHead'), oldC = parseInt($moduleHead.find('div.currentControl').html()), oldL = parseInt($moduleHead.find('div.landmarkControl').html()); @@ -233,7 +233,7 @@ $(document).ready(function () { $moduleHead.children('div.landmarkControl').html(oldL - difL); // change sum rate - var rateIndicator = $('span.rateIndicator'), + let rateIndicator = $('span.rateIndicator'), old = +rateIndicator.html(); rateIndicator.html(old - difC - difL); @@ -257,18 +257,18 @@ $(document).ready(function () { newName = $input.val(), unit = dataOf($input); - if ($input.data('last-name') == newName) return; + if ($input.data('last-name') === newName) return; $input.data('last-name', $input.val()); $.postJSON(API.setModuleName, { id: unit.id, type: unit.type, name: newName }) - .fail(_ => Popup.error(`Ошибка при изменении названия ${unit.type == 'module' ? 'модуля' : 'мероприятия'}`)) - }; + .fail(_ => Popup.error(`Ошибка при изменении названия ${unit.type === 'module' ? 'модуля' : 'мероприятия'}`)) + } // Update rates $modules.on('keydown', 'input.inputCredit', keyDownOnlyNumber); - var oldMaxRate = 0; + let oldMaxRate = 0; $modules.on('focusin', 'input.inputCurrentControl, input.inputLandmarkControl', e => oldMaxRate = $(e.target).select().val()); @@ -276,20 +276,20 @@ $(document).ready(function () { e => setNewRateAndControl($(e.target).turnOff(), oldMaxRate)); function setNewRateAndControl($rateInput, oldMaxRate) { - var $moduleHeads = $('.moduleHead'), + let $moduleHeads = $('.moduleHead'), currentControl = $moduleHeads.children('.currentControl').sum(true), landmarkControl = $moduleHeads.children('.landmarkControl').sum(true); // Макс. балл соседней ячейки - var subtract = parseInt(0 + $rateInput.parent().siblings().children('.inputCredit').val()), + let subtract = parseInt(0 + $rateInput.parent().siblings().children('.inputCredit').val()), newMaxRate = parseInt(0 + $rateInput.val()), isExam = $('div.ExamModule').length > 0, maxPossibleSumRate = isExam ? 60 : 100; - var rateIndicator = currentControl + landmarkControl + newMaxRate - subtract - oldMaxRate; + let rateIndicator = currentControl + landmarkControl + newMaxRate - subtract - oldMaxRate; if (rateIndicator > maxPossibleSumRate) { - if (newMaxRate == 0) { + if (newMaxRate === 0) { $rateInput.val(0); } else { $rateInput.turnOn().val(oldMaxRate); @@ -298,10 +298,10 @@ $(document).ready(function () { } // Меняем max балл - if (newMaxRate == oldMaxRate) { + if (newMaxRate === oldMaxRate) { $rateInput.turnOn(); } else { - var control = $rateInput.parent().hasClass('landmarkControl') ? 'landmark' : 'current'; + let control = $rateInput.parent().hasClass('landmarkControl') ? 'landmark' : 'current'; $.postJSON(API.setSubModuleMaxAndControl, { 'id': dataOf($rateInput).id, @@ -314,9 +314,9 @@ $(document).ready(function () { if (isExam) rateIndicator += 40; $('div.rateIndicatorDIV span.rateIndicator').html(rateIndicator); - if (control == 'current') + if (control === 'current') $rateInput.parent().parent().find('div.landmarkControl').children('input.inputLandmarkControl').val(0); - if (control == 'landmark') + if (control === 'landmark') $rateInput.parent().parent().find('div.currentControl').children('input.inputCurrentControl').val(0); }