mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
N°3198 n:n relations in edit mode : refresh remote class fields on extkey change
This commit is contained in:
@@ -1971,6 +1971,11 @@ HTML
|
||||
$sNullValue = $oAttDef->GetNullValue(); // used for the ValidateField() call in js/forms-json-utils.js
|
||||
$sFieldToValidateId = $iId; // can be different than the displayed field (for example in TagSet)
|
||||
|
||||
// List of attributes that depend on the current one
|
||||
// Might be modified depending on the current field
|
||||
$sWizardHelperJsVarName = "oWizardHelper{$sFormPrefix}";
|
||||
$aDependencies = MetaModel::GetDependentAttributes($sClass, $sAttCode);
|
||||
|
||||
switch ($oAttDef->GetEditClass())
|
||||
{
|
||||
case 'Date':
|
||||
@@ -2261,6 +2266,7 @@ EOF
|
||||
break;
|
||||
|
||||
case 'ExtKey':
|
||||
/** @var \AttributeExternalKey $oAttDef */
|
||||
$aEventsList[] = 'validate';
|
||||
$aEventsList[] = 'change';
|
||||
|
||||
@@ -2279,6 +2285,19 @@ EOF
|
||||
$sHTMLValue = UIExtKeyWidget::DisplayFromAttCode($oPage, $sAttCode, $sClass, $oAttDef->GetLabel(),
|
||||
$oAllowedValues, $value, $iId, $bMandatory, $sFieldName, $sFormPrefix, $aExtKeyParams);
|
||||
$sHTMLValue .= "<!-- iFlags: $iFlags bMandatory: $bMandatory -->\n";
|
||||
|
||||
$bHasExtKeyUpdatingRemoteClassFields = (
|
||||
array_key_exists('replaceDependenciesByRemoteClassFields', $aArgs)
|
||||
&& ($aArgs['replaceDependenciesByRemoteClassFields'])
|
||||
);
|
||||
if ($bHasExtKeyUpdatingRemoteClassFields)
|
||||
{
|
||||
// On this field update we need to update all the corresponding remote class fields
|
||||
// Used when extkey widget is in a linkedset indirect
|
||||
$sWizardHelperJsVarName = $aArgs['wizHelperRemote'];
|
||||
$aDependencies = $aArgs['remoteCodes'];
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'RedundancySetting':
|
||||
@@ -2476,15 +2495,39 @@ EOF
|
||||
$sNullValue = "'$sNullValue'"; // Add quotes to turn this into a JS string if it's not a number
|
||||
}
|
||||
$sOriginalValue = ($iFlags & OPT_ATT_MUSTCHANGE) ? json_encode($value) : 'undefined';
|
||||
$oPage->add_ready_script("$('#$sFieldToValidateId').bind('".implode(' ',
|
||||
$aEventsList)."', function(evt, sFormId) { return ValidateField('$sFieldToValidateId', '$sPattern', $bMandatory, sFormId, $sNullValue, $sOriginalValue) } );\n"); // Bind to a custom event: validate
|
||||
$sEventList = implode(' ', $aEventsList);
|
||||
$oPage->add_ready_script(<<<JS
|
||||
$('#$sFieldToValidateId')
|
||||
.bind('$sEventList',
|
||||
function(evt, sFormId) {
|
||||
// Bind to a custom event: validate
|
||||
return ValidateField('$sFieldToValidateId', '$sPattern', $bMandatory, sFormId, $sNullValue, $sOriginalValue);
|
||||
}
|
||||
);
|
||||
JS
|
||||
);
|
||||
}
|
||||
$aDependencies = MetaModel::GetDependentAttributes($sClass, $sAttCode); // List of attributes that depend on the current one
|
||||
|
||||
// handle dependent fields updates (init for WizardHelper JS object)
|
||||
if (count($aDependencies) > 0)
|
||||
{
|
||||
// Unbind first to avoid duplicate event handlers in case of reload of the whole (or part of the) form
|
||||
$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
|
||||
//--- Add an event handler to launch a custom event: validate
|
||||
// * Unbind first to avoid duplicate event handlers in case of reload of the whole (or part of the) form
|
||||
// * We were using off/on directly on the node before, but that was causing an issue when adding dynamically new nodes
|
||||
// indeed the events weren't attached on the of the new nodes !
|
||||
// So we're adding the handler on a node above, and we're using a selector to catch only the event we're interested in !
|
||||
$sDependencies = implode("','", $aDependencies);
|
||||
|
||||
$oPage->add_ready_script(<<<JS
|
||||
$('div#field_{$iId}')
|
||||
.off('change.dependencies', '#$iId')
|
||||
.on('change.dependencies', '#$iId',
|
||||
function(evt, sFormId) {
|
||||
return $sWizardHelperJsVarName.UpdateDependentFields(['$sDependencies']);
|
||||
}
|
||||
);
|
||||
JS
|
||||
);
|
||||
}
|
||||
}
|
||||
$oPage->add_dict_entry('UI:ValueMustBeSet');
|
||||
|
||||
Reference in New Issue
Block a user