Ver Fonte

#865 CSV import : mapping several columns to the same fields gives an error. Fix: the wizard does not allow the user to move forward.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3198 a333f486-631f-4898-b8df-5754b55c2be0
romainq há 11 anos atrás
pai
commit
4828bc2a7c

+ 1 - 0
dictionaries/dictionary.itop.ui.php

@@ -579,6 +579,7 @@ Dict::Add('EN US', 'English', 'English', array(
 	'UI:CSVImport:HeaderMappings' => 'Mappings',
 	'UI:CSVImport:HeaderSearch' => 'Search?',
 	'UI:CSVImport:AlertIncompleteMapping' => 'Please select a mapping for every field.',
+	'UI:CSVImport:AlertMultipleMapping' => 'Please make sure that a target field is mapped only once.',
 	'UI:CSVImport:AlertNoSearchCriteria' => 'Please select at least one search criteria',
 	'UI:CSVImport:Encoding' => 'Character encoding',	
 	'UI:UniversalSearchTitle' => 'iTop - Universal Search',

+ 2 - 1
dictionaries/fr.dictionary.itop.ui.php

@@ -451,7 +451,8 @@ Dict::Add('FR FR', 'French', 'Français', array(
 	'UI:CSVImport:HeaderFields' => 'Champs',
 	'UI:CSVImport:HeaderMappings' => 'Correspondance',
 	'UI:CSVImport:HeaderSearch' => 'Recherche ?',
-	'UI:CSVImport:AlertIncompleteMapping' => 'Veuillez choisir le correspondance de chacun des champs.',
+	'UI:CSVImport:AlertIncompleteMapping' => 'Veuillez choisir la correspondance pour chacun des champs.',
+	'UI:CSVImport:AlertMultipleMapping' => 'Veuillez vous assurer que chaque champ cible est sélectionné une seule fois.',
 	'UI:CSVImport:AlertNoSearchCriteria' => 'Veuillez choisir au moins une clef de recherche.',
 	'UI:CSVImport:Encoding' => 'Encodage des caractères',
 

+ 28 - 3
pages/csvimport.php

@@ -862,8 +862,9 @@ EOF
 		$oPage->add('</form>');
 		$oPage->add('</div>');
 		
-		$sAlertIncompleteMapping = Dict::S('UI:CSVImport:AlertIncompleteMapping');
-		$sAlertNoSearchCriteria = Dict::S('UI:CSVImport:AlertNoSearchCriteria');
+		$sAlertIncompleteMapping = addslashes(Dict::S('UI:CSVImport:AlertIncompleteMapping'));
+		$sAlertMultipleMapping = addslashes(Dict::S('UI:CSVImport:AlertMultipleMapping'));
+		$sAlertNoSearchCriteria = addslashes(Dict::S('UI:CSVImport:AlertNoSearchCriteria'));
 		
 		$oPage->add_ready_script(
 <<<EOF
@@ -963,10 +964,17 @@ EOF
 	
 	function CheckValues()
 	{
+		// Reset the highlight in case the check has already been executed with failure
+		$('select[name^=field]').each( function() {
+			$(this).parent().css({'border': '0'});
+		});
+
 		bResult = true;
 		bMappingOk = true;
+		bMultipleMapping = false;
 		bSearchOk = false;
 		$('select[name^=field]').each( function() {
+			$(this).parent().css({'border': '0'});
 			if ($(this).val() == '')
 			{
 				$(this).parent().css({'border': '2px #D81515 solid'});
@@ -975,7 +983,20 @@ EOF
 			}
 			else
 			{
-				$(this).parent().css({'border': '0'});
+				iOccurences = 0;
+				sRefValue = $(this).val();
+				$('select[name^=field]').each( function() {
+					if ($(this).val() == sRefValue)
+					{
+						iOccurences++;
+					}
+				});
+				if (iOccurences > 1)
+				{
+					$(this).parent().css({'border': '2px #D81515 solid'});
+					bResult = false; 
+					bMultipleMapping = true;
+				}
 			}
 		});
 		// At least one search field must be checked
@@ -986,6 +1007,10 @@ EOF
 		{
 			alert("$sAlertIncompleteMapping");
 		}
+		if (bMultipleMapping)
+		{
+			alert("$sAlertMultipleMapping");
+		}
 		if (!bSearchOk)
 		{
 				bResult = false;