[Rt-commit] rt branch, 4.0/cf-cascaded-selects, created. rt-4.0.18rc1-10-g167e933
? sunnavy
sunnavy at bestpractical.com
Tue Oct 8 11:28:03 EDT 2013
The branch, 4.0/cf-cascaded-selects has been created
at 167e933fc003c4ea8fbb14a824ca008540c88576 (commit)
- Log -----------------------------------------------------------------
commit 167e933fc003c4ea8fbb14a824ca008540c88576
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Oct 8 23:01:41 2013 +0800
fully(all kinds of render types) cascaded selects support
previously:
1. Dropdown / Dropdown => Works
2. Select box / Dropdown => Works
3. List / Dropdown => Always renders full list of Thing
4. Dropdown / Select box => Works, but renders as Dropdown / Dropdown
5. Dropdown / List => (not an option)
this commit fixes 3, 4 and 5.
diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 13eb7ef..0afb85a 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1094,11 +1094,6 @@ sub SetRenderType {
$self->FriendlyType));
}
- # XXX: Remove this restriction once we support lists and cascaded selects
- if ( $self->BasedOnObj->id and $type =~ /List/ ) {
- return (0, $self->loc("We can't currently render as a List when basing categories on another custom field. Please use another render type."));
- }
-
return $self->_Set( Field => 'RenderType', Value => $type, @_ );
}
diff --git a/share/html/Admin/Elements/SelectCustomFieldRenderType b/share/html/Admin/Elements/SelectCustomFieldRenderType
index 6484def..e9b5e3f 100644
--- a/share/html/Admin/Elements/SelectCustomFieldRenderType
+++ b/share/html/Admin/Elements/SelectCustomFieldRenderType
@@ -56,11 +56,6 @@ $Default ||= $cf->DefaultRenderType($TypeComposite);
my @types = $cf->RenderTypes($TypeComposite);
-# XXX: We currently don't support cascaded select CFs when
-# rendering as a list, so don't offer it for now.
-if ( $BasedOn ) {
- @types = grep { not /List/ } @types;
-}
</%INIT>
<%ARGS>
$Default => undef
diff --git a/share/html/Elements/EditCustomFieldSelect b/share/html/Elements/EditCustomFieldSelect
index 6cceb5a..b7a3112 100644
--- a/share/html/Elements/EditCustomFieldSelect
+++ b/share/html/Elements/EditCustomFieldSelect
@@ -66,50 +66,74 @@
<script type="text/javascript" src="<%RT->Config->Get('WebPath')%>/NoAuth/js/cascaded.js"></script>
<script type="text/javascript"><!--
jQuery( function () {
- var basedon = document.getElementById(<% $NamePrefix . $CustomField->BasedOnObj->id . "-Values" |n,j%>);
- if (basedon != null) {
- var oldchange = basedon.onchange;
- basedon.onchange = function () {
+ var basedon = jQuery('[name^=<% $NamePrefix . $CustomField->BasedOnObj->id %>-Value][type!=hidden]:input');
+ basedon.each( function() {
+ var oldchange = jQuery(this).onchange;
+ jQuery(this).change( function () {
+ var vals;
+ if ( jQuery(this).is('select') ) {
+ vals = basedon.first().val();
+ }
+ else {
+ vals = [];
+ jQuery(basedon).each( function() {
+ if ( jQuery(this).is(':checked') ) {
+ vals.push(jQuery(this).val());
+ }
+ });
+ }
filter_cascade(
<% "$id-Values" |n,j%>,
- jQuery(basedon).val(),
+ vals,
1
);
if (oldchange != null)
oldchange();
- };
- basedon.onchange();
+ });
+ });
+
+ if ( basedon.is('select') ) {
+ basedon.change();
+ }
+ else {
+ basedon.first().change();
}
});
--></script>
% }
-% if (@category) {
-%# this hidden select is to supply a full list of values,
-%# see filter_cascade() in js/cascaded.js
- <select name="<%$id%>-Values-Complete" id="<%$id%>-Values-Complete" class="hidden" disabled="disabled">
- <option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>(no value)</&></option>
-% $m->out($out);
- </select>
-% }
% if ( $RenderType eq 'List' ) {
<fieldset class="cfedit">
+<div name="<%$id%>-Values" id="<%$id%>-Values">
% if ( $checktype eq 'radio' ) {
- <input type="<% $checktype %>" name="<% $name %>" id="<% $name %>-none" value="" <% keys %default ? '' : ' checked="checked"' |n%> />
+ <div class="none">
+ <input class="none" type="<% $checktype %>" name="<% $name %>" id="<% $name %>-none" value="" <% keys %default ? '' : ' checked="checked"' |n%> />
<label for="<% $name %>-none"><&|/l&>(no value)</&></label><br />
+ </div>
% }
% my $CFVs = $CustomField->Values;
% while ( my $value = $CFVs->Next ) {
% my $content = $value->Name;
% my $labelid = "$name-". $value->id;
+<div name="<% $value->Category %>">
<input type="<% $checktype %>" name="<% $name %>" id="<% $labelid %>" value="<% $content %>" <% $default{ lc $content }? ' checked="checked"' : '' |n%> />
<label for="<% $labelid %>"><% $content %></label><br />
+</div>
% }
+</div>
</fieldset>
% } else {
+% if (@category) {
+%# this hidden select is to supply a full list of values,
+%# see filter_cascade() in js/cascaded.js
+ <select name="<%$id%>-Values-Complete" id="<%$id%>-Values-Complete" class="hidden" disabled="disabled">
+ <option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>(no value)</&></option>
+% $m->out($out);
+ </select>
+% }
<select
name="<%$id%>-Values" id="<%$id%>-Values" class="CF-<%$CustomField->id%>-Edit"
-% if ( $Rows && ( $Multiple || !@category ) ) {
+% if ( $Rows && ( $Multiple || !@category || $RenderType eq 'Select box') ) {
size="<% $Rows %>"
% }
<% $Multiple && qq[multiple="multiple"] |n %> >
diff --git a/share/html/NoAuth/js/cascaded.js b/share/html/NoAuth/js/cascaded.js
index 7559e40..4a66d5a 100644
--- a/share/html/NoAuth/js/cascaded.js
+++ b/share/html/NoAuth/js/cascaded.js
@@ -46,6 +46,34 @@
%#
%# END BPS TAGGED BLOCK }}}
function filter_cascade (id, vals) {
+ var element = document.getElementById(id);
+ if (!element) { return };
+
+ if ( element.tagName == 'SELECT' ) {
+ return filter_cascade_select.apply(this, arguments);
+ }
+ else {
+ if ( !( vals instanceof Array ) ) {
+ vals = [vals];
+ }
+
+ if ( arguments.length == 3 && (vals.length == 0 || (vals.length == 1 && vals[0] == '')) ) {
+ // no category, and the category is from a hierchical cf;
+ // leave it empty
+ jQuery(element).find('div').hide();
+ }
+ else {
+ jQuery(element).find('div').hide().find('input').attr('disabled', 'disabled');
+ jQuery(element).find('div[name=]').show().find('input').attr('disabled', '');
+ jQuery(element).find('div.none').show().find('input').attr('disabled','');
+ for ( var j = 0; j < vals.length; j++ ) {
+ jQuery(element).find('div[name^=' + vals[j] + ']').show().find('input').attr('disabled', '');
+ }
+ }
+ }
+}
+
+function filter_cascade_select (id, vals) {
var select = document.getElementById(id);
var complete_select = document.getElementById(id + "-Complete" );
if ( !( vals instanceof Array ) ) {
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list