Alphabetically sorting the Slices in the Search Bar

Customisation Title Alphabetically sorting the Slices in the Search Bar
Purpose of Customisation To alphabetically sort the list of Slices that a user can search in from the Search dialog in the Livelink header.
Author Greg Griffiths
Date of Customisation 02 March 2004
Covers Livelink Livelink 9
Livelink Modules WebSearchBroker
Affected Templates \websbroker\html\fieldbrokerlist.html
Customisation Format HTML
Download Here Download as a ZIP file (Pre 9.2)  Download as a ZIP file (9.2+)

Several recent requests in the Livelink Knowledge Center concerned sorting the list of Slices - listed in the dropdown list on every Livelink page - in alphabetical order. Having written some code to sort Form View Names in a Form Template I already hade most of the code prewritten for this.

The main difference between the requirements for that customisation and this one where :

To this end, a slightly customised Javascript is run after the list has been populated, which finds the start of the Slice list and then reorders the Slices alphabetically and then updates the dropdown list accordingly. One of our users (John Greathouse) has pointed out that the original customisation did not work on the Advanced Search page, this has now been fixed. The code is shown below :

;if ( showGlobalSlice ) && IsDefined( bsModule )
    <OPTION VALUE="">--------
    <OPTION VALUE='GlobalSearch'>`[WebBrokeredSearch_HTMLLabel.GlobalSearch]`
    <OPTION VALUE="`.URL()`?func=bs.prompt">`[WebBrokeredSearch_HTMLLabel.GlobalSearchExpanded]`
;end
</SELECT>
<script>
var arr_optionsValue = new Array(); // array to hold the Value of the OPTIONS
var arr_optionsText = new Array(); // array to hold the Text of the OPTIONS
var ds; // Index of current selected Option
var theDD; // reference to the Drop Down
var startPos=0; // reference to the first Slice
// if on the Standard Search Page
if (document.SearchBarForm)
{
    theDD=document.SearchBarForm.collections_search_selected;
}
// if on the Advanced Search Page
if (document.searchFrm)
{
    theDD=document.searchFrm.collections_search_selected;
}
 
// find the location of the seperator
for (count=0;count<theDD.options.length;count++)
{
    if (theDD.options[count].text=="--------")
    {
        startPos=count+1;
        break;
    }
}
 
// get the text of each OPTION tag
for (count=startPos;count<theDD.options.length;count++)
{
    arr_optionsText[count] = theDD.options[count].text;
}
 
// sort the array
arr_optionsText.sort();
 
// add the values
for (i=0;i<arr_optionsText.length;i++)
{
    for (j=0;j<theDD.options.length;j++)
    {
        if (theDD.options[j].text==arr_optionsText[i])
        {
            arr_optionsValue[i]=theDD.options[j].value;
        }
    }
}
 
// cut the list to just be the main search areas
theDD.options.length=startPos;
 
// add the slices in alphabetical order
for (i=0;i<(arr_optionsText.length-startPos);i++)
{
    theDD.options[i+startPos]= new Option(arr_optionsText[i],arr_optionsValue[i]);
}
</script>

;;end

In Livelink 9.2, there was a slight change to this file, so the customisation is amended accordingly, simply place all the Javascript code shown above in red at the foot of the main part of the template file as shown below :

        ;end
    ;end
</SELECT>
<script>
var arr_optionsValue = new Array(); // array to hold the Value of the OPTIONS
var arr_optionsText = new Array(); // array to hold the Text of the OPTIONS

...

At the same time, I also took the opportunity to add closing <OPTION> tags to the values in the dropdown to get syntactically correct HTML.

;if Length( withinQuery ) > 0
    // Display the within line if this is a popup, if it is a selected scope, or
    // if FromHereExpanded is 'TRUE' because we just came from a popup.
    ;if ( doPopup || _WithinSelected( hilightList ) || request.FromHereExpanded == 'TRUE' )
        <OPTION SELECTED VALUE="`Str.String( brokersRec[1 ].DATAID ) + '&' + locationId + '&' + locationName `">`brokersRec[ 1].NAME`</OPTION>
    ;end
 
    ;if doPopup
        <OPTION VALUE="`.URL()`?func=ll&objType=258&objAction=searchprompt&locationId=`locationId`&locationName=`Web.Escape( locationName)`&withinQuery=TRUE&FromHereExpanded=TRUE">`[WebSBroker_HTMLLabel.FromHereExpanded]`</OPTION>
        <OPTION VALUE="">--------</OPTION>
    ;end
    ;if ( doPopup || ( IsFeature( request,'FromHereExpanded' ) && request.FromHereExpanded == 'TRUE' ) )
        ;for i = 2 to Length( brokersRec )
            <OPTION VALUE="`brokersRec[ i].DATAID`">`brokersRec[ i ].NAME`</OPTION>
        ;end
    ;else
        ;for i = 2 to Length( brokersRec )
            ;rec = brokersRec[ i ]
            ;IsInList = False
            ;if ( ( rec.DATAID in hilightList ) && (rec.DATAID != libraryReference ) )
                ;IsInList = True
            ;end
            <OPTION `( IsInList ) ? "SELECTED" : ""`VALUE="`rec.DATAID`">`rec.NAME`</OPTION>
        ;end
    ;end
;else
    ;for i = 1 to Length( brokersRec )
        ;rec = brokersRec[ i ]
        ;IsInList = False
        ;if ( ( rec.DATAID in hilightList ) || ( i == 1&& noDefaultSelection( brokersRec, hilightList ) ) )
            ;IsInList = True
        ;end
        <OPTION `( IsInList ) ? "SELECTED" : ""`VALUE="`rec.DATAID`">`rec.NAME`</OPTION>
    ;end
;end
;boolean showGlobalSlice = true;
;if IsDefined( request )
    ;if IsFeature( request, 'objAction' ) && ( !Str.CmpI(request.objAction ,'searchprompt' ) )
        ;showGlobalSlice = false;
    ;end
;end
;if ( showGlobalSlice ) && IsDefined( bsModule )
    <OPTION VALUE="">--------</OPTION>
    <OPTION VALUE='GlobalSearch'>`[WebBrokeredSearch_HTMLLabel.GlobalSearch]`</OPTION>
    <OPTION VALUE="`.URL()`?func=bs.prompt">`[WebBrokeredSearch_HTMLLabel.GlobalSearchExpanded]`</OPTION>
;end

The resultant code now shows the available Search Slices in alphabetical order and ensures that the dropdown in now using correct HTML, as shown in the following screenshots :

Current New
Screenshot Screenshot
Website Designed by Adservio Consulting Valid HTML 4.01 Strict    Valid CSS!    Level A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0