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

using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using CommunityServer.Controls;
using CommunityServer.Galleries.Components;
using CommunityServer.Galleries.Controls;

namespace CommunityServer.ControlPanel.Controls.Galleries
{
	/// <summary>
	///		Summary description for SkinOptionsLayoutControl.
	/// </summary>
	public class SkinOptionsLayoutControl : UserControl
	{

		#region Public Properties

		public Gallery Gallery
		{
			get{return gallery;}
			set{gallery = value;}
		}

		#endregion

		#region Child Controls

		protected HtmlTableRow AlbumListingArrangement, AlbumSortOption;
		
		protected HelpIcon Helpicon2;
		protected FormLabel Formlabel2;
		protected FormLabel Formlabel3;
		protected TextBox CategoryListingColumns;
		protected RegularExpressionValidator Regularexpressionvalidator1;
		protected RequiredFieldValidator Requiredfieldvalidator1;
		protected FormLabel Formlabel4;
		protected TextBox CategoryListingRows;
		protected RegularExpressionValidator Regularexpressionvalidator2;
		protected RequiredFieldValidator Requiredfieldvalidator2;
		protected HelpIcon Helpicon3;
		protected FormLabel Formlabel8;
		protected FormLabel Formlabel5;
		protected TextBox PictureListingColumns;
		protected RegularExpressionValidator Regularexpressionvalidator3;
		protected RequiredFieldValidator Requiredfieldvalidator3;
		protected FormLabel Formlabel6;
		protected TextBox PictureListingRows;
		protected RegularExpressionValidator Regularexpressionvalidator4;
		protected RequiredFieldValidator Requiredfieldvalidator4;
		protected HelpIcon Helpicon4;
		protected FormLabel Formlabel7;
		protected GalleryThreadSortDropDownList PicturesSortBy;
		protected PostCategoriesSortDropDownList AlbumsSortBy;
		protected CommunityServer.ControlPanel.Controls.HelpIcon Helpicon1;
		protected CommunityServer.ControlPanel.Controls.FormLabel Formlabel1;
		protected CommunityServer.ControlPanel.Controls.StatusMessage Status;
		protected System.Web.UI.HtmlControls.HtmlTable SkinOptions;

		#endregion
		
		private Gallery gallery;


		private void Page_Load(object sender, EventArgs e)
		{
			if(GalleryConfiguration.Instance().EnableThemes)
			{
				if(!IsPostBack && Gallery != null)
				{
					CategoryListingColumns.Text = Gallery.CategoryListingColumns.ToString();
					CategoryListingRows.Text = Gallery.CategoryListingRows.ToString();
					PictureListingColumns.Text = Gallery.PictureListingColumns.ToString();
					PictureListingRows.Text = Gallery.PictureListingRows.ToString();
					PicturesSortBy.GenerateList(Gallery);
					AlbumsSortBy.GenerateList() ;
					PicturesSortBy.SelectedSortByValue = Gallery.ThreadSortBy;
					PicturesSortBy.SelectedSortOrderValue = Gallery.ThreadSortOrder;
					AlbumsSortBy.SelectedSortByValue = Gallery.CategorySortBy;

					if (Gallery.CategorizationType != CategorizationType.Album)
					{
						AlbumListingArrangement.Visible = false;
						AlbumSortOption.Visible = false;
					}
				}
			}
			else
			{
				SkinOptions.Visible = false;
				Status.Success = false;
				Status.Visible = true;
				Status.ResourceName = "CP_Photos_SkinOptions_ThemesDisabed";
			}

		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		public void GetFormValues(Gallery g)
		{
			if(GalleryConfiguration.Instance().EnableThemes)
			{
				g.CategoryListingColumns = int.Parse(CategoryListingColumns.Text);
				g.CategoryListingRows = int.Parse(CategoryListingRows.Text);
				g.PictureListingColumns = int.Parse(PictureListingColumns.Text);
				g.PictureListingRows = int.Parse(PictureListingRows.Text);
				g.ThreadSortBy = PicturesSortBy.SelectedSortByValue;
				g.ThreadSortOrder = PicturesSortBy.SelectedSortOrderValue;
				g.CategorySortBy = AlbumsSortBy.SelectedSortByValue;
			}
		}


	}
}
