<%
' ********************************************************************
' Copyright (C) 2001 Microsoft Corporation. All rights reserved.
'
'	IMPORTANT.  Please read the legal.txt file, located in the
'	"<CMS Install Directory>\Server\httpexec\WBC\Internals"
'	directory, governing the use of this internal file."
' ********************************************************************

' ********************************************************************
' File:		/NR/System/WBC/Internals/ServerControls/CNCListControl.inc
' Version: 	Microsoft Content Management Server
' Author:	Microsoft Corporation.
' Purpose:	Responsible for Displaying a List of Content Management Server objects
'
' Public Interface of CNCListControl
'	- Sub InitListControl( pNCListRenderer, colObjects )
'	- Sub SetDisplayRange( nColBegin, nColEnd )
'	- Sub DisplayList()
'	- Property ObjectsPerRow [read/write]
'	- Property SubdivisionsPerObject [read/write]
'	- Property ItemSpacing [read/write]
'	- Property ItemPadding [read/write]
'
' INCListRenderer Callback Interface of CNCListControl
'	- Sub RenderSubdivisionHeadTDAttrib( nSubdivisionIndex )
'	- Sub RenderSubdivisionHeadTDContent( nSubdivisionIndex )
'	- Sub RenderItemTDAttrib( pObject, nCollectionIndex, nDisplayIndex, nSubdivisionIndex )
'	- Sub RenderItemTDContent( pObject, nCollectionIndex, nDisplayIndex, nSubdivisionIndex )
' ********************************************************************

' -- Error Strings
Const IDS_NCLIST_ERR_RENDERER = "<div><b>CNCListControl Error:</b> Nothing is passed in for the CNCListRenderer.</div>"
Const IDS_NCLIST_ERR_COLLECTION = "<div><b>CNCListControl Error:</b> Collection not properly initialized.</div>"
Const IDS_NCLIST_ERR_RANGE = "<div><b>CNCListControl Error:</b> Invalid range passed in.</div>"
Const IDS_NCLIST_ERR_NOINIT = "<div><b>CNCListControl Error:</b> InitListControl() has not been called before calling DisplayList().</div>"


Class CNCListControl

	' -- Property to configure UI layout and display
	Public ObjectsPerRow
	Public SubdivisionsPerObject

	Public ItemSpacing
	Public ItemPadding

	' -- Module internal state management
	Private m_bInitCalled
	' -- Mandatory parameters passed in by cleint for controlling the module
	Private m_pNCLCRenderer, m_colNRObjects
	' -- Display Range
	Private m_nColBegin, m_nColEnd

	' ---- [Private] Initialize the TreeControl module
	Private Sub Class_Initialize()
		m_bInitCalled = False

		' -- Default values for mandatory settings configured through InitTreeControl()
		Set m_pNCLCRenderer = Nothing
		Set m_colNRObjects = Nothing

		' -- Default values for optional settings configured through properties
		ObjectsPerRow = 1
		SubdivisionsPerObject = 1
		ItemSpacing = 0
		ItemPadding = 0

		m_nColBegin = -1
		m_nColEnd = -1
	End Sub

	' ---- [Public] Initialize the Control with mandatory parameters
	Public Sub InitListControl( pNCListRenderer, colNRObjects )
		' -- validate parameters first
		If (pNCListRenderer Is Nothing) Then
			Call Response.Write(IDS_NCLIST_ERR_RENDERER)
			Exit Sub
		End If
		If (colNRObjects Is Nothing) Then
			Call Response.Write(IDS_NCLIST_ERR_COLLECTION)
			Exit Sub
		End If

		' -- flag that module has been initialized
		m_bInitCalled = True

		' -- Cache passed in values
		Set m_pNCLCRenderer = pNCListRenderer
		Set m_colNRObjects = colNRObjects

	End Sub

	' ---- [Public] Sets the range of items in collection to be displayed
	Public Sub SetDisplayRange( nColBegin, nColEnd )
		m_nColBegin = nColBegin
		m_nColEnd = nColEnd
		' -- any meaningless range should be treated as -1, -1
		If (m_nColBegin > m_nColEnd) Then
			m_nColBegin = -1
			m_nColEnd = -1
		End If
		' -- enforec maximum on m_nColEnd
		If (m_nColEnd > (m_colNRObjects.Count-1)) Then
			m_nColEnd = m_colNRObjects.Count-1
		End If

	End Sub

	' ---- [Public] Display a List of Content Management Server objects
	Public Sub DisplayList()
		' -- check if InitListControl() has been called
		If (m_bInitCalled = False) Then
			Call Response.Write(IDS_NCLIST_ERR_NOINIT)
			Exit Sub
		End If

		' -- Start the <table>
		Call Response.Write( vbCrLf & "<table width=100% border='0' cellspacing=" & ItemSpacing & _
											" cellpadding=" & ItemPadding & ">" & vbCrLf )

		' -- generate top row table cells for subdivision headings, only if ObjectsPerRow = 1
		Dim nSubdivisionIndex
		If (ObjectsPerRow = 1) Then
			Response.Write( vbTab & "<tr>" & vbCrLf )
			For nSubdivisionIndex = 0 To SubdivisionsPerObject-1
				Response.Write( "<td " )
				Call m_pNCLCRenderer.RenderSubdivisionHeadTDAttrib( nSubdivisionIndex )
				Response.Write( ">" )
				Call m_pNCLCRenderer.RenderSubdivisionHeadTDContent( nSubdivisionIndex )
				Response.Write( "</td>" )
			Next
			Response.Write( vbTab & "</tr>" & vbCrLf )
		End If

		' -- figure how many rows we need to render
		Dim nItems, nRowsMax
		If (m_nColBegin < 0) And (m_nColEnd < 0) Then
			nItems = m_colNRObjects.Count
			m_nColBegin = 0
			m_nColEnd = m_colNRObjects.Count-1
		Else
			nItems = m_nColEnd - m_nColBegin + 1
		End If

		' -- display items if non-zero number of items
		If (nItems > 0) Then
			nRowsMax = (nItems-1) \ ObjectsPerRow	' DIV operation

			' -- render the rows and columns of the table
			Dim nRowIndex, nRowOffset, nCollectionIndex, nDisplayIndex
			For nRowIndex = 0 To nRowsMax
				Response.Write( vbTab & "<tr>" & vbCrLf )
				For nRowOffset = 0 To (ObjectsPerRow-1)
					nDisplayIndex = nRowIndex*ObjectsPerRow + nRowOffset
					nCollectionIndex = m_nColBegin + nDisplayIndex
					If ((m_nColEnd < 0) Or (nCollectionIndex <= m_nColEnd)) Then
						Response.Write( vbTab & vbTab )
						' -- repeat callback for each item "SubdivisionsPerObject" number of times,
						'		each time generating a block of <td>...</td>
						For nSubdivisionIndex = 0 To SubdivisionsPerObject-1
							Response.Write( "<td valign='top' " )
							Call m_pNCLCRenderer.RenderItemTDAttrib( m_colNRObjects(nCollectionIndex), nCollectionIndex, nDisplayIndex, nSubdivisionIndex )
							Response.Write( ">" )
							Call m_pNCLCRenderer.RenderItemTDContent( m_colNRObjects(nCollectionIndex), nCollectionIndex, nDisplayIndex, nSubdivisionIndex )
							Response.Write( "</td>" )
						Next
						Response.Write( vbCrLf )
					Else
						Response.Write( vbTab & vbTab & "<td>&nbsp;</td>" & vbCrLf )
					End If
				Next
				Response.Write( vbTab & "</tr>" & vbCrLf )
			Next
		End If

		' -- end of table
		Call Response.Write( "</table>" & vbCrLf )
	End Sub

End Class

%>