[Rt-commit] rt branch, 4.0/cf-cascaded-selects, repushed
? sunnavy
sunnavy at bestpractical.com
Tue Oct 8 11:28:06 EDT 2013
The branch 4.0/cf-cascaded-selects was deleted and repushed:
was 3a1f0faed7cdcabcbca73f60e1007cb2c364adef
now 167e933fc003c4ea8fbb14a824ca008540c88576
1: 864fdac ! 1: 167e933 fully(all kinds of render types) cascaded selects support
@@ -10,9 +10,7 @@
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
+ this commit fixes 3, 4 and 5.
diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
--- a/lib/RT/CustomField.pm
@@ -53,18 +51,30 @@
<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');
+- 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]:input');
-+ if (basedon.size()) {
-+ var oldchange = basedon.get(0).onchange;
-+ basedon.change( 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',
-- basedon.value,
-+ jQuery(this).val(),
+ <% "$id-Values" |n,j%>,
+- jQuery(basedon).val(),
++ vals,
1
);
if (oldchange != null)
@@ -72,12 +82,13 @@
- };
- basedon.onchange();
+ });
++ });
+
-+ if ( basedon.is('select') ) {
-+ basedon.change();
-+ } else {
-+ basedon.filter(':checked').change();
-+ }
++ if ( basedon.is('select') ) {
++ basedon.change();
++ }
++ else {
++ basedon.first().change();
}
});
--></script>
@@ -96,10 +107,10 @@
+<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">
++ <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>
++ </div>
% }
% my $CFVs = $CustomField->Values;
% while ( my $value = $CFVs->Next ) {
@@ -123,7 +134,11 @@
+% }
<select
name="<%$id%>-Values" id="<%$id%>-Values" class="CF-<%$CustomField->id%>-Edit"
- % if ( $Rows && ( $Multiple || !@category ) ) {
+-% 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
--- a/share/html/NoAuth/js/cascaded.js
@@ -131,7 +146,7 @@
@@
%#
%# END BPS TAGGED BLOCK }}}
- function filter_cascade (id, val) {
+ function filter_cascade (id, vals) {
+ var element = document.getElementById(id);
+ if (!element) { return };
+
@@ -139,27 +154,27 @@
+ return filter_cascade_select.apply(this, arguments);
+ }
+ else {
-+ // it's checkbox or radio
-+ if ( val == '' && arguments.length == 3 ) {
++ 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 {
-+ if ( val == '' ) {
-+ jQuery(element).find('div').show().find('input:disabled').attr('disabled', '');
++ 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', '');
+ }
-+ 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) {
++function filter_cascade_select (id, vals) {
var select = document.getElementById(id);
var complete_select = document.getElementById(id + "-Complete" );
-
-
+ if ( !( vals instanceof Array ) ) {
2: 3a1f0fa < -: ------- use "Select box" instead of Dropdown if user chooses it
More information about the Rt-commit
mailing list