<!--#include virtual="/NR/System/WBC/Internals/Main/WBCApp.inc"-->
<!-- #include virtual="/NR/System/WBC/Customizable/WBCFuncPagesConfig/MLSDisplayConfig/ResourceBrowserConfig.inc" -->
<!--#include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/ResourceBrowser/Common/ResourceBrowserCommon.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_ViewAsListOrThumbnail.inc" -->

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

<!--#include virtual="/NR/System/WBC/Internals/ServerControls/GridControl/CNCGridControl.inc"-->
<!--#include file="CNCGridDecorator_ResourcesBrowse.inc" -->
<!--#include virtual="/NR/System/WBC/Internals/ServerControls/ListControl/CNCListControl.inc"-->
<!--#include file="CNCGridDecorator_ThumbnailSort.inc" -->
<!--#include file="CNCListRenderer_ResourcesBrowse.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/ResGallery/CNCASPPageManager_ResourcesBrowse.inc
' Version: 	Microsoft Content Management Server
' Author:	Microsoft Corporation.
' Purpose:	Encapsulate the ASP logic associated with ResGallery.asp
'
' Implements the INCASPPageManager interface:
'	- Sub InitManager()
'	- Property Error
'
' Exposes the following properties:
' 	- Property ASPUtils
'	- Property CodePage
'	- Property Charset
'	- Property ViewStateControl
'	- Property ResourceGallery
'	- Property Resources
'	- Property StartItem
'	- Property EndItem
'	- Property PagingConfigControl
'	- Property GridControlForThumbnailSort
'	- Property ListControlForViewAsThumbnail
'	- Property GridControlForViewAsList
'	- Property URLGoBackLink
'	- Property URLRefreshPage
'	- Property URLDeleteButton
'	- Property URLAddButton
'	- Property EnableDeleteButton
'	- Property PagingControl
' ********************************************************************

Class CNCASPPageManager_ResourcesBrowse
	' -- The Charset ASP page will be running under
	Public Charset

	' -- Some UI and links needed in the ASP page
	Public URLGoBackLink
	Public URLDeleteButton
	Public URLAddButton
	Public URLRefreshPage
	Public EnableDeleteButton

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

	' -- Objects needed in both "View As List" or "View As Thumbnail" cases
	Public ResourceGallery
	Public Resources
	Public StartItem
	Public EndItem
	Public PagingConfigControl
	Public PagingControl
	Public Error

	' -- Object needed when "View As List"
	Public GridControlForViewAsList

	' -- Objects needed when "View As Thumbnail"
	Public GridControlForThumbnailSort
	Public ListControlForViewAsThumbnail

	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
		
	' ---- [Private] Standard Class_Initialize
	Private Sub Class_Initialize()
		Set m_pASPUtils = Nothing
		Set ResourceGallery = Nothing
		Set Resources = Nothing
		URLGoBackLink = "../GalleriesBrowse/GalleriesBrowse.asp"
		m_strCodePage = ""
		URLDeleteButton = "#"
		URLAddButton = "#"
		URLRefreshPage = "#"
		Error = ""
	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()
		
		Call SetupBrowseContext()
		' -- Set up URL needed for links in the ASP page
		If (ResourceGallery Is Nothing) Then
			Error = IDS_ERR_GALLERY_NOT_FOUND
			Exit Sub
		End If
		Call SetupCharset()
		Call SetupLinksURL()

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

		' -- Set up objects needed in both views
		Call SetupPagingConfigControl()
		Call SetupPagingControl()
		Call SetupDisplayIndices()

		' -- Given ViewStateControl has been set up, we know whether it is "View As Tree" or "View As List"
		If (ViewStateControl.CurrentState = IDS_STATE_VIEWAS_LIST) Then
			Call SetupForViewAsList()
		Else
			Call SetupForViewAsThumbnail()
		End If

		' -- Stop propagation of certain querystring parameters on controls that do round-tripping
		If Request.QueryString(IDS_PAGESTATUS_AFTDELETE) = "True" Then
			PagingControl.CurrentPage = 1
			Call PagingControl.StopPropagateParameter(IDS_QPARAM_PAGESTATUS)
			Call PagingConfigControl.StopPropagateParameter(IDS_QPARAM_PAGESTATUS)
			Call PagingControl.StopPropagateParameter(IDS_QPARAM_TIMESTAMP)
			Call PagingConfigControl.StopPropagateParameter(IDS_QPARAM_TIMESTAMP)
		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
	
	' ---- 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(ResourceGallery, m_pASPUTils)
	End Sub
	
	' ---- [Private] Sets up the browsing context (Gallery)
	Private Sub SetupBrowseContext()
		Dim strGalleryGUID, pGallery
		
		m_strGalleryGUID = GetGuidFromQueryString(IDS_QPARAM_GALLERY)
		Set ResourceGallery = AutoSession.Searches.GetByGUID(m_strGalleryGUID)
		
		If Not (ResourceGallery is Nothing) Then
			Set Resources = ResourceGallery.Resources
		End If
	End Sub

	' ---- [Private] Set up the Charset this ASP page will be running under
	Private Sub SetupCharset()
		Charset = GetCharacterSetForResource(ResourceGallery)
	End Sub

	' ---- [Private] Set up URL needed for links in the ASP page
	Private Sub SetupLinksURL
		URLGoBackLink = "../GalleriesBrowse/GalleriesBrowse.asp?NRMODE=Unpublished&" & IDS_QPARAM_GALLERY & "=" & m_strGalleryGUID

		URLDeleteButton = "../ResourceDelete/ResourceDelete.asp?NRMODE=Update" & "&" & URLEncodedQueryString()

		URLAddButton = "../ResourceCreate/ResourceCreate.asp?" & URLEncodedQueryString()

		URLRefreshPage = GetBaseURL()
	End Sub

	' ---- [Private] This function will remove unwanted query string parameter.  Reason for this is the ResourceDelete.asp
	'         		is passing special query string for this page to do refresh and page control handing on boundary
	'         		case (e.g. delete the last item in page 3 of 3 should put this page to page 2 of 2 after delete)
	Function GetBaseURL()
		Dim pQParam, strParamName
		Dim bFirstParam

		GetBaseURL = Request.ServerVariables("URL") & "?"
		bFirstParam = true
		For Each pQParam In Request.QueryString
			' mask out some Querystring Params that should not be propagated to the next page
			strParamName = CStr(pQParam)
			If not (strParamName = IDS_QPARAM_PAGESTATUS or strParamName = IDS_QPARAM_TIMESTAMP) Then
				If bFirstParam Then
					bFirstParam = false
					GetBaseURL = GetBaseURL & Server.URLEncode(pQParam) & "=" & Server.URLEncode(Request.QueryString(pQParam))
				Else
					GetBaseURL = GetBaseURL  & "&" & Server.URLEncode(pQParam) & "=" & Server.URLEncode(Request.QueryString(pQParam))
				End if
			End If
		Next

		GetBaseURL = GetBaseURL & "&" & IDS_QPARAM_TIMESTAMP & "=" & CDbl(CDate(now))

	End Function

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

		Dim pStateControlRendererViewAs
		Set pStateControlRendererViewAs = New CNCStateRenderer_ViewAsListOrThumbnail


		Call ViewStateControl.InitStateControl( IDS_STATE_ID_RESOURCES_VIEWAS, pStateControlRendererViewAs, IDS_STATE_VIEWAS_LIST, True )
		Call ViewStateControl.AddState( IDS_STATE_VIEWAS_LIST )
		Call ViewStateControl.AddState( IDS_STATE_VIEWAS_THUMBNAIL )
	End Sub

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

		Call PagingConfigControl.InitPagingConfigControl( IDS_PAGINGCONFIG_ID_RESOURCES, 5, True )
	End Sub


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

		Dim pNCPagingRenderer
		Set pNCPagingRenderer = New CNCPagingRenderer_Common

		Call PagingControl.InitPagingControl( pNCPagingRenderer, Resources.Count, PagingConfigControl.ItemsPerPage )
		If (PagingConfigControl.IsSetNewValue = True) Then
			' PagingConfigControl has just been set a new value, set PagingControl back to Page 1
			PagingControl.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 StartItem
		If (Resources.Count = 0) Then
			StartItem = 0
		Else
			StartItem = (PagingControl.CurrentPage - 1)*(PagingConfigControl.ItemsPerPage) + 1
		End If
		' -- calculate the EndItem
		If (PagingConfigControl.ItemsPerPage < 0) Then
			' -- a minus one value from PagingConfigControl means "All" case
			EndItem = Resources.Count
		Else
			EndItem = PagingControl.CurrentPage * PagingConfigControl.ItemsPerPage
		End If
		EndItem = Min(Resources.Count, EndItem)
	End Sub

	' ---- [Private] Set up GridControl for displaying Resources as a sortable List
	Private Sub SetupForViewAsList()
		Set GridControlForViewAsList = New CNCGridControl

		Dim pNCGridDecoratorResourcesAsList
		Set pNCGridDecoratorResourcesAsList = New CNCGridDecorator_ResourcesBrowse
		Call GridControlForViewAsList.InitGridControl( IDS_GRIDID_RESOURCES, pNCGridDecoratorResourcesAsList, Resources, True )

		Call GridControlForViewAsList.SetDisplayRange( StartItem-1 , EndItem-1 )
		Call GridControlForViewAsList.AddColumn( IDS_GRIDINDEX_DELETECHKBOX, False )
		Call GridControlForViewAsList.AddColumn( IDS_GRIDINDEX_DISPLAYNAME, True )
		Call GridControlForViewAsList.AddColumn( IDS_GRIDINDEX_REPLACE, False )
		Call GridControlForViewAsList.AddColumn( IDS_GRIDINDEX_PROPERTIES, False )
		Call GridControlForViewAsList.AddColumn( IDS_GRIDINDEX_TYPE, True )
		Call GridControlForViewAsList.AddColumn( IDS_GRIDINDEX_SIZE, True )
		Call GridControlForViewAsList.AddColumn( IDS_GRIDINDEX_LASTMOD, True )
		Call GridControlForViewAsList.AddColumn( IDS_GRIDINDEX_DESC, False )

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

	End Sub

	' ---- [Private] Set up ListControl for displaying Resources as Thumbnails
	Private Sub SetupForViewAsThumbnail()
		' leveraging the CNCGridControl for the sorting links
		Set GridControlForThumbnailSort = New CNCGridControl

		Dim pGridDecoratorResourcesAsTnSort
		Set pGridDecoratorResourcesAsTnSort = New CNCGridDecorator_ThumbnailSort
		Call GridControlForThumbnailSort.InitGridControl( IDS_GRIDID_RESOURCES, pGridDecoratorResourcesAsTnSort, Resources, True )

		Call GridControlForThumbnailSort.AddColumn( "DisplayName", True )
		Call GridControlForThumbnailSort.AddColumn( "Type", True )
		Call GridControlForThumbnailSort.AddColumn( "Size", True )
		Call GridControlForThumbnailSort.AddColumn( "LastModifiedDate", True )
		GridControlForThumbnailSort.AscendingIndicatorHTML = "<img valign=bottom border=0 src='" & IDS_RESOURCEBROWSER_IMG_PATH & IDS_IMG_ICON_ARROW_UP & "'>"
		GridControlForThumbnailSort.DescendingIndicatorHTML = "<img valign=bottom border=0 src='" & IDS_RESOURCEBROWSER_IMG_PATH & IDS_IMG_ICON_ARROW_DOWN & "'>"
		GridControlForThumbnailSort.ItemSpacing = 5
		GridControlForThumbnailSort.ItemPadding = 5
		GridControlForThumbnailSort.ContentItemsVisible = False

		' the CNCListControl for displaying the list of resources as thumbnail
		Set ListControlForViewAsThumbnail = New CNCListControl

		Dim pNCListRendererResourcesAsThumbnail
		Set pNCListRendererResourcesAsThumbnail = New CNCListRenderer_ResourcesBrowse
		Call ListControlForViewAsThumbnail.InitListControl( pNCListRendererResourcesAsThumbnail, Resources )

		Call ListControlForViewAsThumbnail.SetDisplayRange( StartItem-1, EndItem-1 )
		ListControlForViewAsThumbnail.ObjectsPerRow = 2
		ListControlForViewAsThumbnail.ItemSpacing = 1
		ListControlForViewAsThumbnail.ItemPadding = 13

	End Sub

End Class

%>