X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Fshare%2Fhtml%2FElements%2FSelectStatus;h=ac46b113198c0d1454498850f35a1c8ef8b9e4c0;hb=7322f2afedcc2f427e997d1535a503613a83f088;hp=5718a2a9d958ed71bc3a7d2dd10925f437998521;hpb=fb4ab1073f0d15d660c6cdc4e07afebf68ef3924;p=freeside.git diff --git a/rt/share/html/Elements/SelectStatus b/rt/share/html/Elements/SelectStatus index 5718a2a9d..ac46b1131 100755 --- a/rt/share/html/Elements/SelectStatus +++ b/rt/share/html/Elements/SelectStatus @@ -2,7 +2,7 @@ %# %# COPYRIGHT: %# -%# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC +%# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC %# %# %# (Except where explicitly superseded by other copyright notices) @@ -46,24 +46,101 @@ %# %# END BPS TAGGED BLOCK }}} % my $onchange_attr = $onchange ? " onchange=\"$onchange\"" : ''; - <% $onchange_attr |n%>> +% if ( $DefaultValue ) { + +% } +% 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) { + +% } % } -<%ONCE> -my $queue = new RT::Queue($session{'CurrentUser'}); -my @status = $queue->StatusArray(); - +<%INIT> +### XXX: no cover for Tools/MyDay.html + +my %statuses_by_lifecycle; +if ( @Statuses ) { + $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 %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 ]; + } + + if (not keys %statuses_by_lifecycle) { + for my $lifecycle (map { RT::Lifecycle->Load($_) } RT::Lifecycle->List($Type)) { + $statuses_by_lifecycle{$lifecycle->Name} = [ $lifecycle->Valid ]; + } + } +} + +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; + } + } + %statuses_by_lifecycle = %simplified; +} + +my $group_by_lifecycle = keys %statuses_by_lifecycle > 1; + <%ARGS> $Name => undef +$Type => undef, + +@Statuses => () +$Object => undef, +@Lifecycles => (), + $Default => '' $SkipDeleted => 0 $DefaultValue => 1 $DefaultLabel => "-" + +$Multiple => 0 +$Size => 6 + $onchange => ''