//------------------------------------------------------------------------------
// <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;

namespace CommunityServer.ControlPanel.Controls
{
	/// <summary>
	/// Summary description for ControlPanelChangeManageView.
	/// </summary>
	public class ControlPanelChangeManageView : LinkButton
	{
		CSContext csContext;

		ControlPanelManageView currentView;
		public ControlPanelManageView CurrentView
		{
			get { return currentView; }
			set { currentView = value; }
		}

		string viewChangeUrl = "~/ControlPanel/Setup.aspx";
		public string ViewChangeUrl
		{
			get { return viewChangeUrl; }
			set { viewChangeUrl = value; }
		}

		public ControlPanelChangeManageView() : base()
		{
			csContext = CSContext.Current;
			currentView = csContext.User.ControlPanelManageView;
		}
	
		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);
			this.Click += new EventHandler(OnClick);
		}

		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad (e);
			if (CurrentView == ControlPanelManageView.Grid)
				this.Text = CommunityServer.ControlPanel.Components.ResourceManager.GetString("CP_ControlPanelChangeManageView_ChangeToTree");
			else
				this.Text = CommunityServer.ControlPanel.Components.ResourceManager.GetString("CP_ControlPanelChangeManageView_ChangeToGrid");				
		}

		private void OnClick(object sender, System.EventArgs e)
		{
			if (CurrentView == ControlPanelManageView.Grid)
				csContext.User.ControlPanelManageView = ControlPanelManageView.Tree;
			else
				csContext.User.ControlPanelManageView = ControlPanelManageView.Grid;

			Users.UpdateUser(csContext.User);
			Page.Response.Redirect(ViewChangeUrl);
		}
	}
}
