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

using System;
using System.Web.UI.WebControls;
using CommunityServer.Blogs.Components;
using CommunityServer.Components;
using CommunityServer.ControlPanel.UI;
using CommunityServer.ControlPanel.Controls;
using ResourceManager = CommunityServer.ControlPanel.Components.ResourceManager;
using StatusMessage = CommunityServer.ControlPanel.Controls.StatusMessage;

namespace CommunityServer.ControlPanel.Blogs
{
	/// <summary>
	/// Summary description for PostEditorPage.
	/// </summary>
	public class GeneralOptionsPage : BaseBlogPage
	{

		#region Child Controls

		protected CommunityServer.ControlPanel.Controls.ConfigOKStatusMessage Status;
		protected TextBox Email;
        protected CheckBox EnableContact;
        protected ResourceLinkButton SaveButton;
        protected RequiredFieldValidator EmailValidator;
		protected CheckBox BlockSpamFeedbackNotifications;
		protected TextBox ModerationNotificationThreshold;

		#endregion

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

		private void Page_Load(object sender, EventArgs e)
		{
			if(!IsPostBack)
			{
				EmailValidator.Text = ResourceManager.GetString("CP_Blogs_GeneralOptions_AdminEmail_Required");

				Email.Text = this.CurrentWeblog.Email;
				EnableContact.Checked = this.CurrentWeblog.EnableContact;
				BlockSpamFeedbackNotifications.Checked = CurrentWeblog.BlockSpamFeedbackNotifications;
				ModerationNotificationThreshold.Text = CurrentWeblog.ModeratedFeedbackNotificationThreshold.ToString();
			}
		}

        private void SaveButton_Click(object sender, EventArgs e)
        {
            if(Page.IsValid)
            {
				CurrentWeblog.Email = Email.Text;
				CurrentWeblog.EnableContact = EnableContact.Checked;
				CurrentWeblog.BlockSpamFeedbackNotifications = BlockSpamFeedbackNotifications.Checked;
				CurrentWeblog.ModeratedFeedbackNotificationThreshold = Int32.Parse(ModerationNotificationThreshold.Text.Trim());

				Weblogs.Update(CurrentWeblog);

				Status.Success = true;
				Status.Visible = true;
            }
        }
	}
}
