//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using CommunityServer.Blogs.Components;
using CommunityServer.Blogs.Controls;
using CommunityServer.Components;
using CommunityServer.ControlPanel.Controls;
using CommunityServer.ControlPanel.UI;
using CommunityServer.Controls;
using ResourceControl = CommunityServer.ControlPanel.Controls.ResourceControl;
using ResourceLinkButton = CommunityServer.ControlPanel.Controls.ResourceLinkButton;
using ResourceManager = CommunityServer.ControlPanel.Components.ResourceManager;

namespace CommunityServer.ControlPanel.Blogs
{

	public class PostOptionsPage : BaseBlogPage
	{

		#region Child Controls

        protected DropDownList ExpiredDays;
        protected ResourceLinkButton SaveButton;
		protected ConfigOKStatusMessage Status;
        protected YesNoRadioButtonList ynEnableAnonymousReplies;
        protected YesNoRadioButtonList ynEnableRepliesOverride;
        protected YesNoRadioButtonList ynEnableRatingsOverride;
        protected YesNoRadioButtonList ynEnableTrackbacksOverride;
		protected YesNoRadioButtonList ynEnableCrossPostingDefault;
		protected CommentModerationDropDownList ModerationDDLOverride;
		protected ControlPanelSelectedNavigation SelectedNavigation1;

		#endregion

		override protected void OnInit(EventArgs e)
		{
			this.SaveButton.Click += new EventHandler(this.SaveButton_Click);
			this.Load += new EventHandler(this.Page_Load);
			base.OnInit(e);
		}

		private void Page_Load(object sender, EventArgs e)
		{
            if(!IsPostBack)
            {

                ynEnableRepliesOverride.SelectedValue = CurrentWeblog.EnableCommentsOverride;
                ynEnableRatingsOverride.SelectedValue = CurrentWeblog.EnableRatingsOverride;
                ynEnableTrackbacksOverride.SelectedValue = CurrentWeblog.EnableTrackbacksOverride;
                ynEnableAnonymousReplies.SelectedValue = CurrentWeblog.EnableAnonymousPosting;

                ListItem li = ModerationDDLOverride.Items.FindByValue(CurrentWeblog.ModerationTypeOverride.ToString());
                if(li != null)
                    li.Selected = true;

				ExpiredDays.Items.Add(new ListItem(Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Always"), "999999"));
				ExpiredDays.Items.Add(new ListItem("90 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "90"));
				ExpiredDays.Items.Add(new ListItem("60 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "60"));
				ExpiredDays.Items.Add(new ListItem("30 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "30"));
				ExpiredDays.Items.Add(new ListItem("14 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "14"));
				ExpiredDays.Items.Add(new ListItem("7 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "7"));
				ExpiredDays.Items.Add(new ListItem("6 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "6"));
				ExpiredDays.Items.Add(new ListItem("5 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "5"));
				ExpiredDays.Items.Add(new ListItem("4 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "4"));
				ExpiredDays.Items.Add(new ListItem("3 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "3"));
				ExpiredDays.Items.Add(new ListItem("2 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "2"));
				ExpiredDays.Items.Add(new ListItem("1 " + Components.ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_Days"), "1"));
				ExpiredDays.Items.Add(new ListItem(ResourceManager.GetString("CP_Blogs_PostOptions_ExpiredDays_DisableNewComments"), "0"));
                li = ExpiredDays.Items.FindByValue(CurrentWeblog.CommentExpirationDays.ToString());
                if(li != null)
                    li.Selected = true;

            }
		}

		private void SaveButton_Click(object sender, EventArgs e)
        {
            if(Page.IsValid)
            {

                CurrentWeblog.EnableCommentsOverride = ynEnableRepliesOverride.SelectedValue;
                CurrentWeblog.EnableRatingsOverride = ynEnableRatingsOverride.SelectedValue;
                CurrentWeblog.EnableTrackbacksOverride = ynEnableTrackbacksOverride.SelectedValue;
                CurrentWeblog.EnableAnonymousPosting = ynEnableAnonymousReplies.SelectedValue;
				CurrentWeblog.ModerationTypeOverride = (CommentModerationType)Enum.Parse(typeof(CommentModerationType), ModerationDDLOverride.SelectedValue);
                CurrentWeblog.CommentExpirationDays = Int32.Parse(ExpiredDays.SelectedValue);

            	Weblogs.Update(CurrentWeblog);
				
				Status.Success = true;
				Status.Visible = true;
            }
        }



    }
}
