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