1# -- 2# Copyright (C) 2001-2020 OTRS AG, https://otrs.com/ 3# -- 4# This software comes with ABSOLUTELY NO WARRANTY. For details, see 5# the enclosed file COPYING for license information (GPL). If you 6# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt. 7# -- 8 9package Kernel::System::SysConfig::ValueType::Textarea; 10## nofilter(TidyAll::Plugin::OTRS::Perl::LayoutObject) 11 12use strict; 13use warnings; 14 15use Kernel::System::VariableCheck qw(:all); 16 17use parent qw(Kernel::System::SysConfig::BaseValueType); 18 19our @ObjectDependencies = ( 20 'Kernel::Language', 21 'Kernel::Output::HTML::Layout', 22 'Kernel::System::Log', 23); 24 25=head1 NAME 26 27Kernel::System::SysConfig::ValueType::Textarea - System configuration text-area value type backed. 28 29=head1 PUBLIC INTERFACE 30 31=head2 new() 32 33Create an object. Do not use it directly, instead use: 34 35 use Kernel::System::ObjectManager; 36 local $Kernel::OM = Kernel::System::ObjectManager->new(); 37 my $ValueTypeObject = $Kernel::OM->Get('Kernel::System::SysConfig::ValueType::Textarea'); 38 39=cut 40 41sub new { 42 my ( $Type, %Param ) = @_; 43 44 # Allocate new hash for object. 45 my $Self = {}; 46 bless( $Self, $Type ); 47 48 return $Self; 49} 50 51=head2 SettingRender() 52 53Extracts the effective value from a XML parsed setting. 54 55 my $SettingHTML = $ValueTypeObject->SettingRender( 56 Name => 'SettingName', 57 EffectiveValue => 'Textarea content', # (optional) 58 DefaultValue => 'Textarea content', # (optional) 59 Class => 'My class' # (optional) 60 Item => [ # (optional) XML parsed item 61 { 62 'ValueType' => 'Textarea', 63 'Content' => 'Textarea content', 64 }, 65 ], 66 RW => 1, # (optional) Allow editing. Default 0. 67 IsArray => 1, # (optional) Item is part of the array 68 IsHash => 1, # (optional) Item is part of the hash 69 IDSuffix => 1, # (optional) Suffix will be added to the element ID 70 SkipEffectiveValueCheck => 1, # (optional) If enabled, system will not perform effective value check. 71 # Default: 1. 72 ); 73 74Returns: 75 76 $SettingHTML = '<div class "Field"...</div>'; 77 78=cut 79 80sub SettingRender { 81 my ( $Self, %Param ) = @_; 82 83 if ( !defined $Param{Name} ) { 84 $Kernel::OM->Get('Kernel::System::Log')->Log( 85 Priority => 'error', 86 Message => "Need Name", 87 ); 88 return; 89 } 90 91 $Param{Class} //= ''; 92 $Param{DefaultValue} //= ''; 93 $Param{IDSuffix} //= ''; 94 95 my $LanguageObject = $Kernel::OM->Get('Kernel::Language'); 96 97 my $Name = $Param{Name}; 98 99 my $EffectiveValue = $Param{EffectiveValue}; 100 if ( 101 !defined $EffectiveValue 102 && $Param{Item} 103 && $Param{Item}->[0]->{Content} 104 ) 105 { 106 $EffectiveValue = $Param{Item}->[0]->{Content}; 107 } 108 109 my %EffectiveValueCheck = ( 110 Success => 1, 111 ); 112 113 if ( !$Param{SkipEffectiveValueCheck} ) { 114 %EffectiveValueCheck = $Self->SettingEffectiveValueCheck( 115 EffectiveValue => $EffectiveValue, 116 XMLContentParsed => { 117 Value => [ 118 { 119 Item => $Param{Item}, 120 }, 121 ], 122 }, 123 ); 124 } 125 126 my $HTML = "<div class='SettingContent'>\n"; 127 $HTML 128 .= "<textarea rows='15' cols='50' class=\"$Param{Class}\" type=\"text\" name=\"$Name\"" . 129 " id=\"$Param{Name}$Param{IDSuffix}\""; 130 131 if ( !$Param{RW} ) { 132 $HTML .= "disabled='disabled' "; 133 } 134 135 my $HTMLValue = $Kernel::OM->Get('Kernel::Output::HTML::Layout')->Ascii2Html( 136 Text => $EffectiveValue, 137 Type => 'Normal', 138 ); 139 140 $HTML .= ">$HTMLValue</textarea>\n"; 141 142 if ( !$EffectiveValueCheck{Success} ) { 143 my $Message = $LanguageObject->Translate("Value is not correct! Please, consider updating this field."); 144 145 $HTML .= $Param{IsValid} ? "<div class='BadEffectiveValue'>\n" : "<div>\n"; 146 $HTML .= "<p>* $Message</p>\n"; 147 $HTML .= "</div>\n"; 148 } 149 150 $HTML .= "</div>\n"; 151 152 if ( !$Param{IsArray} && !$Param{IsHash} ) { 153 my $DefaultValueStrg = $LanguageObject->Translate('Default'); 154 155 $HTML .= <<"EOF"; 156 <div class=\"WidgetMessage Bottom\"> 157 $DefaultValueStrg: $Param{DefaultValue} 158 </div> 159EOF 160 } 161 162 return $HTML; 163} 164 165=head2 AddItem() 166 167Generate HTML for new array/hash item. 168 169 my $HTML = $ValueTypeObject->AddItem( 170 Name => 'SettingName', (required) Name 171 DefaultItem => { (required) DefaultItem hash 172 'ValueType' => 'Select', 173 'Content' => 'optiont-1', 174 }, 175 IDSuffix => '_Array1', (optional) IDSuffix is needed for arrays and hashes. 176 ); 177 178Returns: 179 180 $HTML = '<textarea rows=\'15\' cols=\'50\' class="" type="text" name="SettingName"> 181 ... 182 </textarea>'; 183 184=cut 185 186sub AddItem { 187 my ( $Self, %Param ) = @_; 188 189 # Check needed stuff. 190 for my $Needed (qw(Name DefaultItem)) { 191 if ( !$Param{$Needed} ) { 192 $Kernel::OM->Get('Kernel::System::Log')->Log( 193 Priority => 'error', 194 Message => "Need $Needed!", 195 ); 196 return; 197 } 198 } 199 $Param{Class} //= ''; 200 $Param{DefaultValue} //= ''; 201 $Param{IDSuffix} //= ''; 202 203 my $DefaultValue = $Param{DefaultItem}->{Content} || ''; 204 205 my $Result = "<textarea rows='15' cols='100' class=\"$Param{Class} Entry\" type=\"text\" name=\"$Param{Name}\" "; 206 $Result .= "id=\"$Param{Name}$Param{IDSuffix}\">$DefaultValue</textarea>"; 207 208 return $Result; 209} 210 2111; 212 213=head1 TERMS AND CONDITIONS 214 215This software is part of the OTRS project (L<https://otrs.org/>). 216 217This software comes with ABSOLUTELY NO WARRANTY. For details, see 218the enclosed file COPYING for license information (GPL). If you 219did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>. 220 221=cut 222