<!--#include virtual="/NR/System/WBC/Internals/Main/WBCApp.inc"-->
<!-- #include virtual="/NR/System/WBC/Customizable/WBCFuncPagesConfig/MLSDisplayConfig/ResourceBrowserConfig.inc" -->
<!--#include virtual="/NR/System/WBC/Customizable/WBCFuncPagesConfig/UIStringConstants/ResMgntUIStrings.inc" -->

<!--#include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/ResourceBrowser/Management/InternalProgrammingConstants.inc" -->


<!--#include virtual="/NR/System/WBC/Internals/ServerControls/StateControl/CNCStateControl.inc"-->
<!--#include file="CNCStateRenderer_ViewAsTreeOrList.inc" -->

<!-- #include virtual="/NR/System/WBC/Internals/ServerControls/PagingConfigControl/CNCPagingConfigControl.inc"-->

<!--#include virtual="/NR/System/WBC/Internals/ServerControls/TreeControl/CNCTreeControl.inc"-->
<!--#include virtual="/NR/System/WBC/Internals/ServerControls/TreeControl/CNCTreeDom_NRResGalleries.inc"-->
<!--#include file="CNCTreeRenderer_GalleriesBrowse.inc" -->

<!--#include virtual="/NR/System/WBC/Internals/ServerControls/GridControl/CNCGridControl.inc"-->
<!--#include file="CNCGridDecorator_GalleriesBrowse.inc" -->

<!--#include virtual="/NR/System/WBC/Internals/ServerControls/PagingControl/CNCPagingControl.inc"-->
<!--#include virtual="/NR/System/WBC/Internals/ServerControls/PagingControl/CNCPagingRenderer_Common.inc"-->

<%
' ********************************************************************
' 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/WBCFuncPages/Cross-Browser/ResourceBrowser/
'			Management/ResGalleries/CNCASPPageManager_GalleriesBrowse.inc
' Version: 	Microsoft Content Management Server
' Author:	Microsoft Corporation.
' Purpose:	Encapsulate the ASP logic associated with ResGalleries.asp
'
' Implements the INCASPPageManager interface:
'	- Sub InitManager()
'
' Exposes the following properties:
' 	- Property ASPUtils
'	- Property CodePage
'	- Property Charset
'	- Property ViewStateControl
'	- Property TreeControl
'	- Property ResourceGalleries
'	- Property GridStartItem
'	- Property GridEndItem
'	- Property GridPagingConfigControl
'	- Property GridControl
'	- Property GridPagingControl
' ********************************************************************

Class CNCASPPageManager_GalleriesBrowse

	' -- Object that exposes the View state (Tree or List)
	Public ViewStateControl

	' -- Object needed when "View As Tree"
	Public TreeControl

	' -- Objects needed when "View As List"
	Public ResourceGalleries
	Public GridStartItem
	Public GridEndItem
	Public GridPagingConfigControl
	Public GridControl
	Public GridPagingControl

	Private m_strGalleryGUID

	' -- Property that exposes the ASP utility object for the page
	Private m_pASPUtils

	' -- Property that exposes the CodePage for the page
	Private m_strCodePage

	' -- Property that exposes the Charset for the page
	Private m_strCharset
	
	
	' ---- [Private] Class standard initialization routine
	Private Sub Class_Initialize()
		Set m_pASPUtils = Nothing
		Set ViewStateControl= Nothing
		Set TreeControl= Nothing
		Set ResourceGalleries = Nothing
		Set GridStartItem = Nothing
		Set GridEndItem = Nothing
		Set GridPagingConfigControl = Nothing
		Set GridControl = Nothing
		Set GridPagingControl = Nothing

		m_strCodePage = ""
		m_strCharset = ""
		m_strGalleryGUID = ""
	End Sub

	' ---- [Public] InitManaer will take care of all programming logic in the ASP page
	Public Sub InitManager()
		' -- Set up ASP utility object
		Call SetupASPUtils()

		' -- Set up CodePage
		Call SetupCodePage()

		' -- Set up Charset
		Call SetupCharset()
		
		' -- Set up current Gallery, if available
		Call SetupBrowseContext()

		' -- Set up ViewStateControl for the "View As Tree" and "View As List" state
		Call SetupViewStateControl()

		' -- Given ViewStateControl has been set up, we know whether it is "View As Tree" or "View As List"
		If (ViewStateControl.CurrentState = IDS_STATE_VIEWAS_TREE) Then
			Call SetupTreeControl()
		Else
			Call SetupGalleriesCollection()
			Call SetupPagingConfigControl()
			Call SetupPagingControl()
			Call SetupDisplayIndices()
			Call SetupGridControl()
		End If
	End Sub
	
	' --- Property that exposes the ASP Utility object for the page
	Public Property Get ASPUtils()
		Set ASPUtils = m_pASPUtils
	End Property

	' --- Property that exposes the codepage for the page
	Public Property Get CodePage()
		CodePage = m_strCodePage
	End Property

	' --- Property that exposes the charset for the page
	Public Property Get CharSet()
		CharSet = m_strCharSet
	End Property

	' ---- A helper function to retrieve the ASP utility object
	Private Sub SetupASPUtils()
		Set m_pASPUtils = GetInitializedASPUtils()			
	End Sub

	' ---- A helper function to setup the code page that the ASP page
	' ---- will be running under (for multi-language support).
	Private Sub SetupCodePage()	
		m_strCodePage = GetCodePageForResource( Nothing, m_pASPUTils )
	End Sub

	' ---- A helper function to setup the char page that the ASP page
	' ---- will be running under (for multi-language support).
	Private Sub SetupCharset()	
		m_strCharSet = GetCharacterSetForResource( Nothing )
	End Sub

	' ---- [Private] Sets up the browsing context (Gallery)
	Private Sub SetupBrowseContext()
		m_strGalleryGUID = Request.QueryString(IDS_QPARAM_GALLERY)
	End Sub

	' ---- [Private] Set up ViewStateControl for the "View As Tree" and "View As List" state
	Private Sub SetupViewStateControl()
		Set ViewStateControl = New CNCStateControl

		Dim pStateControlRendererViewAs
		Set pStateControlRendererViewAs = New CNCStateRenderer_ViewAsTreeOrList

		Call ViewStateControl.InitStateControl( IDS_STATE_ID_GALLERIES_VIEWAS, pStateControlRendererViewAs, IDS_STATE_VIEWAS_LIST, True )
		Call ViewStateControl.AddState( IDS_STATE_VIEWAS_TREE )
		Call ViewStateControl.AddState( IDS_STATE_VIEWAS_LIST )

	End Sub

	' ---- [Private] Set up TreeControl for displaying Resource Galleries as a Tree
	Private Sub SetupTreeControl()
		Set TreeControl = New CNCTreeControl

		Dim pNCTreeDom, pNCTreeRenderer
		Set pNCTreeDom = New CNCTreeDom_NRResGalleries
		Set pNCTreeRenderer = New CNCTreeRenderer_GalleriesBrowse
		If Request.QueryString("FreshTree") = "True" Then
			Call TreeControl.InitTreeControl( "ResGal", pNCTreeDom, pNCTreeRenderer, True )
			Call TreeControl.PropagateParameter( "FreshTree", "False" )
		Else
			Call TreeControl.InitTreeControl( "ResGal", pNCTreeDom, pNCTreeRenderer, False )
		End If
		Call TreeControl.PropagateParameter( "wbc_gallery", "" )
		Call TreeControl.PropagateParameter( "wbc_display", "tr" )
		Call TreeControl.PropagateParameter(IDS_QPARAM_TIMESTAMP, CDbl(CDate(now)))

		TreeControl.DisplayLeafs = false
		TreeControl.IndentWidth = 35
		TreeControl.NodeSpacing = 5
		TreeControl.NodePadding = 2
	End Sub

	' ---- [Private] Sets up the ResourceGalleries collection
	Private Sub SetupGalleriesCollection()
		Set ResourceGalleries = AutoSession.Searches.UserResourceGalleries
	End Sub

	' ---- [Private] Sets up GridPagingConfigControl
	Private Sub SetupPagingConfigControl()
		Set GridPagingConfigControl = New CNCPagingConfigControl

		Call GridPagingConfigControl.InitPagingConfigControl( IDS_PAGINGCONFIG_ID_GALLERIES, 5, True )
	End Sub


	' ---- [Private] Set up the GridPagingControl, with input from the GridPagingConfigControl
	Private Sub SetupPagingControl()
		Set GridPagingControl = New CNCPagingControl

		Dim pNCPagingRenderer
		Set pNCPagingRenderer = New CNCPagingRenderer_Common

		Call GridPagingControl.InitPagingControl( pNCPagingRenderer, ResourceGalleries.Count, GridPagingConfigControl.ItemsPerPage )
		If (GridPagingConfigControl.IsSetNewValue = True) Then
			' -- PagingConfigControl has just been set a new value, set PagingControl back to Page 1
			GridPagingControl.CurrentPage = 1
		End If

	End Sub

	' ---- [Private] Set up indices which indicate the range of items to be displayed in the Grid
	Private Sub SetupDisplayIndices()
		' -- calculate the GridStartItem
		If (ResourceGalleries.Count = 0) Then
			GridStartItem = 0
		Else
			GridStartItem = (GridPagingControl.CurrentPage - 1)*(GridPagingConfigControl.ItemsPerPage) + 1
		End If
		' -- calculate the GridEndItem
		If (GridPagingConfigControl.ItemsPerPage < 0) Then
			' -- a minus one value from PagingConfigControl means "All" case
			GridEndItem = ResourceGalleries.Count
		Else
			GridEndItem = GridPagingControl.CurrentPage * GridPagingConfigControl.ItemsPerPage
		End If
		GridEndItem = Min(ResourceGalleries.Count, GridEndItem)
	End Sub

	' ----
	Private Sub SetupGridControl()
		Set GridControl = New CNCGridControl

		Dim pNCGridDecorator
		Set pNCGridDecorator = New CNCGridDecorator_GalleriesBrowse

		Call GridControl.InitGridControl( IDS_GRIDID_GALLERIES, pNCGridDecorator, ResourceGalleries, True )
		Call GridControl.SetDisplayRange( GridStartItem-1 , GridEndItem-1 )
		Call GridControl.AddColumn( IDS_GRIDINDEX_NAME, True )
		Call GridControl.AddColumn( IDS_GRIDINDEX_PATH, True )
		Call GridControl.AddColumn( IDS_GRIDINDEX_LASTMOD, True )
		Call GridControl.AddColumn( IDS_GRIDINDEX_DESC, False )

		GridControl.AscendingIndicatorHTML = "<img valign=bottom border=0 src='" & IDS_RESOURCEBROWSER_IMG_PATH & IDS_IMG_ICON_ARROW_UP & "'>"
		GridControl.DescendingIndicatorHTML = "<img valign=bottom  border=0 src='" & IDS_RESOURCEBROWSER_IMG_PATH & IDS_IMG_ICON_ARROW_DOWN & "'>"
		GridControl.ColumnHeadAnchorCSSClass = "WBC_styclsHeavyTextColor1"
		GridControl.ItemSpacing = 1
		GridControl.ItemPadding = 5

	End Sub

End Class

%>