diff options
author | Alexander Sulfrian <alex@spline.inf.fu-berlin.de> | 2015-01-21 02:31:04 +0100 |
---|---|---|
committer | Alexander Sulfrian <alex@spline.inf.fu-berlin.de> | 2015-01-21 03:15:22 +0100 |
commit | 95228db70acea35da946a8e9e50dd9a5fc423174 (patch) | |
tree | fad4a9a4e140ca7ce7f4524b64396cb6ca0af615 /Kernel | |
parent | f7a55ac5cd3e2dd84fd8d7349ad6bf06506bfd89 (diff) | |
download | DefaultRecipient-95228db70acea35da946a8e9e50dd9a5fc423174.tar.gz DefaultRecipient-95228db70acea35da946a8e9e50dd9a5fc423174.tar.bz2 DefaultRecipient-95228db70acea35da946a8e9e50dd9a5fc423174.zip |
Add admin interface for mapping Templates and ResponseChangeDefaultTo
Diffstat (limited to 'Kernel')
3 files changed, 553 insertions, 0 deletions
diff --git a/Kernel/Config/Files/ResponseChangeDefaultTo.xml b/Kernel/Config/Files/ResponseChangeDefaultTo.xml index 0018b85..0c19c0f 100644 --- a/Kernel/Config/Files/ResponseChangeDefaultTo.xml +++ b/Kernel/Config/Files/ResponseChangeDefaultTo.xml @@ -15,4 +15,24 @@ </Hash> </Setting> </ConfigItem> + <ConfigItem Name="Frontend::Module###AdminResponseChangeDefaultToTemplates" Required="0" Valid="1"> + <Description Translatable="1">Frontend module registration for the agent interface.</Description> + <Group>Ticket</Group> + <SubGroup>Frontend::Admin::ModuleRegistration</SubGroup> + <Setting> + <FrontendModuleReg> + <Group>admin</Group> + <Description>Admin</Description> + <Title Translatable="1">Templates <-> ResponseChangeDefaultTo</Title> + <NavBarName>Admin</NavBarName> + <NavBarModule> + <Module>Kernel::Output::HTML::NavBarModuleAdmin</Module> + <Name Translatable="1">Templates <-> ResponseChangeDefaultTo</Name> + <Description Translatable="1">Link templates to ResponseChangeDefaultTo.</Description> + <Block>Queue</Block> + <Prio>300</Prio> + </NavBarModule> + </FrontendModuleReg> + </Setting> + </ConfigItem> </otrs_config> diff --git a/Kernel/Modules/AdminResponseChangeDefaultToTemplates.pm b/Kernel/Modules/AdminResponseChangeDefaultToTemplates.pm new file mode 100644 index 0000000..02a0b36 --- /dev/null +++ b/Kernel/Modules/AdminResponseChangeDefaultToTemplates.pm @@ -0,0 +1,361 @@ +# -- +# Kernel/Modules/AdminResponseChangeDefaultToTemplates.pm - to manage ResponseChangeDefaultTo <-> templates assignments +# Copyright (C) 2015 Alexander Sulfrian <alex@spline.inf.fu-berlin.de> +# -- +# 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::AdminResponseChangeDefaultToTemplates; + +use strict; +use warnings; + +use Kernel::System::ResponseChangeDefaultTo; +use Kernel::System::StandardTemplate; + +sub new { + my ( $Type, %Param ) = @_; + + # allocate new hash for object + my $Self = {%Param}; + bless( $Self, $Type ); + + # check all needed objects + for (qw(ParamObject DBObject QueueObject LayoutObject ConfigObject LogObject)) { + if ( !$Self->{$_} ) { + $Self->{LayoutObject}->FatalError( Message => "Got no $_!" ); + } + } + + $Self->{ResponseChangeDefaultToObject} = + Kernel::System::ResponseChangeDefaultTo->new(%Param); + $Self->{StandardTemplateObject} = + Kernel::System::StandardTemplate->new(%Param); + + return $Self; +} + +sub Run { + my ( $Self, %Param ) = @_; + + # ------------------------------------------------------------ # + # template <-> ResponseChangeDefaultTo 1:n + # ------------------------------------------------------------ # + if ( $Self->{Subaction} eq 'Template' ) { + + # get template data + my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ); + my %StandardTemplateData = $Self->{StandardTemplateObject}->StandardTemplateGet( ID => $ID ); + my $StandardTemplateType = $Self->{LayoutObject}->{LanguageObject}->Translate( + $StandardTemplateData{TemplateType}, + ); + my $Name = $StandardTemplateType . ' - ' . $StandardTemplateData{Name}; + + # get ResponseChangeDefaultTo data + my %ResponseChangeDefaultToData = + $Self->{ResponseChangeDefaultToObject}->List(); + + my %Member = $Self->{ResponseChangeDefaultToObject}->MappingList( + ResponseID => $ID, + ); + + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->_Change( + Data => \%ResponseChangeDefaultToData, + ID => $ID, + Name => $Name, + Mapping => \%Member, + Type => 'Template', + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } + + # ------------------------------------------------------------ # + # templates <-> ResponseChangeDefaultTo n:1 + # ------------------------------------------------------------ # + elsif ( $Self->{Subaction} eq 'ResponseChangeDefaultTo' ) { + + my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ); + my %ResponseChangeDefaultToData = + $Self->{ResponseChangeDefaultToObject}->Get( ID => $ID ); + + # get templates + my %StandardTemplateData = $Self->{StandardTemplateObject}->StandardTemplateList( + Valid => 1, + ); + + if (%StandardTemplateData) { + for my $StandardTemplateID ( sort keys %StandardTemplateData ) { + my %Data = $Self->{StandardTemplateObject}->StandardTemplateGet( + ID => $StandardTemplateID + ); + $StandardTemplateData{$StandardTemplateID} + = $Self->{LayoutObject}->{LanguageObject}->Translate( $Data{TemplateType} ) + . ' - ' + . $Data{Name}; + } + } + + # get assigned templates + my %Member = $Self->{ResponseChangeDefaultToObject}->MappingList( + ResponseChangeDefaultToID => $ID, + ); + + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->_Change( + Data => \%StandardTemplateData, + ID => $ID, + Name => $ResponseChangeDefaultToData{Title}, + Mapping => \%Member, + Type => 'ResponseChangeDefaultTo', + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } + + # ------------------------------------------------------------ # + # add templates to ResponseChangeDefaultTo + # ------------------------------------------------------------ # + elsif ( $Self->{Subaction} eq 'ChangeResponseChangeDefaultTo' ) { + + # challenge token check for write action + $Self->{LayoutObject}->ChallengeTokenCheck(); + + # get current mapping + my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ); + my %Mapping = $Self->{ResponseChangeDefaultToObject}->MappingList( + ResponseChangeDefaultToID => $ID, + ); + + # get new templates + my @TemplatesSelected = $Self->{ParamObject}->GetArray( Param => 'ItemsSelected' ); + my @TemplatesAll = $Self->{ParamObject}->GetArray( Param => 'ItemsAll' ); + + # create hash with selected templates + my %TemplatesSelected = map { $_ => 1 } @TemplatesSelected; + + # check all used templates + for my $TemplateID (@TemplatesAll) { + if ( $TemplatesSelected{$TemplateID} ) { + if ( ! $Mapping{$TemplateID} ) { + $Self->{ResponseChangeDefaultToObject}->MappingAdd( + ResponseID => $TemplateID, + ResponseChangeDefaultToID => $ID, + ); + } + } + else { + if ( $Mapping{$TemplateID} ) { + $Self->{ResponseChangeDefaultToObject}->MappingDelete( + ID => $Mapping{$TemplateID}, + ); + } + } + } + + return $Self->{LayoutObject}->Redirect( OP => "Action=$Self->{Action}" ); + } + + # ------------------------------------------------------------ # + # add queues to template + # ------------------------------------------------------------ # + elsif ( $Self->{Subaction} eq 'ChangeTemplate' ) { + + # challenge token check for write action + $Self->{LayoutObject}->ChallengeTokenCheck(); + + # get current mapping + my $ID = $Self->{ParamObject}->GetParam( Param => 'ID' ); + my %Mapping = $Self->{ResponseChangeDefaultToObject}->MappingList( + ResponseID => $ID, + ); + + # get new queues + my @Selected = $Self->{ParamObject}->GetArray( Param => 'ItemsSelected' ); + my @All = $Self->{ParamObject}->GetArray( Param => 'ItemsAll' ); + + # create hash with selected queues + my %Selected = map { $_ => 1 } @Selected; + + # check all used queues + for my $DefaultToID (@All) { + if ( $Selected{$DefaultToID} ) { + if ( ! $Mapping{$DefaultToID} ) { + $Self->{ResponseChangeDefaultToObject}->MappingAdd( + ResponseID => $ID, + ResponseChangeDefaultToID => $DefaultToID, + ); + } + } + else { + if ( $Mapping{$DefaultToID} ) { + $Self->{ResponseChangeDefaultToObject}->MappingDelete( + ID => $Mapping{$DefaultToID}, + ); + } + } + } + + return $Self->{LayoutObject}->Redirect( OP => "Action=$Self->{Action}" ); + } + + # ------------------------------------------------------------ # + # overview + # ------------------------------------------------------------ # + my $Output = $Self->{LayoutObject}->Header(); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->_Overview(); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; +} + +sub _Change { + my ( $Self, %Param ) = @_; + + my %Data = %{ $Param{Data} }; + my %Mapping = %{ $Param{Mapping} }; + my $Type = $Param{Type} || 'Template'; + my $NeType = 'ResponseChangeDefaultTo'; + $NeType = 'Template' if $Type eq 'ResponseChangeDefaultTo'; + + $Self->{LayoutObject}->Block( Name => 'Overview' ); + $Self->{LayoutObject}->Block( Name => 'ActionList' ); + $Self->{LayoutObject}->Block( Name => 'ActionOverview' ); + $Self->{LayoutObject}->Block( Name => 'Filter' ); + + $Self->{LayoutObject}->Block( + Name => 'Change', + Data => { + ID => $Param{ID}, + Name => $Param{Name}, + ActionHome => 'Admin' . $Type, + NeType => $NeType, + }, + ); + + $Self->{LayoutObject}->Block( Name => "ChangeHeader$NeType" ); + + for my $ID ( sort { uc( $Data{$a} ) cmp uc( $Data{$b} ) } keys %Data ) { + + # set output class + my $Selected = $Mapping{$ID} ? ' checked="checked"' : ''; + + $Self->{LayoutObject}->Block( + Name => 'ChangeRow', + Data => { + Type => $NeType, + ID => $ID, + Name => $Data{$ID}, + Selected => $Selected, + }, + ); + } + + return $Self->{LayoutObject}->Output( + TemplateFile => 'AdminResponseChangeDefaultToTemplates', + Data => \%Param, + ); +} + +sub _Overview { + my ( $Self, %Param ) = @_; + + $Self->{LayoutObject}->Block( + Name => 'Overview', + Data => {}, + ); + + # no actions in action list + # $Self->{LayoutObject}->Block(Name=>'ActionList'); + $Self->{LayoutObject}->Block( Name => 'FilterTemplate' ); + $Self->{LayoutObject}->Block( Name => 'FilterResponseChangeDefaultTo' ); + $Self->{LayoutObject}->Block( Name => 'OverviewResult' ); + + # get std template list + my %StandardTemplateData = $Self->{StandardTemplateObject}->StandardTemplateList( + Valid => 1, + ); + + # if there are results to show + if (%StandardTemplateData) { + for my $StandardTemplateID ( sort keys %StandardTemplateData ) { + my %Data = $Self->{StandardTemplateObject}->StandardTemplateGet( + ID => $StandardTemplateID, + ); + $StandardTemplateData{$StandardTemplateID} + = $Self->{LayoutObject}->{LanguageObject}->Translate( $Data{TemplateType} ) + . ' - ' + . $Data{Name}; + } + for my $StandardTemplateID ( + sort { uc( $StandardTemplateData{$a} ) cmp uc( $StandardTemplateData{$b} ) } + keys %StandardTemplateData + ) + { + + # set output class + $Self->{LayoutObject}->Block( + Name => 'List1n', + Data => { + Name => $StandardTemplateData{$StandardTemplateID}, + Subaction => 'Template', + ID => $StandardTemplateID, + }, + ); + } + } + + # otherwise it displays a no data found message + else { + $Self->{LayoutObject}->Block( + Name => 'NoTemplatesFoundMsg', + Data => {}, + ); + } + + # get queue data + my %ResponseChangeDefaultToData = + $Self->{ResponseChangeDefaultToObject}->List(); + + # if there are results to show + if (%ResponseChangeDefaultToData) { + for my $ID ( + sort { uc( $ResponseChangeDefaultToData{$a} ) cmp + uc( $ResponseChangeDefaultToData{$b} ) } + keys %ResponseChangeDefaultToData + ) + { + + # set output class + $Self->{LayoutObject}->Block( + Name => 'Listn1', + Data => { + Name => $ResponseChangeDefaultToData{$ID}, + Subaction => 'ResponseChangeDefaultTo', + ID => $ID, + }, + ); + } + } + + # otherwise it displays a no data found message + else { + $Self->{LayoutObject}->Block( + Name => 'NoResponseChangeDefaultToFoundMsg', + Data => {}, + ); + } + + # return output + return $Self->{LayoutObject}->Output( + TemplateFile => 'AdminResponseChangeDefaultToTemplates', + Data => \%Param, + ); +} + +1; diff --git a/Kernel/Output/HTML/Standard/AdminResponseChangeDefaultToTemplates.tt b/Kernel/Output/HTML/Standard/AdminResponseChangeDefaultToTemplates.tt new file mode 100644 index 0000000..090716f --- /dev/null +++ b/Kernel/Output/HTML/Standard/AdminResponseChangeDefaultToTemplates.tt @@ -0,0 +1,172 @@ +# -- +# AdminResponseChangeDefaultToTemplates.tt - provides HTML form for AdminInterface +# Copyright (C) 2015 Alexander Sulfrian <alex@spline.inf.fu-berlin.de> +# -- +# 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") %] +<div class="MainBox ARIARoleMain LayoutFixedSidebar SidebarFirst"> + <h1>[% Translate("Manage Template-ResponseChangeDefaultTo Relations") | html %]</h1> + + <div class="SidebarColumn"> + +[% RenderBlockStart("ActionList") %] + <div class="WidgetSimple"> + <div class="Header"> + <h2><label>[% Translate("Actions") | html %]</label></h2> + </div> + <div class="Content"> + <ul class="ActionList"> +[% RenderBlockStart("ActionOverview") %] + <li> + <a href="[% Env("Baselink") %]Action=[% Env("Action") %]" class="CallForAction Fullsize Center"><span><i class="fa fa-caret-left"></i>[% Translate("Go to overview") | html %]</span></a> + </li> +[% RenderBlockEnd("ActionOverview") %] + </ul> + </div> + </div> +[% RenderBlockEnd("ActionList") %] + +[% RenderBlockStart("Filter") %] + <div class="WidgetSimple"> + <div class="Header"> + <h2><label for="Filter">[% Translate("Filter") | html %]</label></h2> + </div> + <div class="Content"> + <input type="text" id="Filter" class="FilterBox" placeholder="[% Translate("Just start typing to filter...") | html %]" name="Filter" value="" title="[% Translate("Filter") | html %]" /> + </div> + </div> +[% RenderBlockEnd("Filter") %] + +[% RenderBlockStart("FilterTemplate") %] + <div class="WidgetSimple"> + <div class="Header"> + <h2><label for="FilterTemplates">[% Translate("Filter for Templates") | html %]</label></h2> + </div> + <div class="Content"> + <input type="text" id="FilterTemplates" class="FilterBox" placeholder="[% Translate("Just start typing to filter...") | html %]" name="FilterTemplates" value="" title="[% Translate("Filter for Templates") | html %]" /> + </div> + </div> +[% RenderBlockEnd("FilterTemplate") %] +[% RenderBlockStart("FilterResponseChangeDefaultTo") %] + <div class="WidgetSimple"> + <div class="Header"> + <h2><label for="FilterResponseChangeDefaultTo">[% Translate("Filter for ResponseChangeDefaultTo") | html %]</label></h2> + </div> + <div class="Content"> + <input type="text" id="FilterResponseChangeDefaultTo" class="FilterBox" placeholder="[% Translate("Just start typing to filter...") | html %]" name="FilterResponseChangeDefaultTo" value="" title="[% Translate("Filter for ResponseChangeDefaultTo") | html %]" /> + </div> + </div> +[% RenderBlockEnd("FilterResponseChangeDefaultTo") %] + + </div> + + <div class="ContentColumn"> + <div class="WidgetSimple"> + +[% RenderBlockStart("OverviewResult") %] + <div class="Header"> + <h2>[% Translate("Overview") | html %]</h2> + </div> + <div class="Content LayoutGrid ColumnsWithSpacing"> + <div class="Size1of2"> + <ul class="Tablelike" id="Templates"> + <li class="Header">[% Translate("Templates") | html %]</li> + <li class="FilterMessage Hidden">[% Translate("No matches found.") | html %]</li> +[% RenderBlockStart("NoTemplatesFoundMsg") %] + <li>[% Translate("No data found.") | html %]</li> +[% RenderBlockEnd("NoTemplatesFoundMsg") %] +[% RenderBlockStart("List1n") %] + <li><a href="[% Env("Baselink") %]Action=[% Env("Action") %];Subaction=[% Data.Subaction | uri %];ID=[% Data.ID | uri %]" class="AsBlock">[% Data.Name | html %]</a></li> +[% RenderBlockEnd("List1n") %] + </ul> + </div> + <div class="Size1of2"> + <ul class="Tablelike" id="ResponseChangeDefaultTo"> + <li class="Header">[% Translate("ResponseChangeDefaultTo") | html %]</li> + <li class="FilterMessage Hidden">[% Translate("No matches found.") | html %]</li> +[% RenderBlockStart("NoResponseChangeDefaultToFoundMsg") %] + <li>[% Translate("No data found.") | html %]</li> +[% RenderBlockEnd("NoResponseChangeDefaultToFoundMsg") %] +[% RenderBlockStart("Listn1") %] + <li><a href="[% Env("Baselink") %]Action=[% Env("Action") %];Subaction=[% Data.Subaction | uri %];ID=[% Data.ID | uri %]" class="AsBlock">[% Data.Name | html %]</a></li> +[% RenderBlockEnd("Listn1") %] + </ul> + </div> + <div class="Clear"></div> + </div> + +[% WRAPPER JSOnDocumentComplete %] +<script type="text/javascript">//<![CDATA[ + Core.UI.Table.InitTableFilter($('#FilterTemplates'), $('#Templates')); + Core.UI.Table.InitTableFilter($('#FilterResponseChangeDefaultTo'), $('#ResponseChangeDefaultTo')); +//]]></script> +[% END %] +[% RenderBlockEnd("OverviewResult") %] +[% RenderBlockStart("Change") %] + <div class="Header"> + <h2> +[% RenderBlockStart("ChangeHeaderResponseChangeDefaultTo") %] + [% Translate("Change ResponseChangeDefaultTo Relations for Template") | html %] +[% RenderBlockEnd("ChangeHeaderResponseChangeDefaultTo") %] +[% RenderBlockStart("ChangeHeaderTemplate") %] + [% Translate("Change Template Relations for ResponseChangeDefaultTo") | html %] +[% RenderBlockEnd("ChangeHeaderTemplate") %] + <a href="[% Env("Baselink") %]Action=[% Data.ActionHome | uri %];Subaction=Change;ID=[% Data.ID | uri %]">[% Data.Name | html %]</a> + </h2> + </div> + <div class="Content "> + <form action="[% Env("CGIHandle") %]" method="post" name="matrix"> + <input type="hidden" name="Action" value="[% Env("Action") %]"/> + <input type="hidden" name="Subaction" value="Change[% Data.Type | html %]"/> + <input type="hidden" name="ID" value="[% Data.ID | html %]"/> + <table class="DataTable VariableWidth" id="ItemsTable"> + <thead> + <tr> + <th>[% Translate(Data.NeType) | html %]</th> + <th class="[% Data.Mark | html %]"> + <input type="checkbox" id="SelectAllItemsSelected" name="ItemsSelected" title="[% Translate("Toggle active state for all") | html %]" value="" /> + [% Translate("Active") | html %] + </th> + </tr> + </thead> + <tbody> +[% RenderBlockStart("ChangeRow") %] + <tr> + <td><a href="[% Env("Baselink") %]Action=Admin[% Data.Type | uri %];Subaction=Change;ID=[% Data.ID | uri %]">[% Data.Name | html %]</a></td> + <td class="[% Data.Mark | html %]"> + <input type="checkbox" name="ItemsSelected" title="[% Translate("Toggle active state for %s", Data.Name) | html %]" value="[% Data.ID | html %]" [% Data.Selected %]/> + <input type="hidden" name="ItemsAll" value="[% Data.ID | html %]"/> + + </td> + </tr> +[% RenderBlockEnd("ChangeRow") %] + </tbody> + </table> + <div class="Field SpacingTop"> + <button class="Primary CallForAction" type="submit" value="[% Translate("Submit") | html %]"><span>[% Translate("Submit") | html %]</span></button> + [% Translate("or") | html %] + <a href="[% Env("Baselink") %]Action=[% Env("Action") %]">[% Translate("Cancel") | html %]</a> + </div> + <div class="Clear"></div> + </form> + </div> +[% WRAPPER JSOnDocumentComplete %] +<script type="text/javascript">//<![CDATA[ +Core.Form.InitSelectAllCheckboxes($('table td input:checkbox[name=ItemsSelected]'), $('#SelectAllItemsSelected')); +$('input:checkbox[name=ItemsSelected]').bind('click', function () { + Core.Form.SelectAllCheckboxes($(this), $('#SelectAllItemsSelected')); +}); +Core.UI.Table.InitTableFilter($('#Filter'), $('#ItemsTable')); +//]]></script> +[% END %] +[% RenderBlockEnd("Change") %] + </div> + </div> + <div class="Clear"></div> + +</div> +[% RenderBlockEnd("Overview") %] |