Bläddra i källkod

#1000 Implemented the behavior for the flag OPT_ATT_MUSTCHANGE, and took the opportunity to add a feedback when a field is mandatory OR when the format is wrong

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3394 a333f486-631f-4898-b8df-5754b55c2be0
romainq 10 år sedan
förälder
incheckning
d976849129

+ 5 - 1
application/cmdbabstract.class.inc.php

@@ -1854,7 +1854,8 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
 				{
 					$sNullValue = "'$sNullValue'"; // Add quotes to turn this into a JS string if it's not a number
 				}
-				$oPage->add_ready_script("$('#$iId').bind('".implode(' ', $aEventsList)."', function(evt, sFormId) { return ValidateField('$iId', '$sPattern', $bMandatory, sFormId, $sNullValue) } );\n"); // Bind to a custom event: validate
+				$sOriginalValue = ($iFlags & OPT_ATT_MUSTCHANGE) ? "'".addslashes($value)."'" : 'undefined';
+				$oPage->add_ready_script("$('#$iId').bind('".implode(' ', $aEventsList)."', function(evt, sFormId) { return ValidateField('$iId', '$sPattern', $bMandatory, sFormId, $sNullValue, $sOriginalValue) } );\n"); // Bind to a custom event: validate
 			}
 			$aDependencies = MetaModel::GetDependentAttributes($sClass, $sAttCode); // List of attributes that depend on the current one
 			if (count($aDependencies) > 0)
@@ -1863,6 +1864,9 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
 				$oPage->add_ready_script("$('#$iId').unbind('change.dependencies').bind('change.dependencies', function(evt, sFormId) { return oWizardHelper{$sFormPrefix}.UpdateDependentFields(['".implode("','", $aDependencies)."']) } );\n"); // Bind to a custom event: validate
 			}
 		}
+		$oPage->add_dict_entry('UI:ValueMustBeSet');
+		$oPage->add_dict_entry('UI:ValueMustBeChanged');
+		$oPage->add_dict_entry('UI:ValueInvalidFormat');
 		return "<div>{$sHTMLValue}</div>";
 	}
 

+ 4 - 0
css/light-grey.css

@@ -1416,3 +1416,7 @@ div.ui-dialog-header {
     padding-bottom: 10px;
     padding-top: 7px;
 }
+.form_field_error {
+	border: 1px solid #933;
+	background: #fcc;
+}

+ 15 - 15
datamodels/1.x/itop-change-mgmt-1.0.0/datamodel.itop-change-mgmt.xml

@@ -457,7 +457,7 @@
                 <hidden/>
               </attribute>
               <attribute id="agent_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="agent_email">
                 <hidden/>
@@ -466,13 +466,13 @@
                 <mandatory/>
               </attribute>
               <attribute id="supervisor_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="manager_group_id">
                 <mandatory/>
               </attribute>
               <attribute id="manager_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="outage">
                 <hidden/>
@@ -1488,7 +1488,7 @@
                 <hidden/>
               </attribute>
               <attribute id="agent_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="agent_email">
                 <hidden/>
@@ -1497,13 +1497,13 @@
                 <mandatory/>
               </attribute>
               <attribute id="supervisor_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="manager_group_id">
                 <mandatory/>
               </attribute>
               <attribute id="manager_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="outage">
                 <hidden/>
@@ -2465,7 +2465,7 @@
                 <hidden/>
               </attribute>
               <attribute id="agent_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="agent_email">
                 <hidden/>
@@ -2474,13 +2474,13 @@
                 <mandatory/>
               </attribute>
               <attribute id="supervisor_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="manager_group_id">
                 <mandatory/>
               </attribute>
               <attribute id="manager_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="outage">
                 <hidden/>
@@ -3471,7 +3471,7 @@
                 <hidden/>
               </attribute>
               <attribute id="agent_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="agent_email">
                 <hidden/>
@@ -3480,13 +3480,13 @@
                 <mandatory/>
               </attribute>
               <attribute id="supervisor_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="manager_group_id">
                 <mandatory/>
               </attribute>
               <attribute id="manager_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="outage">
                 <hidden/>
@@ -4547,7 +4547,7 @@
                 <hidden/>
               </attribute>
               <attribute id="agent_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="agent_email">
                 <hidden/>
@@ -4556,13 +4556,13 @@
                 <mandatory/>
               </attribute>
               <attribute id="supervisor_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="manager_group_id">
                 <mandatory/>
               </attribute>
               <attribute id="manager_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="outage">
                 <hidden/>

+ 7 - 7
datamodels/1.x/itop-incident-mgmt-1.0.0/datamodel.itop-incident-mgmt.xml

@@ -54,7 +54,7 @@
                 <read_only/>
               </attribute>
               <attribute id="description">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="start_date">
                 <read_only/>
@@ -63,28 +63,28 @@
                 <mandatory/>
               </attribute>
               <attribute id="org_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="service_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="servicesubcategory_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="product">
                 <must_prompt/>
               </attribute>
               <attribute id="impact">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="urgency">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="priority">
                 <read_only/>
               </attribute>
               <attribute id="workgroup_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="agent_email">
                 <hidden/>

+ 7 - 7
datamodels/1.x/itop-problem-mgmt-1.0.0/datamodel.itop-problem-mgmt.xml

@@ -213,7 +213,7 @@
                 <read_only/>
               </attribute>
               <attribute id="description">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="ticket_log">
                 <hidden/>
@@ -222,28 +222,28 @@
                 <read_only/>
               </attribute>
               <attribute id="org_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="service_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="servicesubcategory_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="product">
                 <must_prompt/>
               </attribute>
               <attribute id="impact">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="urgency">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="priority">
                 <read_only/>
               </attribute>
               <attribute id="workgroup_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="agent_id">
                 <hidden/>

+ 7 - 7
datamodels/1.x/itop-request-mgmt-1.0.0/datamodel.itop-request-mgmt.xml

@@ -91,7 +91,7 @@
                 <read_only/>
               </attribute>
               <attribute id="description">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="start_date">
                 <read_only/>
@@ -100,28 +100,28 @@
                 <mandatory/>
               </attribute>
               <attribute id="org_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="service_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="servicesubcategory_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="product">
                 <must_prompt/>
               </attribute>
               <attribute id="impact">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="urgency">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="priority">
                 <read_only/>
               </attribute>
               <attribute id="workgroup_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="agent_email">
                 <hidden/>

+ 7 - 7
datamodels/1.x/itop-tickets-1.0.0/datamodel.itop-tickets.xml

@@ -422,7 +422,7 @@
                 <read_only/>
               </attribute>
               <attribute id="description">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="start_date">
                 <read_only/>
@@ -431,28 +431,28 @@
                 <mandatory/>
               </attribute>
               <attribute id="org_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="service_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="servicesubcategory_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="product">
                 <must_prompt/>
               </attribute>
               <attribute id="impact">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="urgency">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="priority">
                 <read_only/>
               </attribute>
               <attribute id="workgroup_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="agent_email">
                 <hidden/>

+ 4 - 4
datamodels/2.x/itop-problem-mgmt/datamodel.itop-problem-mgmt.xml

@@ -169,7 +169,7 @@
                 <read_only/>
               </attribute>
               <attribute id="org_id">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="team_id">
                 <hidden/>
@@ -178,7 +178,7 @@
                 <hidden/>
               </attribute>
               <attribute id="description">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="start_date">
                 <read_only/>
@@ -199,10 +199,10 @@
                 <normal/>
               </attribute>
               <attribute id="impact">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="urgency">
-                <must_change/>
+                <must_prompt/>
               </attribute>
               <attribute id="priority">
                 <read_only/>

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

@@ -1196,7 +1196,10 @@ When associated with a trigger, each action is given an "order" number, specifyi
 	'Class:ShortcutOQL/Attribute:auto_reload_sec+' => 'The minimum allowed is 5 seconds',
 
 	'UI:FillAllMandatoryFields' => 'Please fill all mandatory fields.',
-	
+	'UI:ValueMustBeSet' => 'Please specify a value',
+	'UI:ValueMustBeChanged' => 'Please change the value',
+	'UI:ValueInvalidFormat' => 'Invalid format',
+
 	'UI:CSVImportConfirmTitle' => 'Please confirm the operation',
 	'UI:CSVImportConfirmMessage' => 'Are you sure you want to do this?',
 	'UI:CSVImportError_items' => 'Errors: %1$d',

+ 3 - 0
dictionaries/fr.dictionary.itop.ui.php

@@ -1036,6 +1036,9 @@ Lors de l\'association à un déclencheur, on attribue à chaque action un numé
 	'Class:ShortcutOQL/Attribute:auto_reload_sec+' => 'Le minimum permis est de 5 secondes',
 
 	'UI:FillAllMandatoryFields' => 'Veuillez remplir tous les champs obligatoires.',
+	'UI:ValueMustBeSet' => 'Veuillez spécifier une valeur pour ce champ',
+	'UI:ValueMustBeChanged' => 'Veuillez modifier la valeur de ce champ',
+	'UI:ValueInvalidFormat' => 'Format invalide',
 	
 	'UI:CSVImportConfirmTitle' => 'Veuillez confirmer cette opération',
 	'UI:CSVImportConfirmMessage' => 'Etes-vous sûr(e) de vouloir faire cela ?',

+ 28 - 6
js/forms-json-utils.js

@@ -146,7 +146,7 @@ function CheckFields(sFormId, bDisplayAlert)
 	return (oFormErrors['err_'+sFormId] == 0); // If no error, submit the form
 }
 
-function ReportFieldValidationStatus(sFieldId, sFormId, bValid)
+function ReportFieldValidationStatus(sFieldId, sFormId, bValid, sExplain)
 {
 	if (bValid)
 	{
@@ -163,13 +163,21 @@ function ReportFieldValidationStatus(sFieldId, sFormId, bValid)
 			oFormErrors['input_'+sFormId] = sFieldId;
 		}
 		// Visual feedback
-		$('#v_'+sFieldId).html('<img src="../images/validation_error.png" style="vertical-align:middle"/>');
+		$('#v_'+sFieldId).html('<img src="../images/validation_error.png" style="vertical-align:middle" data-tooltip="'+sExplain+'"/>');
+		$('#v_'+sFieldId).tooltip({
+			items: 'span',
+			tooltipClass: 'form_field_error',
+			content: function() {
+				return $(this).find('img').attr('data-tooltip'); // As opposed to the default 'content' handler, do not escape the contents of 'title'
+			}
+		});
 	}
 }
 
-function ValidateField(sFieldId, sPattern, bMandatory, sFormId, nullValue)
+function ValidateField(sFieldId, sPattern, bMandatory, sFormId, nullValue, originalValue)
 {
 	var bValid = true;
+	var sExplain = '';
 	if ($('#'+sFieldId).attr('disabled'))
 	{
 		bValid = true; // disabled fields are not checked
@@ -185,6 +193,19 @@ function ValidateField(sFieldId, sPattern, bMandatory, sFormId, nullValue)
 		else if (bMandatory && (currentVal == nullValue))
 		{
 			bValid = false;
+			sExplain = Dict.S('UI:ValueMustBeSet');
+		}
+		else if ((originalValue != undefined) && (currentVal == originalValue))
+		{
+			bValid = false;
+			if (originalValue == nullValue)
+			{
+				sExplain = Dict.S('UI:ValueMustBeSet');
+			}
+			else
+			{
+				sExplain = Dict.S('UI:ValueMustBeChanged');
+			}
 		}
 		else if (currentVal == nullValue)
 		{
@@ -196,9 +217,10 @@ function ValidateField(sFieldId, sPattern, bMandatory, sFormId, nullValue)
 			re = new RegExp(sPattern);
 			//console.log('Validating field: '+sFieldId + ' current value: '+currentVal + ' pattern: '+sPattern );
 			bValid = re.test(currentVal);
+			sExplain = Dict.S('UI:ValueInvalidFormat');
 		}
 	}
-	ReportFieldValidationStatus(sFieldId, sFormId, bValid);
+	ReportFieldValidationStatus(sFieldId, sFormId, bValid, sExplain);
 	//console.log('Form: '+sFormId+' Validating field: '+sFieldId + ' current value: '+currentVal+' pattern: '+sPattern+' result: '+bValid );
 	return true; // Do not stop propagation ??
 }
@@ -229,7 +251,7 @@ function ValidateCKEditField(sFieldId, sPattern, bMandatory, sFormId, nullValue)
 		bValid = true;
 	}
 
-	ReportFieldValidationStatus(sFieldId, sFormId, bValid);
+	ReportFieldValidationStatus(sFieldId, sFormId, bValid, '');
 
 	setTimeout(function(){ValidateCKEditField(sFieldId, sPattern, bMandatory, sFormId, nullValue);}, 500);
 }
@@ -321,7 +343,7 @@ function ValidateCaseLogField(sFieldId, bMandatory, sFormId)
 			}
 		}
 	}
-	ReportFieldValidationStatus(sFieldId, sFormId, bValid);
+	ReportFieldValidationStatus(sFieldId, sFormId, bValid, '');
 	return bValid;
 }
 // Manage a 'duration' field