lib/TWiki/UI/ChangeForm.pm
changeset 0 414e01d06fd5
child 1 e2915a7cbdfa
equal deleted inserted replaced
-1:000000000000 0:414e01d06fd5
       
     1 # Module of TWiki Enterprise Collaboration Platform, http://TWiki.org/
       
     2 #
       
     3 # Copyright (C) 1999-2007 Peter Thoeny, peter@thoeny.org
       
     4 # and TWiki Contributors. All Rights Reserved. TWiki Contributors
       
     5 # are listed in the AUTHORS file in the root of this distribution.
       
     6 # NOTE: Please extend that file, not this notice.
       
     7 #
       
     8 # This program is free software; you can redistribute it and/or
       
     9 # modify it under the terms of the GNU General Public License
       
    10 # as published by the Free Software Foundation; either version 2
       
    11 # of the License, or (at your option) any later version. For
       
    12 # more details read LICENSE in the root of this distribution.
       
    13 #
       
    14 # This program is distributed in the hope that it will be useful,
       
    15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
       
    17 #
       
    18 # As per the GPL, removal of this notice is prohibited.
       
    19 
       
    20 =pod
       
    21 
       
    22 ---+ package TWiki::UI::ChangeForm
       
    23 
       
    24 Service functions used by the UI packages
       
    25 
       
    26 =cut
       
    27 
       
    28 package TWiki::UI::ChangeForm;
       
    29 
       
    30 use strict;
       
    31 use Error qw( :try );
       
    32 use Assert;
       
    33 
       
    34 require TWiki;
       
    35 
       
    36 =pod
       
    37 
       
    38 ---+ ClassMethod generate( $session, $theWeb, $theTopic, $editaction )
       
    39 
       
    40 Generate the page that supports selection of the form.
       
    41 
       
    42 =cut
       
    43 
       
    44 sub generate {
       
    45     my( $session, $web, $topic, $editaction ) = @_;
       
    46     ASSERT($session->isa( 'TWiki')) if DEBUG;
       
    47 
       
    48     my $page = $session->templates->readTemplate( 'changeform' );
       
    49     my $q = $session->{cgiQuery};
       
    50 
       
    51     my $store = $session->{store};
       
    52     my $formName = $q->param( 'formtemplate' ) || '';
       
    53     unless( $formName ) {
       
    54         my( $meta, $tmp ) = $store->readTopic( undef, $web, $topic, undef );
       
    55         my $form = $meta->get( 'FORM' );
       
    56         $formName = $form->{name} if $form;
       
    57     }
       
    58     $formName = 'none' if( !$formName );
       
    59 
       
    60     my $prefs = $session->{prefs};
       
    61     my $legalForms = $prefs->getWebPreferencesValue( 'WEBFORMS', $web );
       
    62     $legalForms =~ s/^\s*//;
       
    63     $legalForms =~ s/\s*$//;
       
    64     my @forms = split( /[,\s]+/, $legalForms );
       
    65     unshift @forms, 'none';
       
    66 
       
    67     my $formList = '';
       
    68     my $formElemCount = 0;
       
    69     foreach my $form ( @forms ) {
       
    70     	$formElemCount++;
       
    71         $formList .= CGI::br() if( $formList );
       
    72         my $formElemId = 'formtemplateelem' . $formElemCount;
       
    73         my $props = {
       
    74             type => 'radio',
       
    75             name => 'formtemplate',
       
    76             id => $formElemId,
       
    77             value => $form
       
    78            };
       
    79         $props->{checked} = 'checked' if $form eq $formName;
       
    80         $formList .= CGI::input( $props );
       
    81 	my ($formWeb, $formTopic) = $session->normalizeWebTopicName($web, $form);
       
    82         my $formLabelContent = ' ' . ( $store->topicExists( $formWeb, $formTopic ) ? 
       
    83 	  '[['.$formWeb.'.'.$formTopic.']['.$form.']]' : $form );
       
    84         $formList .= CGI::label( { for => $formElemId}, $formLabelContent );
       
    85     }
       
    86     $page =~ s/%FORMLIST%/$formList/go;
       
    87 
       
    88     my $parent = $q->param( 'topicparent' ) || '';
       
    89     $page =~ s/%TOPICPARENT%/$parent/go;
       
    90 
       
    91     my $redirectTo = $q->param( 'redirectto' ) || '';
       
    92     $page =~ s/%REDIRECTTO%/$redirectTo/go;
       
    93 
       
    94     $page = $session->handleCommonTags( $page, $web, $topic );
       
    95     $page = $session->renderer->getRenderedVersion( $page, $web, $topic );
       
    96 
       
    97     my $text = CGI::hidden( -name => 'text', -value => $q->param( 'text' ) );
       
    98     $page =~ s/%TEXT%/$text/go;
       
    99     $text = '';
       
   100     #$text = CGI::hidden( -name => 'action', -value => $editaction ) if $editaction;
       
   101     $text .= "<input type=\"hidden\" name=\"action\" value=\"$editaction\" />" if $editaction;
       
   102     $page =~ s/%EDITACTION%/$text/go;
       
   103 
       
   104     return $page;
       
   105 }
       
   106 1;