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

using System;
using System.Web.UI.WebControls;
using CommunityServer.ControlPanel.Controls;
using CommunityServer.ControlPanel.UI;
using CommunityServer.Controls;
using CommunityServer.Galleries;
using CommunityServer.Galleries.Components;
using FormLabel = CommunityServer.ControlPanel.Controls.FormLabel;
using ResourceControl = CommunityServer.ControlPanel.Controls.ResourceControl;
using HelpIcon = CommunityServer.ControlPanel.Controls.HelpIcon;
using ResourceLinkButton = CommunityServer.ControlPanel.Controls.ResourceLinkButton;


namespace CommunityServerWeb.ControlPanel.Photos.Options
{
	/// <summary>
	/// Summary description for CategorizationOptions.
	/// </summary>
	public class CategorizationOptions : BaseGalleryPage
	{
		#region Child Controls

		protected ResourceLinkButton SaveButton;
		protected DropDownList CategorizeBy;

		#endregion
	
		private void Page_Load(object sender, EventArgs e)
		{
			if(!IsPostBack)
			{
				CategorizeBy.Items.Add(new ListItem(CommunityServer.ControlPanel.Components.ResourceManager.GetString("CP_Photos_CategorizationOptions_CategorizeByTags"), ((int) CategorizationType.Tag).ToString()));
				CategorizeBy.Items.Add(new ListItem(CommunityServer.ControlPanel.Components.ResourceManager.GetString("CP_Photos_CategorizationOptions_CategorizeByAlbums"), ((int) CategorizationType.Album).ToString()));

				CategorizeBy.SelectedValue = ((int) this.CurrentGallery.CategorizationType).ToString();
			}
		}

		#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);
			this.SaveButton.Click += new EventHandler(SaveButton_Click);
		}
		
		/// <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 EventHandler(this.Page_Load);

		}
		#endregion

		private void SaveButton_Click(object sender, EventArgs e)
		{
			if(Page.IsValid)
			{
				CurrentGallery.CategorizationType = (CategorizationType) int.Parse(CategorizeBy.SelectedValue);

				CommunityServer.Galleries.Galleries.Update(CurrentGallery);

				// need to redirect so the NavBar gets updated...
				Response.Redirect(Request.Url.ToString());
			}
		}
	}
}
