~kosova/+junk/tuxfamily-twiki

« back to all changes in this revision

Viewing changes to foswiki/lib/Foswiki/Form/ListFieldDefinition.pm

  • Committer: James Michael DuPont
  • Date: 2009-07-18 19:58:49 UTC
  • Revision ID: jamesmikedupont@gmail.com-20090718195849-vgbmaht2ys791uo2
added foswiki

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# See bottom of file for license and copyright details
 
2
 
 
3
=begin TML
 
4
 
 
5
---++ package Foswiki::Form::ListFieldDefinition
 
6
Form field definitions that accept lists of values in the field definition.
 
7
This is different to being multi-valued, which means the field type
 
8
can *store* multiple values.
 
9
 
 
10
=cut
 
11
 
 
12
package Foswiki::Form::ListFieldDefinition;
 
13
use base 'Foswiki::Form::FieldDefinition';
 
14
 
 
15
use strict;
 
16
use Assert;
 
17
 
 
18
=begin TML
 
19
 
 
20
---++ ObjectMethod finish()
 
21
Break circular references.
 
22
 
 
23
=cut
 
24
 
 
25
# Note to developers; please undef *all* fields in the object explicitly,
 
26
# whether they are references or not. That way this method is "golden
 
27
# documentation" of the live fields in the object.
 
28
sub finish {
 
29
    my $this = shift;
 
30
    $this->SUPER::finish();
 
31
    undef $this->{_options};
 
32
}
 
33
 
 
34
# PROTECTED - parse the {value} and extract a list of options.
 
35
# Done lazily to avoid repeated topic reads.
 
36
sub getOptions {
 
37
 
 
38
    # $web and $topic are where the form definition lives
 
39
    my $this = shift;
 
40
 
 
41
    return $this->{_options} if $this->{_options};
 
42
 
 
43
    my @vals = ();
 
44
 
 
45
    @vals = split( /,/, $this->{value} );
 
46
    if ( !scalar(@vals) ) {
 
47
        my $topic = $this->{definingTopic} || $this->{name};
 
48
        my $session = $this->{session};
 
49
        my ( $fieldWeb, $fieldTopic ) =
 
50
          $session->normalizeWebTopicName( $this->{web}, $topic );
 
51
        my $store = $session->{store};
 
52
        if ( $store->topicExists( $fieldWeb, $fieldTopic ) ) {
 
53
            my ( $meta, $text ) =
 
54
              $store->readTopic( $session->{user}, $fieldWeb, $fieldTopic,
 
55
                undef );
 
56
 
 
57
            # Process SEARCHES for Lists
 
58
            $text =
 
59
              $this->{session}
 
60
              ->handleCommonTags( $text, $this->{web}, $topic, $meta );
 
61
 
 
62
            # SMELL: yet another table parser
 
63
            my $inBlock = 0;
 
64
            foreach ( split( /\r?\n/, $text ) ) {
 
65
                if (/^\s*\|\s*\*Name\*\s*\|/) {
 
66
                    $inBlock = 1;
 
67
                }
 
68
                elsif (/^\s*\|\s*([^|]*?)\s*\|/) {
 
69
                    push( @vals, TAINT($1) ) if ($inBlock);
 
70
                }
 
71
                else {
 
72
                    $inBlock = 0;
 
73
                }
 
74
            }
 
75
        }
 
76
    }
 
77
    @vals = map { $_ =~ s/^\s*(.*)\s*$/$1/; $_; } @vals;
 
78
 
 
79
    $this->{_options} = \@vals;
 
80
 
 
81
    return $this->{_options};
 
82
}
 
83
 
 
84
1;
 
85
__DATA__
 
86
 
 
87
Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/, http://Foswiki.org/
 
88
 
 
89
# Copyright (C) 2008-2009 Foswiki Contributors. All Rights Reserved.
 
90
# Foswiki Contributors are listed in the AUTHORS file in the root
 
91
# of this distribution. NOTE: Please extend that file, not this notice.
 
92
#
 
93
# Additional copyrights apply to some or all of the code in this
 
94
# file as follows:
 
95
#
 
96
# Copyright (C) 2001-2007 TWiki Contributors. All Rights Reserved.
 
97
# TWiki Contributors are listed in the AUTHORS file in the root
 
98
# of this distribution. NOTE: Please extend that file, not this notice.
 
99
#
 
100
This program is free software; you can redistribute it and/or
 
101
modify it under the terms of the GNU General Public License
 
102
as published by the Free Software Foundation; either version 2
 
103
of the License, or (at your option) any later version. For
 
104
more details read LICENSE in the root of this distribution.
 
105
 
 
106
This program is distributed in the hope that it will be useful,
 
107
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
108
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
109
 
 
110
As per the GPL, removal of this notice is prohibited.
 
111