<%

' ---- [Private]
Private Sub GenerateSeparator( bOwePreviousGroupSeparator )
	If (bOwePreviousGroupSeparator = True) Then
		Response.Write("<option value=''>&nbsp;&nbsp;--------------------------------") 
	End If
	bOwePreviousGroupSeparator = False
End Sub	

' ---- [Private]
Function IsEditSiteMode
	IsEditSiteMode = ( AreEditSiteOpsVisible() And _
						(Not AutoSession.ThisPosting Is Nothing) )
End Function 

Function GenerateFormTag()
	GenerateFormTag = Not ( IsAuthoringMode() And IsBodyBeginHookCalled() )
End Function

' -----------------------------------------------------------------------------
' 
'	[Public] This subroutine displays the Droplist version of the WBC Console
'
' -----------------------------------------------------------------------------
Sub EmbedDroplistConsole()

	If (IsWBCVisible = True) Then 
		' variable to keep track of whether separator is needed
		Dim bOwePreviousGroupSeparator
		bOwePreviousGroupSeparator = False
		
		Call GenerateJavascriptHandler()
		If GenerateFormTag Then
%>
			<form name="WBC_frmDroplistConsole">
<%
		End If
%>
		<select name="WBC_selDroplistConsole" onChange="WBC_OnSelectWBCLink()">
<%		
		' -- 1) Channel or Posting Indicator
		Dim pCurrentContext
		Set pCurrentContext = GetCurrentObject()
		
		If (pCurrentContext.IsChannel = True) Then
%>
			<option value="">&nbsp;&nbsp;Channel:
<%		
			bOwePreviousGroupSeparator = True
			
		ElseIf (pCurrentContext.IsPosting = True) Then
%>
			<option value="">&nbsp;&nbsp;Pages Status:<b> <%= AutoSession.ThisPosting.State %> </b>
<%
			' Check if this is the unapproved version, and if it is, let the user know.
			If AutoSession.ThisPosting.State = AutoSession.ThisPosting.StateUnapprovedVersion _
				And AutoSession.ThisPosting.StateApprovedVersion = "Published"  Then %>
				<option value="">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_PAGE_HAS_LIVE %>
<%
			End If
			bOwePreviousGroupSeparator = True
		Else
%>
			<option value="">&nbsp;&nbsp;Error: Unknown Object Context
<%
			bOwePreviousGroupSeparator = True
		End If
		Call GenerateSeparator( bOwePreviousGroupSeparator )
		
		' -- 2) Manager Group
		bOwePreviousGroupSeparator = False
		If AreTaskAssistantsVisible() Then
			If AutoSession.UserCanAuthor Then 
				bOwePreviousGroupSeparator = True
%>
				<option value="Production Manager">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_PRODUCTION_MANAGER %> <%
			End If
			If AutoSession.UserCanApprove Then 
				bOwePreviousGroupSeparator = True
%>
				<option value="ApprovalAssistant">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_APPROVAL_ASSISTANT %> <%
			End If
		End If

		If IsResourceManagerLinkVisible() Then
			bOwePreviousGroupSeparator = True  
%>
			<option value="Resource Management">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_RESOURCE_MANAGER %> 
<%
		End If

		' -- 3) Possible Page Actions
		If AreEditSiteOpsVisible() Then
			'We know preview is always going to be here
			'so we close off the item above
			Call GenerateSeparator( bOwePreviousGroupSeparator )
			bOwePreviousGroupSeparator = True %>	
			<option value="Preview">&nbsp;&nbsp;<%=IDS_UI_CONSOLE_PREVIEW%> 
<%
			If Not AutoSession.ThisPosting Is Nothing Then
				If IsConnectedPagesJumpLinkVisible Then %>
					<option value="Go To Connected Page">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_GOTO_CONNECTED %>
<%
				End If
			End If

			' -- 4) Posting Operations
			'We need to close off the preview of above. Also we don't
			'need to keep track of bOwePreviousGroupSeparator b/c we know we
			'must have one
			Call GenerateSeparator(bOwePreviousGroupSeparator)
			bOwePreviousGroupSeparator = True		
			If IsNewPostingLinkVisible() Then  %>	
				<option value="Create Page in Channel">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_CREATE_SIMPLE_PAGE %>
<%
			End If 
			If IsNewConnectedPostingLinkVisible Then 
%>	
				<option value="Create Connected Page">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_CREATE_CONNECTED_PAGE %>
<%
			End If
	
			If IsEditSiteMode Then
				If AutoSession.ThisPosting.CanSetProperties Then 
%>
					<option value="Edit">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_EDIT %> 
<%
				End If
				If AutoSession.ThisPosting.CanDelete Then 
%>
					<option value="Delete">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_DELETE %> 
<%
				End If 
				If IsMoveLinkVisible Then 
%>
					<option value="Move">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_MOVE %>
<%
				End If 
%>
				<option value="Copy">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_COPY %>
<%
			End If
				
			' -- 5) WorkFlow
			If IsEditSiteMode Then 
				
				If AutoSession.ThisPosting.CanSubmit OR AutoSession.ThisPosting.CanApprove Then
					Call GenerateSeparator(bOwePreviousGroupSeparator)
				End If
				
				If AutoSession.ThisPosting.CanSubmit Then 
					bOwePreviousGroupSeparator = True %>
					<option value="Submit">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_SUBMIT %>
<% 
				End If
				
				If AutoSession.ThisPosting.CanApprove Then 
					bOwePreviousGroupSeparator = True%>
					<option value="Approve">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_APPROVE %> 
					<option value="Decline">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_DECLINE %> 
<% 
				End If
				
			End If
		
			' -- 6) Page details
			If IsEditSiteMode Then 
				Call GenerateSeparator(bOwePreviousGroupSeparator)
				bOwePreviousGroupSeparator = True 
%>
				<option value="Page Properties/Schedule">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_PAGE_PROPERTIES %>
<%  
				If AutoSession.UserCanAuthor Then 
%>
					<option value="Revision History">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_REVISION_HISTORY %> 
					<option value="View Revisions by Date">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_VIEW_REVISION_BY_DATE %>
<%
				End If
			End If
	
			' -- 7) Channel Properties link
			If AutoSession.ThisChannel.CanSetProperties Then 
				Call GenerateSeparator(bOwePreviousGroupSeparator)
%>
				<option value="Channel Properties/Schedule">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_CHANNEL_PROPERTIES %>
<%
				
			End If
	
		ElseIf AreAuthCmdsVisible() Then

			bOwePreviousGroupSeparator = True
%>
			<option value="AuthPreview">&nbsp;&nbsp;<%=IDS_UI_CONSOLE_PREVIEW%>
<%
	
			If IsAuthPreviewConnectedPageVisible Then 
%>
				<option value="Preview Connected Page">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_PREVIEW_CONNECTED %>
<%
			End If
			Call GenerateSeparator(bOwePreviousGroupSeparator)
%>
			<option value="AuthSave">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_SAVE %>
			<option value="AuthSaveAndExit">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_SAVEANDEXIT %>
			<option value="AuthCancel">&nbsp;&nbsp;<%= IDS_UI_CONSOLE_EXIT %> 
<%
			
		End If 
%>
		</select>
<%
		If GenerateFormTag Then
%>	
			</form>
<%
		End If
		
	End If	' If IsWBCVisible

End Sub

' -----------------------------------------------------------------------------
' 
'	[Public] JavaScript handler function for the droplist console
'
' -----------------------------------------------------------------------------
Sub GenerateJavascriptHandler()
%>
	<script language="JavaScript" type="text/javascript">
	<!--
		
		function WBC_OnSelectWBCLink()
		{
			var lFormsMax = document.forms.length - 1;
			var lIndex = 0;
			var pWBCDropList = null;

			// search for our WBC_selDroplistConsole
			for (lIndex = 0; !pWBCDropList && lIndex <= lFormsMax; lIndex++)
			{
					pWBCDropList = document.forms[lIndex].WBC_selDroplistConsole
			}
			if (!pWBCDropList)
			{
				alert("Failed to retrieve WBC Droplist!");
				return;
			}

			var strTarget

		
			strTarget = pWBCDropList.options[pWBCDropList.selectedIndex].value
			switch (strTarget)
			{
<%	If AreTaskAssistantsVisible() Then %>			
				case "Production Manager":
					WBC_openWindowOnFocus("<%= GetProductionManagerURL() %>", IDS_WIN_PRODUCTIONMANAGER_NAME, WBC_getPoppedUpWindowFeatures(IDS_WIN_PRODUCTIONMANAGER_FEATURES, window.top));
					break;
				case "ApprovalAssistant":
					WBC_openWindowOnFocus("<%= GetApprovalAssistantURL() %>", IDS_WIN_APPROVALASSISTANT_NAME, WBC_getPoppedUpWindowFeatures(IDS_WIN_APPROVALASSISTANT_FEATURES, window.top));
					break;
<%	End If
	If IsNewPostingLinkVisible() Then %>
				case "Create Page in Channel":
					WBC_openWindowOnFocus("<%=GetCreateSimplePostingDlgURL()%>", IDS_WINNAME_PAGE_CREATION, WBC_getPoppedUpWindowFeatures(IDS_WINFEATURES_PAGE_CREATION, window.top));
					break;	
<%	End If
	If IsNewConnectedPostingLinkVisible Then %>
				case "Create Connected Page":
					WBC_openWindowOnFocus("<%= GetCreateConnectedPostingDlgURL() %>", IDS_WINNAME_PAGE_CREATION , WBC_getPoppedUpWindowFeatures(IDS_WINFEATURES_PAGE_CREATION, window.top)); 
					break;	
<%	End If		
	If IsConnectedPagesJumpLinkVisible Then %>
				case "Go To Connected Page":
					WBC_openWindowOnFocus("<%= GetConnectedPostingQuickJumpUrl() %>", IDS_WIN_GOTO_CONNECTED_SELECTION, WBC_getPoppedUpWindowFeatures(IDS_WIN_GOTO_CONNECTED_SELECTION_FEATURES, window.top));
					break;
<%	End If
	If AreEditSiteOpsVisible() And AutoSession.ThisChannel.CanSetProperties Then %>
				case "Channel Properties/Schedule":
					window.open("<%=GetChannelPropertiesUrl()%>", IDS_WIN_PAGEPROPS_NAME, IDS_WIN_PAGEPROPS_FEATURES);
					break;

<%	End If
	If IsResourceManagerLinkVisible() Then %>
				case "Resource Management":
					WBC_openWindowOnFocus('<%= GetResourceManagerURL() %>', IDS_WIN_RESOURCE_MANAGEMENT_NAME, WBC_getPoppedUpWindowFeatures(IDS_WIN_RESOURCE_MANAGEMENT_FEATURES, window.top));
					break;
<%	End If 
	If AreEditSiteOpsVisible() Then %>
				case "Preview":
					WBC_openWindowOnFocus("<%=GetPreviewUrl(GetCurrentObject())%>", IDS_WIN_PREVIEW, WBC_getPoppedUpWindowFeatures(IDS_WIN_PREVIEW_FEATURES, window.top));
					break;
<%
		If Not AutoSession.ThisPosting Is Nothing Then 
			If AutoSession.ThisPosting.CanSetProperties Then %>
				case "Edit":
					window.top.location = "<%=GetAuthoringUrl(AutoSession.ThisPosting)%>";
					break;
<%			End If 
			If IsMoveLinkVisible() Then %>
				case "Move":
					WBC_openWindowOnFocus('<%= GetPostingMoveUrl() %>', IDS_WIN_PAGEMOVEDLG_NAME, IDS_WIN_PAGEMOVEDLG_FEATURES);
					break;
<%			End If %>

				case "Copy":
					WBC_openWindowOnFocus('<%= GetPostingCopyUrl() %>', IDS_WIN_PAGECOPYDLG_NAME, IDS_WIN_PAGECOPYDLG_FEATURES);
					break;
<%
			If AutoSession.ThisPosting.CanDelete Then %>
				case "Delete":
					window.top.location = "<%=GetDeleteUrl%>";
					break;
<%			End If 
			If AutoSession.UserCanAuthor Then %>
				case "Revision History":
					WBC_openWindowOnFocus('<%=GetPageRevisionReportUrl()%>', IDS_WIN_PAGEREVISION_NAME, WBC_getPoppedUpWindowFeatures(IDS_WIN_PAGEREVISION_FEATURES, window.top));
					break;
				
				case "View Revisions by Date":
					WBC_openWindowOnFocus('<%=GetPageRevisionByDateUrl()%>', IDS_WIN_PAGEREVISION_BY_DATE_NAME, IDS_WIN_PAGEREVISION_BY_DATE_FEATURES);
					break;
<%			End If %>

				case "Page Properties/Schedule":
					window.open("<%=GetPropertiesUrl()%>", IDS_WIN_PAGEPROPS_NAME, IDS_WIN_PAGEPROPS_FEATURES);
					break;
<%			If AutoSession.ThisPosting.CanSubmit Then %>
				case "Submit":
					window.top.location = "<%=GetSubmitUrl%>";
					break;
<%			End If 
			If AutoSession.ThisPosting.CanApprove Then %>
				case "Approve":
					window.top.location = "<%=GetApproveUrl%>";
					break;
				case "Decline":
					window.top.location = "<%=GetDeclineUrl%>";
					break;
<%			End If
		End If 
	ElseIf AreAuthCmdsVisible() Then 
%>				
				case "AuthPreview":
					WBC_onAuthPreview(<%=Bool2LCaseStr(AreAuthCmdsFunctional)%>);
					break;
<%		If IsAuthPreviewConnectedPageVisible Then %>
				case "Preview Connected Page":
					WBC_openWindowOnFocus("<%=GetAuthPreviewConnectedDlgURL()%>", IDS_WIN_AUTHPREVIEW_CONNECTED_SELECTION_NAME, WBC_getPoppedUpWindowFeatures(IDS_WIN_AUTHPREVIEW_CONNECTED_SELECTION_FEATURES, window.top));
					break;
<%		End If %>
				case "AuthSave":
					WBC_onAuthSave(<%=Bool2LCaseStr(AreAuthCmdsFunctional)%>, '<%=GetAuthSaveURL%>', IDS_ACTION_SAVE);
					break;
				case "AuthSaveAndExit":
					WBC_onAuthSave(<%=Bool2LCaseStr(AreAuthCmdsFunctional)%>, '<%=GetAuthSaveAndExitURL%>', IDS_ACTION_SAVEANDEXIT);
					break;
				case "AuthCancel":
					WBC_onAuthCancel(<%=Bool2LCaseStr(AreAuthCmdsFunctional)%>, '<%=GetAuthCancelURL()%>');
					break;
<%	End If %>
			}

			// reset drop list to select 1st item
			pWBCDropList.selectedIndex = 0;
		}
	// -->
	</script>

<%
End Sub

' -----------------------------------------------------------------------------
' 
'	[Public] This subroutine is supplied for backward compatibility with the 
'			pre-4.0 release of Content Management Server.
'
' -----------------------------------------------------------------------------
Sub EmbedDropDownEditSiteConsole()
 	Call EmbedDroplistConsole()
End Sub

%>