summaryrefslogtreecommitdiff
path: root/httemplate/elements/duration.html
blob: 106e56ba09f809abc13146bfbe3168dda2c8e4ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<% $opt{'prefix'} %><INPUT TYPE  = "text"
                           NAME  = "<% $opt{field} %>"
                           ID    = "<% $opt{id} %>"
                           VALUE = "<% $value |h %>"
                           <% $size %>
                           <% $maxlength %>
                           <% $style %>
                           <% $opt{autocomplete} ? 'autocomplete="off"' : '' %>
                           <% $opt{disabled} %>
                           <% $onchange %>
                    ><SELECT NAME = "<% $opt{field} %>_units"
                           ID    = "<% $opt{id} %>_units"
                           onChange = "<% $opt{field} %>_units_changed(this)"
                    >
                    <OPTION VALUE="1">minutes</OPTION>
                    <OPTION SELECTED VALUE="60">hours</OPTION>
                    </SELECT><% $opt{'postfix'} %>
<SCRIPT TYPE="text/javascript">
  function <% $opt{field} %>_units_changed(what) {
    var units = what.options[what.selectedIndex].value;
    if ( units == 60 ) { // changed from minutes to hours, so /60

      var value = what.form.<% $opt{field} %>.value;
      value = value / 60;
      what.form.<% $opt{field} %>.value = value;

    } else if ( units == 1 ) { // changed from hours to minutes, so *60

      var value = what.form.<% $opt{field} %>.value;
      value = Math.round(value * 60);
      what.form.<% $opt{field} %>.value = value;

    }
  }
</SCRIPT>
<%init>

my %opt = @_;

my $value = length($opt{curr_value}) ? $opt{curr_value} : $opt{value};
$value = $value / 60;

my $onchange = $opt{'onchange'}
                 ? join(' ', map $_.'="'. $opt{'onchange'}. '(this)"',
                                 qw( onChange onKeyDown onKeyUp onKeyPress )
                       )
                 : '';

$opt{'size'} ||= 4;
my $size = 'SIZE="'. $opt{'size'}. '"';

$opt{'maxlength'} ||= 3;
my $maxlength = 'MAXLENGTH="'. $opt{'maxlength'}. '"';

$opt{'disabled'} = &{ $opt{'disabled'} }( \%opt )
  if ref($opt{'disabled'}) eq 'CODE';
$opt{'disabled'} = 'DISABLED'
  if $opt{'disabled'} && $opt{'disabled'} !~ /disabled/i; # uuh... yeah?

my @style = ref($opt{'style'})
              ? @{ $opt{'style'} }
              : $opt{'style'}
                ? ( $opt{'style'} )
                : ();

push @style, 'text-align: '. $opt{'text-align'}
  if $opt{'text-align'};

push @style, 'background-color: #dddddd'
  if $opt{'disabled'} && ! $opt{'nodarken_disabled'};

my $style = scalar(@style) ? 'STYLE="'. join(';', @style). '"' : '';

</%init>