1
votes

I have documents that have 3 fields that can be used to "categorized" the document. For the breadcrumbs, I want to have these fields shown and the link will open up a view at that "category" level (open single category in view).

Now all "category" fields are not mandatory in the document. I thought I'd write up a SSJS function that would return the necessary object to control the breadcrumbs, but I am having a tough time figuring out what to do to have the link actually work.

My function looks like this, so far:

function getBreadCrumbs(doc:NotesDocument) {
    var breadCrumbs=[];

        //always add home as first level
    var thisCrumb = {label:"Home", page:"/home"};
    breadCrumbs.push(thisCrumb);

    if(doc.hasItem("CategoryV2")) {
        var label:String = doc.getItemValueString('CategoryV2');
        if(label!="") {
            var thisCrumb = {label:label, page:"/home"};
            breadCrumbs.push(thisCrumb);
        }
    }

    if(doc.hasItem("SectionNameV2")) {
        var label:String = doc.getItemValueString('SectionNameV2');
        if(label!="") {
            var thisCrumb = {label:label, page:"/home"};
            breadCrumbs.push(thisCrumb);
        }
    }

    if(doc.hasItem("SubSectionNameV2")) {
        var label:String = doc.getItemValueString('SubSectionNameV2');
        if(label!="") {
            var thisCrumb = {label:label, page:"/home"};
            breadCrumbs.push(thisCrumb);
        }
    }

    if(doc.hasItem("Subject")) {
        var label:String = doc.getItemValueString('Subject');
        if(label!="") {
            var thisCrumb = {label:label};
            breadCrumbs.push(thisCrumb);
        }
    }

    return breadCrumbs;
}

What would be needed to have the link actually work: does the "page" object need to be named something else?

Thanks for the help/tips

1

1 Answers

1
votes

Silly me...

In the breadcrumbs control peoperties, I forgot to specify that the Href property was equal to crumb.page... Note that the .xsp is also required for the link to actually work.

So, the function that works looks like this:

function getBreadCrumbs(doc:NotesDocument) {
    var breadCrumbs=[];

        //always add home as first level
    var thisCrumb = {label:"Home", page:"/home.xsp"};
    breadCrumbs.push(thisCrumb);

    if(doc.hasItem("CategoryV2")) {
        var label:String = doc.getItemValueString('CategoryV2');
        if(label!="") {
            var thisCrumb = {label:label, page:"/home.xsp?category="+label};
            breadCrumbs.push(thisCrumb);
        }
    }

    if(doc.hasItem("SectionNameV2")) {
        var label:String = doc.getItemValueString('SectionNameV2');
        if(label!="") {
            var thisCrumb = {label:label, page:"/allDocs.xsp&section="+label};
            breadCrumbs.push(thisCrumb);
        }
    }

    if(doc.hasItem("SubSectionNameV2")) {
        var label:String = doc.getItemValueString('SubSectionNameV2');
        if(label!="") {
            var thisCrumb = {label:label, page:"/allDocs.xsp?subsection="+label};
            breadCrumbs.push(thisCrumb);
        }
    }

    if(doc.hasItem("Subject")) {
        var label:String = doc.getItemValueString('Subject');
        if(label!="") {
            var thisCrumb = {label:label};
            breadCrumbs.push(thisCrumb);
        }
    }

    return breadCrumbs;
}

And the code in the custom control is now:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xc="http://www.ibm.com/xsp/custom"
    xmlns:xe="http://www.ibm.com/xsp/coreex">

    <xe:breadCrumbs id="breadCrumbs1">
        <xe:this.treeNodes>
            <xe:repeatTreeNode indexVar="1" var="crumb">
                <xe:this.children>
                    <xe:basicLeafNode label="#{crumb.label}" href="#{javascript:crumb.page}">
                    </xe:basicLeafNode>
                </xe:this.children>
                <xe:this.value><![CDATA[#{javascript:getBreadCrumbs(document1.getDocument());}]]></xe:this.value>
            </xe:repeatTreeNode>
        </xe:this.treeNodes>
    </xe:breadCrumbs>
</xp:view>

What I missed was to set the the "Href" of the basicLeaNode with the value coming from the SSJS function. I had the label, but when I added the code in the SSJS function to build the fref, I totally forgot to modify the custom control to add this property...

It was a loooooooooooooooon day...

Just as an FYI, the allDocs.xsp page displays a view and I filter the view using the URL parameter.