Skip to content

Commit

Permalink
Issue #3070: Change AJAXUpdate handling in relevant dynamic fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhaerter authored and svenoe committed Feb 28, 2024
1 parent 2660af8 commit 7877329
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 115 deletions.
27 changes: 5 additions & 22 deletions Kernel/System/DynamicField/Driver/BaseEntity.pm
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ sub EditFieldRender {
$FieldClass .= ' Validate_Required';
}

# set ajaxupdate class
if ( $Param{AJAXUpdate} ) {
$FieldClass .= ' FormUpdate';
}

# set error css class
if ( $Param{ServerError} ) {
$FieldClass .= ' ServerError';
Expand Down Expand Up @@ -355,28 +360,6 @@ sub EditFieldRender {
);
}

if ( $Param{AJAXUpdate} ) {

my $FieldSelector = '#' . $FieldName;

my $FieldsToUpdate = '';
if ( IsArrayRefWithData( $Param{UpdatableFields} ) ) {

# Remove current field from updatable fields list
my @FieldsToUpdate = grep { $_ ne $FieldName } @{ $Param{UpdatableFields} };

# quote all fields, put commas in between them
$FieldsToUpdate = join( ', ', map {"'$_'"} @FieldsToUpdate );
}

# add js to call FormUpdate()
$Param{LayoutObject}->AddJSOnDocumentComplete( Code => <<"EOF");
\$('$FieldSelector').bind('change', function (Event) {
Core.AJAX.FormUpdate(\$(this).parents('form'), 'AJAXUpdate', '$FieldName', [ $FieldsToUpdate ]);
});
EOF
}

# call EditLabelRender on the common Driver
# only a single label is returned, even for MultiValue fields
my $LabelString = $Self->EditLabelRender(
Expand Down
30 changes: 5 additions & 25 deletions Kernel/System/DynamicField/Driver/BaseReference.pm
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ sub EditFieldRender {
$FieldClass .= ' Validate_Required';
}

# set ajaxupdate class
if ( $Param{AJAXUpdate} ) {
$FieldClass .= ' FormUpdate';
}

# set error css class
if ( $Param{ServerError} ) {
$FieldClass .= ' ServerError';
Expand Down Expand Up @@ -367,31 +372,6 @@ sub EditFieldRender {
);
}

if ( $Param{AJAXUpdate} ) {

my $FieldSelector = '#' . $FieldName;

my $FieldsToUpdate = '';
if ( IsArrayRefWithData( $Param{UpdatableFields} ) ) {

# Remove current field from updatable fields list
my @FieldsToUpdate = grep { $_ ne $FieldName } @{ $Param{UpdatableFields} };

# quote all fields, put commas in between them
$FieldsToUpdate = join( ', ', map {"'$_'"} @FieldsToUpdate );
}

# add js to call FormUpdate()
$Param{LayoutObject}->AddJSOnDocumentComplete( Code => <<"EOF");
\$('$FieldSelector').bind('change', function (Event) {
Core.AJAX.FormUpdate(\$(this).parents('form'), 'AJAXUpdate', '$FieldName', [ $FieldsToUpdate ]);
});
Core.App.Subscribe('Event.AJAX.FormUpdate.Callback', function(Data) {
var FieldName = '$FieldName';
});
EOF
}

# call EditLabelRender on the common Driver
my $LabelString = $Self->EditLabelRender(
%Param,
Expand Down
20 changes: 5 additions & 15 deletions Kernel/System/DynamicField/Driver/BaseSelect.pm
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ sub EditFieldRender {
$FieldClass .= ' Validate_Required';
}

# set ajaxupdate class
if ( $Param{AJAXUpdate} ) {
$FieldClass .= ' FormUpdate';
}

# set error css class
if ( $Param{ServerError} ) {
$FieldClass .= ' ServerError';
Expand Down Expand Up @@ -401,23 +406,8 @@ sub EditFieldRender {

if ( $Param{AJAXUpdate} ) {

my $FieldSelector = '#' . $FieldName;

my $FieldsToUpdate = '';
if ( IsArrayRefWithData( $Param{UpdatableFields} ) ) {

# Remove current field from updatable fields list
my @FieldsToUpdate = grep { $_ ne $FieldName } @{ $Param{UpdatableFields} };

# quote all fields, put commas in between them
$FieldsToUpdate = join( ', ', map {"'$_'"} @FieldsToUpdate );
}

# add js to call FormUpdate()
$Param{LayoutObject}->AddJSOnDocumentComplete( Code => <<"EOF");
\$('$FieldSelector').bind('change', function (Event) {
Core.AJAX.FormUpdate(\$(this).parents('form'), 'AJAXUpdate', '$FieldName', [ $FieldsToUpdate ]);
});
Core.App.Subscribe('Event.AJAX.FormUpdate.Callback', function(Data) {
var FieldName = '$FieldName';
if (Data[FieldName] && \$('#' + FieldName).hasClass('DynamicFieldWithTreeView')) {
Expand Down
27 changes: 5 additions & 22 deletions Kernel/System/DynamicField/Driver/Checkbox.pm
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ sub EditFieldRender {
$FieldClass .= ' ServerError';
}

# set ajaxupdate class
if ( $Param{AJAXUpdate} ) {
$FieldClass .= ' FormUpdate';
}

my %FieldTemplateData = (
'FieldNameUsed' => $FieldNameUsed,
'FieldClass' => $FieldClass,
Expand Down Expand Up @@ -491,28 +496,6 @@ sub EditFieldRender {
);
}

if ( $Param{AJAXUpdate} ) {

my $FieldSelector = '#' . $FieldName;

my $FieldsToUpdate = '';
if ( IsArrayRefWithData( $Param{UpdatableFields} ) ) {

# Remove current field from updatable fields list
my @FieldsToUpdate = grep { $_ ne $FieldName } @{ $Param{UpdatableFields} };

# quote all fields, put commas in between them
$FieldsToUpdate = join( ', ', map {"'$_'"} @FieldsToUpdate );
}

# add js to call FormUpdate()
$Param{LayoutObject}->AddJSOnDocumentComplete( Code => <<"EOF");
\$('$FieldSelector').bind('change', function (Event) {
Core.AJAX.FormUpdate(\$(this).parents('form'), 'AJAXUpdate', '$FieldName', [ $FieldsToUpdate ]);
});
EOF
}

# call EditLabelRender on the common Driver
my $LabelString = $Self->EditLabelRender(
%Param,
Expand Down
20 changes: 5 additions & 15 deletions Kernel/System/DynamicField/Driver/Multiselect.pm
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@ sub EditFieldRender {
$FieldClass .= ' Validate_Required';
}

# set ajaxupdate class
if ( $Param{AJAXUpdate} ) {
$FieldClass .= ' FormUpdate';
}

# set error css class
if ( $Param{ServerError} ) {
$FieldClass .= ' ServerError';
Expand Down Expand Up @@ -435,23 +440,8 @@ sub EditFieldRender {

if ( $Param{AJAXUpdate} ) {

my $FieldSelector = '#' . $FieldName;

my $FieldsToUpdate = '';
if ( IsArrayRefWithData( $Param{UpdatableFields} ) ) {

# Remove current field from updatable fields list
my @FieldsToUpdate = grep { $_ ne $FieldName } @{ $Param{UpdatableFields} };

# quote all fields, put commas in between them
$FieldsToUpdate = join( ', ', map {"'$_'"} @FieldsToUpdate );
}

# add js to call FormUpdate()
$Param{LayoutObject}->AddJSOnDocumentComplete( Code => <<"EOF");
\$('$FieldSelector').bind('change', function (Event) {
Core.AJAX.FormUpdate(\$(this).parents('form'), 'AJAXUpdate', '$FieldName', [ $FieldsToUpdate ]);
});
Core.App.Subscribe('Event.AJAX.FormUpdate.Callback', function(Data) {
var FieldName = '$FieldName';
if (Data[FieldName] && \$('#' + FieldName).hasClass('DynamicFieldWithTreeView')) {
Expand Down
21 changes: 5 additions & 16 deletions Kernel/System/DynamicField/Driver/WebService.pm
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ sub EditFieldRender {
$FieldClass .= ' Validate_Required';
}

# set ajaxupdate class
if ( $Param{AJAXUpdate} ) {
$FieldClass .= ' FormUpdate';
}

# set error css class
if ( $Param{ServerError} ) {
$FieldClass .= ' ServerError';
Expand Down Expand Up @@ -337,24 +342,8 @@ sub EditFieldRender {

if ( $Param{AJAXUpdate} ) {

my $FieldSelector = '#' . $FieldName;

my $FieldsToUpdate = '[ ]';
if ( IsArrayRefWithData( $Param{UpdatableFields} ) ) {

# Remove current field from updatable fields list
my @FieldsToUpdate = grep { $_ ne $FieldName } @{ $Param{UpdatableFields} };

$FieldsToUpdate = $Kernel::OM->Get('Kernel::System::JSON')->Encode(
Data => \@FieldsToUpdate,
);
}

# add js to call FormUpdate()
$Param{LayoutObject}->AddJSOnDocumentComplete( Code => <<"EOF");
\$('$FieldSelector').bind('change', function (Event) {
Core.AJAX.FormUpdate(\$(this).parents('form'), 'AJAXUpdate', '$FieldName', $FieldsToUpdate );
});
Core.App.Subscribe('Event.AJAX.FormUpdate.Callback', function(Data) {
var FieldName = '$FieldName';
if (Data[FieldName] && \$('#' + FieldName).hasClass('DynamicFieldWithTreeView')) {
Expand Down

0 comments on commit 7877329

Please sign in to comment.