Disclaimer

Instructions for implementing a javascript user criteria saver for ENCompass. Use at your own risk. TCC is not responsible for damage or problems caused by the use of these JavaScripts. No warranties or guarantees of any kind are implied or assumed.

ENCompass User Criteria Saver

Update January 31,2005: Revised scripts and instructions for ENCompass 3.5 Update December 1,2005: Revised scripts and instructions for ENCompass 3.6
These scripts are meant to be used with the ENCompass product by Endeavor Systems, Inc.™ ENCompass has a nasty habit of losing all data input by a user if the "+" or "-" signs are used to open or close a collection. For example, if a user decided to perform a Subject Keyword search for "Navajo" OR "Hopi" As a Phrase returning 50 hits per page and entered this criteria, then decided to open a collection to choose a particular database to search, the user would have to re-enter "Subject Keyword", "Navajo", "Hopi", "As A Phrase", "NOT" and 50 hits per page (assuming none of these drop downs were the default).

The javascripts enclosed in criteria.zip are meant to preserve the user's criteria when a collection hierarchy button ("+" or "-") is clicked. The scripts automatically check a child if the parent was checked when the parent was opened. All user choices are maintained. For example, if a parent is checked and a child of this parent is un-checked by the user, then a second collection is opened or closed, the integrity of the user's choice for the former collections remains intact.

Instructions

  • Always back up a file before making changes!!!
  • Just to be safe, comment out, don't delete, existing code before you make changes to your copy.
  • Instructions are in bold
  • Explanations are italicized.
  • Enough with the warnings, here are the instructions.

  1. Download the JavaScripts from http://somedia.tccd.net/code/encompass/criteria.zip

  2. Drop the file "tcc.js" in your html directory.
    (by default, the html directory is located at /m1/encompass/yourcollection/tomcat/webapps/logicrouter/html/)
    These are the javascripts that do all the work.

  3. In childbrowse.xsl find:

    <script LANGUAGE="JavaScript1.2" type="text/javascript">
       document.write("&lt;script LANGUAGE='JavaScript1.2' SRC='/html/validate.js'&gt;&lt;\/script&gt;");
    </script>


    Below it, add this line:

    <script type="text/javascript" src="/html/tcc.js"/>

    This allows the javascripts to be used from childbrowse.xsl

  4. In childbrowseadvanced.xsl find:

    <script type="text/javascript" src="/html/validate.js"/>
    <script type="text/javascript" src="/html/getcheck.js"/>

    Below it, add this line:

    <script type="text/javascript" src="/html/tcc.js"/>

    This allows the javascripts to be used from childbrowseadvanced.xsl

  5. In childbrowse.xsl and childbrowseadvanced.xsl find:

    </body>

    ABOVE the </body> tag, add:

    <script language="Javascript">
       setChecks();
       removeHierCookie();
    </script>

    This reads the cookies once the page has loaded and sets the input fields based on the cookies.

  6. In childbrowse.xsl and childbrowseadvanced.xsl (ENCompass 2.x)
    OR
    In childtools.xsl (ENCompass 3.x) find all instances of:

    <img src="/images/mns.gif" alt="collapse thread" border="1" class="hidden"/>
    and
    <img src="/images/pls.gif" alt="collapse thread" border="1" class="hidden"/>

    (There are 2 instances of each)

    Replace them to read:

    <img src="/images/mns.gif" alt="collapse thread" border="1" class="hidden" onclick="getChecks()"/>
    <xsl:call-template name="FormatHierTest">
       <xsl:with-param name="hier_val" select="@hier"/>
       <xsl:with-param name="object_id">
          <xsl:value-of select="*[name()=$object_ID]"/>
       </xsl:with-param>
    </xsl:call-template>

    and


    <img src="/images/pls.gif" alt="collapse thread" border="1" class="hidden" onclick="getChecks()"/>
    <xsl:call-template name="FormatHierTest">
       <xsl:with-param name="hier_val" select="@hier"/>
       <xsl:with-param name="object_id">
          <xsl:value-of select="*[name()=$object_ID]"/>
       </xsl:with-param>
    </xsl:call-template>

    This runs the scripts when the user clicks a "+" or "-" that collects all the current data and stores it in a cookie.

  7. In misctools.xsl, find:

    <!-- ############################################################################ -->

       <xsl:template name="FormatHier">
          <xsl:param name="hier_val"/>
          <script language="javascript">jsIndent("<xsl:value-of select="$hier_val"/>")</script>
       </xsl:template>

    <!-- ############################################################################ -->

    Below this, add:

       <xsl:template name="FormatHierTest">
          <xsl:param name="hier_val"/>
          <xsl:param name="object_id"/>
          <script language="javascript">hierTest("<xsl:value-of select="$hier_val"/>", "<xsl:value-of select="$object_id"/>")</script>
       </xsl:template>

    <!-- ############################################################################ -->

    This takes information sent from the xsl:call-template added in step 6 above and calls a javascript that creates a cookie with hierarchy information.

    That should do it for saving criteria when users click the "+" and "-" buttons.

    There are a couple of other features and scripts included that you may want to take advantage of:
  • To set default collections,
    1. Open your default ENCompass search page in your web browser.
    2. Click the View XML button.
    3. Make note of the <OI>#</OI> numbers associated with the collections you wish to be defaults.
    4. Now open tcc.js and find Set Default Collections Here
    5. Follow the instructions you find there.
  • To set default search types (Global, Subject, Name, Title) in childbrowseadvanced.xsl:
    1. Open tcc.js.
    2. Find Set default search types.
    3. Follow the examples.
  • To add a "Set All Checks" button:
    • In childbrowse.xsl or childbrowseadvanced.xsl where you would like the button to appear, add:

      <input type="button" value="Set All" onclick="setAllChecks(true);" />

      (Note that this button must be between the <form></form> tags)

  • To add a "Clear All Checks" button:
    • In childbrowse.xsl or childbrowseadvanced.xsl where you would like the button to appear, add:

      <input type="button" value="Clear All" onclick="setAllChecks(false);" />

      (Note that this button must be between the <form></form> tags)

  • To add a "Reset All To Defaults" button:
    • In childbrowse.xsl or childbrowseadvanced.xsl where you would like the button to appear, add:

      <input type="button" name="Reset" value="Reset" onclick="clearChecks();"/>

      (Note that this button must be between the <form></form> tags)

  • To change "Search Native Interface" to "Search [the real name of this database]":
    1. Open object/getimage.xsl
    2. Find:

      <xsl:for-each select="../RETRIEVEINFO/NU">
         <xsl:if test="string(text())">
            <br/>

    3. Underneath it, add this line:

      <script src="/html/tcc.js"/>

    4. At the end of a long URL, find:

      <xsl:call-template name="getNU"/></a>

    5. Change it to:

      <script language="javascript">getDatabase('<xsl:value-of select="."/>');</script></a>

    6. Open tcc.js and find:

      getDatabase()

    7. Follow the examples to add databases to which your institution subscribes.

How It Works

When the user clicks a "+" or "-" to open or close a collection, the getChecks() javascript and the FormatHierTest xsl template are called. These scripts gather the values of each input field, checkbox, and hierarchy name and value and create name-value strings, which it stores as cookies on the user's browser.

The page then reloads with the altered state of the collection (open or closed.) After the page loads (or near the end of the load), the setChecks() javascript is called. This script reads and parses the cookies, then sets all the values to the state before the page refreshed.

With these scripts, we can also set default values for the user's first visit to the page. We can also make it easy for the user to set every checkbox, to clear every checkbox, and to reset the forms to the default states.

Troubleshooting

Questions can be sent to Jim Robinson at Tarrant County College, but the help I can provide is limited due to time constraints and lack of access to your system for debugging... ;-)

Some hints about debugging javascripts:

  • If a script isn't working as you'd expect, try putting an alert message in the function to see if the code is being reached and that it is returning what you expect. For example:
    function testFunction() {
       var myForm = document.forms['myForm'];
       alert("myForm="+myForm);
       other code...;
    }
  • If the code isn't being called, check the syntax, the path to the javascript source, and your objects. Don't be afraid to stick an object in an alert message to make sure it's an object.
  • Download a free Firefox browser Get Firefox! and choose Tools->JavaScript Console.
  • Download an Opera browser (http://www.opera.com) and turn on "Report JavaScript Errors".
  • Remember: browser detection is poor coding...object detection will serve you much better.
-03.28.03