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

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

namespace CommunityServer.ControlPanel.Blogs
{
	/// <summary>
	/// Summary description for PostEditorPage.
	/// </summary>
	public class DescriptiveOptionsPage : BaseBlogPage
	{
        protected RequiredFieldValidator TitleValidator;
        protected TextBox Title;
        protected TextBox Description;
        protected TextBox News;
		protected TextBox MetaTagDescription;
		protected TextBox MetaTagKeywords;
		protected TextBox RawHTMLHeader;
		protected PlaceHolder RawHTMLPanel;
		protected ResourceLinkButton SaveButton;
		protected ConfigOKStatusMessage Status;
	
		private void Page_Load(object sender, EventArgs e)
		{
			if(!IsPostBack)
			{
				TitleValidator.Text = ResourceManager.GetString("CP_Blogs_DescOptions_BlogTitle_Required");
			    Title.Text = this.CurrentWeblog.Name;
                Description.Text = this.CurrentWeblog.Description;
                News.Text = this.CurrentWeblog.News;
				MetaTagDescription.Text = this.CurrentWeblog.MetaTagDescription;
				MetaTagKeywords.Text = this.CurrentWeblog.MetaTagKeywords;

				if (WeblogConfiguration.Instance().EnableRawHeadEditing)
					RawHTMLHeader.Text = this.CurrentWeblog.RawAdditionalHeader;
				else
					RawHTMLPanel.Visible = false;
			}
		}

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

        private void SaveButton_Click(object sender, EventArgs e)
        {
            if(Page.IsValid)
            {
                CurrentWeblog.Name = Title.Text;
                CurrentWeblog.Description = Description.Text;
                CurrentWeblog.News = News.Text;
				CurrentWeblog.MetaTagDescription = Transforms.StripHtmlXmlTags(MetaTagDescription.Text);
				CurrentWeblog.MetaTagKeywords = Transforms.StripHtmlXmlTags(MetaTagKeywords.Text);
				
				if (WeblogConfiguration.Instance().EnableRawHeadEditing)
					CurrentWeblog.RawAdditionalHeader = RawHTMLHeader.Text;

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