<!--#include virtual="/NR/System/WBC/Internals/Main/WBCApp.inc"-->

<!--#include virtual="/NR/System/WBC/Customizable/WBCFuncPagesConfig/UIStringConstants/PageCreationWizardUIStrings.inc" -->
<!--#include virtual="/NR/System/WBC/Customizable/WBCFuncPagesConfig/MLSDisplayConfig/PageCreationWizardConfig.inc" -->

<!--#include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/PageCreationWizard/EntryProgrammingConstants.inc" -->
<!--#include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/PageCreationWizard/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_NRTmplGalleries.inc"-->
<!--#include file="CNCTreeRenderer_TemplateGalleriesBrowse.inc" -->

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

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

<!-- #include virtual="/NR/System/WBC/Internals/Integration/InternalHooks/URLGenerationHooks/PostingCreationHooks.inc" -->
<!-- #include virtual="/NR/System/WBC/Customizable/Hooks/URLGenerationHooks/PostingCreationHooks.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/PageCreationWizard/
'			TemplateGalleriesBrowse/CNCASPPageManager_TemplateGalleriesBrowse.inc
' Version: 	Microsoft Content Management Server
' Author:	Microsoft Corporation.
' Purpose:	Encapsulate the ASP logic associated with TemplateGalleriesBrowse.asp
'
' Implements the INCASPPageManager interface:
'	- Sub InitManager()
'
' Exposes the following properties:
'	- Property CreatingConnectedPage
'	- Property CurrentPageNode
'	- Property CurrentChannelNode
'	- Property ViewStateControl
'	- Property TreeControl
'	- Property TemplateGalleries
'	- Property GridStartItem
'	- Property GridEndItem
'	- Property GridPagingConfigControl
'	- Property GridControl
'	- Property GridPagingControl
'	- Property Error
'   - Property URLGoBackLink
'	- Property ASPUtilsObject
'	- Property Charset
'	- Property CodePage
' ********************************************************************

Class CNCASPPageManager_TemplateGalleriesBrowse

	' -- Flag that says whether we are creating simple / connected page
	Public CreatingConnectedPage

	' -- Page Node
	Public CurrentPageNode

	' -- Channel Node
	Public CurrentChannelNode

	' -- 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 TemplateGalleries
	Public GridStartItem
	Public GridEndItem
	Public GridPagingConfigControl
	Public GridControl
	Public GridPagingControl

	' Error Handling
	Public Error

	' Go Back URL
	Public URLGoBackLink


	' -- MLS info
	Public ASPUtilsObject

	' -- Charset
	Public Charset

	' -- CodePage
	Public CodePage


	' ---- [Private] Class standard initialization routine
	Private Sub Class_Initialize()
		Set ViewStateControl= Nothing
		Set TreeControl= Nothing
		Set TemplateGalleries = Nothing
		Set GridStartItem = Nothing
		Set GridEndItem = Nothing
		Set GridPagingConfigControl = Nothing
		Set GridControl = Nothing
		Set GridPagingControl = Nothing
		Set CurrentPageNode = Nothing
		Set CurrentChannelNode = Nothing
		Set ASPUtilsObject = Nothing
		Dim strPageGuid
		Dim strChannelGuid
		Dim bPageGuidError
		
		strChannelGuid = GetChannelGuidFromQueryString()
		If 	strChannelGuid = "" Then
			Error = IDS_UI_ERR_CHANNEL_NOT_FOUND
			Exit Sub
		End If
		
		strPageGuid = GetConnectedPageGuidFromQueryString(bPageGuidError)
		If bPageGuidError = True Then
				Error = IDS_UI_ERR_PAGE_NOT_FOUND
				Exit Sub
		End If
		
		URLGoBackLink = "../ChannelsBrowse/ChannelsBrowse.asp?" & _
						IDS_QPARAM_NRMODE & "=" & IDS_NRMODE_UNPUBLISHED & "&" & _
						IDS_QSTR_PAGECREATIONWIZARD_CONNECTEDPAGE & "=" & strPageGuid & "&" & _
						IDS_QSTR_PAGECREATIONWIZARD_DESTINATIONCHANNEL & "=" & strChannelGuid
		' -- call Internal Hook
		Call OnInternalCustomizePostingCreationDlgURL( URLGoBackLink )

		' -- call external Customizable Hook
		Call OnCustomizePostingCreationDlgURL( URLGoBackLink )

		Error = ""
	End Sub

	' ---- [Public] InitManaer will take care of all programming logic in the ASP page
	Public Sub InitManager()
		' -- Set up Boolean control to tell if we are creating a connected page or not
		'    and return URL
		Call SetupBooleanCreatingConnectedPage

		' -- Set up Required Object so we know if we are missing any query string
		Call SetupRequiredObject

		If Error = "" Then
			' -- Setup MLS Info
			Call SetupMLSInfo()

			' -- 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_PAGECREATIONWIZARD_VIEWAS_TREE) Then
				Call SetupTreeControl()
			Else
				Call SetupTemplateGalleriesCollection()
				Call SetupPagingConfigControl()
				Call SetupPagingControl()
				Call SetupDisplayIndices()
				Call SetupGridControl()
			End If
		End If
	End Sub

	' ---- [Private] Setup boolean so TemplateGalleriesBrowse.asp can tell if we
	'                are creating a  Simple page / connected page
	Private Sub SetupBooleanCreatingConnectedPage
		Dim strPageGuid

		strPageGuid = Request.QueryString(IDS_QSTR_PAGECREATIONWIZARD_CONNECTEDPAGE)

		If strPageGuid <> ""  Then
			CreatingConnectedPage = True
		Else
			CreatingConnectedPage = False
		End If
	End Sub


	' ---- [Private] Create all the objects that QPARAM carries
	'
	Private Sub SetUpRequiredObject
		Dim strPageGuid
		Dim strChannelGuid

		strChannelGuid = Request.QueryString(IDS_QSTR_PAGECREATIONWIZARD_DESTINATIONCHANNEL)

		If	strChannelGuid = "" Then
			Error = IDS_UI_ERR_CHANNEL_NOT_FOUND
		Else
			Set CurrentChannelNode = AutoSession.Searches.GetByGUID(strChannelGuid)
			If (CurrentChannelNode is Nothing) Then
				Error = IDS_UI_ERR_CHANNEL_NOT_FOUND
			End If
		End If

		'If there is no eror then we chk for page guid
		If Error = "" Then

			'We only want to do chking if we know we have a connected page.
			'If simple page, these query string parameter will be missing
			If CreatingConnectedPage Then

				strPageGuid = Request.QueryString(IDS_QSTR_PAGECREATIONWIZARD_CONNECTEDPAGE)

				If strPageGuid = "" Then
					Error = IDS_UI_ERR_PAGE_NOT_FOUND
				Else
					Set CurrentPageNode = AutoSession.Searches.GetByGUID(strPageGuid)
					If (CurrentPageNode is Nothing) Then
						Error = IDS_UI_ERR_PAGE_NOT_FOUND
					End If
				End If
			End If
		End If

	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_PAGECREATIONWIZARD_TEMPLATE_GALLERIES_VIEWAS, pStateControlRendererViewAs, IDS_STATE_PAGECREATIONWIZARD_VIEWAS_LIST, True )
		Call ViewStateControl.AddState( IDS_STATE_PAGECREATIONWIZARD_VIEWAS_TREE )
		Call ViewStateControl.AddState( IDS_STATE_PAGECREATIONWIZARD_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_NRTmplGalleries
		Set pNCTreeRenderer = New CNCTreeRenderer_TemplateGalleriesBrowse

		If Request.QueryString(IDS_QSTR_PAGECREATIONWIZARD_FRESHTREE) = IDS_PAGECREATIONWIZARD_FRESHTREE_TRUE Then
			Call TreeControl.InitTreeControl( "TmplGal", pNCTreeDom, pNCTreeRenderer, True)
		Else
			Call TreeControl.InitTreeControl( "TmplGal", pNCTreeDom, pNCTreeRenderer, False)
		End If

		' During round trip, these QPARAM will be retained when come back from server
		Call TreeControl.PropagateParameter( IDS_QSTR_PAGECREATIONWIZARD_FRESHTREE, IDS_PAGECREATIONWIZARD_FRESHTREE_FALSE )
		Call TreeControl.PropagateParameter( "NRMODE", "Unpublished" )
		Call TreeControl.PropagateParameter(IDS_QSTR_PAGECREATIONWIZARD_TIMESTAMP, CDbl(CDate(now)))


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

	' ---- [Private] Sets up the TemplateGalleries collection
	Private Sub SetupTemplateGalleriesCollection()
		Set TemplateGalleries = AutoSession.Searches.UserTemplateGalleries
	End Sub

	' ---- [Private] Sets up GridPagingConfigControl
	Private Sub SetupPagingConfigControl()

		Set GridPagingConfigControl = New CNCPagingConfigControl
		Call GridPagingConfigControl.InitPagingConfigControl( IDS_PAGINGCONFIG_ID_PAGECREATIONWIZARD_TEMPLATEGALLERIES, 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, TemplateGalleries.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()
		If TemplateGalleries.Count = 0 then
			GridStartItem = 1
		Else
			GridStartItem = (GridPagingControl.CurrentPage - 1)*(GridPagingConfigControl.ItemsPerPage) + 1

		End If
		If (GridPagingConfigControl.ItemsPerPage < 0) Then
			' -- a minus one value from PagingConfigControl means "All" case
			GridEndItem = TemplateGalleries.Count
		Else
			GridEndItem = GridPagingControl.CurrentPage * GridPagingConfigControl.ItemsPerPage
		End If
		GridEndItem = Min(TemplateGalleries.Count, GridEndItem)
	End Sub

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

		Dim pNCGridDecorator
		Set pNCGridDecorator = New CNCGridDecorator_TemplateGalleriesBrowse

		Call GridControl.InitGridControl( IDS_GRIDID_PAGECREATIONWIZARD_TEMPLATEGALLERIES, pNCGridDecorator, TemplateGalleries, True )
		Call GridControl.SetDisplayRange( GridStartItem-1 , GridEndItem-1 )
		Call GridControl.AddColumn( IDS_GRIDINDEX_PAGECREATIONWIZARD_NAME, True )
		Call GridControl.AddColumn( IDS_GRIDINDEX_PAGECREATIONWIZARD_LOCATION, True )
		Call GridControl.AddColumn( IDS_GRIDINDEX_PAGECREATIONWIZARD_LASTMOD, True )


		GridControl.ColumnHeadAnchorCSSClass = "WBC_styclsHeavyTextColor1"
		GridControl.ItemSpacing = 1
		GridControl.ItemPadding = 5

	End Sub

	' ---- [Private] Set up the MLS info this ASP page will be running under
	Private Sub SetupMLSInfo()
		Set ASPUtilsObject = GetInitializedASPUtils()

		' -- call functions in WBC/Customizable/MLSDisplayConfig/PageCreationWizardConfig.inc
		'	 to determine CodePage and Charset setting
		CodePage = GetCodePageForPageCreationWizard( CurrentChannelNode, CurrentPageNode, ASPUtilsObject )
		Charset = GetCharacterSetForPageCreationWizard( CurrentChannelNode, CurrentPageNode )
	End Sub

End Class

%>
