diff options
author | Ivan Kohler <ivan@freeside.biz> | 2014-04-05 16:46:29 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2014-04-05 16:46:29 -0700 |
commit | ac127e9cc71ed1cfebb159095dd59b3507e54e98 (patch) | |
tree | c1e741cfbe7a64567202b48e7b4a6725a67f6896 /httemplate/elements/select-time.html | |
parent | a57c537ff9ef2a57de3225fbd49772be4b81e74c (diff) |
installers, RT#16584
Diffstat (limited to 'httemplate/elements/select-time.html')
-rw-r--r-- | httemplate/elements/select-time.html | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/httemplate/elements/select-time.html b/httemplate/elements/select-time.html new file mode 100644 index 000000000..6e22e1e3d --- /dev/null +++ b/httemplate/elements/select-time.html @@ -0,0 +1,49 @@ +% unless ( $opt{'js_only'} ) { + <SELECT NAME="<% $opt{'field'} %>" SIZE="1" <%$disabled%> <%$onchange%> > +% for ( my $t = 0; $t <=1440; $t += $increment ) { + <OPTION VALUE="<% $t %>" + <% ( $curr_value eq '' && $t == $selected_default ) + || $curr_value == $t + ? 'SELECTED' : '' + %> + ><% pretty_time($t) %> +% } + </SELECT> +% } +<%init> + +my %opt = @_; +my $increment = $opt{increment} || 30; +my $selected_default = $opt{selected_default}; +my $disabled = $opt{'disabled'} || ''; + +my $curr_value = $opt{curr_value}; + +my $onchange = ''; +if ( $opt{'onchange'} ) { + $onchange = $opt{'onchange'}; + $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/; + $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack. all onchange + #callbacks should act the same + $onchange = 'onChange="'. $onchange. '"' unless $onchange =~ /^onChange=/i; +} + +sub pretty_time { + my $t = shift; + + return 'Midnight' if $t == 0 || $t == 1440; + return 'Noon' if $t == 720; + + my $h = int( $t / 60 ); + my $m = $t % 60; + + my $ap = 'AM'; + if ( $h == 0 || $h == 24 ) { $h = 12; } + elsif ( $h == 12 ) { $ap = 'PM'; } + elsif ( $h > 12 ) { $ap = 'PM'; $h -= 12; } + + sprintf('%02d:%02d'." $ap", $h, $m); + +} + +</%init> |