diff --git a/Kernel/Modules/AdminDynamicFieldLens.pm b/Kernel/Modules/AdminDynamicFieldLens.pm index 6b226a3f6..27c030222 100644 --- a/Kernel/Modules/AdminDynamicFieldLens.pm +++ b/Kernel/Modules/AdminDynamicFieldLens.pm @@ -42,35 +42,23 @@ sub new { # field types which are usable as attribute df $Self->{IsAttributeFieldCapable} = { - - # see https://github.com/RotherOSS/issues/3186 - Agent => 0, + Agent => 1, Checkbox => 1, # see https://github.com/RotherOSS/otobo/issues/3809 - ContactWD => 0, - - # see https://github.com/RotherOSS/issues/3186 - CustomerCompany => 0, - - # see https://github.com/RotherOSS/issues/3186 - CustomerUser => 0, + ContactWD => 0, + CustomerCompany => 1, + CustomerUser => 1, # see https://github.com/RotherOSS/otobo/issues/3793 - Database => 0, - Date => 1, - DateTime => 1, - Dropdown => 1, - - # see https://github.com/RotherOSS/issues/3186 - FAQ => 0, - GeneralCatalog => 1, - - # see https://github.com/RotherOSS/issues/3186 - ITSMConfigItem => 0, - - # see https://github.com/RotherOSS/issues/3186 - ITSMConfigItemVersion => 0, + Database => 0, + Date => 1, + DateTime => 1, + Dropdown => 1, + FAQ => 1, + GeneralCatalog => 1, + ITSMConfigItem => 1, + ITSMConfigItemVersion => 1, # see https://github.com/RotherOSS/otobo/issues/3789 Lens => 0, @@ -86,10 +74,8 @@ sub new { Set => 1, Text => 1, TextArea => 1, - - # see https://github.com/RotherOSS/issues/3186 - Ticket => 0, - Title => 1, + Ticket => 1, + Title => 1, # see https://github.com/RotherOSS/otobo/issues/3446 WebService => 0, diff --git a/Kernel/Modules/AgentReferenceSearch.pm b/Kernel/Modules/AgentReferenceSearch.pm index ef574b33d..89a0f43e8 100644 --- a/Kernel/Modules/AgentReferenceSearch.pm +++ b/Kernel/Modules/AgentReferenceSearch.pm @@ -108,26 +108,63 @@ sub Run { # Get config for the dynamic field and check the sanity. my $DynamicFieldBackendObject = $Kernel::OM->Get('Kernel::System::DynamicField::Backend'); - my $DynamicFieldConfig = $Kernel::OM->Get('Kernel::System::DynamicField')->DynamicFieldGet( + my $InitialDynamicFieldConfig = $Kernel::OM->Get('Kernel::System::DynamicField')->DynamicFieldGet( Name => $FieldName, ); - if ( - !IsHashRefWithData($DynamicFieldConfig) - || - !$DynamicFieldBackendObject->HasBehavior( - DynamicFieldConfig => $DynamicFieldConfig, - Behavior => 'IsReferenceField', - ) - ) - { + if ( !IsHashRefWithData($InitialDynamicFieldConfig) ) { return $LayoutObject->JSONReply( Data => { Success => 0, Messsage => qq{Error reading the dynamic field '$FieldName'!}, - } + }, ); } + # Check if we deal with a reference field + my $IsReferenceField = $DynamicFieldBackendObject->HasBehavior( + DynamicFieldConfig => $InitialDynamicFieldConfig, + Behavior => 'IsReferenceField', + ); + + my $DynamicFieldConfig; + if ( !$IsReferenceField ) { + + # Check if we deal with a lens field with a reference attribute field + if ( $InitialDynamicFieldConfig->{FieldType} eq 'Lens' ) { + + # TODO perhaps better use 'AttributeDFConfigGet' + $DynamicFieldConfig = $Kernel::OM->Get('Kernel::System::DynamicField')->DynamicFieldGet( + ID => $InitialDynamicFieldConfig->{Config}{AttributeDF}, + ); + if ( !IsHashRefWithData($InitialDynamicFieldConfig) ) { + return $LayoutObject->JSONReply( + Data => { + Success => 0, + Messsage => qq{Error reading the dynamic field '$FieldName'!}, + }, + ); + } + + $IsReferenceField = $DynamicFieldBackendObject->HasBehavior( + DynamicFieldConfig => $DynamicFieldConfig, + Behavior => 'IsReferenceField', + ); + + if ( !$IsReferenceField ) { + return $LayoutObject->JSONReply( + Data => { + Success => 0, + Messsage => qq{Error reading the dynamic field '$FieldName'!}, + }, + ); + } + $DynamicFieldConfig->{Name} = $FieldName; + } + } + else { + $DynamicFieldConfig = $InitialDynamicFieldConfig; + } + # search referenced object my $MaxResults = int( $ParamObject->GetParam( Param => 'MaxResults' ) || 20 ); my $Term = $ParamObject->GetParam( Param => 'Term' ) || ''; diff --git a/Kernel/System/DynamicField/Driver/BaseReference.pm b/Kernel/System/DynamicField/Driver/BaseReference.pm index 405a6c634..83f8f4404 100644 --- a/Kernel/System/DynamicField/Driver/BaseReference.pm +++ b/Kernel/System/DynamicField/Driver/BaseReference.pm @@ -1068,7 +1068,11 @@ sub GetFieldState { my $DynamicFieldConfig = $Param{DynamicFieldConfig}; return () if !IsArrayRefWithData( $DynamicFieldConfig->{Config}{ReferenceFilterList} ); - return () if none { $Param{ChangedElements}->{ $_->{EqualsObjectAttribute} // '' } } $DynamicFieldConfig->{Config}{ReferenceFilterList}->@*; + return () + if ( + ( none { $Param{ChangedElements}->{ $_->{EqualsObjectAttribute} // '' } } $DynamicFieldConfig->{Config}{ReferenceFilterList}->@* ) + && !$Param{Lens} + ); my $Value = $Param{GetParam}{DynamicField}{ 'DynamicField_' . $DynamicFieldConfig->{Name} }; diff --git a/Kernel/System/DynamicField/Driver/Lens.pm b/Kernel/System/DynamicField/Driver/Lens.pm index b1df7886c..352d9781a 100644 --- a/Kernel/System/DynamicField/Driver/Lens.pm +++ b/Kernel/System/DynamicField/Driver/Lens.pm @@ -611,6 +611,10 @@ sub GetFieldState { DynamicFieldConfig => $DynamicFieldConfig, Behavior => 'IsACLReducible', ); + my $SetsDynamicContent = $Self->HasBehavior( + DynamicFieldConfig => $DynamicFieldConfig, + Behavior => 'SetsDynamicContent', + ); my %Return; my $ReferenceID = $DFParam->{ $DynamicFieldConfig->{Config}{ReferenceDFName} } ? $DFParam->{ $DynamicFieldConfig->{Config}{ReferenceDFName} }[0] : undef; @@ -692,8 +696,26 @@ sub GetFieldState { $DFParam->{"DynamicField_$DynamicFieldConfig->{Name}"} = $AttributeFieldValue; } + if ($SetsDynamicContent) { + + my $AttributeDFConfig = $Self->_GetAttributeDFConfig( + LensDynamicFieldConfig => $DynamicFieldConfig, + ); + + my %GetFieldState = $Param{DynamicFieldBackendObject}->GetFieldState( + %Param, + Lens => 1, + DynamicFieldConfig => $AttributeDFConfig, + ); + + return ( + %GetFieldState, + %Return, + ); + } + # if this field is non ACL reducible, set the field values - return %Return if !$IsACLReducible; + return %Return unless $IsACLReducible; # get possible values if ACLReducible # this is what the FieldRestrictions object would do for other fields diff --git a/var/httpd/htdocs/js/Core.AJAX.js b/var/httpd/htdocs/js/Core.AJAX.js index a4659a2c4..4a84a5391 100644 --- a/var/httpd/htdocs/js/Core.AJAX.js +++ b/var/httpd/htdocs/js/Core.AJAX.js @@ -472,6 +472,33 @@ Core.AJAX = (function (TargetNS) { $Element.val( '' ); $ReferenceElement.val( '' ); } + + // trigger reference search if autocomplete + if ( $Element.is('input') ) { + + var $AutocompleteElement = $Element.parent().find('.DynamicFieldReference'); + + // check for surrounding set and if so, send setindex as request param + var SetIndexStrg = ''; + var SetOuterFieldList = $Element.parents('.DFSetOuterField'); + if ( SetOuterFieldList.length ) { + var MultiValueClass = Array.from(SetOuterFieldList[0].parentElement.classList).find(c => c.startsWith('MultiValue')); + if (MultiValueClass !== undefined && MultiValueClass != '') { + var SetIndexRegExp = new RegExp(/^MultiValue_(\d+)$/); + var MatchResults = SetIndexRegExp.exec(MultiValueClass); + SetIndexStrg = ';SetIndex=' + MatchResults[1]; + } + } + + var URL = Core.Config.Get('Baselink'), + QueryString = "Action=AgentReferenceSearch;ObjectID=" + DataValue[0][0] + + ";Field=" + $AutocompleteElement.attr('id') + + SetIndexStrg + ';'; + + QueryString += Core.AJAX.SerializeForm($Element.closest('form'), {'Action': 1, 'Subaction': 1, 'Term': 1, 'Field': 1, 'MaxResults': 1}); + TargetNS.FunctionCall(URL, QueryString, function (Result) { + }); + } return; }