v4 style
[freeside.git] / httemplate / elements / duration.html
1 <% $opt{'prefix'} %><INPUT TYPE  = "text"
2                            NAME  = "<% $opt{field} %>"
3                            ID    = "<% $opt{id} %>"
4                            VALUE = "<% $value |h %>"
5                            <% $size %>
6                            <% $maxlength %>
7                            <% $style %>
8                            <% $opt{autocomplete} ? 'autocomplete="off"' : '' %>
9                            <% $opt{disabled} %>
10                            <% $onchange %>
11                     ><SELECT NAME = "<% $opt{field} %>_units"
12                            ID    = "<% $opt{id} %>_units"
13                            onChange = "<% $opt{field} %>_units_changed(this)"
14                     >
15                     <OPTION VALUE="1">minutes</OPTION>
16                     <OPTION SELECTED VALUE="60">hours</OPTION>
17                     </SELECT><% $opt{'postfix'} %>
18 <SCRIPT TYPE="text/javascript">
19   function <% $opt{field} %>_units_changed(what) {
20     var units = what.options[what.selectedIndex].value;
21     if ( units == 60 ) { // changed from minutes to hours, so /60
22
23       var value = what.form.<% $opt{field} %>.value;
24       value = value / 60;
25       what.form.<% $opt{field} %>.value = value;
26
27     } else if ( units == 1 ) { // changed from hours to minutes, so *60
28
29       var value = what.form.<% $opt{field} %>.value;
30       value = Math.round(value * 60);
31       what.form.<% $opt{field} %>.value = value;
32
33     }
34   }
35 </SCRIPT>
36 <%init>
37
38 my %opt = @_;
39
40 my $value = length($opt{curr_value}) ? $opt{curr_value} : $opt{value};
41 $value = $value / 60;
42
43 my $onchange = $opt{'onchange'}
44                  ? join(' ', map $_.'="'. $opt{'onchange'}. '(this)"',
45                                  qw( onChange onKeyDown onKeyUp onKeyPress )
46                        )
47                  : '';
48
49 $opt{'size'} ||= 4;
50 my $size = 'SIZE="'. $opt{'size'}. '"';
51
52 $opt{'maxlength'} ||= 3;
53 my $maxlength = 'MAXLENGTH="'. $opt{'maxlength'}. '"';
54
55 $opt{'disabled'} = &{ $opt{'disabled'} }( \%opt )
56   if ref($opt{'disabled'}) eq 'CODE';
57 $opt{'disabled'} = 'DISABLED'
58   if $opt{'disabled'} && $opt{'disabled'} !~ /disabled/i; # uuh... yeah?
59
60 my @style = ref($opt{'style'})
61               ? @{ $opt{'style'} }
62               : $opt{'style'}
63                 ? ( $opt{'style'} )
64                 : ();
65
66 push @style, 'text-align: '. $opt{'text-align'}
67   if $opt{'text-align'};
68
69 push @style, 'background-color: #dddddd'
70   if $opt{'disabled'} && ! $opt{'nodarken_disabled'};
71
72 my $style = scalar(@style) ? 'STYLE="'. join(';', @style). '"' : '';
73
74 </%init>