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 }}}
48 %# Build up the set of cascading select boxes as "guides"
49 %# each one limits the options of the final one a bit
50 %# (perhaps by tweaking the .display style?)
53 % my $out = $m->scomp('SELF:options', %ARGS, SelectedRef => \$selected, CategoryRef => \@category);
54 % if (!$HideCategory and @category and not $CustomField->BasedOnObj->id) {
55 %# XXX - Hide this select from w3m?
56 <select onchange="filter_cascade_by_id(<% $name |n,j %>, this.value)" name="<% $name %>-Category" class="CF-<%$CustomField->id%>-Edit">
57 <option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>-</&></option>
58 % foreach my $cat (@category) {
59 % my ($depth, $name) = @$cat;
60 <option value="<% $name %>"><% ' ' x $depth |n %><% $name %></option>
63 % } elsif ($CustomField->BasedOnObj->id) {
65 <script type="text/javascript"><!--
67 var basedon = jQuery('[name^="'+<% $BasedOnName || $NamePrefix . $CustomField->BasedOnObj->id . '-Value' |n,j %>+'"][type!="hidden"]:input:not(.hidden)');
68 basedon.each( function() {
69 var oldchange = jQuery(this).onchange;
70 jQuery(this).change( function () {
72 if ( jQuery(this).is('select') ) {
73 vals = basedon.first().val();
77 jQuery(basedon).each( function() {
78 if ( jQuery(this).is(':checked') ) {
79 vals.push(jQuery(this).val());
88 if (oldchange != null)
93 if ( basedon.is('select') ) {
97 basedon.first().change();
103 % if ( $RenderType eq 'List' ) {
104 <fieldset class="cfedit">
105 <div data-name="<%$name%>" id="<%$name%>">
106 % if ( $checktype eq 'radio' ) {
108 <input class="none" type="<% $checktype %>" name="<% $name %>" id="<% $name %>-none" value="" <% keys %default ? '' : ' checked="checked"' |n%> />
109 <label for="<% $name %>-none"><&|/l&>(no value)</&></label><br />
112 % my $CFVs = $CustomField->Values;
113 % while ( my $value = $CFVs->Next ) {
114 % my $content = $value->Name;
115 % my $labelid = "$name-". $value->id;
116 <div data-name="<% $value->Category || '' %>">
117 <input type="<% $checktype %>" name="<% $name %>" id="<% $labelid %>" value="<% $content %>" <% $default{ lc $content }? ' checked="checked"' : '' |n%> />
118 <label for="<% $labelid %>"><% $content %></label><br />
125 %# this hidden select is to supply a full list of values,
126 %# see filter_cascade_select() in js/cascaded.js
127 <select name="<%$name%>-Complete" id="<%$name%>-Complete" class="hidden" disabled="disabled">
128 <option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>(no value)</&></option>
133 name="<%$name%>" id="<%$name%>" class="CF-<%$CustomField->id%>-Edit"
134 % if ( $Rows && ( $Multiple || !@category || $RenderType eq 'Select box') ) {
137 <% $Multiple && qq[multiple="multiple"] |n %> >
138 <option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>(no value)</&></option>
143 # Handle render types
144 $RenderType ||= $CustomField->RenderType;
145 if ( $RenderType eq 'Dropdown' ) {
146 # Turn it into a dropdown
150 my ($checktype, $name);
151 if ( $MaxValues == 1 and $RenderType eq 'List' ) {
152 ($checktype, $name) = ('radio', $Name || $NamePrefix . $CustomField->Id . '-Value');
154 ($checktype, $name) = ('checkbox', $Name || $NamePrefix . $CustomField->Id . '-Values');
157 @Default = grep defined && length, @Default;
158 if ( !@Default && $Values ) {
159 @Default = map $_->Content, @{ $Values->ItemsArrayRef };
161 my %default = map {lc $_ => 1} @Default;
165 $CustomField => undef
168 $BasedOnName => undef
179 % @Default = grep defined && length, @Default;
180 % # $Values->HasEntry is too slow here
181 % if ( !@Default && $Values ) {
182 % @Default = map $_->Content, @{$Values->ItemsArrayRef};
184 % $_ = lc $_ foreach @Default;
186 % my $CFVs = $CustomField->Values;
188 % while ( my $value = $CFVs->Next ) {
189 % my $name = $value->Name;
190 % my $category = $value->Category || '';
191 % my $level = (split /:/, $category, 2)[0] || '';
193 % if ($levels[-1] eq $level) {
196 % } elsif (index($level, $levels[-1]) != 0) {
197 % $m->out('</optgroup>');
203 % if ( length $level ) {
204 % push @$CategoryRef, [0+@levels, $level];
205 <optgroup style="padding-left: <% @levels/2 %>em" label="<% $category %>">
206 % push @levels, $level;
208 <option value="<% $name %>"
209 % if ( grep $_ eq lc $name, @Default )
214 ><% $name %></option>
220 $CustomField => undef
223 $SelectedRef => undef
224 $CategoryRef => undef