N°1624 Fix bulk transition integrity exception when "org_id" was not checked.

This commit is contained in:
Molkobain
2018-10-03 15:08:54 +02:00
parent 10b7fa6014
commit 7fddd6acdc
2 changed files with 21 additions and 14 deletions

View File

@@ -409,8 +409,12 @@ function ToggleDurationField(field_id) {
function PropagateCheckBox(bCurrValue, aFieldsList, bCheck) { function PropagateCheckBox(bCurrValue, aFieldsList, bCheck) {
if (bCurrValue == bCheck) { if (bCurrValue == bCheck) {
for (var i = 0; i < aFieldsList.length; i++) { for (var i = 0; i < aFieldsList.length; i++) {
$('#enable_'+aFieldsList[i]).attr('checked', bCheck); var sFieldId = aFieldsList[i];
ToogleField(bCheck, aFieldsList[i]); $('#enable_'+sFieldId).attr('checked', bCheck);
ToogleField(bCheck, sFieldId);
// Cascade propagation
$('#enable_'+sFieldId).trigger('change');
} }
} }
} }

View File

@@ -1205,6 +1205,8 @@ EOF
$aExpectedAttributes = MetaModel::GetTransitionAttributes($sClass, $sStimulus, $sState); $aExpectedAttributes = MetaModel::GetTransitionAttributes($sClass, $sStimulus, $sState);
$aDetails = array(); $aDetails = array();
$sFormId = 'apply_stimulus';
$sFormPrefix = $sFormId.'_';
$iFieldIndex = 0; $iFieldIndex = 0;
$aFieldsMap = array(); $aFieldsMap = array();
$aValues = array(); $aValues = array();
@@ -1220,6 +1222,7 @@ EOF
$sReadyScript = ''; $sReadyScript = '';
foreach($aExpectedAttributes as $sAttCode => $iExpectCode) foreach($aExpectedAttributes as $sAttCode => $iExpectCode)
{ {
$sFieldInputId = $sFormPrefix.$sAttCode;
// Prompt for an attribute if // Prompt for an attribute if
// - the attribute must be changed or must be displayed to the user for confirmation // - the attribute must be changed or must be displayed to the user for confirmation
// - or the field is mandatory and currently empty // - or the field is mandatory and currently empty
@@ -1232,19 +1235,19 @@ EOF
if (count($aPrerequisites) > 0) if (count($aPrerequisites) > 0)
{ {
// When 'enabling' a field, all its prerequisites must be enabled too // When 'enabling' a field, all its prerequisites must be enabled too
$sFieldList = "['".implode("','", $aPrerequisites)."']"; $sFieldList = "['{$sFormPrefix}".implode("','{$sFormPrefix}", $aPrerequisites)."']";
$oP->add_ready_script("$('#enable_{$sAttCode}').bind('change', function(evt, sFormId) { return PropagateCheckBox( this.checked, $sFieldList, true); } );\n"); $oP->add_ready_script("$('#enable_{$sFieldInputId}').bind('change', function(evt, sFormId) { return PropagateCheckBox( this.checked, $sFieldList, true); } );\n");
} }
$aDependents = MetaModel::GetDependentAttributes($sClass, $sAttCode); // List of attributes that are needed for the current one $aDependents = MetaModel::GetDependentAttributes($sClass, $sAttCode); // List of attributes that are needed for the current one
if (count($aDependents) > 0) if (count($aDependents) > 0)
{ {
// When 'disabling' a field, all its dependent fields must be disabled too // When 'disabling' a field, all its dependent fields must be disabled too
$sFieldList = "['".implode("','", $aDependents)."']"; $sFieldList = "['{$sFormPrefix}".implode("','{$sFormPrefix}", $aDependents)."']";
$oP->add_ready_script("$('#enable_{$sAttCode}').bind('change', function(evt, sFormId) { return PropagateCheckBox( this.checked, $sFieldList, false); } );\n"); $oP->add_ready_script("$('#enable_{$sFieldInputId}').bind('change', function(evt, sFormId) { return PropagateCheckBox( this.checked, $sFieldList, false); } );\n");
} }
$aArgs = array('this' => $oObj); $aArgs = array('this' => $oObj);
$sHTMLValue = cmdbAbstractObject::GetFormElementForField($oP, $sClass, $sAttCode, $oAttDef, $oObj->Get($sAttCode), $oObj->GetEditValue($sAttCode), $sAttCode, '', $iExpectCode, $aArgs); $sHTMLValue = cmdbAbstractObject::GetFormElementForField($oP, $sClass, $sAttCode, $oAttDef, $oObj->Get($sAttCode), $oObj->GetEditValue($sAttCode), $sFieldInputId, '', $iExpectCode, $aArgs);
$sComments = '<input type="checkbox" checked id="enable_'.$sAttCode.'" onClick="ToogleField(this.checked, \''.$sAttCode.'\')"/>'; $sComments = '<input type="checkbox" checked id="enable_'.$sFieldInputId.'" onClick="ToogleField(this.checked, \''.$sFieldInputId.'\')"/>';
if (!isset($aValues[$sAttCode])) if (!isset($aValues[$sAttCode]))
{ {
$aValues[$sAttCode] = array(); $aValues[$sAttCode] = array();
@@ -1272,11 +1275,11 @@ EOF
} }
$sTip .= "</ul></p>"; $sTip .= "</ul></p>";
$sTip = addslashes($sTip); $sTip = addslashes($sTip);
$sReadyScript .= "$('#multi_values_$sAttCode').qtip( { content: '$sTip', show: 'mouseover', hide: 'mouseout', style: { name: 'dark', tip: 'leftTop' }, position: { corner: { target: 'rightMiddle', tooltip: 'leftTop' }} } );\n"; $sReadyScript .= "$('#multi_values_$sFieldInputId').qtip( { content: '$sTip', show: 'mouseover', hide: 'mouseout', style: { name: 'dark', tip: 'leftTop' }, position: { corner: { target: 'rightMiddle', tooltip: 'leftTop' }} } );\n";
$sComments .= '<div class="multi_values" id="multi_values_'.$sAttCode.'">'.count($aValues[$sAttCode]).'</div>'; $sComments .= '<div class="multi_values" id="multi_values_'.$sFieldInputId.'">'.count($aValues[$sAttCode]).'</div>';
} }
$aDetails[] = array('label' => '<span>'.$oAttDef->GetLabel().'</span>', 'value' => "<span id=\"field_$sAttCode\">$sHTMLValue</span>", 'comments' => $sComments); $aDetails[] = array('label' => '<span>'.$oAttDef->GetLabel().'</span>', 'value' => "<span id=\"field_$sFieldInputId\">$sHTMLValue</span>", 'comments' => $sComments);
$aFieldsMap[$sAttCode] = $sAttCode; $aFieldsMap[$sAttCode] = $sFieldInputId;
$iFieldIndex++; $iFieldIndex++;
} }
} }
@@ -1289,7 +1292,7 @@ EOF
$oP->add('</div>'); $oP->add('</div>');
} }
$oP->add("<div class=\"wizContainer\">\n"); $oP->add("<div class=\"wizContainer\">\n");
$oP->add("<form id=\"apply_stimulus\" method=\"post\" onSubmit=\"return OnSubmit('apply_stimulus');\">\n"); $oP->add("<form id=\"{$sFormId}\" method=\"post\" onSubmit=\"return OnSubmit('{$sFormId}');\">\n");
$oP->add("<table><tr><td>\n"); $oP->add("<table><tr><td>\n");
$oP->details($aDetails); $oP->details($aDetails);
$oP->add("</td></tr></table>\n"); $oP->add("</td></tr></table>\n");
@@ -1328,7 +1331,7 @@ EOF
$oP->add_ready_script( $oP->add_ready_script(
<<<EOF <<<EOF
// Starts the validation when the page is ready // Starts the validation when the page is ready
CheckFields('apply_stimulus', false); CheckFields('{$sFormId}', false);
$sReadyScript $sReadyScript
EOF EOF
); );