From cdb3d52423f9afbcf406f17cc20c730b51ee1f6e Mon Sep 17 00:00:00 2001 From: Jesse Weaver Date: Wed, 4 Nov 2009 20:36:08 -0700 Subject: [PATCH] Move jumping functionality to search This moves the "Jump to name preference functionality" to the search bar: if your search term is found to be the exact name of a syspref, then it is jumped to instead of executing a normal search. --- admin/preferences.pl | 57 +++++++------------ .../prog/en/js/pages/preferences.js | 35 +++++++----- .../prog/en/modules/admin/preferences.tmpl | 44 +++----------- 3 files changed, 49 insertions(+), 87 deletions(-) diff --git a/admin/preferences.pl b/admin/preferences.pl index 146fe3f8fc..b4f32a0312 100755 --- a/admin/preferences.pl +++ b/admin/preferences.pl @@ -104,7 +104,7 @@ sub _get_chunk { } sub TransformPrefsToHTML { - my ( $data, $highlighted_pref ) = @_; + my ( $data, $searchfield ) = @_; my @lines; my $dbh = C4::Context->dbh; @@ -135,10 +135,20 @@ sub TransformPrefsToHTML { } my $chunk = _get_chunk( $value, %$piece ); - $chunk->{'highlighted'} = 1 if ( $highlighted_pref && $name =~ /$highlighted_pref/ ); + # No highlighting of inputs yet, but would be useful + $chunk->{'highlighted'} = 1 if ( $searchfield && $name =~ /^$searchfield$/i ); push @chunks, $chunk; - push @names, { name => $name, highlighted => ( $highlighted_pref && ( $name =~ /$highlighted_pref/i ? 1 : 0 ) ) }; + + my $name_entry = { name => $name }; + if ( $searchfield ) { + if ( $name =~ /^$searchfield$/i ) { + $name_entry->{'jumped'} = 1; + } elsif ( $name =~ /$searchfield/i ) { + $name_entry->{'highlighted'} = 1; + } + } + push @names, $name_entry; } else { push @chunks, $piece; } @@ -170,24 +180,6 @@ sub _get_pref_files { return %results; } -sub JumpPref { - my ( $input, $tab, $jumpfield ) = @_; - - return ( $tab ) if ( $jumpfield !~ /^[a-zA-Z_0-9-]+$/ ); - - my %tab_files = _get_pref_files( $input, 1 ); - - while ( my ( $tab, $tabfile ) = each %tab_files ) { - while ( <$tabfile> ) { - return ( $tab, $1 ) if ( /pref: ($jumpfield)/i ); - } - - close $tabfile; - } - - return ( "", "" ); -} - sub SearchPrefs { my ( $input, $searchfield ) = @_; my @tabs; @@ -222,10 +214,14 @@ sub SearchPrefs { foreach my $piece ( @$line ) { if ( ref( $piece ) eq 'HASH' ) { - if ( ref( $piece->{'choices'} ) eq 'HASH' && grep( { $_ && matches( $_ ) } values( %{ $piece->{'choices'} } ) ) ) { - $matched = 1; + if ( $piece->{'pref'} =~ /^$searchfield$/i ) { + my ( undef, $LINES ) = TransformPrefsToHTML( $data, $searchfield ); + + return { search_jumped => 1, tab => $tab_name, tab_title => $title, LINES => $LINES }; } elsif ( matches( $piece->{'pref'} ) ) { $matched = 1; + } elsif ( ref( $piece->{'choices'} ) eq 'HASH' && grep( { $_ && matches( $_ ) } values( %{ $piece->{'choices'} } ) ) ) { + $matched = 1; } } elsif ( matches( $piece ) ) { $matched = 1; @@ -285,18 +281,6 @@ if ( $op eq 'save' ) { print $input->redirect( '/cgi-bin/koha/admin/preferences.pl?tab=' . $tab ); exit; -} elsif ( $op eq 'jump' ) { - my $jumpfield = $input->param( 'jumpfield' ); - $template->param( jumpfield => $jumpfield ); - - my $new_tab; - ( $new_tab, $highlighted ) = JumpPref( $input, $tab, $jumpfield ); - - if ( $highlighted ) { - $tab = $new_tab; - } else { - $template->param( jump_not_found => 1 ); - } } my @TABS; @@ -318,6 +302,7 @@ if ( $op eq 'search' ) { if ( @TABS ) { $tab = ''; # No need to load a particular tab, as we found results + $template->param( search_jumped => 1 ) if ( $TABS[0]->{'search_jumped'} ); } else { $template->param( search_not_found => 1, @@ -326,7 +311,7 @@ if ( $op eq 'search' ) { } if ( $tab ) { - my ( $tab_title, $LINES ) = TransformPrefsToHTML( GetTab( $input, $tab ), $highlighted, ( $op eq 'jump' ) ); + my ( $tab_title, $LINES ) = TransformPrefsToHTML( GetTab( $input, $tab ), $highlighted ); push @TABS, { tab_title => $tab_title, LINES => $LINES }; $template->param( diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/pages/preferences.js b/koha-tmpl/intranet-tmpl/prog/en/js/pages/preferences.js index 26686d2d4f..ff9d93204a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/pages/preferences.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/pages/preferences.js @@ -41,10 +41,19 @@ $( document ).ready( function () { } ).end() .find( 'select.preference' ).change( mark_modified ); - if ( document.location.search.indexOf( 'jumpfield' ) != -1 ) { - document.location.hash = "highlighted"; + window.onbeforeunload = function () { + if ( KOHA.Preferences.Modified ) { + return _( "You have made changes to system preferences." ); + } } + $( '.prefs-tab .action .cancel' ).click( function () { KOHA.Preferences.Modified = false } ); + + $( '.prefs-tab .save-all' ).attr( 'disabled', true ).click( function () { + KOHA.Preferences.Save( this.form ); + return false; + } ); + $( '.prefs-tab .expand-textarea' ).show().click( function () { $( this ).hide().nextAll( 'textarea, input[type=submit]' ) .animate( { height: 'show', queue: false } ) @@ -53,17 +62,6 @@ $( document ).ready( function () { return false; } ).nextAll( 'textarea, input[type=submit]' ).hide().css( { opacity: 0 } ); - $( '.prefs-tab .save-all' ).attr( 'disabled', true ).click( function () { - KOHA.Preferences.Save( this.form ); - return false; - } ); - - window.onbeforeunload = function () { - if ( KOHA.Preferences.Modified ) { - return _( "You have made changes to system preferences." ); - } - } - $("h3").attr("class","expanded").attr("title",_("Click to expand this section")); var collapsible = $(".collapsed,.expanded"); @@ -78,5 +76,14 @@ $( document ).ready( function () { } ); - $( '.prefs-tab .action .cancel' ).click( function () { KOHA.Preferences.Modified = false } ); + if ( to_highlight ) { + var words = to_highlight.split( ' ' ); + $( '.prefs-tab table' ).find( 'td, th' ).not( '.name-cell' ).each( function ( i, td ) { + $.each( words, function ( i, word ) { $( td ).highlight( word ) } ); + } ).find( 'option' ).removeHighlight(); + } + + if ( search_jumped ) { + document.location.hash = "jumped"; + } } ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tmpl index 1f9c66cb33..37a4c20865 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tmpl @@ -10,18 +10,8 @@ @@ -36,15 +26,6 @@
-
-
- - " /> - - " /> - -
-

System preferences

@@ -66,17 +47,8 @@ - -

- - - -

-

- - - -

+
+

@@ -86,8 +58,10 @@
PreferenceValue
- - - - " name="pref_" id="pref_" class="preference preference-" value="" autocomplete="off" /> -- 2.39.2