Skip to content

Commit

Permalink
Issue #12631: Replace old dynamic filter JavaScript code with jQuery
Browse files Browse the repository at this point in the history
MantisBT was using a very old and messy method for handling dynamic
filters with client side JavaScript. This involved a lot of inline
JavaScript throughout the HTML output which is blocking our progress
towards bug #11826 - completely removing all inline JavaScript from the
HTML output.

This patch removes the old dynamic filter JavaScript approach and
replaces it with a smaller, faster, more reliable and easier to maintain
jQuery equivalent.
  • Loading branch information
davidhicks committed Dec 26, 2010
1 parent 0d602be commit 7790835
Show file tree
Hide file tree
Showing 18 changed files with 188 additions and 720 deletions.
4 changes: 2 additions & 2 deletions admin/check/check_display_inc.php
Expand Up @@ -37,8 +37,8 @@
check_print_section_header_row( 'Display' );

check_print_test_row(
'dhtml_filters = ON requires use_javascript = ON',
!config_get_global( 'dhtml_filters' ) || config_get_global( 'use_javascript' )
'use_dynamic_filters = ON requires use_javascript = ON',
!config_get_global( 'use_dynamic_filters' ) || ( config_get_global( 'use_dynamic_filters' ) && config_get_global( 'use_javascript' ) )
);

check_print_test_row(
Expand Down
11 changes: 6 additions & 5 deletions config_defaults_inc.php
Expand Up @@ -2925,12 +2925,13 @@
$g_view_filters = SIMPLE_DEFAULT;

/**
* This switch enables the use of xmlhttprequest protocol to speed up the
* filter display. Rather than launching a separate page, the filters are
* updated in-line in the view_all_bugs_page.
* @global int $g_dhtml_filters
* This switch enables the use of AJAX to dynamically load and create filter
* form controls upon request. This method will reduce the amount of data that
* needs to be transferred upon each page load dealing with filters and thus
* will result in speed improvements and bandwidth reduction.
* @global int $g_use_dynamic_filters
*/
$g_dhtml_filters = ON;
$g_use_dynamic_filters = ON;

/**
* The threshold required for users to be able to create permalinks. To turn
Expand Down
276 changes: 104 additions & 172 deletions core/filter_api.php

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions core/helper_api.php
Expand Up @@ -147,24 +147,24 @@ function check_selected( $p_var, $p_val = true ) {
# catch the case where one entry is 0 and the other is a string.
if( is_string( $t_this_var ) && is_string( $p_val ) ) {
if( $t_this_var === $p_val ) {
echo ' selected="selected" ';
echo ' selected="selected"';
return;
}
}
else if( $t_this_var == $p_val ) {
echo ' selected="selected" ';
echo ' selected="selected"';
return;
}
}
} else {
if( is_string( $p_var ) && is_string( $p_val ) ) {
if( $p_var === $p_val ) {
echo ' selected="selected" ';
echo ' selected="selected"';
return;
}
}
else if( $p_var == $p_val ) {
echo ' selected="selected" ';
echo ' selected="selected"';
return;
}
}
Expand All @@ -189,24 +189,24 @@ function check_checked( $p_var, $p_val = true ) {
# catch the case where one entry is 0 and the other is a string.
if( is_string( $t_this_var ) && is_string( $p_val ) ) {
if( $t_this_var === $p_val ) {
echo ' checked="checked" ';
echo ' checked="checked"';
return;
}
}
else if( $t_this_var == $p_val ) {
echo ' checked="checked" ';
echo ' checked="checked"';
return;
}
}
} else {
if( is_string( $p_var ) && is_string( $p_val ) ) {
if( $p_var === $p_val ) {
echo ' checked="checked" ';
echo ' checked="checked"';
return;
}
}
else if( $p_var == $p_val ) {
echo ' checked="checked" ';
echo ' checked="checked"';
return;
}
}
Expand Down
1 change: 1 addition & 0 deletions core/obsolete.php
Expand Up @@ -156,3 +156,4 @@
config_obsolete( 'show_queries_list' );
config_obsolete( 'administrator_email', 'webmaster_email' );
config_obsolete( 'session_key' );
config_obsolete( 'dhtml_filters', 'use_dynamic_filters' );
2 changes: 1 addition & 1 deletion core/print_api.php
Expand Up @@ -532,7 +532,7 @@ function print_subproject_option_list( $p_parent_id, $p_project_id = null, $p_fi
}
echo $t_full_id . '"';
check_selected( $p_project_id, $t_full_id );
echo '>' . str_repeat( '&nbsp;', count( $p_parents ) ) . str_repeat( '&raquo;', count( $p_parents ) ) . ' ' . string_attribute( project_get_field( $t_id, 'name' ) ) . '</option>' . "\n";
echo '>' . str_repeat( '&#160;', count( $p_parents ) ) . str_repeat( '&#187;', count( $p_parents ) ) . ' ' . string_attribute( project_get_field( $t_id, 'name' ) ) . '</option>' . "\n";
print_subproject_option_list( $t_id, $p_project_id, $p_filter_project_id, $p_trace, $p_parents );
}
}
Expand Down
17 changes: 10 additions & 7 deletions docbook/Admin_Guide/en-US/Configuration.xml
Expand Up @@ -2095,13 +2095,16 @@
</listitem>
</varlistentry>
<varlistentry>
<term>$g_dhtml_filters = OFF;</term>
<listitem>
<para>Controls the use of DHTML filters that will display the
filter in view page using DHTML and javascript. Default is OFF.
This requires $g_use_javascript to ne set to ON. This may not work
in all browsers as it requires xmlhttprequest
functionality.
<term>$g_use_dynamic_filters = ON;</term>
<listitem>
<para>This switch enables the use of AJAX to dynamically
load and create filter form controls upon request.
This method will reduce the amount of data that needs
to be transferred upon each page load dealing with
filters and thus will result in speed improvements and
bandwidth reduction. This requires $g_use_javascript
to be set to ON. By default, this configuration option
is set to ON.
</para>
</listitem>
</varlistentry>
Expand Down
1 change: 0 additions & 1 deletion javascript/addLoadEvent.js

This file was deleted.

52 changes: 52 additions & 0 deletions javascript/common.js
Expand Up @@ -73,6 +73,40 @@ $(document).ready( function() {
}
});

$('a.dynamic-filter-expander').click(function(event) {
event.preventDefault();
var fieldID = $(this).attr('id');
var targetID = fieldID + '_target';
var viewType = $('#filters_form_open input[name=view_type]').val();
$('#' + targetID).html('<span class="dynamic-filter-loading">' + translations['loading'] + "</span>");
$.ajax({
url: 'return_dynamic_filters.php',
data: 'view_type=' + viewType + '&filter_target=' + fieldID,
cache: false,
context: $('#' + targetID),
success: function(html) {
$(this).html(html);
$('input[type=checkbox]#use_date_filters').click(function() {
if (!$(this).is(':checked')) {
$('form#filters_form_open select[name=start_year]').attr('disabled', 'disabled');
$('form#filters_form_open select[name=start_month]').attr('disabled', 'disabled');
$('form#filters_form_open select[name=start_day]').attr('disabled', 'disabled');
$('form#filters_form_open select[name=end_year]').attr('disabled', 'disabled');
$('form#filters_form_open select[name=end_month]').attr('disabled', 'disabled');
$('form#filters_form_open select[name=end_day]').attr('disabled', 'disabled');
} else {
$('form#filters_form_open select[name=start_year]').removeAttr('disabled');
$('form#filters_form_open select[name=start_month]').removeAttr('disabled');
$('form#filters_form_open select[name=start_day]').removeAttr('disabled');
$('form#filters_form_open select[name=end_year]').removeAttr('disabled');
$('form#filters_form_open select[name=end_month]').removeAttr('disabled');
$('form#filters_form_open select[name=end_day]').removeAttr('disabled');
}
});
}
});
});

$('input.autofocus:first, select.autofocus:first, textarea.autofocus:first').focus();

$('input[type=checkbox].check_all').click(function() {
Expand Down Expand Up @@ -171,6 +205,24 @@ $(document).ready( function() {
});
$('[name=form_set_project]').children('.button').hide();
setBugLabel();

$('input[type=checkbox]#use_date_filters').click(function() {
if (!$(this).is(':checked')) {
$('form[name=filters] select[name=start_year]').attr('disabled', 'disabled');
$('form[name=filters] select[name=start_month]').attr('disabled', 'disabled');
$('form[name=filters] select[name=start_day]').attr('disabled', 'disabled');
$('form[name=filters] select[name=end_year]').attr('disabled', 'disabled');
$('form[name=filters] select[name=end_month]').attr('disabled', 'disabled');
$('form[name=filters] select[name=end_day]').attr('disabled', 'disabled');
} else {
$('form[name=filters] select[name=start_year]').removeAttr('disabled');
$('form[name=filters] select[name=start_month]').removeAttr('disabled');
$('form[name=filters] select[name=start_day]').removeAttr('disabled');
$('form[name=filters] select[name=end_year]').removeAttr('disabled');
$('form[name=filters] select[name=end_month]').removeAttr('disabled');
$('form[name=filters] select[name=end_day]').removeAttr('disabled');
}
});
});

function setBugLabel() {
Expand Down
47 changes: 0 additions & 47 deletions javascript/dev/addLoadEvent.js

This file was deleted.

0 comments on commit 7790835

Please sign in to comment.