|
54 | 54 | </span>
|
55 | 55 | </div>
|
56 | 56 |
|
57 |
| -<form action="<%RT->Config->Get('WebPath')%>/Admin/Lifecycles/Advanced.html" name="ModifyLifecycleAdvanced" method="post" enctype="multipart/form-data" class="mx-auto max-width-sm"> |
| 57 | + |
| 58 | +<form action="<%RT->Config->Get('WebPath')%>/Admin/Lifecycles/Advanced.html" name="ModifyLifecycleAdvanced" method="post" enctype="multipart/form-data" class="mx-auto max-width-lg"> |
58 | 59 | <input type="hidden" class="hidden" name="Name" value="<% $LifecycleObj->Name %>" />
|
59 | 60 | <input type="hidden" class="hidden" name="Type" value="<% $LifecycleObj->Type %>" />
|
60 |
| - |
| 61 | + <&| /Widgets/TitleBox, title => loc('Basics'), content_class => 'mx-auto width-sm' &> |
61 | 62 | <div class="form-row">
|
62 | 63 | <span class="col-12">
|
63 | 64 | <textarea class="form-control" rows="30" name="Config"><% $Config |n %></textarea>
|
|
83 | 84 | <& /Elements/Submit, Label => loc('Delete'), Name => 'Delete' &>
|
84 | 85 | </div>
|
85 | 86 | </div>
|
| 87 | + </&> |
86 | 88 | </form>
|
87 | 89 |
|
| 90 | + |
| 91 | + |
| 92 | +<form action="<%RT->Config->Get('WebPath')%>/Admin/Lifecycles/Advanced.html" name="ModifyLifecycleAdvancedMappings" method="post" enctype="multipart/form-data" class="mx-auto max-width-lg"> |
| 93 | + <input type="hidden" class="hidden" name="Name" value="<% $LifecycleObj->Name %>" /> |
| 94 | + <input type="hidden" class="hidden" name="Type" value="<% $LifecycleObj->Type %>" /> |
| 95 | + <&| /Widgets/TitleBox, title => loc('Mappings'), content_class => 'mx-auto width-sm' &> |
| 96 | + |
| 97 | + <div class="form-row"> |
| 98 | + <span class="col-12"> |
| 99 | + <textarea class="form-control" rows="30" name="Maps"><% $Maps |n %></textarea> |
| 100 | + </span> |
| 101 | + </div> |
| 102 | + |
| 103 | + <div class="form-row invalid-json hidden"> |
| 104 | + <div class="col-12"> |
| 105 | + <div class="alert alert-danger mb-0"><&|/l&>Invalid JSON</&></div> |
| 106 | + </div> |
| 107 | + </div> |
| 108 | + |
| 109 | + <div class="form-row"> |
| 110 | + <div class="col-6 d-flex"> |
| 111 | + <& /Elements/Submit, Label => loc('Validate Mappings'), Name => 'ValidateMaps' &> |
| 112 | + </div> |
| 113 | + <div class="col-6"> |
| 114 | + <& /Elements/Submit, Label => loc('Save Mappings'), Name => 'UpdateMaps' &> |
| 115 | + </div> |
| 116 | + </div> |
| 117 | + </&> |
| 118 | +</form> |
| 119 | + |
| 120 | + |
88 | 121 | <%INIT>
|
89 | 122 | my ($title, @results);
|
90 | 123 | my $LifecycleObj = RT::Lifecycle->new();
|
|
100 | 133 | push @results, loc("The graphical lifecycle builder is not currently supported on IE 11. You can update the lifecycle configuration using the Advanced tab or access the lifecycle editor in a supported browser.");
|
101 | 134 | }
|
102 | 135 |
|
| 136 | +if ( !defined $Maps && ( my $all_maps = RT->Config->Get('Lifecycles')->{__maps__} ) ) { |
| 137 | + for my $item ( grep {/^\Q$Name\E -> | -> \Q$Name\E$/} keys %$all_maps ) { |
| 138 | + $Maps->{$item} = $all_maps->{$item}; |
| 139 | + } |
| 140 | + $Maps = JSON::to_json( $Maps || {}, { canonical => 1, pretty => 1 } ); |
| 141 | +} |
| 142 | + |
103 | 143 | my $redirect_to ='/Admin/Lifecycles/Advanced.html';
|
104 | 144 | my %redirect_args;
|
105 | 145 |
|
|
157 | 197 | );
|
158 | 198 | }
|
159 | 199 | }
|
| 200 | +elsif ( $ValidateMaps || $UpdateMaps ) { |
| 201 | + my $maps = JSON::from_json($Maps || '{}'); |
| 202 | + |
| 203 | + my ( $valid, @warnings ) |
| 204 | + = $LifecycleObj->ValidateLifecycleMaps( Maps => $maps, CurrentUser => $session{CurrentUser} ); |
| 205 | + |
| 206 | + my $updated; |
| 207 | + if ($valid) { |
| 208 | + if ($ValidateMaps) { |
| 209 | + push @results, loc('Mappings is valid'); |
| 210 | + } |
| 211 | + else { |
| 212 | + # Maps will be merged into existing value, here we remove existing values so admins can delete items |
| 213 | + |
| 214 | + ( $updated, my $msg ) = RT::Lifecycle->UpdateMaps( |
| 215 | + CurrentUser => $session{CurrentUser}, |
| 216 | + Maps => $maps, |
| 217 | + Name => $Name, |
| 218 | + ); |
| 219 | + push @results, $msg; |
| 220 | + } |
| 221 | + |
| 222 | + } |
| 223 | + else { |
| 224 | + push @results, @warnings; |
| 225 | + } |
| 226 | + |
| 227 | + %redirect_args = ( |
| 228 | + Name => $Name, |
| 229 | + Type => $Type, |
| 230 | + |
| 231 | + # Get the latest canonicalized data if updated successfully |
| 232 | + $updated ? () : ( Maps => $Maps ), |
| 233 | + ); |
| 234 | +} |
160 | 235 |
|
161 | 236 | MaybeRedirectForResults(
|
162 | 237 | Actions => \@results,
|
|
172 | 247 | $Validate => undef
|
173 | 248 | $Update => undef
|
174 | 249 | $Delete => undef
|
| 250 | +$ValidateMaps => undef |
| 251 | +$UpdateMaps => undef |
| 252 | +$Maps => undef |
175 | 253 | </%ARGS>
|
0 commit comments