summaryrefslogtreecommitdiff
path: root/httemplate/elements/select.html
blob: 5249a6dc3e43d33d7521af7d0e3f4f63a12a2106 (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
75
76
77
78
79
% unless ( $opt{'js_only'} ) {

<SELECT NAME          = "<% $opt{field} %>"
        ID            = "<% $opt{id} %>"
        previousValue = "<% $curr_value %>"
        previousText  = "<% $labels->{$curr_value} || $curr_value %>"
        <% $style %>
        <% $opt{disabled} %>
        <% $onchange %>
>

% if ( $opt{options} ) {
%
%   foreach my $option ( @{ $opt{options} } ) { #just arrayref for now

      <OPTION VALUE="<% $option %>"
              <% $opt{curr_value} eq $option ? 'SELECTED' : '' %>
      >
        <% $labels->{$option} || $option %>
      </OPTION>

%   }
%
% } else { #deprecated weird value hashref used only by reason.html
%
%   my $aref = $opt{'value'}->{'values'};
%   my $vkey = $opt{'value'}->{'vcolumn'};
%   my $ckey = $opt{'value'}->{'ccolumn'};
%   foreach my $v (@$aref) {

      <OPTION VALUE="<% $v->$vkey %>"
              <% ($opt{curr_value} eq $v->$vkey) ? 'SELECTED' : '' %>
      >
        <% $v->$ckey %>
      </OPTION>

%   }
%
% }

</SELECT>

% }
<%init>

my %opt = @_;

my $onchange = $opt{'onchange'}
                 ? 'onChange="'. $opt{'onchange'}. '(this)"'
                 : '';

my $labels = $opt{'option_labels'} || $opt{'labels'};

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;
}

$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'} )
                : ();

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


</%init>