[Rt-commit] rt branch, 4.0/cf-cascaded-selects, created. rt-4.0.5-82-g3a1f0fa
? sunnavy
sunnavy at bestpractical.com
Sat Jun 23 11:07:02 EDT 2012
The branch, 4.0/cf-cascaded-selects has been created
at 3a1f0faed7cdcabcbca73f60e1007cb2c364adef (commit)
- Log -----------------------------------------------------------------
commit 864fdaced956dcce8f091d2b8031d666c63c3c99
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sat Jun 23 21:56:21 2012 +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 and 5.
"Dropdown/Select box" still renders as "Dropdown/Dropdown" though
diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 91afa3e..c26432e 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1020,11 +1020,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 5034c4d..521bbf5 100755
--- 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 b3fefbd..db0c990 100644
--- a/share/html/Elements/EditCustomFieldSelect
+++ b/share/html/Elements/EditCustomFieldSelect
@@ -66,47 +66,58 @@
<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');
- if (basedon != null) {
- var oldchange = basedon.onchange;
- basedon.onchange = function () {
+ var basedon = jQuery('[name^=<% $NamePrefix . $CustomField->BasedOnObj->id %>-Value]:input');
+ if (basedon.size()) {
+ var oldchange = basedon.get(0).onchange;
+ basedon.change( function () {
filter_cascade(
'<% $id %>-Values',
- basedon.value,
+ jQuery(this).val(),
1
);
if (oldchange != null)
oldchange();
- };
- basedon.onchange();
+ });
+
+ if ( basedon.is('select') ) {
+ basedon.change();
+ } else {
+ basedon.filter(':checked').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 ) ) {
diff --git a/share/html/NoAuth/js/cascaded.js b/share/html/NoAuth/js/cascaded.js
index fb20b32..572ea05 100644
--- a/share/html/NoAuth/js/cascaded.js
+++ b/share/html/NoAuth/js/cascaded.js
@@ -46,6 +46,33 @@
%#
%# END BPS TAGGED BLOCK }}}
function filter_cascade (id, val) {
+ var element = document.getElementById(id);
+ if (!element) { return };
+
+ if ( element.tagName == 'SELECT' ) {
+ return filter_cascade_select.apply(this, arguments);
+ }
+ else {
+ // it's checkbox or radio
+ if ( val == '' && arguments.length == 3 ) {
+ // no category, and the category is from a hierchical cf;
+ // leave it empty
+ jQuery(element).find('div').hide();
+ }
+ else {
+ if ( val == '' ) {
+ jQuery(element).find('div').show().find('input:disabled').attr('disabled', '');
+ }
+ else {
+ jQuery(element).find('div').hide().find('input').attr('disabled', 'disabled');
+ jQuery(element).find('div[name=], div[name^=' + val + ']').show().find('input').attr('disabled', '');
+ }
+ jQuery(element).find('div.none').show().find('input').attr('disabled','');
+ }
+ }
+}
+
+function filter_cascade_select (id, val) {
var select = document.getElementById(id);
var complete_select = document.getElementById(id + "-Complete" );
commit 3a1f0faed7cdcabcbca73f60e1007cb2c364adef
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sat Jun 23 22:18:50 2012 +0800
use "Select box" instead of Dropdown if user chooses it
this fixes the 4th case in 864fdac
diff --git a/share/html/Elements/EditCustomFieldSelect b/share/html/Elements/EditCustomFieldSelect
index db0c990..7eebdbf 100644
--- a/share/html/Elements/EditCustomFieldSelect
+++ b/share/html/Elements/EditCustomFieldSelect
@@ -120,7 +120,7 @@ jQuery( function () {
% }
<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 %> >
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list