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

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using CommunityServer.Components;

namespace CommunityServer.Controls
{
	/// <summary>
	/// Summary description for LiteralOrLink.
	/// </summary>
	public class LiteralOrLink : HyperLink, IText
	{
		public LiteralOrLink()
		{
			//
			// TODO: Add constructor logic here
			//
		}

        public Control Control
        {
            get{ return this;}
        }

        private bool _textOnly = false;

        public bool TextOnly
        {
            get{return _textOnly;}
            set{_textOnly = value;}
        }

        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            if(TextOnly || Globals.IsNullorEmpty(this.NavigateUrl))
            {
                writer.Write(this.Text);   
            }
            else
            {
                base.Render (writer);
            }
        }

	}

	public class EditableLink : LiteralOrLink
	{

		protected bool CanUserEdit
		{
			get{ return CSContext.Current.User.IsAdministrator;}
		}


		private string _updateFunction = null;
		public string AjaxFunction
		{
			get{ return _updateFunction;}
			set{_updateFunction = value;}
		}

		private string _ajaxID = null;
		public string AjaxClientID
		{
			get{return _ajaxID;}
			set{_ajaxID = value;}
		}



		protected override void Render(HtmlTextWriter writer)
		{
			bool enableEdit = CanUserEdit && !Globals.IsNullorEmpty(this.AjaxFunction);

			if(enableEdit)
			{
				this.NavigateUrl = null;
				InlineEditorHelper.RenderStartInLine(HtmlTextWriterTag.Div, writer,this.AjaxClientID,this.AjaxFunction);
			}
			base.Render (writer);

			if(enableEdit)
				InlineEditorHelper.RenderEndInLine(HtmlTextWriterTag.Div, writer);
		}

	}
}
