Bug 8401 - Search term deleted from system preference content
Summary: Search term deleted from system preference content
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: System Administration (show other bugs)
Version: master
Hardware: All All
: P3 critical (vote)
Assignee: Bugs List
QA Contact:
URL:
Keywords:
: 9404 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-07-10 06:06 UTC by Katrin Fischer
Modified: 2019-06-27 09:24 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Who signed the patch off:
Text to go in the release notes:
Version(s) released in:


Attachments
screenshot (65.04 KB, image/png)
2012-07-10 06:06 UTC, Katrin Fischer
Details
Patch for preferences.js to repair highlighting bug 8401 (1.00 KB, patch)
2013-01-17 18:59 UTC, Fred P
Details | Diff | Splinter Review
Bug 8401 : Highlighting of search terms in preference causes loss of data (1.37 KB, patch)
2013-01-17 21:58 UTC, Chris Cormack
Details | Diff | Splinter Review
Bug 8401 : Highlighting of search terms in preference causes loss of data (1.37 KB, patch)
2013-01-17 21:59 UTC, Chris Cormack
Details | Diff | Splinter Review
[SIGNED-OFF] Bug 8401 : Highlighting of search terms in preference causes loss of data (1.46 KB, patch)
2013-01-17 22:14 UTC, Katrin Fischer
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Katrin Fischer 2012-07-10 06:06:57 UTC
Created attachment 10734 [details]
screenshot

While testing something else... I found a bug in the highlighting of the system preference editor.

I used the system preference search on top of the module page and searched for "query".

I was looking for the OPACNoResultsFound system preference. When opening the preference to check its content it showed: Something {_KW}

This is not correct. Searching "NoResults" shows the correct content when opening the preference: Something {QUERY_KW}
Comment 1 Jorge de Cardenas 2013-01-16 15:47:42 UTC
I can confirm this behavior and it can have some serious consequences. I was working with the Self Checkout and was editing the SCOUserCSS. I have several entries similar to #selfCheckOutHeader. To get back to the SCOUserCSS I would search for "self". If I made any changes and saved, the word "self" would be dropped from any entry. Example: #selfCheckOutHeader would become #CheckOutHeader.
Comment 2 Owen Leonard 2013-01-16 16:03:53 UTC
*** Bug 9404 has been marked as a duplicate of this bug. ***
Comment 3 Fred P 2013-01-16 16:05:25 UTC
Example: Search for "opac" in the global system preferences. The search term "opac" will mysteriously vanish from OPACUserCSS entries that contain the term. Our pseudo-class "#opac-main" becomes "#-main"

The same thing happens when searching for self-checkout css. I am searching for SCO to change the SCOUserCSS. All of my css entries for SCOUserCSS show up with the letter combination "sco" edited out. 

The result of this bug is that when I re-save the css changes, my custom css breaks because the entries are saved as "-main" instead of "opac-main" or "selfhelp" instead of "scoselfhelp"

The same thing happens to custom javascript code. For example in the SCOUserJS: "document.write(myscore);" becomes "document.write(myre);"

The workflow at issue is:
1. Use the same term or letter combination in your custom css or javascript as part of the preference name. Enter your custom css and javascript in the global system preferences.

2. Search for the preference using part of the name.
< Search term drops out of css and javascript >

3. Make a change to the preferences and save.
< site css and javascript suddenly broken >
Comment 4 Katrin Fischer 2013-01-16 16:44:55 UTC
I had it happen to me too which ended in rewriting checking lots of html code.
Upping severity a bit, as this bug results in unintentional data loss.
Comment 5 Fred P 2013-01-16 16:49:03 UTC
I believe the problem originates with this file: 

File:   jquery.highlight-3.js
Path:   /home/koha/kohaclone/koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins

Removal of this function appears to resolve the issue, 
 not sure about side-effects:
--------------------------------------

jQuery.fn.removeHighlight = function() {
 return this.find("span.term").each(function() {
  this.parentNode.firstChild.nodeName;
  with (this.parentNode) {
   replaceChild(this.firstChild, this);
   normalize();

-----------------------------------------
Comment 6 Owen Leonard 2013-01-16 17:01:08 UTC
(In reply to comment #5)
> Removal of this function appears to resolve the issue, 
>  not sure about side-effects:

Side-effects would be breaking the functionality of search term highlighting in all areas of the staff client which use the plugin.

The solution is either to disable search term highlighting altogether on this page (perhaps the short-term solution) or to fix the scope of the highlighting so that it excludes textareas (something I'm not sure is possible).
Comment 7 Fred P 2013-01-16 17:41:07 UTC
Instead of editing jquery plug-ins, which may be referenced offsite, a simple edit to the Koha code fixes the problem. Needs testing, but I am not seeing any issues. Notice this function only affects the preferences table:

File:       preferences.js
Path:      /home/koha/kohaclone/koha-tmpl/intranet-tmpl/prog/en/js/pages

   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();
    }

Replace the second-to-last line:

+       } )
    }
Comment 8 Jorge de Cardenas 2013-01-17 14:25:32 UTC
This seem to work disabling highlighting on both 'option' and 'textarea'

File:       preferences.js
Path:      /home/koha/kohaclone/koha-tmpl/intranet-tmpl/prog/en/js/pages

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, textarea' ).removeHighlight();
}

changed 
.find( 'option' ).removeHighlight();
to
.find( 'option, textarea' ).removeHighlight();
Comment 9 Fred P 2013-01-17 18:59:06 UTC Comment hidden (obsolete)
Comment 10 Chris Cormack 2013-01-17 21:58:55 UTC Comment hidden (obsolete)
Comment 11 Chris Cormack 2013-01-17 21:59:48 UTC Comment hidden (obsolete)
Comment 12 Katrin Fischer 2013-01-17 22:14:03 UTC
Created attachment 14690 [details] [review]
[SIGNED-OFF] Bug 8401 : Highlighting of search terms in preference causes loss of data

To test:

1/ Go to system preferences
2/ Go to SCOUserCSS
3/ Add #self
4/ Search for self
5/ Open SCOUserCSS
6/ Note it now contains only # (Do not click save)
7/ Apply the patch
8/ Refresh the page, and check SCOUserCSS and note it now says #self
9/ Rejoice!

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Works nicely and passes all tests.
Comment 13 Jared Camins-Esakov 2013-01-18 01:55:18 UTC
This patch has been pushed to master. Welcome to our 201st committer, Fred Pierre!
Comment 14 Chris Cormack 2013-01-24 01:57:38 UTC
Pushed to 3.8.x and 3.10.x will be in 3.8.10 and 3.10.3