From c0e9bcbdd692eebe172b9b159ff32d5b8d7200d3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD=20=D0=A8=D0=B0=D0=BB=D0=B8?=
 =?UTF-8?q?=D0=BC=D0=BE=D0=B2?= <solidovic@gmail.com>
Date: Mon, 22 Sep 2014 17:53:00 +0400
Subject: [PATCH] big fix

---
 .../teacher/discipline/EditStructure.twig     |   2 +-
 .../media/js/discipline/CreateDiscipline.js   |   7 +-
 .../media/js/discipline/EditStructure.js      | 127 +++++++++++-------
 ~dev_rating/media/js/discipline/general.js    |   2 +-
 4 files changed, 85 insertions(+), 53 deletions(-)

diff --git a/~dev_rating/application/views/teacher/discipline/EditStructure.twig b/~dev_rating/application/views/teacher/discipline/EditStructure.twig
index d0f9a4f7b..8d77d4b09 100644
--- a/~dev_rating/application/views/teacher/discipline/EditStructure.twig
+++ b/~dev_rating/application/views/teacher/discipline/EditStructure.twig
@@ -9,7 +9,7 @@
 {% block map_content %}
 	<p class="notification" style="display: none;">{{ Discipline.SemesterNum }} семестр {{ Discipline.SemesterYear }}/{{ Discipline.SemesterYear + 1 }} учебного года</p>
 	<div class="RateIndicatorDIV">
-		Количество баллов: <span class="RateIndicator">{{ Map.MaxRate }}{% if Map.isSetBonus == true %} + 10 бонусных баллов{% endif %}</span>
+		Количество баллов: <span class="RateIndicator">{{ Map.MaxRate }}</span>{% if Map.isSetBonus == true %} + 10 бонусных баллов{% endif %}
 	</div>
 	<div class="studyMap StructureTable">
 		<div class="name">Виды контрольных мероприятий</div>
diff --git a/~dev_rating/media/js/discipline/CreateDiscipline.js b/~dev_rating/media/js/discipline/CreateDiscipline.js
index 4dfdf9731..8eb5da693 100644
--- a/~dev_rating/media/js/discipline/CreateDiscipline.js
+++ b/~dev_rating/media/js/discipline/CreateDiscipline.js
@@ -3,6 +3,7 @@ $(function() {
 
 	// Изменения базовых параметров дисциплины
     $(".AddDiscipline").click(function(){
+		var thisObj = $(this);
     	$(this).attr("disabled", true);
 		var BonusRate = $(".BonusRate").first().prop("checked");
 		$.post(
@@ -19,11 +20,11 @@ $(function() {
 			function(data){
 				data = $.parseJSON(data);
 				if(data.success === true) {
-					$(this).hide();
+					//thisObj.hide();
 					EventInspector_ShowMsg('Дисциплина добавлена', 'success');
-					setTimeout('location.replace("'+URLdir+'discipline/structure/'+data.DisciplineID+'")',1000); 
+					//setTimeout('location.replace("'+URLdir+'discipline/structure/'+data.DisciplineID+'")', 1000); 
 				} else {
-					$(this).removeAttr('disabled');
+					thisObj.removeAttr('disabled');
 					EventInspector_ShowMsg('Ошибка при добавление дисциплины', 'error');
 				}
 			}
diff --git a/~dev_rating/media/js/discipline/EditStructure.js b/~dev_rating/media/js/discipline/EditStructure.js
index da47faead..f21e2c48d 100644
--- a/~dev_rating/media/js/discipline/EditStructure.js
+++ b/~dev_rating/media/js/discipline/EditStructure.js
@@ -49,7 +49,7 @@ $(function() {
 			var credit = parseInt($(this).val());
 			maxCredits = maxCredits + ((isNum(credit)) ? credit : 0);
 		});
-		subModulesDiv.prev().children('.currentControl').text(maxCredits);
+		subModulesDiv.prev().children('div.currentControl').text(maxCredits);
 	}
 	// Подсчет рубежного контроля
 	function CountLandmarkControl(subModulesDiv){
@@ -58,7 +58,7 @@ $(function() {
 			var credit = parseInt($(this).val());
 			maxCredits = maxCredits + ((isNum(credit)) ? credit : 0); 
 		});
-		subModulesDiv.prev().children('.landmarkControl').text(maxCredits);
+		subModulesDiv.prev().children('div.landmarkControl').text(maxCredits);
 	}
 	
 	// Изменение типа подмодуля
@@ -107,7 +107,7 @@ $(function() {
 		
 		// Ограничение 100 баллов
 		var MaxSumRate = 100;
-		if ($('.ExamModule').first().length > 0) MaxSumRate = 60;
+		if ($('div.ExamModule').first().length > 0) MaxSumRate = 60;
 		
 		var currentControl = 0;
 		$('div.moduleHead').children('div.currentControl').each(function(){
@@ -141,10 +141,8 @@ $(function() {
 			
 			// Счетчик баллов
 			var RateIndicarot = currentControl + landmarkControl + NewMaxRate - subtract - OldMaxRate;
-			if ($('div').is('.ExamModule')) RateIndicarot += 40;
-			$('.RateIndicatorDIV .RateIndicator').html(RateIndicarot);
-			if ($('div').is('.BonusModule'))
-				$('.RateIndicatorDIV .RateIndicator').append(' + 10 бонусных баллов');
+			if ($('div.ExamModule').length > 0) RateIndicarot += 40;
+			$('div.RateIndicatorDIV span.RateIndicator').html(RateIndicarot);
 			
 			// Меняем тип
 			ControlType = 'CurrentControl'; // По-умолчанию 
@@ -154,10 +152,10 @@ $(function() {
 				ChangeSubmoduleControlType(ID, ControlType);
 			
 			if (ControlType == 'CurrentControl')
-				thisObj.parent().parent().find('.landmarkControl').children('.inputLandmarkControl').val('0');
+				thisObj.parent().parent().find('div.landmarkControl').children('input.inputLandmarkControl').val('0');
 				
 			if (ControlType == 'LandmarkControl')
-				thisObj.parent().parent().find('.currentControl').children('.inputCurrentControl').val('0');
+				thisObj.parent().parent().find('div.currentControl').children('input.inputCurrentControl').val('0');
 		}
 		
 		// Подсчет текущего и рубежного контроля после изменений
@@ -203,48 +201,54 @@ $(function() {
 	
 	// Переместить вверх МОДУЛЬ
     $(".moduleList").on('click', '.upModule', function(){
-        var parentDIV = $(this).parent('div').parent('div').parent('div');
-        parentDIV.insertBefore(parentDIV.prev('.moduleGroup'));
-		
-		var ModuleID = parentDIV.attr('id');
-		// Для того, который СТАЛ находится ниже
-		var nextModuleID = parentDIV.next('div').attr('id');
-		SwapModuleOrder(ModuleID, nextModuleID);
+        var parentDIV = $(this).parent().parent().parent();
+		var moduleGroupDiv = parentDIV.prev('div.moduleGroup');
+		if (moduleGroupDiv.length > 0) {
+			parentDIV.insertBefore(parentDIV.prev('.moduleGroup'));
+			
+			var ModuleID = parentDIV.attr('id');
+			// Для того, который СТАЛ находится ниже
+			var nextModuleID = parentDIV.next().attr('id');
+			SwapModuleOrder(ModuleID, nextModuleID);
+		}
     });
 	
 	// Переместить вниз МОДУЛЬ
     $(".moduleList").on('click', '.downModule', function(){
-        var parentDIV = $(this).parent('div').parent('div').parent('div');
+        var parentDIV = $(this).parent().parent().parent();
 		var moduleGroupDiv = parentDIV.next('div.moduleGroup');
 		if (moduleGroupDiv.length > 0) {
 			parentDIV.insertAfter(moduleGroupDiv);
 			
 			var ModuleID = parentDIV.attr('id');
 			// Для того, который СТАЛ находится выше
-			var prevModuleID = parentDIV.prev('div').attr('id');
+			var prevModuleID = parentDIV.prev().attr('id');
 			SwapModuleOrder(ModuleID, prevModuleID);
 		}
     });
 	
 	// Переместить вверх мероприятие
     $(".moduleList").on('click', '.upSubModule', function(){
-        var parentDIV = $(this).parent('div').parent('div');
-        parentDIV.insertBefore(parentDIV.prev());
-		
-		var SubmoduleID = parentDIV.attr('id');
-		var nextSubmoduleID = parentDIV.next('div').attr('id');
-		SwapSubmoduleOrder(SubmoduleID, nextSubmoduleID);
+        var parentDIV = $(this).parent().parent();
+		var subModule = parentDIV.prev('div.subModule');
+		if (subModule.length > 0) {
+			parentDIV.insertBefore(parentDIV.prev());
+			
+			var SubmoduleID = parentDIV.attr('id');
+			var nextSubmoduleID = parentDIV.next().attr('id');
+			SwapSubmoduleOrder(SubmoduleID, nextSubmoduleID);
+		}
     });
 	
 	// Переместить вниз мероприятие
     $(".moduleList").on('click', '.downSubModule', function(){
-        var parentDIV = $(this).parent('div').parent('div');
+        var parentDIV = $(this).parent().parent();
 		var subModule = parentDIV.next('div.subModule');
 		if (subModule.length > 0) {
 			parentDIV.insertAfter(subModule);
 			
 			var SubmoduleID = parentDIV.attr('id');
-			var prevSubmoduleID = parentDIV.prev('div').attr('id');
+			var prevSubmoduleID = parentDIV.prev().attr('id');
 			SwapSubmoduleOrder(SubmoduleID, prevSubmoduleID);
 		}
     });
@@ -261,10 +265,15 @@ $(function() {
 				data = $.parseJSON(data);
 				if(data.success === true) {
 					var ExamModule = $('div.ExamModule');
-					if (ExamModule.length > 0)
-						$('div.ExamModule').before(GetModuleTmp());
-					else
-						$('div.moduleList').append(GetModuleTmp());
+					var BonusModule = $('div.BonusModule');
+					if (BonusModule.length > 0)
+						$('div.BonusModule').before(GetModuleTmp());
+					else {
+						if (ExamModule.length > 0)
+							$('div.ExamModule').before(GetModuleTmp());
+						else
+							$('div.moduleList').append(GetModuleTmp());
+					}
 						
 					// К добавленному модулю добавляем ID
 					var thisModuleDIV = $('div.moduleGroup').eq(OrderNum - 1);
@@ -331,7 +340,7 @@ $(function() {
 		$.post(
 			URLdir + 'handler/map/DeleteModule',
 			{
-				'ModuleID': $(this).parent('').parent('').parent('').attr('id'),
+				'ModuleID': $(this).parent().parent().parent().attr('id'),
 				'SubmodulesID': JSONSubmodules,
 				'CurrentModuleOrder': CurrentModuleOrder,
 				'ChangeOrderModulesID': ChangeOrderModulesID
@@ -339,7 +348,29 @@ $(function() {
 			function(data){
 				data = $.parseJSON(data);
 				if(data.success === true) {
-					thisObj.parent('').parent('').parent('').remove();
+					thisObj.parent().parent().parent().remove();
+					
+					var c = 0;
+					$('div.moduleGroup')
+						.children('div.moduleHead')
+						.children('div.currentControl')
+						.each(function(){
+							c += parseInt($(this).text());
+						});
+						
+					var l = 0;
+					$('div.moduleGroup')
+						.children('div.moduleHead')
+						.children('div.landmarkControl')
+						.each(function(){
+							l += parseInt($(this).text());
+						});
+					
+					var e = 0;
+					if ($('div.ExamModule').length > 0) e = 40;
+					
+					$('span.RateIndicator').html(c + l + e);
+						
 					EventInspector_ShowMsg('Модуль удален', 'success');
 				}
 				else EventInspector_ShowMsg('Ошибка при удаление модуля', 'error');
@@ -365,36 +396,36 @@ $(function() {
 			return $(element).attr("id");
 		});
 		var ChangeOrderSubmodulesID = '[' + AttrID.get() + ']';
-		ChangeSubmoduleMaxRate($(this).parent('').parent('').attr('id'), 0);
 		//
 		$.post(
 			URLdir + 'handler/map/DeleteSubmodule',
 			{
-				'SubmoduleID': $(this).parent('').parent('').attr('id'),
+				'SubmoduleID': $(this).parent().parent().attr('id'),
 				'CurrentSubmoduleOrder': CurrentSubmoduleOrder,
 				'ChangeOrderSubmodulesID': ChangeOrderSubmodulesID
 			},
 			function(data){
 				data = $.parseJSON(data);
 				if(data.success === true) {
-					var sub = thisObj.parent('').parent('');
-					var mod = sub.parent('').parent('').find('.moduleHead');
+					var sub = thisObj.parent().parent();
+					var mod = sub.parent().parent().find('div.moduleHead');
 					// get old submodule values
-					var dif1 = sub.find('.currentControl').find('input').val();
-					var dif2 = sub.find('.landmarkControl').find('input').val();
+					var dif1 = parseInt(sub.find('div.currentControl').find('input').val());
+					var dif2 = parseInt(sub.find('div.landmarkControl').find('input').val());
 					
 					// change module header
-					var old = mod.find('.currentControl').html();
-					mod.children('.currentControl').html(old - dif1);
+					var old = parseInt(mod.find('div.currentControl').html());
+					mod.children('div.currentControl').html(old - dif1);
 
-					old = mod.find('.landmarkControl').html();
-					mod.children('.landmarkControl').html(old - dif2);
-
-					// change max rate
-					old = $('.RateIndicator').html(); 
-					$('.RateIndicator').html(old - dif1 - dif2);
-					thisObj.parent('div').parent('div').remove();
+					old = parseInt(mod.find('div.landmarkControl').html());
+					mod.children('div.landmarkControl').html(old - dif2);
 
+					// change sum rate
+					var RateIndicator = $('span.RateIndicator');
+					old = RateIndicator.html();
+					RateIndicator.html(old - dif1 - dif2);
+					
+					thisObj.parent().parent().remove();
 					EventInspector_ShowMsg('Мероприятие удалено', 'success');
 				}
 				else EventInspector_ShowMsg('Ошибка при удаление мероприятия', 'error');
@@ -404,7 +435,7 @@ $(function() {
 	
 	// Отмена удаления модулей/мероприятий
 	$('.moduleList').on('click', '.cancel ', function(){
-		$(this).parent().parent().children('.actions').css('display', 'block');
+		$(this).parent().parent().children('div.actions').css('display', 'block');
 		$(this).parent().remove();
 	});
 	
diff --git a/~dev_rating/media/js/discipline/general.js b/~dev_rating/media/js/discipline/general.js
index 757b412d3..29a1c35fe 100644
--- a/~dev_rating/media/js/discipline/general.js
+++ b/~dev_rating/media/js/discipline/general.js
@@ -62,7 +62,7 @@ $(function() {
 		var NameFilter = $(this).val();
 
 		if (NameFilter.length <= 0) {
-			SelectSubject.html('');
+			$('.SelectSubject').html('');
 			return;
 		}
 
-- 
GitLab