Skip to content

Commit

Permalink
Refactor printing of filter view type toggle
Browse files Browse the repository at this point in the history
Define a new API function filter_print_view_type_toggle() to avoid
duplicating code to handle display of the menu item to switch between
simple and advanced filter modes

Fixes #22316
  • Loading branch information
dregad committed Feb 5, 2017
1 parent f0fceac commit 4edd0b3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 34 deletions.
48 changes: 36 additions & 12 deletions core/filter_api.php
Expand Up @@ -2411,9 +2411,6 @@ function filter_draw_selection_area2( $p_page_number, $p_for_screen = true, $p_e
</h4>
<div class="widget-toolbar">
<?php
$f_switch_view_link = (config_get('use_dynamic_filters'))
? 'view_all_set.php?type=6&amp;view_type='
: 'view_filters_page.php?view_type=';
$t_view_filters = config_get('view_filters');

if( ( ( SIMPLE_ONLY != $t_view_filters ) && ( ADVANCED_ONLY != $t_view_filters ) ) ||
Expand All @@ -2425,15 +2422,11 @@ function filter_draw_selection_area2( $p_page_number, $p_for_screen = true, $p_e
</a>
<ul class="dropdown-menu dropdown-menu-right dropdown-yellow dropdown-caret dropdown-closer">
<?php
if( ( SIMPLE_ONLY != $t_view_filters ) && ( ADVANCED_ONLY != $t_view_filters ) ) {
echo '<li>';
if( FILTER_VIEW_TYPE_ADVANCED == $t_view_type ) {
echo '<a href="' . $f_switch_view_link . FILTER_VIEW_TYPE_SIMPLE . '"><i class="ace-icon fa fa-toggle-off"></i>&#160;&#160;' . lang_get('simple_filters') . '</a>';
} else {
echo '<a href="' . $f_switch_view_link . FILTER_VIEW_TYPE_ADVANCED . '"><i class="ace-icon fa fa-toggle-on"></i>&#160;&#160;' . lang_get('advanced_filters') . '</a>';
}
echo '</li>';
}
$t_url = config_get( 'use_dynamic_filters' )
? 'view_all_set.php?type=6&amp;view_type='
: 'view_filters_page.php?view_type=';
filter_print_view_type_toggle( $t_url, $t_filter['_view_type'] );

if( access_has_project_level( config_get( 'create_permalink_threshold' ) ) ) {
echo '<li>';
echo '<a href="permalink_page.php?url=' . urlencode( filter_get_url( $t_filter ) ) . '">';
Expand Down Expand Up @@ -3444,3 +3437,34 @@ function filter_is_accessible( $p_filter_id, $p_user_id = null ) {
}
return false;
}

/**
* Prints the simple/advanced menu item toggle if needed
* @param string $p_url Target URL, must end with 'view_type='
* @param string $p_view_type Filter view type (FILTER_VIEW_TYPE_SIMPLE or
* FILTER_VIEW_TYPE_ADVANCED)
*/
function filter_print_view_type_toggle( $p_url, $p_view_type ) {
$t_view_filters = config_get( 'view_filters' );
if( $t_view_filters == SIMPLE_ONLY || $t_view_filters == ADVANCED_ONLY ) {
return;
}

if( $p_view_type == FILTER_VIEW_TYPE_ADVANCED ) {
$t_url = $p_url . FILTER_VIEW_TYPE_SIMPLE;
$t_icon = 'fa-toggle-off';
$t_lang_string = 'simple_filters';
} else {
$t_url = $p_url . FILTER_VIEW_TYPE_ADVANCED;
$t_icon = 'fa-toggle-on';
$t_lang_string = 'advanced_filters';
}

echo '<li>';
printf( '<a href="%s"><i class="ace-icon fa %s"></i>&#160;&#160;%s</a>',
$t_url,
$t_icon,
lang_get( $t_lang_string )
);
echo '</li>';
}
12 changes: 2 additions & 10 deletions manage_filter_edit_page.php
Expand Up @@ -110,18 +110,10 @@
<i class="ace-icon fa fa-bars bigger-125"></i>
</a>
<ul class="dropdown-menu dropdown-menu-right dropdown-yellow dropdown-caret dropdown-closer">
<li>
<?php
$f_switch_view_link = 'manage_filter_edit_page.php?filter_id=' . $f_filter_id . '&view_type=';
if( ( SIMPLE_ONLY != config_get( 'view_filters' ) ) && ( ADVANCED_ONLY != config_get( 'view_filters' ) ) ) {
if( FILTER_VIEW_TYPE_ADVANCED == $t_filter['_view_type'] ) {
echo '<a href="' . $f_switch_view_link . FILTER_VIEW_TYPE_SIMPLE . '"><i class="ace-icon fa fa-toggle-off"></i>&#160;&#160;' . lang_get('simple_filters') . '</a>';
} else {
echo '<a href="' . $f_switch_view_link . FILTER_VIEW_TYPE_ADVANCED . '"><i class="ace-icon fa fa-toggle-on"></i>&#160;&#160;' . lang_get('advanced_filters') . '</a>';
}
}
$t_url = 'manage_filter_edit_page.php?filter_id=' . $f_filter_id . '&view_type=';
filter_print_view_type_toggle( $t_url, $t_filter['_view_type'] );
?>
</li>
</ul>
</div>
</div>
Expand Down
16 changes: 4 additions & 12 deletions view_filters_page.php
Expand Up @@ -126,22 +126,14 @@
<i class="ace-icon fa fa-bars bigger-125"></i>
</a>
<ul class="dropdown-menu dropdown-menu-right dropdown-yellow dropdown-caret dropdown-closer">
<li>
<?php
$f_switch_view_link = 'view_filters_page.php?static=' . (int)$f_static;
$t_url = 'view_filters_page.php?static=' . (int)$f_static;
if( $t_named_filter ) {
$f_switch_view_link .= '&filter_id=' . $f_filter_id;
}
$f_switch_view_link .= '&view_type=';
if( ( SIMPLE_ONLY != config_get( 'view_filters' ) ) && ( ADVANCED_ONLY != config_get( 'view_filters' ) ) ) {
if( FILTER_VIEW_TYPE_ADVANCED == $t_filter['_view_type'] ) {
echo '<a href="' . $f_switch_view_link . FILTER_VIEW_TYPE_SIMPLE . '"><i class="ace-icon fa fa-toggle-off"></i>&#160;&#160;' . lang_get('simple_filters') . '</a>';
} else {
echo '<a href="' . $f_switch_view_link . FILTER_VIEW_TYPE_ADVANCED . '"><i class="ace-icon fa fa-toggle-on"></i>&#160;&#160;' . lang_get('advanced_filters') . '</a>';
}
$t_url .= '&filter_id=' . $f_filter_id;
}
$t_url .= '&view_type=';
filter_print_view_type_toggle( $t_url, $t_filter['_view_type'] );
?>
</li>
</ul>
</div>
</div>
Expand Down

0 comments on commit 4edd0b3

Please sign in to comment.