From df2febaff3da0b336f944e166339276f8796feaf Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 21 Jan 2015 05:58:16 +0100 Subject: Modules/AdminDefaultTo: Add module to manage DefaultTo entries Add admin frontend module, template and appropriate config to manage the DefaultTo entries via the admin web interface. --- DefaultTo.sopm | 2 + Kernel/Config/Files/DefaultTo.xml | 20 ++ Kernel/Modules/AdminDefaultTo.pm | 351 ++++++++++++++++++++++++++ Kernel/Output/HTML/Standard/AdminDefaultTo.tt | 212 ++++++++++++++++ 4 files changed, 585 insertions(+) create mode 100644 Kernel/Modules/AdminDefaultTo.pm create mode 100644 Kernel/Output/HTML/Standard/AdminDefaultTo.tt diff --git a/DefaultTo.sopm b/DefaultTo.sopm index ea6abc8..1cad73b 100644 --- a/DefaultTo.sopm +++ b/DefaultTo.sopm @@ -12,8 +12,10 @@ ? + + diff --git a/Kernel/Config/Files/DefaultTo.xml b/Kernel/Config/Files/DefaultTo.xml index 9dd0f64..2a075a5 100644 --- a/Kernel/Config/Files/DefaultTo.xml +++ b/Kernel/Config/Files/DefaultTo.xml @@ -15,6 +15,26 @@ + + Frontend module registration for the agent interface. + Ticket + Frontend::Admin::ModuleRegistration + + + admin + Admin + DefaultTo + Admin + + Kernel::Output::HTML::NavBarModuleAdmin + DefaultTo + Create and manage DefaultTo entries. + Queue + 300 + + + + Frontend module registration for the agent interface. Ticket diff --git a/Kernel/Modules/AdminDefaultTo.pm b/Kernel/Modules/AdminDefaultTo.pm new file mode 100644 index 0000000..042c55c --- /dev/null +++ b/Kernel/Modules/AdminDefaultTo.pm @@ -0,0 +1,351 @@ +# -- +# Kernel/Modules/AdminTemplate.pm - provides admin DefaultTo module +# Copyright (C) 2015 Alexander Sulfrian +# -- +# This software comes with ABSOLUTELY NO WARRANTY. For details, see +# the enclosed file COPYING for license information (AGPL). If you +# did not receive this file, see http://www.gnu.org/licenses/agpl.txt. +# -- + +package Kernel::Modules::AdminTemplate; + +use strict; +use warnings; + +use Kernel::System::DefaultTo; + +sub new { + my ( $Type, %Param ) = @_; + + # allocate new hash for object + my $Self = {%Param}; + bless( $Self, $Type ); + + # check all needed objects + for my $Needed (qw(ParamObject DBObject LayoutObject ConfigObject LogObject)) { + if ( !$Self->{$Needed} ) { + $Self->{LayoutObject}->FatalError( Message => "Got no $Needed!" ); + } + } + $Self->{DefaultToObject} = Kernel::System::DefaultTo->new(%Param); + + return $Self; +} + +sub Run { + my ( $Self, %Param ) = @_; + + # ------------------------------------------------------------ # + # change + # ------------------------------------------------------------ # + if ( $Self->{Subaction} eq 'Change' ) { + my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ) || ''; + my %Data = $Self->{DefaultToObject}->Get( + ID => $ID, + ); + + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Self->_Edit( + Action => 'Change', + %Data, + ); + $Output .= $Self->{LayoutObject}->Output( + TemplateFile => 'AdminDefaultTo', + Data => \%Param, + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } + + # ------------------------------------------------------------ # + # change action + # ------------------------------------------------------------ # + elsif ( $Self->{Subaction} eq 'ChangeAction' ) { + + # challenge token check for write action + $Self->{LayoutObject}->ChallengeTokenCheck(); + + my @NewIDs = $Self->{ParamObject}->GetArray( Param => 'IDs' ); + my ( %GetParam, %Errors ); + for my $Parameter (qw(ID Title RemoveDefault AddNew NewAddress + Comment)) { + $GetParam{$Parameter} = $Self->{ParamObject}->GetParam( + Param => $Parameter + ) || ''; + } + + # check needed data + $Errors{ 'TitleInvalid' } = 'ServerError' if !$GetParam{Title}; + + # check if a DefaultTo entry exist with this title + my $TitleExists = $Self->{DefaultToObject}->TitleExistsCheck( + Title => $GetParam{Title}, + ID => $GetParam{ID} + ); + + if ($TitleExists) { + $Errors{TitleExists} = 1; + $Errors{'TitleInvalid'} = 'ServerError'; + } + + # if no errors occurred + if ( !%Errors ) { + + if ( $Self->{DefaultToObject}->Update( + %GetParam, + UserID => $Self->{UserID}, + ) + ) + { + $Self->_Overview(); + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->{LayoutObject}->Notify( Info => 'Template updated!' ); + $Output .= $Self->{LayoutObject}->Output( + TemplateFile => 'AdminDefaultTo', + Data => \%Param, + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } + } + + # something has gone wrong + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->{LayoutObject}->Notify( Priority => 'Error' ); + $Self->_Edit( + Action => 'Change', + Errors => \%Errors, + %GetParam, + ); + $Output .= $Self->{LayoutObject}->Output( + TemplateFile => 'AdminDefaultTo', + Data => \%Param, + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } + + # ------------------------------------------------------------ # + # add + # ------------------------------------------------------------ # + elsif ( $Self->{Subaction} eq 'Add' ) { + my %GetParam; + $GetParam{Title} = $Self->{ParamObject}->GetParam( Param => 'Title' ); + + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Self->_Edit( + Action => 'Add', + %GetParam, + ); + $Output .= $Self->{LayoutObject}->Output( + TemplateFile => 'AdminDefaultTo', + Data => \%Param, + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } + + # ------------------------------------------------------------ # + # add action + # ------------------------------------------------------------ # + elsif ( $Self->{Subaction} eq 'AddAction' ) { + + # challenge token check for write action + $Self->{LayoutObject}->ChallengeTokenCheck(); + + my @NewIDs = $Self->{ParamObject}->GetArray( Param => 'IDs' ); + my ( %GetParam, %Errors ); + + for my $Parameter (qw(ID Title RemoveDefault AddNew NewAddress + Comment)) { + $GetParam{$Parameter} = $Self->{ParamObject}->GetParam( Param => $Parameter ) || ''; + } + + # check needed data + $Errors{ 'TitleInvalid' } = 'ServerError' if !$GetParam{Title}; + + # check if a DefaultTo entry exists with this title + my $TitleExists = $Self->{DefaultToObject}->TitleExistsCheck( Title => $GetParam{Title} ); + if ($TitleExists) { + $Errors{TitleExists} = 1; + $Errors{'TitleInvalid'} = 'ServerError'; + } + + # if no errors occurred + if ( !%Errors ) { + + # add DefaultTo entry + my $ID = $Self->{DefaultToObject}->Add + %GetParam, + UserID => $Self->{UserID}, + ); + + if ($ID) { + $Self->_Overview(); + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->{LayoutObject}->Notify( Info => 'Template added!' ); + $Output .= $Self->{LayoutObject}->Output( + TemplateFile => 'AdminDefaultTo', + Data => \%Param, + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } + } + + # something has gone wrong + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->{LayoutObject}->Notify( Priority => 'Error' ); + $Self->_Edit( + Action => 'Add', + Errors => \%Errors, + %GetParam, + ); + $Output .= $Self->{LayoutObject}->Output( + TemplateFile => 'AdminDefaultTo', + Data => \%Param, + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } + + # ------------------------------------------------------------ # + # delete action + # ------------------------------------------------------------ # + elsif ( $Self->{Subaction} eq 'Delete' ) { + + # challenge token check for write action + $Self->{LayoutObject}->ChallengeTokenCheck(); + + my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ); + + my $Delete = $Self->{DefaultToObject}->Delete( + ID => $ID, + ); + if ( !$Delete ) { + return $Self->{LayoutObject}->ErrorScreen(); + } + + return $Self->{LayoutObject}->Redirect( OP => "Action=$Self->{Action}" ); + } + + # ------------------------------------------------------------ + # overview + # ------------------------------------------------------------ + else { + $Self->_Overview(); + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->{LayoutObject}->Output( + TemplateFile => 'AdminDefaultTo', + Data => \%Param, + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } +} + +sub _Edit { + my ( $Self, %Param ) = @_; + + $Self->{LayoutObject}->Block( + Name => 'Overview', + Data => \%Param, + ); + + $Self->{LayoutObject}->Block( Name => 'ActionList' ); + $Self->{LayoutObject}->Block( Name => 'ActionOverview' ); + + $Param{DefaultToTitleString} = ''; + + $Param{DefaultToRemoveDefaultOption} = $Self->{LayoutObject}->BuildSelection( + Data => $Self->{ConfigObject}->Get('YesNoOptions'), + Name => 'RemoveDefault', + SelectedID => $Param{RemoveDefault} || 0, + ); + + $Param{DefaultToAddNewOption} = $Self->{LayoutObject}->BuildSelection( + Data => $Self->{ConfigObject}->Get('YesNoOptions'), + Name => 'AddNew', + SelectedID => $Param{AddNew} || 0, + ); + + $Param{DefaultToNewAddressString} = ''; + + $Self->{LayoutObject}->Block( + Name => 'OverviewUpdate', + Data => { + %Param, + %{ $Param{Errors} }, + }, + ); + + # shows header + if ( $Param{Action} eq 'Change' ) { + $Self->{LayoutObject}->Block( Name => 'HeaderEdit' ); + } + else { + $Self->{LayoutObject}->Block( Name => 'HeaderAdd' ); + } + + # show appropriate messages for ServerError + if ( defined $Param{Errors}->{TitleExists} && $Param{Errors}->{TitleExists} == 1 ) { + $Self->{LayoutObject}->Block( Name => 'ExistTitleServerError' ); + } + else { + $Self->{LayoutObject}->Block( Name => 'TitleServerError' ); + } + + return 1; +} + +sub _Overview { + my ( $Self, %Param ) = @_; + + $Self->{LayoutObject}->Block( + Name => 'Overview', + Data => \%Param, + ); + + $Self->{LayoutObject}->Block( Name => 'ActionList' ); + $Self->{LayoutObject}->Block( Name => 'ActionAdd' ); + $Self->{LayoutObject}->Block( Name => 'Filter' ); + + $Self->{LayoutObject}->Block( + Name => 'OverviewResult', + Data => \%Param, + ); + my %List = $Self->{DefaultToObject}->List(); + + for my $ID ( sort { $List{$a} cmp $List{$b} } keys %List ) + { + my %DefaultTo = $Self->{DefaultToObject}->Get( + ID => $ID, + ); + + $Self->{LayoutObject}->Block( + Name => 'OverviewResultRow', + Data => { + %DefaultTo, + }, + ); + } + + # otherwise it displays a no data found message + else { + $Self->{LayoutObject}->Block( + Name => 'NoDataFoundMsg', + Data => {}, + ); + } + + return 1; +} + +1; diff --git a/Kernel/Output/HTML/Standard/AdminDefaultTo.tt b/Kernel/Output/HTML/Standard/AdminDefaultTo.tt new file mode 100644 index 0000000..04e4c91 --- /dev/null +++ b/Kernel/Output/HTML/Standard/AdminDefaultTo.tt @@ -0,0 +1,212 @@ +# -- +# AdminDefaultTo.tt - provides HTML form for AdminDefaultTo +# Copyright (C) 2015 Alexander Sulfrian +# -- +# This software comes with ABSOLUTELY NO WARRANTY. For details, see +# the enclosed file COPYING for license information (AGPL). If you +# did not receive this file, see http://www.gnu.org/licenses/agpl.txt. +# -- + +[% RenderBlockStart("Overview") %] +
+

[% Translate("Manage DefaultTo") | html %]

+ +
+[% RenderBlockStart("ActionList") %] +
+

[% Translate("Actions") | html %]

+
+ +
+
+[% RenderBlockStart("Filter") %] +
+
+

+
+
+ +
+
+[% RenderBlockEnd("Filter") %] +[% RenderBlockEnd("ActionList") %] + +
+
+

[% Translate("Hint") | html %]

+
+
+ +

+ [% Translate("With DefaultTo you could change or extend the default To address in a ticket response dependent on the used template.") | html %] +

+

+ [% Translate("Attention") | html %]: + [% Translate("Don't forget to add new DefaultTo entries to templates.") | html %] +

+
+
+
+
+ +[% RenderBlockStart("OverviewResult") %] +
+
+

[% Translate("List") | html %]

+
+
+ + + + + + + + + + + + + + + + + +[% RenderBlockStart("NoDataFoundMsg") %] + + + +[% RenderBlockEnd("NoDataFoundMsg") %] +[% RenderBlockStart("OverviewResultRow") %] + + + + + + + + + + +[% RenderBlockEnd("OverviewResultRow") %] + +
[% Translate("Title") | html %][% Translate("Remove default") | html %][% Translate("Add new") | html %][% Translate("New address") | html %][% Translate("Comment") | html %][% Translate("Changed") | html %][% Translate("Created") | html %][% Translate("Delete") | html %]
+ [% Translate("No data found.") | html %] +
+ [% Data.Name | html %] + [% Translate(Data.RemoveDefault) | html %][% Translate(Data.AddNew) | html %][% Data.NewAddress | html %][% Data.Comment | truncate(26) | html %][% Data.ChangeTime | Localize("TimeShort") %][% Data.CreateTime | Localize("TimeShort") %] + + [% Translate("Delete this entry") | html %] + + +
+
+
+[% WRAPPER JSOnDocumentComplete %] + +[% END %] +[% RenderBlockEnd("OverviewResult") %] +[% RenderBlockStart("OverviewUpdate") %] + +
+
+[% RenderBlockStart("HeaderAdd") %] +

[% Translate("Add DefaultTo") | html %]

+[% RenderBlockEnd("HeaderAdd") %] +[% RenderBlockStart("HeaderEdit") %] +

[% Translate("Edit DefaultTo") | html %]

+[% RenderBlockEnd("HeaderEdit") %] +
+
+
+ + + +
+ +
+ +
+

[% Translate("This field is required.") | html %]

+
+
+[% RenderBlockStart("TitleServerError") %] +

[% Translate("This field is required.") | html %]

+[% RenderBlockEnd("TitleServerError") %] +[% RenderBlockStart("ExistTitleServerError") %] +

[% Translate("A DefaultTo entry with this title already exists!") | html %]

+[% RenderBlockEnd("TitleServerError") %] +
+
+
+ + +
+ [% Data.DefaultToRemoveDefaultOption %] +
+

[% Translate("This field is required.") | html %]

+
+
+

[% Translate("This field is required.") | html %]

+
+
+
+ + +
+ [% Data.DefaultToAddNewOption %] +
+

[% Translate("This field is required.") | html %]

+
+
+

[% Translate("This field is required.") | html %]

+
+
+
+ + +
+ +
+

[% Translate("This field is required.") | html %]

+
+
+

[% Translate("This field is required.") | html %]

+
+
+
+ + +
+ +
+
+ +
+ + [% Translate("or") | html %] + [% Translate("Cancel") | html %] +
+
+
+
+
+
+[% RenderBlockEnd("OverviewUpdate") %] +
+
+
+[% RenderBlockEnd("Overview") %] -- cgit v1.2.3-1-g7c22