X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Fshare%2Fhtml%2FAdmin%2FElements%2FEditScrips;h=8334cf291701fb81d30578b5f3fb056c8aae9f29;hb=7322f2afedcc2f427e997d1535a503613a83f088;hp=25cafb42faf10ddc261d5ae61aa838343210fd50;hpb=3ceb32ebb390aa8aa5fffdfc095be35ef7e54bbe;p=freeside.git diff --git a/rt/share/html/Admin/Elements/EditScrips b/rt/share/html/Admin/Elements/EditScrips index 25cafb42f..8334cf291 100755 --- a/rt/share/html/Admin/Elements/EditScrips +++ b/rt/share/html/Admin/Elements/EditScrips @@ -2,7 +2,7 @@ %# %# COPYRIGHT: %# -%# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC +%# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC %# %# %# (Except where explicitly superseded by other copyright notices) @@ -50,86 +50,151 @@
-

<&|/l&>Current Scrips

+

<&|/l&>Scrips

+
<&|/l&>Scrips normally run after each individual change to a ticket.
+% my $scrips = $find_scrips->(Stage => 'TransactionCreate'); +<& /Elements/CollectionList, %common_applied_args, Collection => $scrips &> +% unless ( $scrips->Count ) { +

<&|/l&>(No scrips)

+% } + +

<&|/l&>Batch scrips

+
<&|/l&>Batch scrips run after a set of related changes to a ticket.
+% $scrips = $find_scrips->(Stage => 'TransactionBatch'); +<& /Elements/CollectionList, %common_applied_args, Collection => $scrips &> +% unless ( $scrips->Count ) { +

<&|/l&>(No scrips)

+% } + +<& /Elements/Submit, + Name => 'RemoveScrips', + Caption => loc("Un-apply selected scrips"), + Label => loc("Update"), +&> + +

<&|/l&>Not applied scrips

+% $scrips = $find_scrips->(Added => 0); <& /Elements/CollectionList, - OrderBy => 'Description', - Order => 'ASC', - Rows => 100, + Rows => $Rows, + Page => 1, %ARGS, - Format => $Format, - DisplayFormat => "__CheckBox.{DeleteScrip}__, $Format", - Collection => $Scrips, + Collection => $scrips, + Format => $Format, + DisplayFormat => "__CheckBox.{AddScrip}__, $Format", AllowSorting => 1, - PassArguments => [ qw(Query Format Rows Page Order OrderBy id) ], + PassArguments => [ qw(Format Rows Page Order OrderBy id) ], &> - -% if ( $Scrips->Count ) { -

<&|/l&>(Check box to delete)

-% } else { +% unless ( $scrips->Count ) {

<&|/l&>(No scrips)

% } + +<& SelectStageForAdded &> + <& /Elements/Submit, - Caption => loc("Delete selected scrips"), - Label => loc("Delete") + Name => 'AddScrips', + Caption => loc("Apply selected scrips"), + Label => loc("Update"), &> +
<%init> my (@actions); -my $Scrips = RT::Scrips->new($session{'CurrentUser'}); - -my $QueueObj = RT::Queue->new($session{'CurrentUser'}); if ( $id ) { + my $QueueObj = RT::Queue->new($session{'CurrentUser'}); $QueueObj->Load( $id ); - unless ( $QueueObj->id ) { - push @actions, loc("Couldn't load queue #[_1]", $id) + Abort(loc("Couldn't load queue #[_1]", $id)) unless $QueueObj->id; +} +$id ||= 0; + +my $find_scrips = sub { + my %args = (Added => 1, @_); + my $scrips = RT::Scrips->new($session{'CurrentUser'}); + $scrips->LimitByStage( $args{'Stage'} ) + if $args{'Stage'}; + my $method = $args{'Added'}? 'LimitToAdded' : 'LimitToNotAdded'; + $scrips->$method(0, $id); + $scrips->ApplySortOrder if $args{'Added'}; + $scrips->FindAllRows; + return $scrips; +}; + +$Format ||= RT->Config->Get('AdminSearchResultFormat')->{'Scrips'}; +my $Rows = RT->Config->Get('AdminSearchResultRows')->{'Scrips'} || 50; +my $DisplayFormat = $Format; +if ( $id ) { + $DisplayFormat = "__RemoveCheckBox__, $DisplayFormat"; +} else { + $DisplayFormat = "__CheckBox.{RemoveScrip}__, $DisplayFormat"; +} +$DisplayFormat .= ", __Move.{$id}__"; + +my %common_applied_args = ( + %ARGS, + Format => $Format, + DisplayFormat => $DisplayFormat, + Rows => 0, + Page => 1, + AllowSorting => 0, + PassArguments => [ qw(Format id) ], +); + +if ( $RemoveScrips ) { + foreach my $sid ( @RemoveScrip ) { + my $scrip = RT::Scrip->new( $session{'CurrentUser'} ); + $scrip->Load( $sid ); + next unless $scrip->id; + + my ($status, $msg) = $scrip->RemoveFromObject( $id ); + push @actions, $msg; } } -if ($QueueObj->id) { - $Scrips->LimitToQueue($id); - $Format ||= RT->Config->Get('AdminSearchResultFormat')->{'Scrips'}; +if ( $AddScrips ) { + foreach my $sid ( @AddScrip ) { + my $scrip = RT::Scrip->new( $session{'CurrentUser'} ); + $scrip->Load( $sid ); + next unless $scrip->id; + + my ($status, $msg) = $scrip->AddToObject( $id, Stage => $Stage ); + push @actions, $msg; + } } -else { - $Scrips->LimitToGlobal(); - $Format ||= RT->Config->Get('AdminSearchResultFormat')->{'GlobalScrips'}; + +if ( $MoveScripUp ) { + my $scrip = RT::ObjectScrip->new( $session{'CurrentUser'} ); + $scrip->LoadByCols( Scrip => $MoveScripUp, ObjectId => $id ); + if ( $scrip->id ) { + my ($status, $msg) = $scrip->MoveUp; + push @actions, $msg; + } } -# deal with modifying and deleting existing scrips -# we still support DeleteScrip-id format but array is preferred - -my @not_deleted; -foreach my $id ( grep $_, @DeleteScrip, map /^DeleteScrip-(\d+)/, keys %ARGS ) { - my $scrip = RT::Scrip->new($session{'CurrentUser'}); - $scrip->Load( $id ); - my $a = $scrip->FirstAttribute('Immutable'); - if ( defined($a) and $a->Content ) { - # then disable the scrip instead of deleting it - my ($retval, $msg) = $scrip->SetStage('Disabled'); - if ( $retval ) { - push @actions, loc("Scrip disabled (cannot delete system scrips)"); - } else { - push @actions, $msg; - push @not_deleted, $id; - } - } else { # not an immutable scrip - my ($retval, $msg) = $scrip->Delete; - if ($retval) { - push @actions, loc("Scrip deleted"); - } - else { - push @actions, $msg; - push @not_deleted, $id; - } +if ( $MoveScripDown ) { + my $scrip = RT::ObjectScrip->new( $session{'CurrentUser'} ); + $scrip->LoadByCols( Scrip => $MoveScripDown, ObjectId => $id ); + if ( $scrip->id ) { + my ($status, $msg) = $scrip->MoveDown; + push @actions, $msg; } } -$DECODED_ARGS->{DeleteScrip} = \@not_deleted; + <%ARGS> $id => undef $title => undef $Format => undef -@DeleteScrip => () + +@RemoveScrip => () +$RemoveScrips => undef + +@AddScrip => () +$AddScrips => undef +$Stage => 'TransactionCreate' + +$MoveScripUp => undef +$MoveScripDown => undef +