This commit was generated by cvs2svn to compensate for changes in r8690,
[freeside.git] / rt / share / html / Widgets / Form / Select
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %# 
5 %# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
6 %#                                          <jesse@bestpractical.com>
7 %# 
8 %# (Except where explicitly superseded by other copyright notices)
9 %# 
10 %# 
11 %# LICENSE:
12 %# 
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
16 %# from www.gnu.org.
17 %# 
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 %# General Public License for more details.
22 %# 
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28 %# 
29 %# 
30 %# CONTRIBUTION SUBMISSION POLICY:
31 %# 
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
37 %# 
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
46 %# 
47 %# END BPS TAGGED BLOCK }}}
48 <%DOC>
49 see docs/using_forms_widgets.pod
50 </%DOC>
51 <div id="form-box-<% lc $Name %>" class="widget">
52 % if ( $Description ) {
53 <span class="label"><% $Description %></span>
54 % }
55 <span class="value"><& SELF:InputOnly, %ARGS &></span>
56 </div>
57 <%ARGS>
58 $Name
59 $Description      => undef,
60 </%ARGS>
61
62 <%METHOD InputOnly>
63 <%ARGS>
64 $Name
65 $Description      => undef,
66
67 @Values           => (),
68 $ValuesCallback   => undef,
69 %ValuesLabel      => (),
70 @CurrentValue     => (),
71
72 $Default            => 1,
73 @DefaultValue       => (),
74 $DefaultLabel       => undef,
75
76 $Alternative      => 0,
77 $AlternativeLabel => loc('other...'),
78
79 $Multiple         => 0,
80 </%ARGS>
81 <select name="<% $Name %>">
82
83 % if ( $Default ) {
84 % my $selected = '';
85 % $selected = 'selected="selected"' unless @CurrentValue;
86 <option value="__empty_value__" <% $selected |n %>><% $DefaultLabel %></option>
87 % }
88
89 % foreach my $v( @Values ) {
90 % my $selected = '';
91 % $selected = 'selected="selected"' if delete $CurrentValue{ $v };
92 <option value="<% $v %>" <% $selected |n %>><% loc($ValuesLabel{ $v } || $v) %></option>
93 % }
94
95 % if ( $Alternative ) {
96 %     my $selected = '';
97 %     $selected = 'selected="selected"' if keys %CurrentValue;
98 <option value="__alternative_value__" <% $selected |n %>><% $AlternativeLabel %></option>
99 % }
100
101 </select>
102 % if ( $Alternative ) {
103 <input type="text" class="alternative" name="Alternative-<% $Name %>" value="<% join ', ', @CurrentValue %>" />
104 % }
105 <%INIT>
106 my %CurrentValue = map {$_ => 1} grep defined, @CurrentValue;
107 if ( $ValuesCallback ) {
108     my $values = $ValuesCallback->(
109         CurrentUser => $session{'CurrentUser'},
110         Name        => $Name,
111     );
112     if ( ref $values eq 'ARRAY' ) {
113         @Values = @$values;
114     } else {
115         %ValuesLabel = %$values;
116         @Values = keys %ValuesLabel;
117     }
118 }
119 unless (defined $DefaultLabel ) {
120     $DefaultLabel = loc('Use system default ([_1])', join ', ', map{ loc($ValuesLabel{$_} || $_) } @DefaultValue);
121 }
122 </%INIT>
123 </%METHOD>
124
125 <%METHOD Process>
126 <%ARGS>
127 $Name
128
129 $Arguments        => {},
130
131 @Values           => (),
132 %ValuesLabel      => (),
133
134 $Default          => 0,
135 @DefaultValue     => (),
136
137 $Alternative      => 0,
138 $Multiple         => 0,
139 </%ARGS>
140 <%INIT>
141 my $value = $Arguments->{ $Name };
142 if( !defined $value || $value eq '__empty_value__' ) {
143     return undef if $Default;
144     return [ @DefaultValue ] if $Multiple;
145     return $DefaultValue[0];
146 }
147 $value = [$value] unless ref $value;
148
149 if ( $Alternative ) {
150     my $alt = $Arguments->{ "Alternative-". $Name };
151     if( $Multiple ) {
152         push @$value, split /\s*,\s*/, $alt;
153     } else {
154         push @$value, $alt;
155     }
156 }
157
158 splice @$value, 1 unless $Multiple;
159
160 # XXX: check values
161
162 return $value->[0] unless $Multiple;
163 return $value;
164 </%INIT>
165 </%METHOD>