<%

' ********************************************************************
' 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/
'				TasksAssistant/ApprovalAssistant/
'				CNCGridDecorator_ApprovalAssistant.inc
'
' Version: 	Microsoft Content Management Server
' Author:	Microsoft Corporation.
'
' Purpose:	Implements the INCGridDecorator Interface for the
'			Pages to Approve task assistant. Note that pages to
'			approvenon are in a waiting state and non-published. The
'			main server grid control page calls into this component
'			to do the context-sensitive painting of the grid.
'
' Implement INCGridDecorator Interface:
'
'	- Sub RenderColumnHeadTRAttrib()
'	- Sub RenderColumnHeadTDAttrib( strColumnIndex )
'	- Sub RenderColumnHeadTDContent( strColumnIndex )
'	- Sub RenderItemTRAttrib( pObject, nCollectionIndex, nDisplayIndex )
'	- Sub RenderItemTDAttrib( pObject, nCollectionIndex, nDisplayIndex, strColumnIndex )
'	- Sub RenderItemTDContent( pObject, nCollectionIndex, nDisplayIndex, strColumnIndex )
'	- Sub SortCollection( strSortByColumn, colObjects, bAscending )
'
' ********************************************************************

Class CNCGridDecorator_ApprovalAssistant

	' -------------------------------------------------------------------------
	'	[PUBLIC] This method renders the column head TR attribute for the
	'	grid. Since TR is not specific to any one column in the grid, there
	'	is no grid index passed in.
	'
	'	@see CNCGridControl
	' -------------------------------------------------------------------------
	Public Sub RenderColumnHeadTRAttrib()

		Response.Write( "class='" & IDS_CSS_APPROVALASSISTANT_BACKGROUND2 & "' " )

	End Sub  'RenderColumnHeadTRAttrib


	' -------------------------------------------------------------------------
	'	[PUBLIC] This method renders the column head TD attribute for the
	'	grid. The column that is rendered is based on the column index
	'	parameter passed to the function.
	'
	'	@param strColumnIndex [in] - a string that identifies the name of
	'				column to be rendered.
	'
	'	@see CNCGridControl
	' -------------------------------------------------------------------------
	Public Sub RenderColumnHeadTDAttrib( strColumnIndex )

		' case on the column and dump out the attributes for the selected
		' column
		Select Case strColumnIndex

			Case IDS_GRIDINDEX_SELECT
				Response.Write( "width=20 align='center' " )

			Case IDS_GRIDINDEX_DISPLAYNAME
				Response.Write( "align='center' " )

			Case IDS_GRIDINDEX_GOTO
				Response.Write( "align='center' " )

			Case IDS_GRIDINDEX_PATH
				Response.Write( "align='center' " )

			Case IDS_GRIDINDEX_STATUS
				Response.Write( "align='center' " )

			Case IDS_GRIDINDEX_OWNER
				Response.Write( "align='center' " )

			Case IDS_GRIDINDEX_LASTMODIFIED
				Response.Write( "align='center' " )

			Case Else

				Call Err.Raise( ID_ERROR_UNKNOWN_COLUMN_TYPE )

		End Select  'case on column index

		' column names are rendered in heavy (bold) text, so make sure
		' that the style is indicated as an attribute in the TD tag.
		Response.Write( "class='" & IDS_CSS_APPROVALASSISTANT_HEAVYTEXT1 & "' " )

	End Sub  'RenderColumnHeadTDAttrib


	' -------------------------------------------------------------------------
	'	[PUBLIC] This method renders the column head TD content for the
	'	grid. The column that is rendered is based on the column index
	'	parameter passed to the function. The UI strings that are rendered
	' 	are pulled from the ProgrammingConstants module.
	'
	'	@param strColumnIndex [in] - a string that identifies the name of
	'				column to be rendered.
	'
	'	@see CNCGridControl
	' -------------------------------------------------------------------------
	Public Sub RenderColumnHeadTDContent( strColumnIndex )

		Select Case strColumnIndex

			Case IDS_GRIDINDEX_SELECT

				Response.Write( "<img border='0' src='" & IDS_PATH_IMAGES_COMMON_ICONS & IDS_IMG_ICON_APPROVEDECLINE & "'>" )

			Case IDS_GRIDINDEX_DISPLAYNAME

				Call WriteAsNonbreakingBlock( IDS_UI_LABEL_DISPLAYNAME )

			Case IDS_GRIDINDEX_GOTO

				Call WriteAsNonbreakingBlock( IDS_UI_LABEL_GOTO )

			Case IDS_GRIDINDEX_PATH

				Call WriteAsNonbreakingBlock( IDS_UI_LABEL_PATH )

			Case IDS_GRIDINDEX_STATUS

				Call WriteAsNonbreakingBlock( IDS_UI_LABEL_STATUS )

			Case IDS_GRIDINDEX_OWNER

				Call WriteAsNonbreakingBlock( IDS_UI_LABEL_OWNER )

			Case IDS_GRIDINDEX_LASTMODIFIED

				Call WriteAsNonbreakingBlock( IDS_UI_LABEL_LASTMODIFIED )

			Case Else

				Call Err.Raise( ID_ERROR_UNKNOWN_COLUMN_TYPE )

		End Select  ' case on column index

	End Sub  'RenderColumnHeadTDContent


	' -------------------------------------------------------------------------
	'	[PUBLIC] This method adds the attributes for the current row being
	' 	rendered. Its main task is to shade even/odd rows appropriately
	'	according to the defined styles.
	'
	'	@param pObject [in] - the page whose properties are being rendered
	'
	'	@param nCollectionIndex [in] - the index into the collection of pages
	'		being displayed
	'
	'	@param nDisplayIndex [in] - the index into the current group of pages
	'		being displayed. This differs from the collection index as it is
	'		relative to the group of items on the page (e.g. if there are 4
	'		items displayed out of 12 possible, the index is 0 to 3).
	'
	'	@see CNCGridControl
	' -------------------------------------------------------------------------
	Public Sub RenderItemTRAttrib( pObject, nCollectionIndex, nDisplayIndex )

		' render even rows differently from odd rows
		If ( nDisplayIndex Mod 2 = 0 ) Then
			Response.Write( "class='" & IDS_CSS_APPROVALASSISTANT_ALTBG1 & "'" )

		Else
			Response.Write( "class='" & IDS_CSS_APPROVALASSISTANT_ALTBG2 & "'" )

		End If  ' if even row

	End Sub  'RenderItemTRAttribute


	' -------------------------------------------------------------------------
	'	[PUBLIC] This method renders the attributes associated with a
	'	particular item (page) being rendered in the grid.
	'
	'	@param pObject [in] - the page whose properties are being rendered
	'
	'	@param nCollectionIndex [in] - the index into the collection of pages
	'		being displayed
	'
	'	@param nDisplayIndex [in] - the index into the current group of pages
	'		being displayed. This differs from the collection index as it is
	'		relative to the group of items on the page (e.g. if there are 4
	'		items displayed out of 12 possible, the index is 0 to 3).
	'
	'	@param strColumnIndex [in] - a string that identifies the name of
	'				column to be rendered.
	'
	'	@see CNCGridControl
	' -------------------------------------------------------------------------
	Public Sub RenderItemTDAttrib( pObject, nCollectionIndex, nDisplayIndex, strColumnIndex )

		Select Case strColumnIndex

			Case IDS_GRIDINDEX_SELECT
				Response.Write( "align='center' valign='top'" )

			Case IDS_GRIDINDEX_DISPLAYNAME
				Response.Write( "align='left' valign='top'" )

			Case IDS_GRIDINDEX_GOTO
				Response.Write( "align='center' valign='top'" )

			Case IDS_GRIDINDEX_PATH
				Response.Write( "align='left' valign='top'" )

			Case IDS_GRIDINDEX_STATUS
				Response.Write( "align='left' valign='top'" )

			Case IDS_GRIDINDEX_OWNER
				Response.Write( "align='left' valign='top'" )

			Case IDS_GRIDINDEX_LASTMODIFIED
				Response.Write( "align='center' valign='top'" )

			Case Else

				Call Err.Raise( ID_ERROR_UNKNOWN_COLUMN_TYPE )

		End Select  ' case on column index

		Response.Write( "class='" & IDS_CSS_APPROVALASSISTANT_NORMALTEXT0 & "' " )

	End Sub  'RenderItemTDAttrib


	' -------------------------------------------------------------------------
	'	[PUBLIC] This function represents the guts of the grid decorator
	'	control. It is responsible for rendering the contents of the grid
	'	for the current page. The actual table cell that is rendered is
	'	controlled by the column index parameter. This function is called
	'	for each and every DATA cell in the grid.
	'
	'	@param pObject [in] - the page whose properties are being rendered
	'
	'	@param nCollectionIndex [in] - the index into the collection of pages
	'		being displayed
	'
	'	@param nDisplayIndex [in] - the index into the current group of pages
	'		being displayed. This differs from the collection index as it is
	'		relative to the group of items on the page (e.g. if there are 4
	'		items displayed out of 12 possible, the index is 0 to 3).
	'
	'	@param strColumnIndex [in] - a string that identifies the name of
	'				column to be rendered.
	'
	'	@see CNCGridControl
	' -------------------------------------------------------------------------
	Public Sub RenderItemTDContent( pObject, nCollectionIndex, nDisplayIndex, strColumnIndex )

		' instantiate the generic ASP utilities object for the purpose of
		' grabbing the code page that should be used when displaying
		' multi-lingual text.
		Dim pASPUtils
		Set pASPUtils = GetInitializedASPUtils()

		Dim lCodePage
		lCodePage = GetCodePageForTasksAssistant( pASPUtils )

		' determine which cell in the grid should be rendered
		Select Case strColumnIndex

			Case IDS_GRIDINDEX_SELECT

				' make sure the user has rights to approve or decline pages
				' before we show show the checkbox and enable the approve
				' and decline buttons
				Dim bCanApproveDecline
				bCanApproveDecline = pObject.CanApprove

				If bCanApproveDecline Then

					' user can approve/decline, so enable buttons. Note
					' that if the user has access to at least one posting,
					' the buttons are enabled
					g_pASPPageManager.ApproveButtonEnabled = True
					g_pASPPageManager.DeclineButtonEnabled = True

					' write the checkbox into the grid. By checking the box
					' and clicking the approve or decline button, the
					' operation is performed on all selected pages. Note
					' that the receiving ASP page for the form submission must
					' use the same form element name as specified here. The
					' hidden form field contains the GUID of the posting that
					' is being approved/declined.
					Response.Write( "<input type='checkbox' name='" & IDS_FORM_ELEMENT_SELECTFORAPPROVEDECLINE & "' " & _
					   				"value= """ & pObject.GUID & """>")

					' create a hidden form field that will store the GUID of
					' the page that will be approved or declined. This value
					' will be sent to the server
					Response.Write( "<input type='hidden' name='" & IDS_FORM_ELEMENT_PREFIX & "" & pObject.GUID & "'" & "value=""" )

					' the value of the hidden field is the name of the page
					' being displayed
					Call pASPUtils.MBCSWrite( pASPUtils.HTMLEncode( pObject.DisplayName ), lCodePage )

					Response.Write("""" & ">")

				Else

					' the user is not allowed to approve or decline pages
					' so insert a dummy image for the checkbox
					Response.Write( "<img alt='" & IDS_UI_TOOLTIP_CANNOTAPPROVEDECLINE & "' src ='" & IDS_PATH_IMAGES_COMMON_ICONS & IDS_IMG_ICON_INACTIVECHECKBOX & "'>" )

				End If  'if can approve or decline

			Case IDS_GRIDINDEX_DISPLAYNAME

				' for the page name, first render an action icon followed by
				' the name of the page

				Response.write("<table border='0'><tr><td>")
				Response.write("<a href='#' onClick='WBC_openWindowOnFocus(""" & GetWBCPreviewModeURL( pObject )& """,IDS_WIN_PREVIEW, WBC_getPoppedUpWindowFeatures(IDS_WIN_PREVIEW_FEATURES, window.top));")
				Response.write("return false;'>")

				Response.Write( "<img alt='" & IDS_UI_TOOLTIP_PREVIEW & "' border='0' src='" & IDS_PATH_IMAGES_COMMON_ICONS & IDS_IMG_ICON_PREVIEW & "'></a>" & _
								"&nbsp;</td><td class='" & IDS_CSS_APPROVALASSISTANT_NORMALTEXT0 & "' valign='top'>" )

				Call pASPUtils.MBCSWrite( pASPUtils.HTMLEncode( pObject.DisplayName ), lCodePage )

				Response.Write( "</td></tr></table>" )

			Case IDS_GRIDINDEX_GOTO
				Response.write("<a href='#' onClick='WBC_onSelectGoto(" & """" & GetWBCBasicEditURL(pObject) & """" &");return false'>")
				Response.write("<img border=0 src='" & IDS_PATH_IMAGES_COMMON_ICONS & IDS_IMG_ICON_GOTO & "'> </a>")

			Case IDS_GRIDINDEX_PATH

				' display a slash-delimited path to the page
				Call pASPUtils.MBCSWrite( pASPUtils.HTMLEncode( pObject.Parent.DisplayPath ) , lCodePage )

			Case IDS_GRIDINDEX_STATUS

				' display the status of the page (e.g. saved, waiting, etc.)
				Response.Write( pObject.State )

			Case IDS_GRIDINDEX_OWNER

				' display the owner of the page (short user name)
				Call pASPUtils.MBCSWrite( pASPUtils.HTMLEncode( pObject.OwnedBy.ShortName ) , lCodePage )

			Case IDS_GRIDINDEX_LASTMODIFIED

				' dump out the last modified date in a formatted fashion. This
				' requires client-side JavaScript to convert the date to a local
				' time.

				' ideally, we want the last modified date to be a non-breaking
				' piece of text, but this has problems in Netscape with column
				' overlap. Since the column looks much nicer with <nobr> we do
				' a browser check
				Call WriteAsNonbreakingBlock( "<script language='JavaScript' type='text/javascript'>" & vbcrlf & _
											  "<!--"  & vbcrlf & _
											  "WBC_writeUTC2Local('" & FormatDate( pObject.LastModifiedDate ) & "');"  & vbcrlf & _
											  "//-->"  & vbcrlf & _
											  "</script>"  & vbcrlf )
			Case Else

				Call Err.Raise( ID_ERROR_UNKNOWN_COLUMN_TYPE )

		End Select  ' case on column index

	End Sub  'RenderItemTDContent


	' -------------------------------------------------------------------------
	'	[PUBLIC] This function renders the grid content (or lack there-of)
	'	when there are no items to show. Simply display a text string
	' 	indicating this fact
	'
	'	@see CNCGridControl
	' -------------------------------------------------------------------------
	Public Sub RenderEmptyGrid()

		Response.Write( "<span class='" & IDS_CSS_APPROVALASSISTANT_NORMALTEXT1 & "'>" & _
						IDS_UI_MSG_NOPAGESTOAPPROVE & _
						"</span>" )

	End Sub  'RenderEmptyGrid


	' -------------------------------------------------------------------------
	'	[PUBLIC] If sorting functionality is to be provided on the grid
	'	control, this function does the actual work of sorting. For
	'	columns that are sortable, the control calls upon the ROM to
	' 	do the work.
	'
	'	@param strSortByColumn [in] - the string that identifies the column
	'		to be sorted.
	'
	'	@param colObjects [in] - the collection of objects to be sorted (pages
	'		in this case).
	'
	'	@param bAscending [in] - sort ascending or decending order
	'
	'	@see CNCGridControl
	' -------------------------------------------------------------------------
	Public Sub SortCollection( strSortByColumn, colObjects, bAscending )

		Select Case strSortByColumn

			Case IDS_GRIDINDEX_DISPLAYNAME
				Call colObjects.SortByDisplayName( bAscending )

			Case IDS_GRIDINDEX_PATH
				Call colObjects.SortByDisplayPath( bAscending )

			Case IDS_GRIDINDEX_OWNER
				Call colObjects.SortByOwner( bAscending )

			Case IDS_GRIDINDEX_LASTMODIFIED
				Call colObjects.SortByLastModifiedDate( bAscending )

			' NOTE: No need to handle else case - if a strange column name
			' is passed in, just don't sort.

		End Select  'case on column type

	End Sub  'SortCollection


End Class  'CNCGridDecorator_ApprovalAssistant

%>