lib/TWiki/Form/Date.pm
author Colas Nahaboo <colas@nahaboo.net>
Sat, 26 Jan 2008 15:50:53 +0100
changeset 0 414e01d06fd5
permissions -rw-r--r--
RELEASE 4.2.0 freetown
colas@0
     1
# See bottom of file for license and copyright details
colas@0
     2
# This packages subclasses TWiki::Form::FieldDefinition to implement
colas@0
     3
# the =date= type
colas@0
     4
colas@0
     5
package TWiki::Form::Date;
colas@0
     6
use base 'TWiki::Form::FieldDefinition';
colas@0
     7
colas@0
     8
use strict;
colas@0
     9
colas@0
    10
use TWiki::Contrib::JSCalendarContrib;
colas@0
    11
colas@0
    12
sub new {
colas@0
    13
    my $class = shift;
colas@0
    14
    my $this = $class->SUPER::new( @_ );
colas@0
    15
    my $size = $this->{size} || '';
colas@0
    16
    $size =~ s/[^\d]//g;
colas@0
    17
    $size = 20 if( !$size || $size < 1 ); # length(31st September 2007)=19
colas@0
    18
    $this->{size} = $size;
colas@0
    19
    return $this;
colas@0
    20
}
colas@0
    21
colas@0
    22
sub renderForEdit {
colas@0
    23
    my( $this, $web, $topic, $value ) = @_;
colas@0
    24
colas@0
    25
    $value = CGI::textfield(
colas@0
    26
        { name => $this->{name},
colas@0
    27
          id => 'id'.$this->{name},
colas@0
    28
          size=> $this->{size},
colas@0
    29
          value => $value,
colas@0
    30
          class => $this->can('cssClasses') ?
colas@0
    31
            $this->cssClasses('twikiInputField', 'twikiEditFormDateField') :
colas@0
    32
              'twikiInputField twikiEditFormDateField'});
colas@0
    33
    my $ifFormat = $TWiki::cfg{JSCalendarContrib}{format} || '%e %b %Y';
colas@0
    34
    TWiki::Contrib::JSCalendarContrib::addHEAD( 'twiki' );
colas@0
    35
    if( $TWiki::cfg{Plugins}{TwistyPlugin}{Enabled} ) {
colas@0
    36
        $value .= '%TWISTY{link="" noscript="hide" start="show"'.
colas@0
    37
          'prefix="&nbsp;"}%';
colas@0
    38
    }
colas@0
    39
    $value .= CGI::image_button(
colas@0
    40
        -name => 'calendar',
colas@0
    41
        -onclick =>
colas@0
    42
          "return showCalendar('id$this->{name}','$ifFormat')",
colas@0
    43
        -src=> $TWiki::cfg{PubUrlPath} . '/' .
colas@0
    44
          $TWiki::cfg{SystemWebName} .
colas@0
    45
            '/JSCalendarContrib/img.gif',
colas@0
    46
        -alt => 'Calendar',
colas@0
    47
        -class => 'twikiButton twikiEditFormCalendarButton' );
colas@0
    48
    if( $TWiki::cfg{Plugins}{TwistyPlugin}{Enabled} ) {
colas@0
    49
        $value .= '%ENDTWISTY%';
colas@0
    50
    }
colas@0
    51
    my $session = $this->{session};
colas@0
    52
    $value = $session->renderer->getRenderedVersion(
colas@0
    53
        $session->handleCommonTags( $value, $web, $topic ));
colas@0
    54
colas@0
    55
    return ( '', $value );
colas@0
    56
}
colas@0
    57
colas@0
    58
1;
colas@0
    59
__DATA__
colas@0
    60
colas@0
    61
Module of TWiki Enterprise Collaboration Platform, http://TWiki.org/
colas@0
    62
colas@0
    63
Copyright (C) 2001-2007 TWiki Contributors. All Rights Reserved.
colas@0
    64
TWiki Contributors are listed in the AUTHORS file in the root of
colas@0
    65
this distribution. NOTE: Please extend that file, not this notice.
colas@0
    66
colas@0
    67
This program is free software; you can redistribute it and/or
colas@0
    68
modify it under the terms of the GNU General Public License
colas@0
    69
as published by the Free Software Foundation; either version 2
colas@0
    70
of the License, or (at your option) any later version. For
colas@0
    71
more details read LICENSE in the root of this distribution.
colas@0
    72
colas@0
    73
This program is distributed in the hope that it will be useful,
colas@0
    74
but WITHOUT ANY WARRANTY; without even the implied warranty of
colas@0
    75
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
colas@0
    76
colas@0
    77
As per the GPL, removal of this notice is prohibited.
colas@0
    78