X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Fshare%2Fhtml%2FElements%2FSelectStatus;h=33d20643c3a1511e2c5345f4f67c52fa1174e760;hp=af1ff615fdd1f6dd4f89deacbcbd4adbaf10f5fa;hb=44dd00a3ff974a17999e86e64488e996edc71e3c;hpb=f3c4966ed1f6ec3db7accd6dcdd3a5a3821d72a7 diff --git a/rt/share/html/Elements/SelectStatus b/rt/share/html/Elements/SelectStatus index af1ff615f..33d20643c 100755 --- a/rt/share/html/Elements/SelectStatus +++ b/rt/share/html/Elements/SelectStatus @@ -2,7 +2,7 @@ %# %# COPYRIGHT: %# -%# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC +%# This software is Copyright (c) 1996-2019 Best Practical Solutions, LLC %# %# %# (Except where explicitly superseded by other copyright notices) @@ -50,55 +50,89 @@ % if ( $DefaultValue ) { % } -% foreach my $status (@status) { -% next if ($SkipDeleted && $status eq 'deleted'); -% my $selected = defined $Default && $status eq $Default ? 'selected="selected"' : ''; +% for my $lifecycle (sort keys %statuses_by_lifecycle) { +% if ($group_by_lifecycle) { + +% } +% foreach my $status (@{$statuses_by_lifecycle{$lifecycle}}) { +% next if ($SkipDeleted && lc $status eq 'deleted'); +% my $selected = defined $Default && $status eq $Default ? 'selected="selected"' : ''; +% } +% if ($group_by_lifecycle) { + +% } % } <%INIT> ### XXX: no cover for Tools/MyDay.html - -my @status; +my %statuses_by_lifecycle; if ( @Statuses ) { - @status = @Statuses; -} -elsif ( $TicketObj ) { - my $current = $TicketObj->Status; - push @status, $current; + $statuses_by_lifecycle{''} = \@Statuses; +} else { + if ( $Object ) { + my $lifecycle = $Object->LifecycleObj; + if ($Object->_Accessible("Status", "read")) { + my $current = $Object->Status; + my @status; + push @status, $current; - my $lifecycle = $TicketObj->QueueObj->Lifecycle; + my %has = (); + foreach my $next ( $lifecycle->Transitions( $current ) ) { + my $check = $lifecycle->CheckRight( $current => $next ); + $has{ $check } = $Object->CurrentUserHasRight( $check ) + unless exists $has{ $check }; + push @status, $next if $has{ $check }; + } + $statuses_by_lifecycle{$lifecycle->Name} = \@status; + } else { + $statuses_by_lifecycle{$lifecycle->Name} = [ $lifecycle->Transitions('') ]; + } + } + for my $lifecycle ( @Lifecycles ) { + $statuses_by_lifecycle{$lifecycle->Name} ||= [ $lifecycle->Valid ]; + } - my %has = (); - foreach my $next ( $lifecycle->Transitions( $current ) ) { - my $check = $lifecycle->CheckRight( $current => $next ); - $has{ $check } = $TicketObj->CurrentUserHasRight( $check ) - unless exists $has{ $check }; - push @status, $next if $has{ $check }; + if (not keys %statuses_by_lifecycle) { + for my $lifecycle (map { RT::Lifecycle->Load($_) } RT::Lifecycle->List($Type)) { + $statuses_by_lifecycle{$lifecycle->Name} = [ $lifecycle->Valid ]; + } } } -elsif ( $QueueObj ) { - @status = $QueueObj->Lifecycle->Transitions(''); -} elsif ( %Queues ) { - for my $id (keys %Queues) { - my $queue = RT::Queue->new($session{'CurrentUser'}); - $queue->Load($id); - push @status, $queue->Lifecycle->Valid if $queue->id; + +if (keys %statuses_by_lifecycle) { + my %simplified; + my $key = sub { + join "\0", sort @{$_[0]}; + }; + for my $name (sort keys %statuses_by_lifecycle) { + my $matched; + my $statuses = $statuses_by_lifecycle{$name}; + for my $simple (sort keys %simplified) { + if ($key->($statuses) eq $key->($simplified{$simple})) { + # Statuses are the same, join 'em! + $simplified{"$simple, $name"} = delete $simplified{$simple}; + $matched++; + last; + } + } + unless ($matched) { + $simplified{$name} = $statuses; + } } - my %seen; - @status = grep { not $seen{$_}++ } @status; -} else { - @status = RT::Queue->Lifecycle->Valid; + %statuses_by_lifecycle = %simplified; } + +my $group_by_lifecycle = keys %statuses_by_lifecycle > 1; <%ARGS> $Name => undef +$Type => undef, @Statuses => () -$TicketObj => undef -$QueueObj => undef -%Queues => () +$Object => undef, +@Lifecycles => (), $Default => '' $SkipDeleted => 0