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

using System;
using CommunityServer.Components;
using CommunityServer.ControlPanel.UI;
using ComponentArt.Web.UI;
using CA = ComponentArt.Web.UI;
using ResourceManager = CommunityServer.ControlPanel.Components.ResourceManager;

namespace CommunityServer.ControlPanel.Tools
{
	/// <summary>
	/// Summary description for EventLogViewer.
	/// </summary>
	public class EventLogViewer : BaseToolsPage
	{
		protected CommunityServer.ControlPanel.Controls.ResourceControl RegionTitle;
		protected CommunityServer.Controls.MPContent DescriptionRegion;
		protected CommunityServer.Controls.Modal Modal1;
		protected CommunityServer.Controls.MPContent TaskRegion;
		protected CommunityServer.Controls.MPContainer MPContainer;
		protected CA.Grid Grid1;

		#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
		
		private void Page_Load(object sender, EventArgs e)
		{
			ConfigureGridSearchBox();
			if (!Page.IsPostBack)
				Bind();
		}

		/// <summary>
		/// this is an excerpt from the base grid control and should be removed if this page derrives from it in the future
		/// </summary>
		private void ConfigureGridSearchBox()
		{
			Grid1.ShowHeader = true;

			//This code along with no GroupBy is required to show the header but disable grouping
			Grid1.GroupByCssClass = "disabled";
			Grid1.GroupByTextCssClass = "disabled";
			Grid1.GroupingNotificationTextCssClass = "disabled";
			Grid1.Levels[0].AllowGrouping = false;

			
			Grid1.ShowSearchBox = true;
			Grid1.SearchTextCssClass="GridHeaderText"; 
			Grid1.SearchOnKeyPress=true; 
		}


		private void Bind()
		{
			Grid1.DataSource = CommonDataProvider.Instance().GetEventLogEntries();
			Grid1.DataBind();

			//Taken from the BaseGridControl Helper function - In the future this page should inherit from that base class
			foreach(CA.GridColumn gc in Grid1.Levels[0].Columns)
			{
				if(gc.Visible)
				{
					gc.SortedDataCellCssClass = "SortedDataCell";
					//Allows for mock resource manager calls in heading text
					//eg HeadingText="ResourceManager.CP_Photos_GridCol_Name"
					if(gc.HeadingText.StartsWith("ResourceManager."))
						gc.HeadingText = ResourceManager.GetString(gc.HeadingText.Replace("ResourceManager.",""));
			
				}
			}
		}
	}
}
