& /Admin/Elements/Header, Title => $title &> <& /Elements/Tabs &> <& /Elements/ListActions, actions => \@results &>
<%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 $content = $form_attribute->Content; my $encoded_content = JSON::to_json($content, { canonical => 1, pretty => 1 } ); my ($title, @results); $title = loc("Modify form [_1]", $form_attribute->Description); if ( $Update ) { Abort( loc('Permission Denied') ) unless $session{'CurrentUser'}->HasRight( Object => $RT::System, Right => 'AdminForm' ); if ( $ARGS{Description} ) { if ($ARGS{Description} !~ /^[\w\s]+$/) { push @results, loc('Invalid form name (can only contain letters, numbers, underscore, and spaces): [_1]', $ARGS{Description}); } elsif ( $ARGS{Description} ne $form_attribute->Description ) { my $attr = RT::Attribute->new( RT->SystemUser ); my ($ret) = $attr->LoadByCols( Name => 'FormTools Form', Description => $ARGS{Description} ); if ($ret) { push @results, loc( 'Name [_1] already exists', $ARGS{Description} ); } else { my ( $ret, $msg ) = $form_attribute->SetDescription( $ARGS{Description} ); if ($ret) { push @results, loc('Updated name'); } else { push @results, loc( "Couldn't update name: [_1]", $msg ); } } } } else { push @results, loc('Missing Name'); } my $new_content = eval { JSON::from_json( $ARGS{Content} ) }; if ( $@ ) { push @results, loc( "Couldn't decode JSON" ); } # because of different line endings, $encoded_content and submitted # $ARGS{Content} could differ even user doesn't change any thing. elsif ( $form_attribute->_SerializeContent($new_content) ne $form_attribute->_SerializeContent($content) ) { my ( $ret, $msg ) = $form_attribute->SetContent($new_content); if ($ret) { push @results, loc('Updated content'); } else { push @results, loc( "Couldn't update content: [_1]", $msg ); } } MaybeRedirectForResults( Actions => \@results, Path => '/Admin/FormTools/Advanced.html', Arguments => { id => $id, Content => $ARGS{Content} }, ); } %INIT> <%ARGS> $id => undef $Update => undef %ARGS>