IBM®
Skip to main content
    Country/region select      Terms of use
 
 
   
     Home      Products      Services & solutions      Support & downloads      My account     
 
developerWorks
AIX and UNIX
Information Mgmt
Lotus
New to Lotus
Products
How to buy
Downloads
Live demos
Technical library
Training
Support
Forums & community
Events
Rational
Tivoli
WebSphere
Java™ technology
Linux
Open source
SOA and Web services
Web development
XML
My developerWorks
About dW
Submit content
Feedback



developerWorks  >  Lotus  >  Technical Library
developerWorks

[back to Anatomy of a Domino e-commerce Web site (Part 1)]

The (ViewCatWebQueryOpen) agent
Here is the code for the (ViewCatWebQueryOpen) agent:

Sub Initialize
    Dim s As New NotesSession
    Dim doc As NotesDocument
    Set doc = s.DocumentContext

    Call DoPrevNextHTML (doc)

End Sub
    Sub DoPrevNextHTML (doc As NotesDocument)

    ' Figure out how many docs are about to be displayed in the view or view catagegory being shown, and
    ' display where this set is in the view (e.g., docs 26-50 of 123), and display previous and/or next links as appropriate

    Dim db As NotesDatabase
    Dim v As NotesView, entry As NotesViewEntry

    Dim intTotal As Integer, intStart As Integer, intCount As Integer, intNextStart As Integer, intPrevStart As Integer
    Dim strCatParm As String, strNextlabel As String, intNextEnd As Integer, strNextParms As String, strPrevParms As String, strPrevLabel As String, intPrevEnd As Integer
    Dim intNext As Integer, intPrev As Integer

    Set db = doc.ParentDatabase
    Dim vPath As Variant

    'Set URL path for return
    vPath=Evaluate({@ReplaceSubstring (@Subset (@DbName; -1); "\\" : " "; "/" : "+")})

    'Parse out the four parameters passed in as part of the URL - View, Category, Start, and Count

    vView = Evaluate ({@Middle (Query_String + "&"; "&View="; "&")}, doc)
    vCat = Evaluate ({@Replacesubstring (@Middle (Query_String + "&"; "&Cat="; "&"); "+" ; " ")}, doc)
    vStart = Evaluate ({@Middle (Query_String + "&"; "&Start="; "&")}, doc)
    vCount = Evaluate ({@Middle (Query_String + "&"; "&Count="; "&")}, doc)
    If vStart(0) = "" Then
      intStart = 1
    Else
      intStart = Cint (vStart(0))
    End If
    'Default Count to 25 if one wasn't provided on URL

    If vCount(0) = "" Then
      intCount = 25
    Else
      intCount = Cint (vCount(0))
    End If

    'Use strCatParm for the navigation links built later in the agent. After the following code, it sould contain, for example,
    '"&Cat=Political+Thought"

    If vCat(0) = "" Then
      strCatParm = ""
    Else
      doc.tempcat = vCat
      vCat2 = Evaluate ({ @Replacesubstring (tempcat; " " ; "+") }, doc)
      strCatParm = "&Cat=" + vCat2(0)
    End If
    'Get the view passed on the URL

    Set v = db.GetView (vView(0))

    'If there is no category the user is browsing, simply count all the documents in the view. If they are browing a category,
    'use the GetEntryByKey method of NotesView to get the first document in a category and then count its siblings to get
    'the total for that category

    If vCat(0) = "" Then
      'doc.PrevNext = "equals blank"
      intTotal = v.AllEntries.Count
    Else
      'doc.prevNext = "else"
      Set entry = v.GetEntryByKey(vCat(0))
      intTotal = entry.SiblingCount
    End If
    'Determine if Previous and Next links are neded, and what the proper Start parameter is for both

    If intStart = 1 Then
      ' No Prev button. Next = start plus count
      intPrev = False
      If intStart + intCount > intTotal Then
        ' No need for next button
        intNext = False
      Else
        intNext = True
        intNextStart = intStart + intCount
      End If
    Else
      intPrev = True
      If intStart + intCount > intTotal Then
        ' No next button
        intNext = False
      Else
        intNext = True
        intNextStart = intStart + intCount
      End If
      intPrevStart = intStart - intCount
      If intPrevStart < 1 Then intPrevStart = 1
    End If
    'Build the HTML (opening and closing tags) for both "Prev" and "Next" links - to be used once verbiage for each
    'link is decided upon

    strHrefStart = {<A HREF="/} + vPath(0) + {/ViewCat?ReadForm&View=} + vView(0) + strCatParm
    strHrefEnd = {</A>}

    'Build the verbiage for the "Next" link. If there are less than Count items left to display, use "Last" instead of "Next"

    If intTotal - intNextStart < intCount Then
      strNextLabel = "Last " + Cstr (intTotal - intNextStart + 1) + " Items"
    Else
      strNextLabel = "Next " + Cstr (intCount) + " Items"
    End If
    'Build parameters for "Next" link

    strNextParms = {&Start=} + Cstr (intNextStart) + "&Count=" + Cstr(intCount)

    'Build verbiage for "Previous" link. If there are less then Count items left to display, use "First" instead of "Previous"

    If intStart - intCount < 0 Then
      strPrevLabel = "First " + Cstr (intCount) + " Items"
    Else
      strPrevLabel = "Previous " + Cstr (intCount) + " Items"
    End If
    'Build parameters for "Previous" link

    strPrevParms = {&Start=} + Cstr (intPrevStart) + {&Count=} + Cstr (intCount)

    'Write links to document if they are needed. If not, these fields will not contain values and will not be visible to users

    If intPrev Then
      doc.Prev = strHrefStart + strPrevParms + {">} + strPrevLabel + strHrefEnd
    End If
    If intNext Then
      doc.Next = strHrefStart + strNextParms + {">} + strNextlabel + strHrefEnd
    End If
    'Build 'Items x through x of x' information
    If (intStart + intCount - 1) > intTotal Then
      intShowing = intTotal
    Else
      intShowing = intStart + intcount - 1
    End If
    'Write it to document
        doc.TotalCount = "Items " + Cstr (intStart) + " through " + Cstr (intShowing) + " of " + Cstr (intTotal)
    'Duplicate the links (provided there are any) and information below the view as well
    doc.Prev_1 = doc.Prev
    doc.Next_1 = doc.Next
    doc.TotalCount_1 = doc.TotalCount
End Sub
    About IBM Privacy Contact