~kosova/+junk/tuxfamily-twiki

« back to all changes in this revision

Viewing changes to foswiki/lib/Foswiki/Configure/Type.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 information
 
2
 
 
3
# Base class of all types. Types are involved *only* in the presentation
 
4
# of values in the configure interface. They do not play any part in
 
5
# loading, saving or checking configuration values.
 
6
#
 
7
package Foswiki::Configure::Type;
 
8
 
 
9
use strict;
 
10
 
 
11
use CGI qw( :any );
 
12
 
 
13
use vars qw( %knownTypes );
 
14
 
 
15
sub new {
 
16
    my ( $class, $id ) = @_;
 
17
 
 
18
    return bless( { name => $id }, $class );
 
19
}
 
20
 
 
21
# Static factory
 
22
sub load {
 
23
    my $id    = shift;
 
24
    my $typer = $knownTypes{$id};
 
25
    unless ($typer) {
 
26
        my $typeClass = 'Foswiki::Configure::Types::' . $id;
 
27
        $typer =
 
28
          eval 'use ' . $typeClass . '; new ' . $typeClass . '("' . $id . '")';
 
29
 
 
30
        # unknown type - give it default string behaviours
 
31
        $typer = new Foswiki::Configure::Type($id) unless $typer;
 
32
        $knownTypes{$id} = $typer;
 
33
    }
 
34
    return $typer;
 
35
}
 
36
 
 
37
# Generates a suitable HTML prompt for the type. Default behaviour
 
38
# is a string 55% of the width of the display area.
 
39
sub prompt {
 
40
    my ( $this, $id, $opts, $value ) = @_;
 
41
 
 
42
    my $size = '55%';
 
43
    if ( $opts =~ /\b(\d+)\b/ ) {
 
44
        $size = $1;
 
45
 
 
46
        # These numbers are somewhat arbitrary..
 
47
        if ( $size > 25 ) {
 
48
            $size = '55%';
 
49
        }
 
50
    }
 
51
    return CGI::textfield(
 
52
        -name    => $id,
 
53
        -size    => $size,
 
54
        -default => $value,
 
55
        -class   => 'foswikiInputField'
 
56
    );
 
57
}
 
58
 
 
59
# Test to determine if two values of this type are equal.
 
60
sub equals {
 
61
    my ( $this, $val, $def ) = @_;
 
62
 
 
63
    if ( !defined $val ) {
 
64
        return 0 if defined $def;
 
65
        return 1;
 
66
    }
 
67
    elsif ( !defined $def ) {
 
68
        return 0;
 
69
    }
 
70
    return $val eq $def;
 
71
}
 
72
 
 
73
# Used to process input values from CGI. Values taken from the query
 
74
# are run through this method before being saved in the value store.
 
75
# It should *not* be used to do validation - use a Checker to do that, or
 
76
# JavaScript invoked from the prompt.
 
77
sub string2value {
 
78
    my ( $this, $val ) = @_;
 
79
    return $val;
 
80
}
 
81
 
 
82
1;
 
83
__DATA__
 
84
#
 
85
# Foswiki - The Free and Open Source Wiki, http://foswiki.org/
 
86
#
 
87
# Copyright (C) 2008 Foswiki Contributors. All Rights Reserved.
 
88
# Foswiki Contributors are listed in the AUTHORS file in the root
 
89
# of this distribution. NOTE: Please extend that file, not this notice.
 
90
#
 
91
# Additional copyrights apply to some or all of the code in this
 
92
# file as follows:
 
93
#
 
94
# Copyright (C) 2000-2006 TWiki Contributors. All Rights Reserved.
 
95
# TWiki Contributors are listed in the AUTHORS file in the root
 
96
# of this distribution. NOTE: Please extend that file, not this notice.
 
97
#
 
98
# This program is free software; you can redistribute it and/or
 
99
# modify it under the terms of the GNU General Public License
 
100
# as published by the Free Software Foundation; either version 2
 
101
# of the License, or (at your option) any later version. For
 
102
# more details read LICENSE in the root of this distribution.
 
103
#
 
104
# This program is distributed in the hope that it will be useful,
 
105
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
106
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
107
#
 
108
# As per the GPL, removal of this notice is prohibited.
 
109
#