Master to 4.2.8
[usit-rt.git] / share / html / Elements / EditCustomFieldSelect
CommitLineData
84fb5b46
MKG
1%# BEGIN BPS TAGGED BLOCK {{{
2%#
3%# COPYRIGHT:
4%#
320f0092 5%# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
84fb5b46
MKG
6%# <sales@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%# 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?)
51% my $selected = 0;
52% my @category;
84fb5b46
MKG
53% my $out = $m->scomp('SELF:options', %ARGS, SelectedRef => \$selected, CategoryRef => \@category);
54% if (!$HideCategory and @category and not $CustomField->BasedOnObj->id) {
84fb5b46 55%# XXX - Hide this select from w3m?
c33a4027 56 <select onchange="filter_cascade_by_id(<% $name |n,j %>, this.value)" name="<% $name %>-Category" class="CF-<%$CustomField->id%>-Edit">
84fb5b46
MKG
57 <option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>-</&></option>
58% foreach my $cat (@category) {
59% my ($depth, $name) = @$cat;
60 <option value="<% $name %>"><% '&nbsp;' x $depth |n %><% $name %></option>
61% }
62 </select><br />
63% } elsif ($CustomField->BasedOnObj->id) {
c33a4027 64
84fb5b46
MKG
65<script type="text/javascript"><!--
66jQuery( function () {
c33a4027 67 var basedon = jQuery('[name^="'+<% $BasedOnName || $NamePrefix . $CustomField->BasedOnObj->id . '-Value' |n,j %>+'"][type!="hidden"]:input:not(.hidden)');
320f0092
MKG
68 basedon.each( function() {
69 var oldchange = jQuery(this).onchange;
70 jQuery(this).change( function () {
71 var vals;
72 if ( jQuery(this).is('select') ) {
73 vals = basedon.first().val();
74 }
75 else {
76 vals = [];
77 jQuery(basedon).each( function() {
78 if ( jQuery(this).is(':checked') ) {
79 vals.push(jQuery(this).val());
80 }
81 });
82 }
af59614d 83 filter_cascade_by_id(
c33a4027 84 <% $name |n,j%>,
320f0092 85 vals,
af59614d 86 true
84fb5b46
MKG
87 );
88 if (oldchange != null)
89 oldchange();
320f0092
MKG
90 });
91 });
92
93 if ( basedon.is('select') ) {
94 basedon.change();
95 }
96 else {
97 basedon.first().change();
84fb5b46
MKG
98 }
99});
100--></script>
101% }
84fb5b46
MKG
102
103% if ( $RenderType eq 'List' ) {
104<fieldset class="cfedit">
c33a4027 105<div data-name="<%$name%>" id="<%$name%>">
84fb5b46 106% if ( $checktype eq 'radio' ) {
320f0092
MKG
107 <div class="none">
108 <input class="none" type="<% $checktype %>" name="<% $name %>" id="<% $name %>-none" value="" <% keys %default ? '' : ' checked="checked"' |n%> />
84fb5b46 109 <label for="<% $name %>-none"><&|/l&>(no value)</&></label><br />
320f0092 110 </div>
84fb5b46
MKG
111% }
112% my $CFVs = $CustomField->Values;
113% while ( my $value = $CFVs->Next ) {
114% my $content = $value->Name;
115% my $labelid = "$name-". $value->id;
c33a4027 116<div data-name="<% $value->Category || '' %>">
84fb5b46
MKG
117 <input type="<% $checktype %>" name="<% $name %>" id="<% $labelid %>" value="<% $content %>" <% $default{ lc $content }? ' checked="checked"' : '' |n%> />
118 <label for="<% $labelid %>"><% $content %></label><br />
320f0092 119</div>
84fb5b46 120% }
320f0092 121</div>
84fb5b46
MKG
122</fieldset>
123% } else {
320f0092
MKG
124% if (@category) {
125%# this hidden select is to supply a full list of values,
126%# see filter_cascade_select() in js/cascaded.js
c33a4027 127 <select name="<%$name%>-Complete" id="<%$name%>-Complete" class="hidden" disabled="disabled">
320f0092
MKG
128 <option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>(no value)</&></option>
129% $m->out($out);
130 </select>
131% }
84fb5b46 132<select
c33a4027 133 name="<%$name%>" id="<%$name%>" class="CF-<%$CustomField->id%>-Edit"
320f0092 134% if ( $Rows && ( $Multiple || !@category || $RenderType eq 'Select box') ) {
84fb5b46
MKG
135 size="<% $Rows %>"
136% }
137<% $Multiple && qq[multiple="multiple"] |n %> >
138<option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>(no value)</&></option>
139% $m->out($out);
140</select>
141% }
142<%init>
143# Handle render types
144$RenderType ||= $CustomField->RenderType;
145if ( $RenderType eq 'Dropdown' ) {
146 # Turn it into a dropdown
147 $Rows = 0;
148}
149
84fb5b46 150my ($checktype, $name);
c33a4027
MKG
151if ( $MaxValues == 1 and $RenderType eq 'List' ) {
152 ($checktype, $name) = ('radio', $Name || $NamePrefix . $CustomField->Id . '-Value');
84fb5b46 153} else {
c33a4027 154 ($checktype, $name) = ('checkbox', $Name || $NamePrefix . $CustomField->Id . '-Values');
84fb5b46
MKG
155}
156
157@Default = grep defined && length, @Default;
158if ( !@Default && $Values ) {
159 @Default = map $_->Content, @{ $Values->ItemsArrayRef };
160}
161my %default = map {lc $_ => 1} @Default;
162</%init>
163<%ARGS>
164$Object => undef
165$CustomField => undef
166$NamePrefix => undef
c33a4027
MKG
167$Name => undef
168$BasedOnName => undef
84fb5b46
MKG
169@Default => ()
170$Values => undef
171$Multiple => 0
172$Rows => undef
173$HideCategory => 0
174$RenderType => undef
175$MaxValues => 1
176</%ARGS>
177
178<%METHOD options>
179% @Default = grep defined && length, @Default;
180% # $Values->HasEntry is too slow here
181% if ( !@Default && $Values ) {
182% @Default = map $_->Content, @{$Values->ItemsArrayRef};
183% }
184% $_ = lc $_ foreach @Default;
185% my $selected;
186% my $CFVs = $CustomField->Values;
187% my @levels;
188% while ( my $value = $CFVs->Next ) {
189% my $name = $value->Name;
190% my $category = $value->Category || '';
191% my $level = (split /:/, $category, 2)[0] || '';
192% while (@levels) {
193% if ($levels[-1] eq $level) {
194% $level = '';
195% last;
196% } elsif (index($level, $levels[-1]) != 0) {
197% $m->out('</optgroup>');
198% pop @levels;
199% } else {
200% last;
201% }
202% }
203% if ( length $level ) {
204% push @$CategoryRef, [0+@levels, $level];
205 <optgroup style="padding-left: <% @levels/2 %>em" label="<% $category %>">
206% push @levels, $level;
207% }
208 <option value="<% $name %>"
209% if ( grep $_ eq lc $name, @Default )
210% {
211% $$SelectedRef = 1;
212 selected="selected"
213% }
214 ><% $name %></option>
215% }
216% for (@levels) {
217 </optgroup>
218% }
219<%ARGS>
220$CustomField => undef
221@Default => ()
222$Values => undef
223$SelectedRef => undef
224$CategoryRef => undef
225</%ARGS>
226</%METHOD>