313 lines
6.9 KiB
Perl
313 lines
6.9 KiB
Perl
# --
|
|
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
|
# --
|
|
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
|
# the enclosed file COPYING for license information (GPL). If you
|
|
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
|
# --
|
|
|
|
package Kernel::Output::HTML::ITSMConfigItem::LayoutText;
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
our @ObjectDependencies = (
|
|
'Kernel::System::Log',
|
|
'Kernel::Output::HTML::Layout',
|
|
'Kernel::Config',
|
|
'Kernel::System::Web::Request'
|
|
);
|
|
|
|
=head1 NAME
|
|
|
|
Kernel::Output::HTML::ITSMConfigItem::LayoutText - layout backend module
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
All layout functions of text objects
|
|
|
|
=head2 new()
|
|
|
|
create an object
|
|
|
|
$BackendObject = Kernel::Output::HTML::ITSMConfigItem::LayoutText->new(
|
|
%Param,
|
|
);
|
|
|
|
=cut
|
|
|
|
sub new {
|
|
my ( $Type, %Param ) = @_;
|
|
|
|
# allocate new hash for object
|
|
my $Self = {};
|
|
bless( $Self, $Type );
|
|
|
|
return $Self;
|
|
}
|
|
|
|
=head2 OutputStringCreate()
|
|
|
|
create output string
|
|
|
|
my $Value = $BackendObject->OutputStringCreate(
|
|
Value => 11, # (optional)
|
|
Item => $ItemRef,
|
|
);
|
|
|
|
=cut
|
|
|
|
sub OutputStringCreate {
|
|
my ( $Self, %Param ) = @_;
|
|
|
|
# check needed stuff
|
|
if ( !$Param{Item} ) {
|
|
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
|
Priority => 'error',
|
|
Message => 'Need Item!',
|
|
);
|
|
return;
|
|
}
|
|
|
|
if ( !defined $Param{Value} ) {
|
|
$Param{Value} = '';
|
|
}
|
|
|
|
# get layout object
|
|
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
|
|
|
|
# translate
|
|
if ( $Param{Item}->{Input}->{Translation} ) {
|
|
$Param{Value} = $LayoutObject->{LanguageObject}->Translate( $Param{Value} );
|
|
}
|
|
|
|
my $LinkFeature = 1;
|
|
|
|
# do not transform links in print view
|
|
if ( $Param{Print} ) {
|
|
$LinkFeature = 0;
|
|
}
|
|
|
|
# transform ascii to html
|
|
$Param{Value} = $LayoutObject->Ascii2Html(
|
|
Text => $Param{Value},
|
|
HTMLResultMode => 1,
|
|
LinkFeature => $LinkFeature,
|
|
);
|
|
|
|
return $Param{Value};
|
|
}
|
|
|
|
=head2 FormDataGet()
|
|
|
|
get form data as hash reference
|
|
|
|
my $FormDataRef = $BackendObject->FormDataGet(
|
|
Key => 'Item::1::Node::3',
|
|
Item => $ItemRef,
|
|
);
|
|
|
|
=cut
|
|
|
|
sub FormDataGet {
|
|
my ( $Self, %Param ) = @_;
|
|
|
|
# check needed stuff
|
|
for my $Argument (qw(Key Item)) {
|
|
if ( !$Param{$Argument} ) {
|
|
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
|
Priority => 'error',
|
|
Message => "Need $Argument!",
|
|
);
|
|
return;
|
|
}
|
|
}
|
|
|
|
my %FormData;
|
|
|
|
# get form data
|
|
$FormData{Value} = $Kernel::OM->Get('Kernel::System::Web::Request')->GetParam( Param => $Param{Key} );
|
|
|
|
# set invalid param
|
|
if ( $Param{Item}->{Input}->{Required} && !defined $FormData{Value} ) {
|
|
$FormData{Invalid} = 1;
|
|
$Param{Item}->{Form}->{ $Param{Key} }->{Invalid} = 1;
|
|
}
|
|
|
|
# value was entered in the form, a regex is defined and the value does not match the regex
|
|
if (
|
|
$FormData{Value}
|
|
&& $Param{Item}->{Input}->{RegEx}
|
|
&& $FormData{Value} !~ m{ $Param{Item}->{Input}->{RegEx} }xms
|
|
)
|
|
{
|
|
|
|
$FormData{Invalid} = 1;
|
|
$Param{Item}->{Form}->{ $Param{Key} }->{Invalid} = 1;
|
|
$Param{Item}->{Form}->{ $Param{Key} }->{RegExErrorMessage} = $Param{Item}->{Input}->{RegExErrorMessage};
|
|
}
|
|
|
|
return \%FormData;
|
|
}
|
|
|
|
=head2 InputCreate()
|
|
|
|
create a input string
|
|
|
|
my $Value = $BackendObject->InputCreate(
|
|
Key => 'Item::1::Node::3',
|
|
Value => 11, # (optional)
|
|
Item => $ItemRef,
|
|
);
|
|
|
|
=cut
|
|
|
|
sub InputCreate {
|
|
my ( $Self, %Param ) = @_;
|
|
|
|
# check needed stuff
|
|
for my $Argument (qw(Key Item)) {
|
|
if ( !$Param{$Argument} ) {
|
|
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
|
Priority => 'error',
|
|
Message => "Need $Argument!",
|
|
);
|
|
return;
|
|
}
|
|
}
|
|
|
|
my $Value = $Param{Value};
|
|
if ( !defined $Param{Value} ) {
|
|
$Value = $Param{Item}->{Input}->{ValueDefault} || '';
|
|
}
|
|
|
|
my $Class = '';
|
|
my $Size = 'W50pc';
|
|
my $Required = $Param{Required};
|
|
my $Invalid = $Param{Invalid};
|
|
my $ItemId = $Param{ItemId};
|
|
|
|
if ($Required) {
|
|
$Class .= ' Validate_Required';
|
|
}
|
|
|
|
if ($Invalid) {
|
|
$Class .= ' ServerError';
|
|
}
|
|
$Class .= ' ' . $Size;
|
|
my $String = "<input type=\"text\" name=\"$Param{Key}\" class=\"$Class\" ";
|
|
|
|
if ($ItemId) {
|
|
$String .= "id=\"$ItemId\" ";
|
|
}
|
|
|
|
if ($Value) {
|
|
|
|
# get layout object
|
|
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
|
|
|
|
# translate
|
|
if ( $Param{Item}->{Input}->{Translation} ) {
|
|
$Value = $LayoutObject->{LanguageObject}->Translate($Value);
|
|
}
|
|
|
|
# transform ascii to html
|
|
$Value = $LayoutObject->Ascii2Html(
|
|
Text => $Value,
|
|
HTMLResultMode => 1,
|
|
);
|
|
}
|
|
|
|
$String .= "value=\"$Value\" ";
|
|
|
|
# add maximum length
|
|
if ( $Param{Item}->{Input}->{MaxLength} ) {
|
|
$String .= "maxlength=\"$Param{Item}->{Input}->{MaxLength}\" ";
|
|
}
|
|
|
|
$String .= '/> ';
|
|
|
|
return $String;
|
|
}
|
|
|
|
=head2 SearchFormDataGet()
|
|
|
|
get search form data
|
|
|
|
my $Value = $BackendObject->SearchFormDataGet(
|
|
Key => 'Item::1::Node::3',
|
|
Item => $ItemRef,
|
|
);
|
|
|
|
=cut
|
|
|
|
sub SearchFormDataGet {
|
|
my ( $Self, %Param ) = @_;
|
|
|
|
# check needed stuff
|
|
if ( !$Param{Key} ) {
|
|
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
|
Priority => 'error',
|
|
Message => 'Need Key!',
|
|
);
|
|
return;
|
|
}
|
|
|
|
# get form data
|
|
my $Value;
|
|
if ( $Param{Value} ) {
|
|
$Value = $Param{Value};
|
|
}
|
|
else {
|
|
$Value = $Kernel::OM->Get('Kernel::System::Web::Request')->GetParam( Param => $Param{Key} );
|
|
}
|
|
return $Value;
|
|
}
|
|
|
|
=head2 SearchInputCreate()
|
|
|
|
create a search input string
|
|
|
|
my $Value = $BackendObject->SearchInputCreate(
|
|
Key => 'Item::1::Node::3',
|
|
Item => $ItemRef,
|
|
);
|
|
|
|
=cut
|
|
|
|
sub SearchInputCreate {
|
|
my ( $Self, %Param ) = @_;
|
|
|
|
# check needed stuff
|
|
for my $Argument (qw(Key Item)) {
|
|
if ( !$Param{$Argument} ) {
|
|
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
|
Priority => 'error',
|
|
Message => "Need $Argument!",
|
|
);
|
|
return;
|
|
}
|
|
}
|
|
|
|
my $Value = $Self->SearchFormDataGet(%Param);
|
|
if ( !defined $Value ) {
|
|
$Value = '';
|
|
}
|
|
|
|
my $String = qq{<input type="text" name="$Param{Key}" value="$Value" class="W50pc" >};
|
|
|
|
return $String;
|
|
}
|
|
|
|
1;
|
|
|
|
=head1 TERMS AND CONDITIONS
|
|
|
|
This software is part of the OTRS project (L<https://otrs.org/>).
|
|
|
|
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
|
the enclosed file COPYING for license information (GPL). If you
|
|
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
|
|
|
=cut
|