1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2017 Best Practical Solutions, LLC
6 %# <sales@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
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
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.
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.
30 %# CONTRIBUTION SUBMISSION POLICY:
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.)
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.
47 %# END BPS TAGGED BLOCK }}}
49 see docs/extending/using_forms_widgets.pod
51 <div id="form-box-<% lc $Name %>" class="widget">
52 % if ( $Description ) {
53 <span class="label"><% $Description %></span>
55 <span class="value"><& SELF:InputOnly, %ARGS &></span>
56 <span class="hints"><% $Hints %></span>
60 $Description => undef,
67 $Description => undef,
70 $ValuesCallback => undef,
76 $DefaultLabel => undef,
79 $AlternativeLabel => loc('other...'),
83 <select name="<% $Name %>" <% $Multiple ? 'multiple="multiple"' : '' |n%>>
87 % $selected = 'selected="selected"' unless $CurrentValue[0];
88 <option value="__empty_value__" <% $selected |n %>><% $DefaultLabel %></option>
91 % foreach my $v( @Values ) {
93 % $selected = 'selected="selected"' if delete $CurrentValue{ $v };
94 <option value="<% $v %>" <% $selected |n %>><% loc(ref($ValuesLabel{ $v }) ? @{ $ValuesLabel{ $v } } : $ValuesLabel{ $v } || $v) %></option>
97 % if ( $Alternative ) {
99 % $selected = 'selected="selected"' if keys %CurrentValue;
100 <option value="__alternative_value__" <% $selected |n %>><% $AlternativeLabel %></option>
104 % if ( $Alternative ) {
105 <input type="text" class="alternative" name="Alternative-<% $Name %>" value="<% join ', ', @CurrentValue %>" />
108 my %CurrentValue = map {$_ => 1} grep defined, @CurrentValue;
109 if ( $ValuesCallback ) {
110 my $values = $ValuesCallback->(
111 CurrentUser => $session{'CurrentUser'},
114 if ( ref $values eq 'ARRAY' ) {
117 %ValuesLabel = %$values;
118 @Values = keys %ValuesLabel;
121 unless (defined $DefaultLabel ) {
122 $DefaultLabel = loc('Use system default ([_1])',
123 join ', ', map loc(ref($ValuesLabel{$_}) ? @{ $ValuesLabel{$_ }} : $ValuesLabel{$_} || $_), grep defined,
146 my $value = $Arguments->{ $Name };
147 if( !defined $value || $value eq '__empty_value__' ) {
148 return undef if $Default;
149 return [ @DefaultValue ] if $Multiple;
150 return $DefaultValue[0];
152 $value = [$value] unless ref $value;
154 if ( $Alternative ) {
155 my $alt = $Arguments->{ "Alternative-". $Name };
157 push @$value, split /\s*,\s*/, $alt;
163 splice @$value, 1 unless $Multiple;
167 return $value->[0] unless $Multiple;