Imports Plumtree.Remote.Portlet
Imports Plumtree.Remote.PRC
Imports Plumtree.Remote.PRC.Collaboration
Imports Plumtree.Remote.PRC.Collaboration.Discussion
Imports Plumtree.Remote.PRC.Collaboration.Project


Public Class DiscussionMessage
  Inherits discussion

#Region " Web Form Designer Generated Code "

  'This call is required by the Web Form Designer.
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

  End Sub
  Protected WithEvents DiscussionMessageMethodDropDownList As System.Web.UI.WebControls.DropDownList
  Protected WithEvents SelectGoButton As System.Web.UI.WebControls.Button
  Protected WithEvents SubjectBox As System.Web.UI.WebControls.TextBox
  Protected WithEvents BodyBox As System.Web.UI.WebControls.TextBox

  Protected WithEvents CreateSubmitButton As System.Web.UI.WebControls.Button
  Protected WithEvents DiscussionMessageIDBox As System.Web.UI.WebControls.TextBox
  Protected WithEvents RemoveSubmitButton As System.Web.UI.WebControls.Button

  'NOTE: The following placeholder declaration is required by the Web Form Designer.
  'Do not delete or move it.
  Private designerPlaceholderDeclaration As System.Object

  Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
  End Sub

#End Region
  'booleans for create, remove search
  Public createDiscussionMessage As Boolean = False
  Public removeDiscussionMessage As Boolean = False
  Public Shadows searchDiscussionMessages As Boolean = False

  'global discussion variable for us to get details and create discussion messages
  Public discussion As IDiscussion = Nothing

  'subject and body for create
  Public subject As String = Nothing
  Public body As String = Nothing

  'discussion message id required for remove discussion message
  Public discussionMessageIDStr As String = Nothing
  Public discussionMessageID As Integer = -1
  Public Sub New()
    AddHandler Page.Init, AddressOf Page_Init
  End Sub
  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'we should be getting the discussion id from the query string from Discussion.aspx
    'put it in session if it exists
    Dim discussionIDStr As String = Request.QueryString.Get(SESSION_DISCUSSION_KEY)
    If Not discussionIDStr Is Nothing Then
      'get the discussion and put it into the session
      Dim discussionID As Integer = Convert.ToInt32(discussionIDStr)
      Dim discussionManager As IDiscussionManager = GetDiscussionManager(Request, Response)
      discussion = discussionManager.GetDiscussion(discussionID)
      Session.Add(SESSION_DISCUSSION_KEY, discussion)
    Else
      'assume that it has already been put in. No error checking for session timeouts. 
      discussion = CType(Session.Item(SESSION_DISCUSSION_KEY), IDiscussion)
    End If

    'set hosted display mode
    Dim portletContext As IPortletContext = PortletContextFactory.CreatePortletContext(Request, Response)
    Dim portletResponse As IPortletResponse = portletContext.GetResponse
    portletResponse.SetHostedDisplayMode(HostedDisplayMode.Hosted)



  End Sub
  Private Sub CreateSubmitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateSubmitButton.Click
    subject = SubjectBox.Text
    body = BodyBox.Text
    createDiscussionMessage = True
    DiscussionMessageMethodDropDownList.SelectedValue = "createMessage"
  End Sub
  Private Sub RemoveSubmitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveSubmitButton.Click
    discussionMessageIDStr = DiscussionMessageIDBox.Text
    discussionMessageID = Int32.Parse(discussionMessageIDStr)
    removeDiscussionMessage = True
    DiscussionMessageMethodDropDownList.SelectedValue = "removeMessage"

  End Sub
  Private Sub SelectGoButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectGoButton.Click
    'retrieve values from submit
    'determine which value, if any, was chosen in the select
    Dim selectStr As String = DiscussionMessageMethodDropDownList.SelectedValue
    If Not selectStr Is Nothing Then
      If (selectStr.Equals("createMessage")) Then
        createDiscussionMessage = True
      ElseIf (selectStr.Equals("removeMessage")) Then
        removeDiscussionMessage = True
      ElseIf (selectStr.Equals("searchMessages")) Then
        searchDiscussionMessages = True
      End If
    End If
  End Sub

End Class
