Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #2251 readonly enhancemenets #2524

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions Kernel/Output/HTML/Layout.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2377,6 +2377,7 @@ build a HTML option element based on given data
Size => 1, # (optional) default 1 element size
Class => 'class', # (optional) a css class, include 'Modernize' to activate InputFields
Disabled => 0, # (optional) default 0 (0|1) disable the element
Readonly => 0, # (optional) default 0 (0|1) set the element readonly
AutoComplete => 'off', # (optional)
OnChange => 'javascript', # (optional)
OnClick => 'javascript', # (optional)
Expand Down Expand Up @@ -3586,6 +3587,8 @@ Depending on the SysConfig settings the controls to set the date could be multip
# client side with JS
Disabled => 1, # optional (1 or 0), when active select and checkbox controls gets the
# disabled attribute and input fields gets the read only attribute
Readonly => 1, # optional (1 or 0), when active all input fields gets the readonly
# attribute
Suffix => 'some suffix', # optional, is attached at the end of Names, IDs etc.
);

Expand Down Expand Up @@ -3709,16 +3712,17 @@ sub BuildDateSelection {
Class => $Validate ? "Validate_DateYear $Class" : $Class,
Title => $Self->{LanguageObject}->Translate('Year'),
Disabled => $Param{Disabled},
Readonly => $Param{Readonly},
);
}
else {
$Param{Year} =
'<input type="text" '
. ( $Validate ? qq{class="Validate_DateYear $Class" } : qq{class="$Class" } )
. qq{name="${Prefix}Year" id="${Prefix}Year${Suffix}" size="4" maxlength="4" }
. sprintf( 'title="%s" ', $Self->{LanguageObject}->Translate('Year') )
. sprintf( 'title="%s" ', $Self->{LanguageObject}->Translate('Year') )
. sprintf( 'value="%02d" ', ( $Param{ $Prefix . 'Year' } || $Y ) )
. ( $Param{Disabled} ? 'readonly' : '' )
. ( ( $Param{Disabled} || $Param{Readonly} ) ? 'readonly' : '' )
. '>';
}

Expand All @@ -3734,16 +3738,17 @@ sub BuildDateSelection {
Class => $Validate ? "Validate_DateMonth $Class" : $Class,
Title => $Self->{LanguageObject}->Translate('Month'),
Disabled => $Param{Disabled},
Readonly => $Param{Readonly},
);
}
else {
$Param{Month} =
'<input type="text" '
. ( $Validate ? qq{class="Validate_DateMonth $Class" } : qq{class="$Class" } )
. qq{name="${Prefix}Month" id="${Prefix}Month${Suffix}" size="2" maxlength="2" }
. sprintf( 'title="%s" ', $Self->{LanguageObject}->Translate('Month') )
. sprintf( 'title="%s" ', $Self->{LanguageObject}->Translate('Month') )
. sprintf( 'value="%02d" ', ( $Param{ $Prefix . 'Month' } || $M ) )
. ( $Param{Disabled} ? 'readonly' : '' )
. ( ( $Param{Disabled} || $Param{Readonly} ) ? 'readonly' : '' )
. '>';
}

Expand Down Expand Up @@ -3789,6 +3794,7 @@ sub BuildDateSelection {
Class => "$DateValidateClasses $Class",
Title => $Self->{LanguageObject}->Translate('Day'),
Disabled => $Param{Disabled},
Readonly => $Param{Readonly},
ValidateDateAfter => $ValidateDateAfterValue,
ValidateDateBefore => $ValidateDateBeforeValue,
);
Expand All @@ -3798,9 +3804,9 @@ sub BuildDateSelection {
'<input type="text" '
. qq{class="${DateValidateClasses}${Class}" }
. qq{name="${Prefix}Day" id="${Prefix}Day${Suffix}" size="2" maxlength="2" }
. sprintf( 'title="%s" ', $Self->{LanguageObject}->Translate('Day') )
. sprintf( 'title="%s" ', $Self->{LanguageObject}->Translate('Day') )
. sprintf( 'value="%02d" ', ( $Param{ $Prefix . 'Day' } || $D ) )
. ( $Param{Disabled} ? 'readonly' : '' )
. ( ( $Param{Disabled} || $Param{Readonly} ) ? 'readonly' : '' )
. '>';

}
Expand All @@ -3821,16 +3827,17 @@ sub BuildDateSelection {
Class => $Validate ? ( 'Validate_DateHour ' . $Class ) : $Class,
Title => $Self->{LanguageObject}->Translate('Hours'),
Disabled => $Param{Disabled},
Readonly => $Param{Readonly},
);
}
else {
$Param{Hour} =
'<input type="text" '
. ( $Validate ? qq{class="Validate_DateHour $Class" } : qq{class="$Class" } )
. qq{name="${Prefix}Hour" id="${Prefix}Hour${Suffix}" size="2" maxlength="2" }
. sprintf( 'title="%s" ', $Self->{LanguageObject}->Translate('Hours') )
. sprintf( 'title="%s" ', $Self->{LanguageObject}->Translate('Hours') )
. sprintf( 'value="%02d" ', ( $Param{ $Prefix . 'Hour' } || $h ) )
. ( $Param{Disabled} ? 'readonly' : '' )
. ( ( $Param{Disabled} || $Param{Readonly} ) ? 'readonly' : '' )
. '>';

}
Expand All @@ -3849,16 +3856,17 @@ sub BuildDateSelection {
Class => $Validate ? ( 'Validate_DateMinute ' . $Class ) : $Class,
Title => $Self->{LanguageObject}->Translate('Minutes'),
Disabled => $Param{Disabled},
Readonly => $Param{Readonly},
);
}
else {
$Param{Minute} =
'<input type="text" '
. ( $Validate ? qq{class="Validate_DateMinute $Class" } : qq{class="$Class" } )
. qq{name="${Prefix}Minute" id="${Prefix}Minute${Suffix}" size="2" maxlength="2" }
. sprintf( 'title="%s" ', $Self->{LanguageObject}->Translate('Minutes') )
. sprintf( 'title="%s" ', $Self->{LanguageObject}->Translate('Minutes') )
. sprintf( 'value="%02d" ', ( $Param{ $Prefix . 'Minute' } || $m ) )
. ( $Param{Disabled} ? 'readonly' : '' )
. ( ( $Param{Disabled} || $Param{Readonly} ) ? 'readonly' : '' )
. '>';
}
}
Expand Down Expand Up @@ -5629,10 +5637,11 @@ sub _BuildSelectionAttributeRefCreate {
}
}

# check HTML params, TODO: the values are not really needed
for (qw(Multiple Disabled)) {
# check HTML params
# NOTE always consider sub _BuildSelectionOuptut() when altering this
for (qw(Multiple Disabled Readonly)) {
if ( $Param{$_} ) {
$Attributes{ lc $_ } = lc $_;
$Attributes{ lc $_ } = undef;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Kernel/System/DynamicField/Driver/BaseDatabase.pm
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ sub EditFieldValueGet {
{
my @Data = $Param{ParamObject}->GetArray( Param => $FieldName );

if ( $Param{DynamicFieldConfig}->{Config}->{MultiValue} ) {
if ( $Param{DynamicFieldConfig}->{Config}{MultiValue} && !$Param{DynamicFieldConfig}->{Readonly} ) {

# delete the template value
pop @Data;
Expand Down
2 changes: 1 addition & 1 deletion Kernel/System/DynamicField/Driver/BaseDateTime.pm
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ sub EditFieldValueGet {
&& ref $Param{ParamObject} eq 'Kernel::System::Web::Request'
)
{
if ( $Param{DynamicFieldConfig}->{Config}->{MultiValue} ) {
if ( $Param{DynamicFieldConfig}->{Config}{MultiValue} ) {
my %Data;

# retrieve value parts as arrays
Expand Down
7 changes: 3 additions & 4 deletions Kernel/System/DynamicField/Driver/BaseEntity.pm
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ sub EditFieldRender {
my $FieldID = $FieldName . '_' . $ValueIndex;
push @SelectionHTML, $Param{LayoutObject}->BuildSelection(
Data => $PossibleValues || {},
Disabled => $Param{Readonly},
Readonly => $Param{Readonly},
Name => $FieldName,
ID => $FieldID,
SelectedID => $Value->[$ValueIndex],
Expand All @@ -289,7 +289,7 @@ sub EditFieldRender {
my @SelectedIDs = grep {$_} $Value->@*;
push @SelectionHTML, $Param{LayoutObject}->BuildSelection(
Data => $PossibleValues || {},
Disabled => $Param{Readonly},
Readonly => $Param{Readonly},
Name => $FieldName,
SelectedID => \@SelectedIDs,
Class => $FieldClass,
Expand Down Expand Up @@ -338,7 +338,6 @@ sub EditFieldRender {

my $SelectionHTML = $Param{LayoutObject}->BuildSelection(
Data => $PossibleValues || {},
Disabled => $Param{Readonly},
Name => $FieldName,
ID => $FieldTemplateData{FieldID},
Translation => $FieldConfig->{TranslatableValues} || 0,
Expand Down Expand Up @@ -421,7 +420,7 @@ sub EditFieldValueGet {
{
my @Data = $Param{ParamObject}->GetArray( Param => $FieldName );

if ( $Param{DynamicFieldConfig}->{Config}{MultiValue} ) {
if ( $Param{DynamicFieldConfig}->{Config}{MultiValue} && !$Param{DynamicFieldConfig}->{Readonly} ) {

# delete the template value
pop @Data;
Expand Down
4 changes: 3 additions & 1 deletion Kernel/System/DynamicField/Driver/BaseScript.pm
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,9 @@ sub EditFieldValueGet {
)
{
$Value = $Param{ParamObject}->GetParam( Param => $FieldName );
if ( $Param{DynamicFieldConfig}->{Config}->{MultiValue} ) {

# TODO check what happens with template data
if ( $Param{DynamicFieldConfig}->{Config}{MultiValue} ) {
my @DataAll = $Param{ParamObject}->GetArray( Param => $FieldName );
my @Data;

Expand Down
6 changes: 4 additions & 2 deletions Kernel/System/DynamicField/Driver/BaseSelect.pm
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ sub EditFieldRender {

my $SelectionHTML = $Param{LayoutObject}->BuildSelection(
Data => $DataValues || {},
Disabled => $Param{Readonly},
Readonly => $Param{Readonly},
Name => $FieldName,
ID => $FieldID,
SelectedID => $Value->[$ValueIndex],
Expand Down Expand Up @@ -473,7 +473,9 @@ sub EditFieldValueGet {
my @Data;

# delete the template value
pop @DataAll;
if ( !$Param{DynamicFieldConfig}->{Readonly} ) {
pop @DataAll;
}

for my $Item (@DataAll) {
push @Data, $Item // '';
Expand Down
4 changes: 3 additions & 1 deletion Kernel/System/DynamicField/Driver/BaseText.pm
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,9 @@ sub EditFieldValueGet {
my @Data;

# delete the template value
pop @DataAll;
if ( !$Param{DynamicFieldConfig}->{Readonly} ) {
pop @DataAll;
}

# delete empty values (can happen if the user has selected the "-" entry)
for my $Item (@DataAll) {
Expand Down
2 changes: 1 addition & 1 deletion Kernel/System/DynamicField/Driver/Checkbox.pm
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ sub EditFieldValueGet {
&& ref $Param{ParamObject} eq 'Kernel::System::Web::Request'
)
{
if ( $Param{DynamicFieldConfig}->{Config}->{MultiValue} ) {
if ( $Param{DynamicFieldConfig}->{Config}{MultiValue} ) {
my @DataValues = $Param{ParamObject}->GetArray( Param => $FieldName );
my @DataUsed = $Param{ParamObject}->GetArray( Param => $FieldName . 'Used' );

Expand Down
2 changes: 1 addition & 1 deletion Kernel/System/DynamicField/Driver/Date.pm
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ sub EditFieldValueGet {
&& ref $Param{ParamObject} eq 'Kernel::System::Web::Request'
)
{
if ( $Param{DynamicFieldConfig}->{Config}->{MultiValue} ) {
if ( $Param{DynamicFieldConfig}->{Config}{MultiValue} ) {
my %Data;

# retrieve value parts as arrays
Expand Down
8 changes: 5 additions & 3 deletions Kernel/System/DynamicField/Driver/WebService.pm
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ sub EditFieldRender {

my $SelectionHTML = $Param{LayoutObject}->BuildSelection(
Data => $DataValues || {},
Disabled => $Param{Readonly},
Readonly => $Param{Readonly},
Name => $FieldName,
ID => $FieldID,
SelectedID => $Value->[$ValueIndex],
Expand Down Expand Up @@ -406,10 +406,12 @@ sub EditFieldValueGet {
{
my @Data = $Param{ParamObject}->GetArray( Param => $FieldName );

if ( $Param{DynamicFieldConfig}->{Config}->{MultiValue} ) {
if ( $Param{DynamicFieldConfig}->{Config}{MultiValue} ) {

# delete the template value
pop @Data;
if ( !$Param{DynamicFieldConfig}->{Readonly} ) {
pop @Data;
}
$Value = \@Data;

}
Expand Down
2 changes: 1 addition & 1 deletion var/httpd/htdocs/js/Core.UI.InputFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ Core.UI.InputFields = (function (TargetNS) {

// Handle form <select> elements that are disabled and elements that were
// disabled with Core.Form.DisableForm();
if ($SelectObj.attr('disabled') || $SearchObj.data('form-disabled')) {
if ($SelectObj.is(':disabled,[readonly]') || $SearchObj.data('form-disabled')) {
$SearchObj.attr('disabled', 'disabled');
// Make background grey and elements white.
$SearchObj.attr('readonly', true);
Expand Down
Loading