<& /Admin/Elements/Header, Title => $title &> <& /Elements/Tabs &> <& /Elements/ListActions, actions => \@results &>
<& /Admin/Elements/FormToolsHelp &> % if ( %dependent_custom_fields ) { % }
<&| /Widgets/TitleBox, title => loc('FormTools Components') &>
% foreach my $item ( @html_components ) {
" ) : () }) %>">

<% loc('Place here') %>

<% $item eq 'html' ? 'HTML' : uc($item) %> <% loc('[_1] Element', uc($item)) %> % if ( $item ne 'hr' || %dependent_custom_fields ) { % }

% if ( $item ne 'hr' || %dependent_custom_fields ) { % } % }
% foreach my $item ( @core_components ) {

<% loc('Place here') %>

<% loc('Core Field') %> <% loc($item) %>

% }
% foreach my $item ( @custom_fields ) {

<% loc('Place here') %>

<% loc('Custom Field') %> <% $item %>

% }
% foreach my $item ( sort keys %other_components ) {

<% loc('Place here') %>

<% $other_components{$item}{type} eq 'hidden' ? loc('Hidden') : loc('Component') %> <% loc($item) %> % if ( $item eq 'Hidden' || ( $item =~ /ShowChoices|ShowBanner/ && %dependent_custom_fields ) ) { % }

% if ( $item eq 'Hidden' || ( $item =~ /ShowChoices|ShowBanner/ && %dependent_custom_fields ) ) { % } % }
<&| /Widgets/TitleBox, title => loc('FormTools Pages') &>
% foreach my $page_name (@form_pages) {
% my $loc_basics = loc('Basics'); <&| /Widgets/TitleBox, title => loc('Content'), titleright_raw => qq{} &>
% my $i = 0; % for my $item ( grep { $_->{type} ne 'hidden' || $_->{'input-name'} ne 'create_ticket' } @{$form->{'formtools-pages'}{$page_name}{content} || []} ) {

<% loc('Place here') %>

% if ( $item->{type} eq 'raw_html' ) { <% uc($item->{wrapper} || 'HTML') %> % } elsif ( ( $item->{comp_name} // '' ) eq 'ShowBanner' ) { <% loc('Component') %> % } elsif ( ( $item->{comp_name} // '' ) eq 'ShowChoices' ) { <% loc('Component') %> % } elsif ( $item->{type} eq 'hidden' ) { <% loc('Hidden') %> % } elsif ( RT::Extension::FormTools::is_core_field($item->{arguments}{name}) ) { <% loc('Core Field') %> % } else { <% loc('Custom Field') %> % } % if ( $item->{type} eq 'raw_html' ) { % if ( $item->{wrapper} ) { <% length( $item->{content} // '' ) > 40 ? substr($item->{content}, 0, 40) . '...' : ( $item->{content} // '' ) %> % } else { <% length $item->{html} > 40 ? substr($item->{html}, 0, 40) . '...' : $item->{html} %> % } % } elsif ( $item->{type} eq 'hidden' ) { <% $item->{'input-name'} %>: <% $item->{'input-value'} %> % } elsif ( $item->{type} eq 'component' && $item->{comp_name} eq 'Field' ) { <% ( RT::Extension::FormTools::is_core_field( $item->{arguments}{name} ) ? loc( $item->{arguments}{name} ) : $item->{arguments}{name} ) || $item->{comp_name} %> <% $item->{arguments}{label} ? "($item->{arguments}{label})" : '' %> % } else { <% $item->{comp_name} %> % } % if ( ( $item->{type} eq 'raw_html' && ( ( $item->{wrapper} // '' ) ne 'hr' || %dependent_custom_fields ) ) || ( $item->{type} eq 'component' && ( $item->{comp_name} eq 'Field' || ( $item->{comp_name} =~ /ShowChoices|ShowBanner/ && %dependent_custom_fields ) ) ) || $item->{type} eq 'hidden' ) { % }

% $i++; % }

<% loc('Place here') %>

% }
<& /Elements/Submit, Name => 'Update', Label => loc('Save Changes') &>
<%INIT> Abort("No form id found") unless $id; my $form_attribute = RT::Attribute->new($session{'CurrentUser'}); my ($ok, $msg) = $form_attribute->Load($id); unless ( $ok ) { Abort("Unable to load form with id $id"); } my $form = $form_attribute->Content; my @results; if ( $AddPage ) { Abort( loc('Permission Denied') ) unless $session{'CurrentUser'}->HasRight( Object => $RT::System, Right => 'AdminForm' ); my @orders = sort { $a <=> $b } map { $form->{'formtools-pages'}{$_}{sort_order} } keys %{$form->{'formtools-pages'}}; my $new_page = RT::Extension::FormTools->GeneratePageId($form); $form->{'formtools-pages'}{$new_page} = { name => 'Page New', sort_order => ( $orders[-2] || 0 ) + 1, }; my ( $ret, $msg ) = $form_attribute->SetContent($form); if ($ret) { push @results, loc('Updated content'); } else { push @results, loc( "Couldn't update content: [_1]", $msg ); } MaybeRedirectForResults( Actions => \@results, Path => '/Admin/FormTools/Modify.html', Arguments => { id => $id, ActiveTab => $new_page }, ); } elsif ( $Update ) { Abort( loc('Permission Denied') ) unless $session{'CurrentUser'}->HasRight( Object => $RT::System, Right => 'AdminForm' ); my $new_content = eval { JSON::from_json( $ARGS{Content} ) }; if ( $@ ) { push @results, loc( "Couldn't decode JSON" ); } else { require List::Util; my %order_name = map { $new_content->{$_}{sort_order} => $_ } keys %$new_content; my @orders = sort { $a <=> $b } keys %order_name; my ( $first_page, $submit_page ); for my $page ( sort { $new_content->{$a}{sort_order} <=> $new_content->{$b}{sort_order} } keys %$new_content ) { if ( $new_content->{$page}{sort_order} == $orders[0] ) { $form->{'formtools-start-page'} = $page; } if ( $orders[-2] && $new_content->{$page}{sort_order} == $orders[-2] ) { push @{ $new_content->{$page}{content} }, { type => 'hidden', 'input-name' => 'create_ticket', 'input-value' => 'create_ticket' }; } if ( my $next_order = List::Util::first { $_ > $new_content->{$page}{sort_order} } @orders ) { $new_content->{$page}{next} = $order_name{$next_order}; } else { $new_content->{$page}{next} = ''; } } $form->{'formtools-pages'} = $new_content; if ( $form_attribute->_SerializeContent($form) ne $form_attribute->_Value('Content') ) { my ( $ret, $msg ) = $form_attribute->SetContent($form); if ($ret) { push @results, loc('Updated content'); } else { push @results, loc( "Couldn't update content: [_1]", $msg ); } } } MaybeRedirectForResults( Actions => \@results, Path => '/Admin/FormTools/Modify.html', Arguments => { id => $id, ActiveTab => $ActiveTab }, ); } my $title = loc("Modify form [_1]", $form_attribute->Description); my $nav_type = 'pill'; # 'tab' or 'pill' my @html_components = qw( h1 h2 h3 hr p html ); my @core_components = qw( Requestors Cc AdminCc Owner Subject Content Due Starts TimeEstimated Attach ); my $queue = RT::Queue->new($session{'CurrentUser'}); $queue->Load($form->{queue}); my $cfs = $queue->TicketCustomFields; my @custom_fields; my %default_values; my %tooltips; my %dependent_custom_fields; my %cf_obj; while ( my $cf = $cfs->Next ) { push @custom_fields, $cf->Name; $cf_obj{$cf->Name} = $cf; if ( $cf->SupportDefaultValues ) { if ( defined( my $default_values = $cf->DefaultValues(Object => $queue) ) ) { $default_values{$cf->Name} = $default_values; } } $tooltips{$cf->Name} = $cf->EntryHint // ''; if ( $cf->Type eq 'Select' ) { $dependent_custom_fields{$cf->Name} = [ map { $_->Name } @{$cf->Values->ItemsArrayRef || {}} ]; } } my %other_components = ( ShowBanner => { type => 'component', comp_name => 'ShowBanner' }, ShowChoices => { type => 'component', comp_name => 'ShowChoices' }, Hidden => { type => 'hidden' }, ); $form->{'formtools-pages'} ||= { RT::Extension::FormTools->GeneratePageId() => { sort_order => 1, name => 'Page 1' }, RT::Extension::FormTools->GeneratePageId() => { sort_order => 999, name => 'Result', content => [ { "content" => "Request Submitted", "html" => "

Request Submitted

", "type" => "raw_html", "wrapper" => "h2" }, { "content" => "Your request has been submitted.", "html" => "

Your request has been submitted.

", "type" => "raw_html", "wrapper" => "p" }, ], }, }; my @form_pages = sort { ( $form->{'formtools-pages'}{$a}{sort_order} || 0 ) <=> ( $form->{'formtools-pages'}{$b}{sort_order} || 0 ) } keys %{ $form->{'formtools-pages'} }; my %form_page_id = map { $_ => CSSClass($_) } @form_pages; my $active_context = { tab => $ActiveTab || $form_page_id{$form_pages[0]} }; <%ARGS> $id => undef $ActiveTab => '' $Update => undef $AddPage => undef <%METHOD ShowCondition> <&| /Elements/LabeledValue, Label => '' &>
{arguments}{show_condition}{enabled} ? 'checked="checked"' : '' |n %> />
<%INIT> return unless %$Options; <%ARGS> $For => '' $Item => {} $Options