Initial project's source code check-in.
This commit is contained in:
commit
b03b0b373f
4573 changed files with 981205 additions and 0 deletions
|
@ -0,0 +1,453 @@
|
|||
// Material sourced from the bluePortal project (http://blueportal.codeplex.com).
|
||||
// Licensed under the Microsoft Public License (available at http://www.opensource.org/licenses/ms-pl.html).
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Collections;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
namespace CSSFriendly
|
||||
{
|
||||
public class ChangePasswordAdapter : System.Web.UI.WebControls.Adapters.WebControlAdapter
|
||||
{
|
||||
private enum State {
|
||||
ChangePassword,
|
||||
Failed,
|
||||
Success,
|
||||
}
|
||||
State _state = State.ChangePassword;
|
||||
|
||||
private WebControlAdapterExtender _extender = null;
|
||||
private WebControlAdapterExtender Extender
|
||||
{
|
||||
get
|
||||
{
|
||||
if (((_extender == null) && (Control != null)) ||
|
||||
((_extender != null) && (Control != _extender.AdaptedControl)))
|
||||
{
|
||||
_extender = new WebControlAdapterExtender(Control);
|
||||
}
|
||||
|
||||
System.Diagnostics.Debug.Assert(_extender != null, "CSS Friendly adapters internal error", "Null extender instance");
|
||||
return _extender;
|
||||
}
|
||||
}
|
||||
|
||||
public ChangePasswordAdapter()
|
||||
{
|
||||
_state = State.ChangePassword;
|
||||
}
|
||||
|
||||
/// ///////////////////////////////////////////////////////////////////////////////
|
||||
/// PROTECTED
|
||||
|
||||
protected override void OnInit(EventArgs e)
|
||||
{
|
||||
base.OnInit(e);
|
||||
|
||||
ChangePassword changePwd = Control as ChangePassword;
|
||||
if (Extender.AdapterEnabled && (changePwd != null))
|
||||
{
|
||||
RegisterScripts();
|
||||
changePwd.ChangedPassword += OnChangedPassword;
|
||||
changePwd.ChangePasswordError += OnChangePasswordError;
|
||||
_state = State.ChangePassword;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CreateChildControls()
|
||||
{
|
||||
base.CreateChildControls();
|
||||
|
||||
ChangePassword changePwd = Control as ChangePassword;
|
||||
if (changePwd != null)
|
||||
{
|
||||
if (changePwd.ChangePasswordTemplate != null)
|
||||
{
|
||||
changePwd.ChangePasswordTemplateContainer.Controls.Clear();
|
||||
changePwd.ChangePasswordTemplate.InstantiateIn(changePwd.ChangePasswordTemplateContainer);
|
||||
changePwd.ChangePasswordTemplateContainer.DataBind();
|
||||
}
|
||||
|
||||
if (changePwd.SuccessTemplate != null)
|
||||
{
|
||||
changePwd.SuccessTemplateContainer.Controls.Clear();
|
||||
changePwd.SuccessTemplate.InstantiateIn(changePwd.SuccessTemplateContainer);
|
||||
changePwd.SuccessTemplateContainer.DataBind();
|
||||
}
|
||||
|
||||
changePwd.Controls.Add(new ChangePasswordCommandBubbler());
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnChangedPassword(object sender, EventArgs e)
|
||||
{
|
||||
_state = State.Success;
|
||||
}
|
||||
|
||||
protected void OnChangePasswordError(object sender, EventArgs e)
|
||||
{
|
||||
if (_state != State.Success)
|
||||
{
|
||||
_state = State.Failed;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderBeginTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
Extender.RenderBeginTag(writer, "AspNet-ChangePassword");
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderBeginTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderEndTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
Extender.RenderEndTag(writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderEndTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderContents(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
ChangePassword changePwd = Control as ChangePassword;
|
||||
if (changePwd != null)
|
||||
{
|
||||
if ((_state == State.ChangePassword) || (_state == State.Failed))
|
||||
{
|
||||
if (changePwd.ChangePasswordTemplate != null)
|
||||
{
|
||||
changePwd.ChangePasswordTemplateContainer.RenderControl(writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteChangePasswordTitlePanel(writer, changePwd);
|
||||
WriteInstructionPanel(writer, changePwd);
|
||||
WriteHelpPanel(writer, changePwd);
|
||||
WriteUserPanel(writer, changePwd);
|
||||
WritePasswordPanel(writer, changePwd);
|
||||
WriteNewPasswordPanel(writer, changePwd);
|
||||
WriteConfirmNewPasswordPanel(writer, changePwd);
|
||||
if (_state == State.Failed)
|
||||
{
|
||||
WriteFailurePanel(writer, changePwd);
|
||||
}
|
||||
WriteSubmitPanel(writer, changePwd);
|
||||
WriteCreateUserPanel(writer, changePwd);
|
||||
WritePasswordRecoveryPanel(writer, changePwd);
|
||||
}
|
||||
}
|
||||
else if (_state == State.Success)
|
||||
{
|
||||
if (changePwd.SuccessTemplate != null)
|
||||
{
|
||||
changePwd.SuccessTemplateContainer.RenderControl(writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteSuccessTitlePanel(writer, changePwd);
|
||||
WriteSuccessTextPanel(writer, changePwd);
|
||||
WriteContinuePanel(writer, changePwd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderContents(writer);
|
||||
}
|
||||
}
|
||||
|
||||
/// ///////////////////////////////////////////////////////////////////////////////
|
||||
/// PRIVATE
|
||||
|
||||
private void RegisterScripts()
|
||||
{
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// Step 1: change password
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
private void WriteChangePasswordTitlePanel(HtmlTextWriter writer, ChangePassword changePwd)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(changePwd.ChangePasswordTitleText))
|
||||
{
|
||||
string className = (changePwd.TitleTextStyle != null) && (!String.IsNullOrEmpty(changePwd.TitleTextStyle.CssClass)) ? changePwd.TitleTextStyle.CssClass + " " : "";
|
||||
className += "AspNet-ChangePassword-ChangePasswordTitlePanel";
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, className);
|
||||
WebControlAdapterExtender.WriteSpan(writer, "", changePwd.ChangePasswordTitleText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteInstructionPanel(HtmlTextWriter writer, ChangePassword changePwd)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(changePwd.InstructionText))
|
||||
{
|
||||
string className = (changePwd.InstructionTextStyle != null) && (!String.IsNullOrEmpty(changePwd.InstructionTextStyle.CssClass)) ? changePwd.InstructionTextStyle.CssClass + " " : "";
|
||||
className += "AspNet-ChangePassword-InstructionPanel";
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, className);
|
||||
WebControlAdapterExtender.WriteSpan(writer, "", changePwd.InstructionText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteFailurePanel(HtmlTextWriter writer, ChangePassword changePwd)
|
||||
{
|
||||
string className = (changePwd.FailureTextStyle != null) && (!String.IsNullOrEmpty(changePwd.FailureTextStyle.CssClass)) ? changePwd.FailureTextStyle.CssClass + " " : "";
|
||||
className += "AspNet-ChangePassword-FailurePanel";
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, className);
|
||||
WebControlAdapterExtender.WriteSpan(writer, "", changePwd.ChangePasswordFailureText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
|
||||
private void WriteHelpPanel(HtmlTextWriter writer, ChangePassword changePwd)
|
||||
{
|
||||
if ((!String.IsNullOrEmpty(changePwd.HelpPageIconUrl)) || (!String.IsNullOrEmpty(changePwd.HelpPageText)))
|
||||
{
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-ChangePassword-HelpPanel");
|
||||
WebControlAdapterExtender.WriteImage(writer, changePwd.HelpPageIconUrl, "Help");
|
||||
WebControlAdapterExtender.WriteLink(writer, changePwd.HyperLinkStyle.CssClass, changePwd.HelpPageUrl, "Help", changePwd.HelpPageText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteUserPanel(HtmlTextWriter writer, ChangePassword changePwd)
|
||||
{
|
||||
if (changePwd.DisplayUserName)
|
||||
{
|
||||
TextBox textbox = changePwd.ChangePasswordTemplateContainer.FindControl("UserName") as TextBox;
|
||||
if (textbox != null)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(textbox.UniqueID);
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-ChangePassword-UserPanel");
|
||||
Extender.WriteTextBox(writer, false, changePwd.LabelStyle.CssClass, changePwd.UserNameLabelText, changePwd.TextBoxStyle.CssClass, changePwd.ChangePasswordTemplateContainer.ID + "_UserName", changePwd.UserName);
|
||||
WebControlAdapterExtender.WriteRequiredFieldValidator(writer, changePwd.ChangePasswordTemplateContainer.FindControl("UserNameRequired") as RequiredFieldValidator, changePwd.ValidatorTextStyle.CssClass, "UserName", changePwd.UserNameRequiredErrorMessage);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void WritePasswordPanel(HtmlTextWriter writer, ChangePassword changePwd)
|
||||
{
|
||||
TextBox textbox = changePwd.ChangePasswordTemplateContainer.FindControl("CurrentPassword") as TextBox;
|
||||
if (textbox != null)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(textbox.UniqueID);
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-ChangePassword-PasswordPanel");
|
||||
Extender.WriteTextBox(writer, true, changePwd.LabelStyle.CssClass, changePwd.PasswordLabelText, changePwd.TextBoxStyle.CssClass, changePwd.ChangePasswordTemplateContainer.ID + "_CurrentPassword", "");
|
||||
WebControlAdapterExtender.WriteRequiredFieldValidator(writer, changePwd.ChangePasswordTemplateContainer.FindControl("CurrentPasswordRequired") as RequiredFieldValidator, changePwd.ValidatorTextStyle.CssClass, "CurrentPassword", changePwd.PasswordRequiredErrorMessage);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteNewPasswordPanel(HtmlTextWriter writer, ChangePassword changePwd)
|
||||
{
|
||||
TextBox textbox = changePwd.ChangePasswordTemplateContainer.FindControl("NewPassword") as TextBox;
|
||||
if (textbox != null)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(textbox.UniqueID);
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-ChangePassword-NewPasswordPanel");
|
||||
Extender.WriteTextBox(writer, true, changePwd.LabelStyle.CssClass, changePwd.NewPasswordLabelText, changePwd.TextBoxStyle.CssClass, changePwd.ChangePasswordTemplateContainer.ID + "_NewPassword", "");
|
||||
WebControlAdapterExtender.WriteRequiredFieldValidator(writer, changePwd.ChangePasswordTemplateContainer.FindControl("NewPasswordRequired") as RequiredFieldValidator, changePwd.ValidatorTextStyle.CssClass, "NewPassword", changePwd.NewPasswordRequiredErrorMessage);
|
||||
WebControlAdapterExtender.WriteRegularExpressionValidator(writer, changePwd.ChangePasswordTemplateContainer.FindControl("RegExpValidator") as RegularExpressionValidator, changePwd.ValidatorTextStyle.CssClass, "NewPassword", changePwd.NewPasswordRegularExpressionErrorMessage, changePwd.NewPasswordRegularExpression);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteConfirmNewPasswordPanel(HtmlTextWriter writer, ChangePassword changePwd)
|
||||
{
|
||||
TextBox textbox = changePwd.ChangePasswordTemplateContainer.FindControl("ConfirmNewPassword") as TextBox;
|
||||
if (textbox != null)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(textbox.UniqueID);
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-ChangePassword-ConfirmNewPasswordPanel");
|
||||
Extender.WriteTextBox(writer, true, changePwd.LabelStyle.CssClass, changePwd.ConfirmNewPasswordLabelText, changePwd.TextBoxStyle.CssClass, changePwd.ChangePasswordTemplateContainer.ID + "_ConfirmNewPassword", "");
|
||||
WebControlAdapterExtender.WriteRequiredFieldValidator(writer, changePwd.ChangePasswordTemplateContainer.FindControl("ConfirmNewPasswordRequired") as RequiredFieldValidator, changePwd.ValidatorTextStyle.CssClass, "ConfirmNewPassword", changePwd.ConfirmPasswordRequiredErrorMessage);
|
||||
WebControlAdapterExtender.WriteCompareValidator(writer, changePwd.ChangePasswordTemplateContainer.FindControl("NewPasswordCompare") as CompareValidator, changePwd.ValidatorTextStyle.CssClass, "ConfirmNewPassword", changePwd.ConfirmPasswordCompareErrorMessage, "NewPassword");
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteSubmitPanel(HtmlTextWriter writer, ChangePassword changePwd)
|
||||
{
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-ChangePassword-SubmitPanel");
|
||||
|
||||
string id = "ChangePassword";
|
||||
id += (changePwd.ChangePasswordButtonType == ButtonType.Button) ? "Push" : "";
|
||||
string idWithType = WebControlAdapterExtender.MakeIdWithButtonType(id, changePwd.ChangePasswordButtonType);
|
||||
Control btn = changePwd.ChangePasswordTemplateContainer.FindControl(idWithType);
|
||||
if (btn != null)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(btn.UniqueID);
|
||||
|
||||
PostBackOptions options = new PostBackOptions(btn, "", "", false, false, false, false, true, changePwd.UniqueID);
|
||||
string javascript = "javascript:" + Page.ClientScript.GetPostBackEventReference(options);
|
||||
javascript = Page.Server.HtmlEncode(javascript);
|
||||
|
||||
Extender.WriteSubmit(writer, changePwd.ChangePasswordButtonType, changePwd.ChangePasswordButtonStyle.CssClass, changePwd.ChangePasswordTemplateContainer.ID + "_" + id, changePwd.ChangePasswordButtonImageUrl, javascript, changePwd.ChangePasswordButtonText);
|
||||
}
|
||||
|
||||
id = "Cancel";
|
||||
id += (changePwd.ChangePasswordButtonType == ButtonType.Button) ? "Push" : "";
|
||||
idWithType = WebControlAdapterExtender.MakeIdWithButtonType(id, changePwd.CancelButtonType);
|
||||
btn = changePwd.ChangePasswordTemplateContainer.FindControl(idWithType);
|
||||
if (btn != null)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(btn.UniqueID);
|
||||
Extender.WriteSubmit(writer, changePwd.CancelButtonType, changePwd.CancelButtonStyle.CssClass, changePwd.ChangePasswordTemplateContainer.ID + "_" + id, changePwd.CancelButtonImageUrl, "", changePwd.CancelButtonText);
|
||||
}
|
||||
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
|
||||
private void WriteCreateUserPanel(HtmlTextWriter writer, ChangePassword changePwd)
|
||||
{
|
||||
if ((!String.IsNullOrEmpty(changePwd.CreateUserUrl)) || (!String.IsNullOrEmpty(changePwd.CreateUserText)))
|
||||
{
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-ChangePassword-CreateUserPanel");
|
||||
WebControlAdapterExtender.WriteImage(writer, changePwd.CreateUserIconUrl, "Create user");
|
||||
WebControlAdapterExtender.WriteLink(writer, changePwd.HyperLinkStyle.CssClass, changePwd.CreateUserUrl, "Create user", changePwd.CreateUserText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WritePasswordRecoveryPanel(HtmlTextWriter writer, ChangePassword changePwd)
|
||||
{
|
||||
if ((!String.IsNullOrEmpty(changePwd.PasswordRecoveryUrl)) || (!String.IsNullOrEmpty(changePwd.PasswordRecoveryText)))
|
||||
{
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-ChangePassword-PasswordRecoveryPanel");
|
||||
WebControlAdapterExtender.WriteImage(writer, changePwd.PasswordRecoveryIconUrl, "Password recovery");
|
||||
WebControlAdapterExtender.WriteLink(writer, changePwd.HyperLinkStyle.CssClass, changePwd.PasswordRecoveryUrl, "Password recovery", changePwd.PasswordRecoveryText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// Step 2: success
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
private void WriteSuccessTitlePanel(HtmlTextWriter writer, ChangePassword changePwd)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(changePwd.SuccessTitleText))
|
||||
{
|
||||
string className = (changePwd.TitleTextStyle != null) && (!String.IsNullOrEmpty(changePwd.TitleTextStyle.CssClass)) ? changePwd.TitleTextStyle.CssClass + " " : "";
|
||||
className += "AspNet-ChangePassword-SuccessTitlePanel";
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, className);
|
||||
WebControlAdapterExtender.WriteSpan(writer, "", changePwd.SuccessTitleText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteSuccessTextPanel(HtmlTextWriter writer, ChangePassword changePwd)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(changePwd.SuccessText))
|
||||
{
|
||||
string className = (changePwd.SuccessTextStyle != null) && (!String.IsNullOrEmpty(changePwd.SuccessTextStyle.CssClass)) ? changePwd.SuccessTextStyle.CssClass + " " : "";
|
||||
className += "AspNet-ChangePassword-SuccessTextPanel";
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, className);
|
||||
WebControlAdapterExtender.WriteSpan(writer, "", changePwd.SuccessText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteContinuePanel(HtmlTextWriter writer, ChangePassword changePwd)
|
||||
{
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-ChangePassword-ContinuePanel");
|
||||
|
||||
string id = "Continue";
|
||||
id += (changePwd.ChangePasswordButtonType == ButtonType.Button) ? "Push" : "";
|
||||
string idWithType = WebControlAdapterExtender.MakeIdWithButtonType(id, changePwd.ContinueButtonType);
|
||||
Control btn = changePwd.SuccessTemplateContainer.FindControl(idWithType);
|
||||
if (btn != null)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(btn.UniqueID);
|
||||
Extender.WriteSubmit(writer, changePwd.ContinueButtonType, changePwd.ContinueButtonStyle.CssClass, changePwd.SuccessTemplateContainer.ID + "_" + id, changePwd.ContinueButtonImageUrl, "", changePwd.ContinueButtonText);
|
||||
}
|
||||
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
public class ChangePasswordCommandBubbler : Control
|
||||
{
|
||||
protected override void OnPreRender(EventArgs e)
|
||||
{
|
||||
base.OnPreRender(e);
|
||||
if (Page.IsPostBack)
|
||||
{
|
||||
ChangePassword changePassword = NamingContainer as ChangePassword;
|
||||
if (changePassword != null)
|
||||
{
|
||||
Control container = changePassword.ChangePasswordTemplateContainer;
|
||||
if (container != null)
|
||||
{
|
||||
CommandEventArgs cmdArgs = null;
|
||||
String[] prefixes = { "ChangePassword", "Cancel", "Continue" };
|
||||
String[] postfixes = { "PushButton", "Image", "Link" };
|
||||
foreach (string prefix in prefixes)
|
||||
{
|
||||
foreach (string postfix in postfixes)
|
||||
{
|
||||
string id = prefix + postfix;
|
||||
Control ctrl = container.FindControl(id);
|
||||
if ((ctrl != null) && (!String.IsNullOrEmpty(Page.Request.Params.Get(ctrl.UniqueID))))
|
||||
{
|
||||
switch (prefix)
|
||||
{
|
||||
case "ChangePassword":
|
||||
cmdArgs = new CommandEventArgs(ChangePassword.ChangePasswordButtonCommandName, this);
|
||||
break;
|
||||
case "Cancel":
|
||||
cmdArgs = new CommandEventArgs(ChangePassword.CancelButtonCommandName, this);
|
||||
break;
|
||||
case "Continue":
|
||||
cmdArgs = new CommandEventArgs(ChangePassword.ContinueButtonCommandName, this);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cmdArgs != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((cmdArgs != null) && (cmdArgs.CommandName == ChangePassword.ChangePasswordButtonCommandName))
|
||||
{
|
||||
Page.Validate();
|
||||
if (!Page.IsValid)
|
||||
{
|
||||
cmdArgs = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (cmdArgs != null)
|
||||
{
|
||||
RaiseBubbleEvent(this, cmdArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,265 @@
|
|||
// Material sourced from the bluePortal project (http://blueportal.codeplex.com).
|
||||
// Licensed under the Microsoft Public License (available at http://www.opensource.org/licenses/ms-pl.html).
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
namespace CSSFriendly
|
||||
{
|
||||
public abstract class CompositeDataBoundControlAdapter : System.Web.UI.WebControls.Adapters.DataBoundControlAdapter
|
||||
{
|
||||
private WebControlAdapterExtender _extender = null;
|
||||
private WebControlAdapterExtender Extender
|
||||
{
|
||||
get
|
||||
{
|
||||
if (((_extender == null) && (Control != null)) ||
|
||||
((_extender != null) && (Control != _extender.AdaptedControl)))
|
||||
{
|
||||
_extender = new WebControlAdapterExtender(Control);
|
||||
}
|
||||
|
||||
System.Diagnostics.Debug.Assert(_extender != null, "CSS Friendly adapters internal error", "Null extender instance");
|
||||
return _extender;
|
||||
}
|
||||
}
|
||||
|
||||
protected string _classMain = "";
|
||||
protected string _classHeader = "";
|
||||
protected string _classData = "";
|
||||
protected string _classFooter = "";
|
||||
protected string _classPagination = "";
|
||||
protected string _classOtherPage = "";
|
||||
protected string _classActivePage = "";
|
||||
|
||||
protected CompositeDataBoundControl View
|
||||
{
|
||||
get { return Control as CompositeDataBoundControl; }
|
||||
}
|
||||
|
||||
protected DetailsView ControlAsDetailsView
|
||||
{
|
||||
get { return Control as DetailsView; }
|
||||
}
|
||||
|
||||
protected bool IsDetailsView
|
||||
{
|
||||
get { return ControlAsDetailsView != null; }
|
||||
}
|
||||
|
||||
protected FormView ControlAsFormView
|
||||
{
|
||||
get { return Control as FormView; }
|
||||
}
|
||||
|
||||
protected bool IsFormView
|
||||
{
|
||||
get { return ControlAsFormView != null; }
|
||||
}
|
||||
|
||||
protected abstract string HeaderText { get; }
|
||||
protected abstract string FooterText { get; }
|
||||
protected abstract ITemplate HeaderTemplate { get; }
|
||||
protected abstract ITemplate FooterTemplate { get; }
|
||||
protected abstract TableRow HeaderRow { get; }
|
||||
protected abstract TableRow FooterRow { get; }
|
||||
protected abstract bool AllowPaging { get; }
|
||||
protected abstract int DataItemCount { get; }
|
||||
protected abstract int DataItemIndex { get; }
|
||||
protected abstract PagerSettings PagerSettings { get; }
|
||||
|
||||
/// ///////////////////////////////////////////////////////////////////////////////
|
||||
/// METHODS
|
||||
|
||||
protected override void OnInit(EventArgs e)
|
||||
{
|
||||
base.OnInit(e);
|
||||
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
RegisterScripts();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderBeginTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
Extender.RenderBeginTag(writer, _classMain);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderBeginTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderEndTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
Extender.RenderEndTag(writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderEndTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderContents(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
if (View != null)
|
||||
{
|
||||
writer.Indent++;
|
||||
|
||||
BuildRow(HeaderRow, _classHeader, writer);
|
||||
BuildItem(writer);
|
||||
BuildRow(FooterRow, _classFooter, writer);
|
||||
BuildPaging(writer);
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderContents(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void BuildItem(HtmlTextWriter writer)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void BuildRow(TableRow row, string cssClass, HtmlTextWriter writer)
|
||||
{
|
||||
if (row != null)
|
||||
{
|
||||
// If there isn't any content, don't render anything.
|
||||
|
||||
bool bHasContent = false;
|
||||
TableCell cell = null;
|
||||
for (int iCell = 0; iCell < row.Cells.Count; iCell++)
|
||||
{
|
||||
cell = row.Cells[iCell];
|
||||
if ((!String.IsNullOrEmpty(cell.Text)) || (cell.Controls.Count > 0))
|
||||
{
|
||||
bHasContent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bHasContent)
|
||||
{
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("div");
|
||||
writer.WriteAttribute("class", cssClass);
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
writer.WriteLine();
|
||||
|
||||
for (int iCell = 0; iCell < row.Cells.Count; iCell++)
|
||||
{
|
||||
cell = row.Cells[iCell];
|
||||
if (!String.IsNullOrEmpty(cell.Text))
|
||||
{
|
||||
writer.Write(cell.Text);
|
||||
}
|
||||
foreach (Control cellChildControl in cell.Controls)
|
||||
{
|
||||
cellChildControl.RenderControl(writer);
|
||||
}
|
||||
}
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("div");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void BuildPaging(HtmlTextWriter writer)
|
||||
{
|
||||
if (AllowPaging && (DataItemCount > 0))
|
||||
{
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("div");
|
||||
writer.WriteAttribute("class", _classPagination);
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
|
||||
int iStart = 0;
|
||||
int iEnd = DataItemCount;
|
||||
int nPages = iEnd - iStart + 1;
|
||||
bool bExceededPageButtonCount = nPages > PagerSettings.PageButtonCount;
|
||||
|
||||
if (bExceededPageButtonCount)
|
||||
{
|
||||
iStart = (DataItemIndex / PagerSettings.PageButtonCount) * PagerSettings.PageButtonCount;
|
||||
iEnd = Math.Min(iStart + PagerSettings.PageButtonCount, DataItemCount);
|
||||
}
|
||||
|
||||
writer.WriteLine();
|
||||
|
||||
if (bExceededPageButtonCount && (iStart > 0))
|
||||
{
|
||||
writer.WriteBeginTag("a");
|
||||
writer.WriteAttribute("class", _classOtherPage);
|
||||
writer.WriteAttribute("href", Page.ClientScript.GetPostBackClientHyperlink(Control, "Page$" + iStart.ToString(), true));
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Write("...");
|
||||
writer.WriteEndTag("a");
|
||||
}
|
||||
|
||||
for (int iDataItem = iStart; iDataItem < iEnd; iDataItem++)
|
||||
{
|
||||
string strPage = (iDataItem + 1).ToString();
|
||||
if (DataItemIndex == iDataItem)
|
||||
{
|
||||
writer.WriteBeginTag("span");
|
||||
writer.WriteAttribute("class", _classActivePage);
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Write(strPage);
|
||||
writer.WriteEndTag("span");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteBeginTag("a");
|
||||
writer.WriteAttribute("class", _classOtherPage);
|
||||
writer.WriteAttribute("href", Page.ClientScript.GetPostBackClientHyperlink(Control, "Page$" + strPage, true));
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Write(strPage);
|
||||
writer.WriteEndTag("a");
|
||||
}
|
||||
}
|
||||
|
||||
if (bExceededPageButtonCount && (iEnd < DataItemCount))
|
||||
{
|
||||
writer.WriteBeginTag("a");
|
||||
writer.WriteAttribute("class", _classOtherPage);
|
||||
writer.WriteAttribute("href", Page.ClientScript.GetPostBackClientHyperlink(Control, "Page$" + (iEnd + 1).ToString(), true));
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Write("...");
|
||||
writer.WriteEndTag("a");
|
||||
}
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("div");
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void RegisterScripts()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,478 @@
|
|||
// Material sourced from the bluePortal project (http://blueportal.codeplex.com).
|
||||
// Licensed under the Microsoft Public License (available at http://www.opensource.org/licenses/ms-pl.html).
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Collections;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
namespace CSSFriendly
|
||||
{
|
||||
public class CreateUserWizardAdapter : System.Web.UI.WebControls.Adapters.WebControlAdapter
|
||||
{
|
||||
private enum State
|
||||
{
|
||||
CreateUser,
|
||||
Failed,
|
||||
Success
|
||||
}
|
||||
State _state = State.CreateUser;
|
||||
string _currentErrorText = "";
|
||||
|
||||
private WebControlAdapterExtender _extender = null;
|
||||
private WebControlAdapterExtender Extender
|
||||
{
|
||||
get
|
||||
{
|
||||
if (((_extender == null) && (Control != null)) ||
|
||||
((_extender != null) && (Control != _extender.AdaptedControl)))
|
||||
{
|
||||
_extender = new WebControlAdapterExtender(Control);
|
||||
}
|
||||
|
||||
System.Diagnostics.Debug.Assert(_extender != null, "CSS Friendly adapters internal error", "Null extender instance");
|
||||
return _extender;
|
||||
}
|
||||
}
|
||||
|
||||
private MembershipProvider WizardMembershipProvider
|
||||
{
|
||||
get
|
||||
{
|
||||
MembershipProvider provider = Membership.Provider;
|
||||
CreateUserWizard wizard = Control as CreateUserWizard;
|
||||
if ((wizard != null) && (!String.IsNullOrEmpty(wizard.MembershipProvider)) && (Membership.Providers[wizard.MembershipProvider] != null))
|
||||
{
|
||||
provider = Membership.Providers[wizard.MembershipProvider];
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
|
||||
public CreateUserWizardAdapter()
|
||||
{
|
||||
_state = State.CreateUser;
|
||||
_currentErrorText = "";
|
||||
}
|
||||
|
||||
/// ///////////////////////////////////////////////////////////////////////////////
|
||||
/// PROTECTED
|
||||
|
||||
protected override void OnInit(EventArgs e)
|
||||
{
|
||||
base.OnInit(e);
|
||||
|
||||
CreateUserWizard wizard = Control as CreateUserWizard;
|
||||
if (Extender.AdapterEnabled && (wizard != null))
|
||||
{
|
||||
RegisterScripts();
|
||||
wizard.CreatedUser += OnCreatedUser;
|
||||
wizard.CreateUserError += OnCreateUserError;
|
||||
_state = State.CreateUser;
|
||||
_currentErrorText = "";
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CreateChildControls()
|
||||
{
|
||||
base.CreateChildControls();
|
||||
|
||||
CreateUserWizard wizard = Control as CreateUserWizard;
|
||||
if (wizard != null)
|
||||
{
|
||||
TemplatedWizardStep activeStep = wizard.ActiveStep as TemplatedWizardStep;
|
||||
if (activeStep != null)
|
||||
{
|
||||
if ((activeStep.ContentTemplate != null) && (activeStep.Controls.Count == 1))
|
||||
{
|
||||
Control container = activeStep.ContentTemplateContainer;
|
||||
if (container != null)
|
||||
{
|
||||
container.Controls.Clear();
|
||||
activeStep.ContentTemplate.InstantiateIn(container);
|
||||
container.DataBind();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnCreatedUser(object sender, EventArgs e)
|
||||
{
|
||||
_state = State.Success;
|
||||
_currentErrorText = "";
|
||||
}
|
||||
|
||||
protected void OnCreateUserError(object sender, CreateUserErrorEventArgs e)
|
||||
{
|
||||
_state = State.Failed;
|
||||
_currentErrorText = "An error has occurred. Please try again.";
|
||||
|
||||
CreateUserWizard wizard = Control as CreateUserWizard;
|
||||
if (wizard != null)
|
||||
{
|
||||
_currentErrorText = wizard.UnknownErrorMessage;
|
||||
switch (e.CreateUserError)
|
||||
{
|
||||
case MembershipCreateStatus.DuplicateEmail:
|
||||
_currentErrorText = wizard.DuplicateEmailErrorMessage;
|
||||
break;
|
||||
case MembershipCreateStatus.DuplicateUserName:
|
||||
_currentErrorText = wizard.DuplicateUserNameErrorMessage;
|
||||
break;
|
||||
case MembershipCreateStatus.InvalidAnswer:
|
||||
_currentErrorText = wizard.InvalidAnswerErrorMessage;
|
||||
break;
|
||||
case MembershipCreateStatus.InvalidEmail:
|
||||
_currentErrorText = wizard.InvalidEmailErrorMessage;
|
||||
break;
|
||||
case MembershipCreateStatus.InvalidPassword:
|
||||
_currentErrorText = wizard.InvalidPasswordErrorMessage;
|
||||
break;
|
||||
case MembershipCreateStatus.InvalidQuestion:
|
||||
_currentErrorText = wizard.InvalidQuestionErrorMessage;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderBeginTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
Extender.RenderBeginTag(writer, "AspNet-CreateUserWizard");
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderBeginTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderEndTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
Extender.RenderEndTag(writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderEndTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderContents(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
CreateUserWizard wizard = Control as CreateUserWizard;
|
||||
if (wizard != null)
|
||||
{
|
||||
TemplatedWizardStep activeStep = wizard.ActiveStep as TemplatedWizardStep;
|
||||
if (activeStep != null)
|
||||
{
|
||||
if (activeStep.ContentTemplate != null)
|
||||
{
|
||||
activeStep.RenderControl(writer);
|
||||
|
||||
if (wizard.CreateUserStep.Equals(activeStep))
|
||||
{
|
||||
WriteCreateUserButtonPanel(writer, wizard);
|
||||
}
|
||||
// Might need to add logic here to render nav buttons for other kinds of
|
||||
// steps (besides the CreateUser step, which we handle above).
|
||||
}
|
||||
else if (wizard.CreateUserStep.Equals(activeStep))
|
||||
{
|
||||
WriteHeaderTextPanel(writer, wizard);
|
||||
WriteStepTitlePanel(writer, wizard);
|
||||
WriteInstructionPanel(writer, wizard);
|
||||
WriteHelpPanel(writer, wizard);
|
||||
WriteUserPanel(writer, wizard);
|
||||
WritePasswordPanel(writer, wizard);
|
||||
WritePasswordHintPanel(writer, wizard); //hbb
|
||||
WriteConfirmPasswordPanel(writer, wizard);
|
||||
WriteEmailPanel(writer, wizard);
|
||||
WriteQuestionPanel(writer, wizard);
|
||||
WriteAnswerPanel(writer, wizard);
|
||||
WriteFinalValidators(writer, wizard);
|
||||
if (_state == State.Failed)
|
||||
{
|
||||
WriteFailurePanel(writer, wizard);
|
||||
}
|
||||
WriteCreateUserButtonPanel(writer, wizard);
|
||||
}
|
||||
else if (wizard.CompleteStep.Equals(activeStep))
|
||||
{
|
||||
WriteStepTitlePanel(writer, wizard);
|
||||
WriteSuccessTextPanel(writer, wizard);
|
||||
WriteContinuePanel(writer, wizard);
|
||||
WriteEditProfilePanel(writer, wizard);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Diagnostics.Debug.Fail("The adapter isn't equipped to handle a CreateUserWizard with a step that is neither templated nor either the CreateUser step or the Complete step.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderContents(writer);
|
||||
}
|
||||
}
|
||||
|
||||
/// ///////////////////////////////////////////////////////////////////////////////
|
||||
/// PRIVATE
|
||||
|
||||
private void RegisterScripts()
|
||||
{
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// Step 1: Create user step
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
private void WriteHeaderTextPanel(HtmlTextWriter writer, CreateUserWizard wizard)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(wizard.HeaderText))
|
||||
{
|
||||
string className = (wizard.HeaderStyle != null) && (!String.IsNullOrEmpty(wizard.HeaderStyle.CssClass)) ? wizard.HeaderStyle.CssClass + " " : "";
|
||||
className += "AspNet-CreateUserWizard-HeaderTextPanel";
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, className);
|
||||
WebControlAdapterExtender.WriteSpan(writer, "", wizard.HeaderText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteStepTitlePanel(HtmlTextWriter writer, CreateUserWizard wizard)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(wizard.ActiveStep.Title))
|
||||
{
|
||||
string className = (wizard.TitleTextStyle != null) && (!String.IsNullOrEmpty(wizard.TitleTextStyle.CssClass)) ? wizard.TitleTextStyle.CssClass + " " : "";
|
||||
className += "AspNet-CreateUserWizard-StepTitlePanel";
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, className);
|
||||
WebControlAdapterExtender.WriteSpan(writer, "", wizard.ActiveStep.Title);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteInstructionPanel(HtmlTextWriter writer, CreateUserWizard wizard)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(wizard.InstructionText))
|
||||
{
|
||||
string className = (wizard.InstructionTextStyle != null) && (!String.IsNullOrEmpty(wizard.InstructionTextStyle.CssClass)) ? wizard.InstructionTextStyle.CssClass + " " : "";
|
||||
className += "AspNet-CreateUserWizard-InstructionPanel";
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, className);
|
||||
WebControlAdapterExtender.WriteSpan(writer, "", wizard.InstructionText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteFailurePanel(HtmlTextWriter writer, CreateUserWizard wizard)
|
||||
{
|
||||
string className = (wizard.ErrorMessageStyle != null) && (!String.IsNullOrEmpty(wizard.ErrorMessageStyle.CssClass)) ? wizard.ErrorMessageStyle.CssClass + " " : "";
|
||||
className += "AspNet-CreateUserWizard-FailurePanel";
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, className);
|
||||
WebControlAdapterExtender.WriteSpan(writer, "", _currentErrorText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
|
||||
private void WriteHelpPanel(HtmlTextWriter writer, CreateUserWizard wizard)
|
||||
{
|
||||
if ((!String.IsNullOrEmpty(wizard.HelpPageIconUrl)) || (!String.IsNullOrEmpty(wizard.HelpPageText)))
|
||||
{
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-CreateUserWizard-HelpPanel");
|
||||
WebControlAdapterExtender.WriteImage(writer, wizard.HelpPageIconUrl, "Help");
|
||||
WebControlAdapterExtender.WriteLink(writer, wizard.HyperLinkStyle.CssClass, wizard.HelpPageUrl, "Help", wizard.HelpPageText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteUserPanel(HtmlTextWriter writer, CreateUserWizard wizard)
|
||||
{
|
||||
TextBox textBox = wizard.FindControl("CreateUserStepContainer").FindControl("UserName") as TextBox;
|
||||
if (textBox != null)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(textBox.UniqueID);
|
||||
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-CreateUserWizard-UserPanel");
|
||||
Extender.WriteTextBox(writer, false, wizard.LabelStyle.CssClass, wizard.UserNameLabelText, wizard.TextBoxStyle.CssClass, "CreateUserStepContainer_UserName", wizard.UserName);
|
||||
WebControlAdapterExtender.WriteRequiredFieldValidator(writer, wizard.FindControl("CreateUserStepContainer").FindControl("UserNameRequired") as RequiredFieldValidator, wizard.ValidatorTextStyle.CssClass, "UserName", wizard.UserNameRequiredErrorMessage);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WritePasswordPanel(HtmlTextWriter writer, CreateUserWizard wizard)
|
||||
{
|
||||
TextBox textBox = wizard.FindControl("CreateUserStepContainer").FindControl("Password") as TextBox;
|
||||
if (textBox != null)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(textBox.UniqueID);
|
||||
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-CreateUserWizard-PasswordPanel");
|
||||
Extender.WriteTextBox(writer, true, wizard.LabelStyle.CssClass, wizard.PasswordLabelText, wizard.TextBoxStyle.CssClass, "CreateUserStepContainer_Password", "");
|
||||
WebControlAdapterExtender.WriteRequiredFieldValidator(writer, wizard.FindControl("CreateUserStepContainer").FindControl("PasswordRequired") as RequiredFieldValidator, wizard.ValidatorTextStyle.CssClass, "Password", wizard.PasswordRequiredErrorMessage);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void WritePasswordHintPanel(HtmlTextWriter writer, CreateUserWizard wizard)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(wizard.PasswordHintText))
|
||||
{
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-CreateUserWizard-PasswordHintPanel");
|
||||
WebControlAdapterExtender.WriteSpan(writer, "", wizard.PasswordHintText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteConfirmPasswordPanel(HtmlTextWriter writer, CreateUserWizard wizard)
|
||||
{
|
||||
TextBox textBox = wizard.FindControl("CreateUserStepContainer").FindControl("ConfirmPassword") as TextBox;
|
||||
if (textBox != null)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(textBox.UniqueID);
|
||||
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-CreateUserWizard-ConfirmPasswordPanel");
|
||||
Extender.WriteTextBox(writer, true, wizard.LabelStyle.CssClass, wizard.ConfirmPasswordLabelText, wizard.TextBoxStyle.CssClass, "CreateUserStepContainer_ConfirmPassword", "");
|
||||
WebControlAdapterExtender.WriteRequiredFieldValidator(writer, wizard.FindControl("CreateUserStepContainer").FindControl("ConfirmPasswordRequired") as RequiredFieldValidator, wizard.ValidatorTextStyle.CssClass, "ConfirmPassword", wizard.ConfirmPasswordRequiredErrorMessage);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteEmailPanel(HtmlTextWriter writer, CreateUserWizard wizard)
|
||||
{
|
||||
TextBox textBox = wizard.FindControl("CreateUserStepContainer").FindControl("Email") as TextBox;
|
||||
if (textBox != null)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(textBox.UniqueID);
|
||||
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-CreateUserWizard-EmailPanel");
|
||||
Extender.WriteTextBox(writer, false, wizard.LabelStyle.CssClass, wizard.EmailLabelText, wizard.TextBoxStyle.CssClass, "CreateUserStepContainer_Email", "");
|
||||
WebControlAdapterExtender.WriteRequiredFieldValidator(writer, wizard.FindControl("CreateUserStepContainer").FindControl("EmailRequired") as RequiredFieldValidator, wizard.ValidatorTextStyle.CssClass, "Email", wizard.EmailRequiredErrorMessage);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteQuestionPanel(HtmlTextWriter writer, CreateUserWizard wizard)
|
||||
{
|
||||
if ((WizardMembershipProvider != null) && WizardMembershipProvider.RequiresQuestionAndAnswer)
|
||||
{
|
||||
TextBox textBox = wizard.FindControl("CreateUserStepContainer").FindControl("Question") as TextBox;
|
||||
if (textBox != null)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(textBox.UniqueID);
|
||||
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-CreateUserWizard-QuestionPanel");
|
||||
Extender.WriteTextBox(writer, false, wizard.LabelStyle.CssClass, wizard.QuestionLabelText, wizard.TextBoxStyle.CssClass, "CreateUserStepContainer_Question", "");
|
||||
WebControlAdapterExtender.WriteRequiredFieldValidator(writer, wizard.FindControl("CreateUserStepContainer").FindControl("QuestionRequired") as RequiredFieldValidator, wizard.ValidatorTextStyle.CssClass, "Question", wizard.QuestionRequiredErrorMessage);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteAnswerPanel(HtmlTextWriter writer, CreateUserWizard wizard)
|
||||
{
|
||||
if ((WizardMembershipProvider != null) && WizardMembershipProvider.RequiresQuestionAndAnswer)
|
||||
{
|
||||
TextBox textBox = wizard.FindControl("CreateUserStepContainer").FindControl("Answer") as TextBox;
|
||||
if (textBox != null)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(textBox.UniqueID);
|
||||
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-CreateUserWizard-AnswerPanel");
|
||||
Extender.WriteTextBox(writer, false, wizard.LabelStyle.CssClass, wizard.AnswerLabelText, wizard.TextBoxStyle.CssClass, "CreateUserStepContainer_Answer", "");
|
||||
WebControlAdapterExtender.WriteRequiredFieldValidator(writer, wizard.FindControl("CreateUserStepContainer").FindControl("AnswerRequired") as RequiredFieldValidator, wizard.ValidatorTextStyle.CssClass, "Answer", wizard.AnswerRequiredErrorMessage);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteFinalValidators(HtmlTextWriter writer, CreateUserWizard wizard)
|
||||
{
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-CreateUserWizard-FinalValidatorsPanel");
|
||||
WebControlAdapterExtender.WriteCompareValidator(writer, wizard.FindControl("CreateUserStepContainer").FindControl("PasswordCompare") as CompareValidator, wizard.ValidatorTextStyle.CssClass, "ConfirmPassword", wizard.ConfirmPasswordCompareErrorMessage, "Password");
|
||||
WebControlAdapterExtender.WriteRegularExpressionValidator(writer, wizard.FindControl("CreateUserStepContainer").FindControl("PasswordRegExpValidator") as RegularExpressionValidator, wizard.ValidatorTextStyle.CssClass, "Password", wizard.PasswordRegularExpressionErrorMessage, wizard.PasswordRegularExpression);
|
||||
WebControlAdapterExtender.WriteRegularExpressionValidator(writer, wizard.FindControl("CreateUserStepContainer").FindControl("EmailRegExpValidator") as RegularExpressionValidator, wizard.ValidatorTextStyle.CssClass, "Email", wizard.EmailRegularExpressionErrorMessage, wizard.EmailRegularExpression);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
|
||||
private void WriteCreateUserButtonPanel(HtmlTextWriter writer, CreateUserWizard wizard)
|
||||
{
|
||||
Control btnParentCtrl = wizard.FindControl("__CustomNav0");
|
||||
if (btnParentCtrl != null)
|
||||
{
|
||||
string id = "_CustomNav0_StepNextButton";
|
||||
string idWithType = WebControlAdapterExtender.MakeIdWithButtonType("StepNextButton", wizard.CreateUserButtonType);
|
||||
Control btn = btnParentCtrl.FindControl(idWithType);
|
||||
if (btn != null)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(btn.UniqueID);
|
||||
|
||||
PostBackOptions options = new PostBackOptions(btn, "", "", false, false, false, false, true, wizard.ID);
|
||||
string javascript = "javascript:" + Page.ClientScript.GetPostBackEventReference(options);
|
||||
javascript = Page.Server.HtmlEncode(javascript);
|
||||
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-CreateUserWizard-CreateUserButtonPanel");
|
||||
|
||||
Extender.WriteSubmit(writer, wizard.CreateUserButtonType, wizard.CreateUserButtonStyle.CssClass, id, wizard.CreateUserButtonImageUrl, javascript, wizard.CreateUserButtonText);
|
||||
|
||||
if (wizard.DisplayCancelButton)
|
||||
{
|
||||
Extender.WriteSubmit(writer, wizard.CancelButtonType, wizard.CancelButtonStyle.CssClass, "_CustomNav0_CancelButton", wizard.CancelButtonImageUrl, "", wizard.CancelButtonText);
|
||||
}
|
||||
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// Complete step
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
private void WriteSuccessTextPanel(HtmlTextWriter writer, CreateUserWizard wizard)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(wizard.CompleteSuccessText))
|
||||
{
|
||||
string className = (wizard.CompleteSuccessTextStyle != null) && (!String.IsNullOrEmpty(wizard.CompleteSuccessTextStyle.CssClass)) ? wizard.CompleteSuccessTextStyle.CssClass + " " : "";
|
||||
className += "AspNet-CreateUserWizard-SuccessTextPanel";
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, className);
|
||||
WebControlAdapterExtender.WriteSpan(writer, "", wizard.CompleteSuccessText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteContinuePanel(HtmlTextWriter writer, CreateUserWizard wizard)
|
||||
{
|
||||
string id = "ContinueButton";
|
||||
string idWithType = WebControlAdapterExtender.MakeIdWithButtonType(id, wizard.ContinueButtonType);
|
||||
Control btn = wizard.FindControl("CompleteStepContainer").FindControl(idWithType);
|
||||
if (btn != null)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(btn.UniqueID);
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-CreateUserWizard-ContinuePanel");
|
||||
Extender.WriteSubmit(writer, wizard.ContinueButtonType, wizard.ContinueButtonStyle.CssClass, "CompleteStepContainer_ContinueButton", wizard.ContinueButtonImageUrl, "", wizard.ContinueButtonText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteEditProfilePanel(HtmlTextWriter writer, CreateUserWizard wizard)
|
||||
{
|
||||
if ((!String.IsNullOrEmpty(wizard.EditProfileUrl)) || (!String.IsNullOrEmpty(wizard.EditProfileText)))
|
||||
{
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-CreateUserWizard-EditProfilePanel");
|
||||
WebControlAdapterExtender.WriteImage(writer, wizard.EditProfileIconUrl, "Edit profile");
|
||||
WebControlAdapterExtender.WriteLink(writer, wizard.HyperLinkStyle.CssClass, wizard.EditProfileUrl, "EditProfile", wizard.EditProfileText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,281 @@
|
|||
// Material sourced from the bluePortal project (http://blueportal.codeplex.com).
|
||||
// Licensed under the Microsoft Public License (available at http://www.opensource.org/licenses/ms-pl.html).
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Collections;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
namespace CSSFriendly
|
||||
{
|
||||
public class DataListAdapter : System.Web.UI.WebControls.Adapters.WebControlAdapter
|
||||
{
|
||||
private WebControlAdapterExtender _extender = null;
|
||||
private WebControlAdapterExtender Extender
|
||||
{
|
||||
get
|
||||
{
|
||||
if (((_extender == null) && (Control != null)) ||
|
||||
((_extender != null) && (Control != _extender.AdaptedControl)))
|
||||
{
|
||||
_extender = new WebControlAdapterExtender(Control);
|
||||
}
|
||||
|
||||
System.Diagnostics.Debug.Assert(_extender != null, "CSS Friendly adapters internal error", "Null extender instance");
|
||||
return _extender;
|
||||
}
|
||||
}
|
||||
|
||||
private int RepeatColumns
|
||||
{
|
||||
get
|
||||
{
|
||||
DataList dataList = Control as DataList;
|
||||
int nRet = 1;
|
||||
if (dataList != null)
|
||||
{
|
||||
if (dataList.RepeatColumns == 0)
|
||||
{
|
||||
if (dataList.RepeatDirection == RepeatDirection.Horizontal)
|
||||
{
|
||||
nRet = dataList.Items.Count;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nRet = dataList.RepeatColumns;
|
||||
}
|
||||
}
|
||||
return nRet;
|
||||
}
|
||||
}
|
||||
|
||||
/// ///////////////////////////////////////////////////////////////////////////////
|
||||
/// PROTECTED
|
||||
|
||||
protected override void OnInit(EventArgs e)
|
||||
{
|
||||
base.OnInit(e);
|
||||
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
RegisterScripts();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderBeginTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
Extender.RenderBeginTag(writer, "AspNet-DataList");
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderBeginTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderEndTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
Extender.RenderEndTag(writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderEndTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderContents(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
DataList dataList = Control as DataList;
|
||||
if (dataList != null)
|
||||
{
|
||||
writer.Indent++;
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("table");
|
||||
writer.WriteAttribute("cellpadding", "0");
|
||||
writer.WriteAttribute("cellspacing", "0");
|
||||
writer.WriteAttribute("summary", Control.ToolTip);
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
|
||||
if (dataList.HeaderTemplate != null)
|
||||
{
|
||||
PlaceHolder container = new PlaceHolder();
|
||||
dataList.HeaderTemplate.InstantiateIn(container);
|
||||
container.DataBind();
|
||||
|
||||
if ((container.Controls.Count == 1) && typeof(LiteralControl).IsInstanceOfType(container.Controls[0]))
|
||||
{
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("caption");
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
|
||||
LiteralControl literalControl = container.Controls[0] as LiteralControl;
|
||||
writer.Write(literalControl.Text.Trim());
|
||||
|
||||
writer.WriteEndTag("caption");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("thead");
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("tr");
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("th");
|
||||
writer.WriteAttribute("colspan", RepeatColumns.ToString());
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
|
||||
writer.WriteLine();
|
||||
container.RenderControl(writer);
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("th");
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("tr");
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("thead");
|
||||
}
|
||||
}
|
||||
|
||||
if (dataList.FooterTemplate != null)
|
||||
{
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("tfoot");
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("tr");
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("td");
|
||||
writer.WriteAttribute("colspan", RepeatColumns.ToString());
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
|
||||
PlaceHolder container = new PlaceHolder();
|
||||
dataList.FooterTemplate.InstantiateIn(container);
|
||||
container.DataBind();
|
||||
container.RenderControl(writer);
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("td");
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("tr");
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("tfoot");
|
||||
}
|
||||
|
||||
if (dataList.ItemTemplate != null)
|
||||
{
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("tbody");
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
|
||||
int nItemsInColumn = (int)Math.Ceiling(((Double)dataList.Items.Count) / ((Double)RepeatColumns));
|
||||
for (int iItem = 0; iItem < dataList.Items.Count; iItem++)
|
||||
{
|
||||
int nRow = iItem / RepeatColumns;
|
||||
int nCol = iItem % RepeatColumns;
|
||||
int nDesiredIndex = iItem;
|
||||
if (dataList.RepeatDirection == RepeatDirection.Vertical)
|
||||
{
|
||||
nDesiredIndex = (nCol * nItemsInColumn) + nRow;
|
||||
}
|
||||
|
||||
if ((iItem % RepeatColumns) == 0)
|
||||
{
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("tr");
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
}
|
||||
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("td");
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
|
||||
foreach (Control itemCtrl in dataList.Items[iItem].Controls)
|
||||
{
|
||||
itemCtrl.RenderControl(writer);
|
||||
}
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("td");
|
||||
|
||||
if (((iItem + 1) % RepeatColumns) == 0)
|
||||
{
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("tr");
|
||||
}
|
||||
}
|
||||
|
||||
if ((dataList.Items.Count % RepeatColumns) != 0)
|
||||
{
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("tr");
|
||||
}
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("tbody");
|
||||
}
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("table");
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderContents(writer);
|
||||
}
|
||||
}
|
||||
|
||||
/// ///////////////////////////////////////////////////////////////////////////////
|
||||
/// PRIVATE
|
||||
|
||||
private void RegisterScripts()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
// Material sourced from the bluePortal project (http://blueportal.codeplex.com).
|
||||
// Licensed under the Microsoft Public License (available at http://www.opensource.org/licenses/ms-pl.html).
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
namespace CSSFriendly
|
||||
{
|
||||
public class DetailsViewAdapter : CompositeDataBoundControlAdapter
|
||||
{
|
||||
protected override string HeaderText { get { return ControlAsDetailsView.HeaderText; } }
|
||||
protected override string FooterText { get { return ControlAsDetailsView.FooterText; } }
|
||||
protected override ITemplate HeaderTemplate { get { return ControlAsDetailsView.HeaderTemplate; } }
|
||||
protected override ITemplate FooterTemplate { get { return ControlAsDetailsView.FooterTemplate; } }
|
||||
protected override TableRow HeaderRow { get { return ControlAsDetailsView.HeaderRow; } }
|
||||
protected override TableRow FooterRow { get { return ControlAsDetailsView.FooterRow; } }
|
||||
protected override bool AllowPaging { get { return ControlAsDetailsView.AllowPaging; } }
|
||||
protected override int DataItemCount { get { return ControlAsDetailsView.DataItemCount; } }
|
||||
protected override int DataItemIndex { get { return ControlAsDetailsView.DataItemIndex; } }
|
||||
protected override PagerSettings PagerSettings { get { return ControlAsDetailsView.PagerSettings; } }
|
||||
|
||||
public DetailsViewAdapter()
|
||||
{
|
||||
_classMain = "AspNet-DetailsView";
|
||||
_classHeader = "AspNet-DetailsView-Header";
|
||||
_classData = "AspNet-DetailsView-Data";
|
||||
_classFooter = "AspNet-DetailsView-Footer";
|
||||
_classPagination = "AspNet-DetailsView-Pagination";
|
||||
_classOtherPage = "AspNet-DetailsView-OtherPage";
|
||||
_classActivePage = "AspNet-DetailsView-ActivePage";
|
||||
}
|
||||
|
||||
protected override void BuildItem(HtmlTextWriter writer)
|
||||
{
|
||||
if (IsDetailsView && (ControlAsDetailsView.Rows.Count > 0))
|
||||
{
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("div");
|
||||
writer.WriteAttribute("class", _classData);
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("ul");
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
|
||||
int countRenderedRows = 0;
|
||||
for (int iRow = 0; iRow < ControlAsDetailsView.Rows.Count; iRow++)
|
||||
{
|
||||
if (ControlAsDetailsView.Fields[iRow].Visible)
|
||||
{
|
||||
DetailsViewRow row = ControlAsDetailsView.Rows[iRow];
|
||||
if ((!ControlAsDetailsView.AutoGenerateRows) &&
|
||||
((row.RowState & DataControlRowState.Insert) == DataControlRowState.Insert) &&
|
||||
(!ControlAsDetailsView.Fields[row.RowIndex].InsertVisible))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("li");
|
||||
string theClass = ((countRenderedRows % 2) == 1) ? "AspNet-DetailsView-Alternate" : "";
|
||||
if ((ControlAsDetailsView.Fields[iRow].ItemStyle != null) && (!String.IsNullOrEmpty(ControlAsDetailsView.Fields[iRow].ItemStyle.CssClass)))
|
||||
{
|
||||
if (!String.IsNullOrEmpty(theClass))
|
||||
{
|
||||
theClass += " ";
|
||||
}
|
||||
theClass += ControlAsDetailsView.Fields[iRow].ItemStyle.CssClass;
|
||||
}
|
||||
if (!String.IsNullOrEmpty(theClass))
|
||||
{
|
||||
writer.WriteAttribute("class", theClass);
|
||||
}
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
writer.WriteLine();
|
||||
|
||||
for (int iCell = 0; iCell < row.Cells.Count; iCell++)
|
||||
{
|
||||
TableCell cell = row.Cells[iCell];
|
||||
writer.WriteBeginTag("span");
|
||||
if (iCell == 0)
|
||||
{
|
||||
writer.WriteAttribute("class", "AspNet-DetailsView-Name");
|
||||
}
|
||||
else if (iCell == 1)
|
||||
{
|
||||
writer.WriteAttribute("class", "AspNet-DetailsView-Value");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteAttribute("class", "AspNet-DetailsView-Misc");
|
||||
}
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
if (!String.IsNullOrEmpty(cell.Text))
|
||||
{
|
||||
writer.Write(cell.Text);
|
||||
}
|
||||
foreach (Control cellChildControl in cell.Controls)
|
||||
{
|
||||
cellChildControl.RenderControl(writer);
|
||||
}
|
||||
writer.WriteEndTag("span");
|
||||
}
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("li");
|
||||
countRenderedRows++;
|
||||
}
|
||||
}
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("ul");
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("div");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
// Material sourced from the bluePortal project (http://blueportal.codeplex.com).
|
||||
// Licensed under the Microsoft Public License (available at http://www.opensource.org/licenses/ms-pl.html).
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
namespace CSSFriendly
|
||||
{
|
||||
public class FormViewAdapter : CompositeDataBoundControlAdapter
|
||||
{
|
||||
protected override string HeaderText { get { return ControlAsFormView.HeaderText; } }
|
||||
protected override string FooterText { get { return ControlAsFormView.FooterText; } }
|
||||
protected override ITemplate HeaderTemplate { get { return ControlAsFormView.HeaderTemplate; } }
|
||||
protected override ITemplate FooterTemplate { get { return ControlAsFormView.FooterTemplate; } }
|
||||
protected override TableRow HeaderRow { get { return ControlAsFormView.HeaderRow; } }
|
||||
protected override TableRow FooterRow { get { return ControlAsFormView.FooterRow; } }
|
||||
protected override bool AllowPaging { get { return ControlAsFormView.AllowPaging; } }
|
||||
protected override int DataItemCount { get { return ControlAsFormView.DataItemCount; } }
|
||||
protected override int DataItemIndex { get { return ControlAsFormView.DataItemIndex; } }
|
||||
protected override PagerSettings PagerSettings { get { return ControlAsFormView.PagerSettings; } }
|
||||
|
||||
public FormViewAdapter()
|
||||
{
|
||||
_classMain = "AspNet-FormView";
|
||||
_classHeader = "AspNet-FormView-Header";
|
||||
_classData = "AspNet-FormView-Data";
|
||||
_classFooter = "AspNet-FormView-Footer";
|
||||
_classPagination = "AspNet-FormView-Pagination";
|
||||
_classOtherPage = "AspNet-FormView-OtherPage";
|
||||
_classActivePage = "AspNet-FormView-ActivePage";
|
||||
}
|
||||
|
||||
protected override void BuildItem(HtmlTextWriter writer)
|
||||
{
|
||||
if ((ControlAsFormView.Row != null) &&
|
||||
(ControlAsFormView.Row.Cells.Count > 0) &&
|
||||
(ControlAsFormView.Row.Cells[0].Controls.Count > 0))
|
||||
{
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("div");
|
||||
writer.WriteAttribute("class", _classData);
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
writer.WriteLine();
|
||||
|
||||
foreach (Control itemCtrl in ControlAsFormView.Row.Cells[0].Controls)
|
||||
{
|
||||
itemCtrl.RenderControl(writer);
|
||||
}
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("div");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,341 @@
|
|||
// Material sourced from the bluePortal project (http://blueportal.codeplex.com).
|
||||
// Licensed under the Microsoft Public License (available at http://www.opensource.org/licenses/ms-pl.html).
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Collections;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
namespace CSSFriendly
|
||||
{
|
||||
public class GridViewAdapter : System.Web.UI.WebControls.Adapters.WebControlAdapter
|
||||
{
|
||||
private WebControlAdapterExtender _extender = null;
|
||||
private WebControlAdapterExtender Extender
|
||||
{
|
||||
get
|
||||
{
|
||||
if (((_extender == null) && (Control != null)) ||
|
||||
((_extender != null) && (Control != _extender.AdaptedControl)))
|
||||
{
|
||||
_extender = new WebControlAdapterExtender(Control);
|
||||
}
|
||||
|
||||
System.Diagnostics.Debug.Assert(_extender != null, "CSS Friendly adapters internal error", "Null extender instance");
|
||||
return _extender;
|
||||
}
|
||||
}
|
||||
|
||||
/// ///////////////////////////////////////////////////////////////////////////////
|
||||
/// PROTECTED
|
||||
|
||||
protected override void OnInit(EventArgs e)
|
||||
{
|
||||
base.OnInit(e);
|
||||
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
RegisterScripts();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderBeginTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
Extender.RenderBeginTag(writer, "AspNet-GridView");
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderBeginTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderEndTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
Extender.RenderEndTag(writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderEndTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderContents(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
GridView gridView = Control as GridView;
|
||||
if (gridView != null)
|
||||
{
|
||||
writer.Indent++;
|
||||
WritePagerSection(writer, PagerPosition.Top);
|
||||
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("table");
|
||||
writer.WriteAttribute("id", gridView.ClientID);
|
||||
writer.WriteAttribute("cellpadding", "0");
|
||||
writer.WriteAttribute("cellspacing", "0");
|
||||
writer.WriteAttribute("summary", Control.ToolTip);
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
|
||||
ArrayList rows = new ArrayList();
|
||||
GridViewRowCollection gvrc = null;
|
||||
|
||||
///////////////////// HEAD /////////////////////////////
|
||||
|
||||
rows.Clear();
|
||||
if (gridView.ShowHeader && (gridView.HeaderRow != null))
|
||||
{
|
||||
rows.Add(gridView.HeaderRow);
|
||||
}
|
||||
gvrc = new GridViewRowCollection(rows);
|
||||
WriteRows(writer, gridView, gvrc, "thead");
|
||||
|
||||
///////////////////// FOOT /////////////////////////////
|
||||
|
||||
rows.Clear();
|
||||
if (gridView.ShowFooter && (gridView.FooterRow != null))
|
||||
{
|
||||
rows.Add(gridView.FooterRow);
|
||||
}
|
||||
gvrc = new GridViewRowCollection(rows);
|
||||
WriteRows(writer, gridView, gvrc, "tfoot");
|
||||
|
||||
///////////////////// BODY /////////////////////////////
|
||||
|
||||
WriteRows(writer, gridView, gridView.Rows, "tbody");
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("table");
|
||||
|
||||
WriteEmptyTextSection(writer);
|
||||
WritePagerSection(writer, PagerPosition.Bottom);
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderContents(writer);
|
||||
}
|
||||
}
|
||||
|
||||
/// ///////////////////////////////////////////////////////////////////////////////
|
||||
/// PRIVATE
|
||||
|
||||
private void RegisterScripts()
|
||||
{
|
||||
}
|
||||
|
||||
private void WriteRows(HtmlTextWriter writer, GridView gridView, GridViewRowCollection rows, string tableSection)
|
||||
{
|
||||
if (rows.Count > 0)
|
||||
{
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag(tableSection);
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
|
||||
foreach (GridViewRow row in rows)
|
||||
{
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("tr");
|
||||
|
||||
string className = GetRowClass(gridView, row);
|
||||
if (!String.IsNullOrEmpty(className))
|
||||
{
|
||||
writer.WriteAttribute("class", className);
|
||||
}
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
|
||||
int i = 0;
|
||||
foreach (TableCell cell in row.Cells)
|
||||
{
|
||||
if (!gridView.Columns[i++].Visible)
|
||||
continue;
|
||||
|
||||
DataControlFieldCell fieldCell = cell as DataControlFieldCell;
|
||||
|
||||
if(tableSection == "tbody" && fieldCell != null
|
||||
&& (fieldCell.Text.Trim() == "") && fieldCell.Controls.Count == 0)
|
||||
cell.Controls.Add(new LiteralControl("<div style=\"width:1px;height:1px;\"> </div>"));
|
||||
else if (tableSection == "thead" && fieldCell != null
|
||||
&& !String.IsNullOrEmpty(gridView.SortExpression)
|
||||
&& fieldCell.ContainingField.SortExpression == gridView.SortExpression)
|
||||
{
|
||||
cell.Attributes["class"] = "AspNet-GridView-Sort";
|
||||
}
|
||||
|
||||
if ((fieldCell != null) && (fieldCell.ContainingField != null))
|
||||
{
|
||||
DataControlField field = fieldCell.ContainingField;
|
||||
if (!field.Visible)
|
||||
{
|
||||
cell.Visible = false;
|
||||
}
|
||||
|
||||
if (field.ItemStyle.Width != Unit.Empty)
|
||||
cell.Style["width"] = field.ItemStyle.Width.ToString();
|
||||
|
||||
if (!field.ItemStyle.Wrap)
|
||||
cell.Style["white-space"] = "nowrap";
|
||||
|
||||
if ((field.ItemStyle != null) && (!String.IsNullOrEmpty(field.ItemStyle.CssClass)))
|
||||
{
|
||||
if (!String.IsNullOrEmpty(cell.CssClass))
|
||||
{
|
||||
cell.CssClass += " ";
|
||||
}
|
||||
cell.CssClass += field.ItemStyle.CssClass;
|
||||
}
|
||||
}
|
||||
|
||||
writer.WriteLine();
|
||||
cell.RenderControl(writer);
|
||||
}
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("tr");
|
||||
}
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag(tableSection);
|
||||
}
|
||||
}
|
||||
|
||||
private string GetRowClass(GridView gridView, GridViewRow row)
|
||||
{
|
||||
string className = "";
|
||||
|
||||
if ((row.RowState & DataControlRowState.Alternate) == DataControlRowState.Alternate)
|
||||
{
|
||||
className += " AspNet-GridView-Alternate ";
|
||||
if (gridView.AlternatingRowStyle != null)
|
||||
{
|
||||
className += gridView.AlternatingRowStyle.CssClass;
|
||||
}
|
||||
}
|
||||
|
||||
if ((row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit)
|
||||
{
|
||||
className += " AspNet-GridView-Edit ";
|
||||
if (gridView.EditRowStyle != null)
|
||||
{
|
||||
className += gridView.EditRowStyle.CssClass;
|
||||
}
|
||||
}
|
||||
|
||||
if ((row.RowState & DataControlRowState.Insert) == DataControlRowState.Insert)
|
||||
{
|
||||
className += " AspNet-GridView-Insert ";
|
||||
}
|
||||
|
||||
if ((row.RowState & DataControlRowState.Selected) == DataControlRowState.Selected)
|
||||
{
|
||||
className += " AspNet-GridView-Selected ";
|
||||
if (gridView.SelectedRowStyle != null)
|
||||
{
|
||||
className += gridView.SelectedRowStyle.CssClass;
|
||||
}
|
||||
}
|
||||
|
||||
return className.Trim();
|
||||
}
|
||||
|
||||
private void WriteEmptyTextSection(HtmlTextWriter writer)
|
||||
{
|
||||
GridView gridView = Control as GridView;
|
||||
if (gridView != null && gridView.Rows.Count == 0)
|
||||
{
|
||||
string className = "AspNet-GridView-Empty";
|
||||
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("div");
|
||||
writer.WriteAttribute("class", className);
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
|
||||
writer.Write(gridView.EmptyDataText);
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("div");
|
||||
}
|
||||
}
|
||||
|
||||
private void WritePagerSection(HtmlTextWriter writer, PagerPosition pos)
|
||||
{
|
||||
GridView gridView = Control as GridView;
|
||||
if ((gridView != null) &&
|
||||
gridView.AllowPaging &&
|
||||
((gridView.PagerSettings.Position == pos) || (gridView.PagerSettings.Position == PagerPosition.TopAndBottom)))
|
||||
{
|
||||
Table innerTable = null;
|
||||
if ((pos == PagerPosition.Top) &&
|
||||
(gridView.TopPagerRow != null) &&
|
||||
(gridView.TopPagerRow.Cells.Count == 1) &&
|
||||
(gridView.TopPagerRow.Cells[0].Controls.Count == 1) &&
|
||||
typeof(Table).IsAssignableFrom(gridView.TopPagerRow.Cells[0].Controls[0].GetType()))
|
||||
{
|
||||
innerTable = gridView.TopPagerRow.Cells[0].Controls[0] as Table;
|
||||
}
|
||||
else if ((pos == PagerPosition.Bottom) &&
|
||||
(gridView.BottomPagerRow != null) &&
|
||||
(gridView.BottomPagerRow.Cells.Count == 1) &&
|
||||
(gridView.BottomPagerRow.Cells[0].Controls.Count == 1) &&
|
||||
typeof(Table).IsAssignableFrom(gridView.BottomPagerRow.Cells[0].Controls[0].GetType()))
|
||||
{
|
||||
innerTable = gridView.BottomPagerRow.Cells[0].Controls[0] as Table;
|
||||
}
|
||||
|
||||
if ((innerTable != null) && (innerTable.Rows.Count == 1))
|
||||
{
|
||||
string className = "AspNet-GridView-Pagination AspNet-GridView-";
|
||||
className += (pos == PagerPosition.Top) ? "Top " : "Bottom ";
|
||||
if (gridView.PagerStyle != null)
|
||||
{
|
||||
className += gridView.PagerStyle.CssClass;
|
||||
}
|
||||
className = className.Trim();
|
||||
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("div");
|
||||
writer.WriteAttribute("class", className);
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
|
||||
TableRow row = innerTable.Rows[0];
|
||||
foreach (TableCell cell in row.Cells)
|
||||
{
|
||||
foreach (Control ctrl in cell.Controls)
|
||||
{
|
||||
writer.WriteLine();
|
||||
ctrl.RenderControl(writer);
|
||||
}
|
||||
}
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("div");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Collections;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
namespace CSSFriendly
|
||||
{
|
||||
public class ImageAdapter : System.Web.UI.WebControls.Adapters.WebControlAdapter
|
||||
{
|
||||
protected override void Render(HtmlTextWriter writer)
|
||||
{
|
||||
Image img = Control as Image;
|
||||
//
|
||||
if (img != null && Page != null)
|
||||
{
|
||||
//
|
||||
HttpBrowserCapabilities browser = Page.Request.Browser;
|
||||
//
|
||||
if (browser.Browser == "IE" &&
|
||||
(browser.Version == "5.0" || browser.Version == "5.5" || browser.Version == "6.0")
|
||||
&& !String.IsNullOrEmpty(img.ImageUrl) && img.ImageUrl.ToLower().EndsWith(".png"))
|
||||
{
|
||||
// add other attributes
|
||||
string imageUrl = img.ImageUrl; // save original URL
|
||||
|
||||
// change original URL to empty
|
||||
img.ImageUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), "WebsitePanel.WebPortal.Code.Adapters.empty.gif");
|
||||
|
||||
imageUrl = img.ResolveClientUrl(imageUrl);
|
||||
img.Attributes["style"] =
|
||||
String.Format("filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='{0}', sizingMethod='scale');",
|
||||
imageUrl);
|
||||
}
|
||||
}
|
||||
//
|
||||
base.Render(writer);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,287 @@
|
|||
// Material sourced from the bluePortal project (http://blueportal.codeplex.com).
|
||||
// Licensed under the Microsoft Public License (available at http://www.opensource.org/licenses/ms-pl.html).
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Collections;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
namespace CSSFriendly
|
||||
{
|
||||
public class LoginAdapter : System.Web.UI.WebControls.Adapters.WebControlAdapter
|
||||
{
|
||||
private enum State
|
||||
{
|
||||
LoggingIn,
|
||||
Failed,
|
||||
Success,
|
||||
}
|
||||
State _state = State.LoggingIn;
|
||||
|
||||
private WebControlAdapterExtender _extender = null;
|
||||
private WebControlAdapterExtender Extender
|
||||
{
|
||||
get
|
||||
{
|
||||
if (((_extender == null) && (Control != null)) ||
|
||||
((_extender != null) && (Control != _extender.AdaptedControl)))
|
||||
{
|
||||
_extender = new WebControlAdapterExtender(Control);
|
||||
}
|
||||
|
||||
System.Diagnostics.Debug.Assert(_extender != null, "CSS Friendly adapters internal error", "Null extender instance");
|
||||
return _extender;
|
||||
}
|
||||
}
|
||||
|
||||
public LoginAdapter()
|
||||
{
|
||||
_state = State.LoggingIn;
|
||||
}
|
||||
|
||||
/// ///////////////////////////////////////////////////////////////////////////////
|
||||
/// PROTECTED
|
||||
|
||||
protected override void OnInit(EventArgs e)
|
||||
{
|
||||
base.OnInit(e);
|
||||
|
||||
Login login = Control as Login;
|
||||
if (Extender.AdapterEnabled && (login != null))
|
||||
{
|
||||
RegisterScripts();
|
||||
login.LoggedIn += OnLoggedIn;
|
||||
login.LoginError += OnLoginError;
|
||||
_state = State.LoggingIn;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CreateChildControls()
|
||||
{
|
||||
base.CreateChildControls();
|
||||
Login login = Control as Login;
|
||||
if ((login != null) && (login.Controls.Count == 1) && (login.LayoutTemplate != null))
|
||||
{
|
||||
Control container = login.Controls[0];
|
||||
if (container != null)
|
||||
{
|
||||
container.Controls.Clear();
|
||||
login.LayoutTemplate.InstantiateIn(container);
|
||||
container.DataBind();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnLoggedIn(object sender, EventArgs e)
|
||||
{
|
||||
_state = State.Success;
|
||||
}
|
||||
|
||||
protected void OnLoginError(object sender, EventArgs e)
|
||||
{
|
||||
_state = State.Failed;
|
||||
}
|
||||
|
||||
protected override void RenderBeginTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
Extender.RenderBeginTag(writer, "AspNet-Login");
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderBeginTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderEndTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
Extender.RenderEndTag(writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderEndTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderContents(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
Login login = Control as Login;
|
||||
if (login != null)
|
||||
{
|
||||
if (login.LayoutTemplate != null)
|
||||
{
|
||||
if (login.Controls.Count == 1)
|
||||
{
|
||||
Control container = login.Controls[0];
|
||||
if (container != null)
|
||||
{
|
||||
foreach (Control c in container.Controls)
|
||||
{
|
||||
c.RenderControl(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteTitlePanel(writer, login);
|
||||
WriteInstructionPanel(writer, login);
|
||||
WriteHelpPanel(writer, login);
|
||||
WriteUserPanel(writer, login);
|
||||
WritePasswordPanel(writer, login);
|
||||
WriteRememberMePanel(writer, login);
|
||||
if (_state == State.Failed)
|
||||
{
|
||||
WriteFailurePanel(writer, login);
|
||||
}
|
||||
WriteSubmitPanel(writer, login);
|
||||
WriteCreateUserPanel(writer, login);
|
||||
WritePasswordRecoveryPanel(writer, login);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderContents(writer);
|
||||
}
|
||||
}
|
||||
|
||||
/// ///////////////////////////////////////////////////////////////////////////////
|
||||
/// PRIVATE
|
||||
|
||||
private void RegisterScripts()
|
||||
{
|
||||
}
|
||||
|
||||
private void WriteTitlePanel(HtmlTextWriter writer, Login login)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(login.TitleText))
|
||||
{
|
||||
string className = (login.TitleTextStyle != null) && (!String.IsNullOrEmpty(login.TitleTextStyle.CssClass)) ? login.TitleTextStyle.CssClass + " " : "";
|
||||
className += "AspNet-Login-TitlePanel";
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, className);
|
||||
WebControlAdapterExtender.WriteSpan(writer, "", login.TitleText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteInstructionPanel(HtmlTextWriter writer, Login login)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(login.InstructionText))
|
||||
{
|
||||
string className = (login.InstructionTextStyle != null) && (!String.IsNullOrEmpty(login.InstructionTextStyle.CssClass)) ? login.InstructionTextStyle.CssClass + " " : "";
|
||||
className += "AspNet-Login-InstructionPanel";
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, className);
|
||||
WebControlAdapterExtender.WriteSpan(writer, "", login.InstructionText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteFailurePanel(HtmlTextWriter writer, Login login)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(login.FailureText))
|
||||
{
|
||||
string className = (login.FailureTextStyle != null) && (!String.IsNullOrEmpty(login.FailureTextStyle.CssClass)) ? login.FailureTextStyle.CssClass + " " : "";
|
||||
className += "AspNet-Login-FailurePanel";
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, className);
|
||||
WebControlAdapterExtender.WriteSpan(writer, "", login.FailureText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteHelpPanel(HtmlTextWriter writer, Login login)
|
||||
{
|
||||
if ((!String.IsNullOrEmpty(login.HelpPageIconUrl)) || (!String.IsNullOrEmpty(login.HelpPageText)))
|
||||
{
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-Login-HelpPanel");
|
||||
WebControlAdapterExtender.WriteImage(writer, login.HelpPageIconUrl, "Help");
|
||||
WebControlAdapterExtender.WriteLink(writer, login.HyperLinkStyle.CssClass, login.HelpPageUrl, "Help", login.HelpPageText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteUserPanel(HtmlTextWriter writer, Login login)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(login.FindControl("UserName").UniqueID);
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-Login-UserPanel");
|
||||
Extender.WriteTextBox(writer, false, login.LabelStyle.CssClass, login.UserNameLabelText, login.TextBoxStyle.CssClass, "UserName", login.UserName);
|
||||
WebControlAdapterExtender.WriteRequiredFieldValidator(writer, login.FindControl("UserNameRequired") as RequiredFieldValidator, login.ValidatorTextStyle.CssClass, "UserName", login.UserNameRequiredErrorMessage);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
|
||||
private void WritePasswordPanel(HtmlTextWriter writer, Login login)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(login.FindControl("Password").UniqueID);
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-Login-PasswordPanel");
|
||||
Extender.WriteTextBox(writer, true, login.LabelStyle.CssClass, login.PasswordLabelText, login.TextBoxStyle.CssClass, "Password", "");
|
||||
WebControlAdapterExtender.WriteRequiredFieldValidator(writer, login.FindControl("PasswordRequired") as RequiredFieldValidator, login.ValidatorTextStyle.CssClass, "Password", login.PasswordRequiredErrorMessage);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
|
||||
private void WriteRememberMePanel(HtmlTextWriter writer, Login login)
|
||||
{
|
||||
if (login.DisplayRememberMe)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(login.FindControl("RememberMe").UniqueID);
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-Login-RememberMePanel");
|
||||
Extender.WriteCheckBox(writer, login.LabelStyle.CssClass, login.RememberMeText, login.CheckBoxStyle.CssClass, "RememberMe", login.RememberMeSet);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteSubmitPanel(HtmlTextWriter writer, Login login)
|
||||
{
|
||||
string id = "Login";
|
||||
string idWithType = WebControlAdapterExtender.MakeIdWithButtonType(id, login.LoginButtonType);
|
||||
Control btn = login.FindControl(idWithType);
|
||||
if (btn != null)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(btn.UniqueID);
|
||||
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-Login-SubmitPanel");
|
||||
|
||||
PostBackOptions options = new PostBackOptions(btn, "", "", false, false, false, false, true, login.UniqueID);
|
||||
string javascript = "javascript:" + Page.ClientScript.GetPostBackEventReference(options);
|
||||
javascript = Page.Server.HtmlEncode(javascript);
|
||||
|
||||
Extender.WriteSubmit(writer, login.LoginButtonType, login.LoginButtonStyle.CssClass, id, login.LoginButtonImageUrl, javascript, login.LoginButtonText);
|
||||
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteCreateUserPanel(HtmlTextWriter writer, Login login)
|
||||
{
|
||||
if ((!String.IsNullOrEmpty(login.CreateUserUrl)) || (!String.IsNullOrEmpty(login.CreateUserText)))
|
||||
{
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-Login-CreateUserPanel");
|
||||
WebControlAdapterExtender.WriteImage(writer, login.CreateUserIconUrl, "Create user");
|
||||
WebControlAdapterExtender.WriteLink(writer, login.HyperLinkStyle.CssClass, login.CreateUserUrl, "Create user", login.CreateUserText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WritePasswordRecoveryPanel(HtmlTextWriter writer, Login login)
|
||||
{
|
||||
if ((!String.IsNullOrEmpty(login.PasswordRecoveryUrl)) || (!String.IsNullOrEmpty(login.PasswordRecoveryText)))
|
||||
{
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-Login-PasswordRecoveryPanel");
|
||||
WebControlAdapterExtender.WriteImage(writer, login.PasswordRecoveryIconUrl, "Password recovery");
|
||||
WebControlAdapterExtender.WriteLink(writer, login.HyperLinkStyle.CssClass, login.PasswordRecoveryUrl, "Password recovery", login.PasswordRecoveryText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,165 @@
|
|||
// Material sourced from the bluePortal project (http://blueportal.codeplex.com).
|
||||
// Licensed under the Microsoft Public License (available at http://www.opensource.org/licenses/ms-pl.html).
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Collections;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
namespace CSSFriendly
|
||||
{
|
||||
public class LoginStatusAdapter : System.Web.UI.WebControls.Adapters.WebControlAdapter
|
||||
{
|
||||
private WebControlAdapterExtender _extender = null;
|
||||
private WebControlAdapterExtender Extender
|
||||
{
|
||||
get
|
||||
{
|
||||
if (((_extender == null) && (Control != null)) ||
|
||||
((_extender != null) && (Control != _extender.AdaptedControl)))
|
||||
{
|
||||
_extender = new WebControlAdapterExtender(Control);
|
||||
}
|
||||
|
||||
System.Diagnostics.Debug.Assert(_extender != null, "CSS Friendly adapters internal error", "Null extender instance");
|
||||
return _extender;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnInit(EventArgs e)
|
||||
{
|
||||
base.OnInit(e);
|
||||
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
RegisterScripts();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderBeginTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
// The LoginStatus is very simple INPUT or A tag so we don't wrap it with an being/end tag (e.g., no DIV wraps it).
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderBeginTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderEndTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
// The LoginStatus is very simple INPUT or A tag so we don't wrap it with an being/end tag (e.g., no DIV wraps it).
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderEndTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderContents(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
LoginStatus loginStatus = Control as LoginStatus;
|
||||
if (loginStatus != null)
|
||||
{
|
||||
string className = (!String.IsNullOrEmpty(loginStatus.CssClass)) ? ("AspNet-LoginStatus " + loginStatus.CssClass) : "AspNet-LoginStatus";
|
||||
|
||||
if (Membership.GetUser() == null)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(loginStatus.LoginImageUrl))
|
||||
{
|
||||
Control ctl = loginStatus.FindControl("ctl03");
|
||||
if (ctl != null)
|
||||
{
|
||||
writer.WriteBeginTag("input");
|
||||
writer.WriteAttribute("id", loginStatus.ClientID);
|
||||
writer.WriteAttribute("type", "image");
|
||||
writer.WriteAttribute("name", ctl.UniqueID);
|
||||
writer.WriteAttribute("title", loginStatus.ToolTip);
|
||||
writer.WriteAttribute("class", className);
|
||||
writer.WriteAttribute("src", loginStatus.ResolveClientUrl(loginStatus.LoginImageUrl));
|
||||
writer.WriteAttribute("alt", loginStatus.LoginText);
|
||||
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
|
||||
Page.ClientScript.RegisterForEventValidation(ctl.UniqueID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Control ctl = loginStatus.FindControl("ctl02");
|
||||
if (ctl != null)
|
||||
{
|
||||
writer.WriteBeginTag("a");
|
||||
writer.WriteAttribute("id", loginStatus.ClientID);
|
||||
writer.WriteAttribute("title", loginStatus.ToolTip);
|
||||
writer.WriteAttribute("class", className);
|
||||
writer.WriteAttribute("href", Page.ClientScript.GetPostBackClientHyperlink(loginStatus.FindControl("ctl02"), ""));
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Write(loginStatus.LoginText);
|
||||
writer.WriteEndTag("a");
|
||||
Page.ClientScript.RegisterForEventValidation(ctl.UniqueID);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.IsNullOrEmpty(loginStatus.LogoutImageUrl))
|
||||
{
|
||||
Control ctl = loginStatus.FindControl("ctl01");
|
||||
if (ctl != null)
|
||||
{
|
||||
writer.WriteBeginTag("input");
|
||||
writer.WriteAttribute("id", loginStatus.ClientID);
|
||||
writer.WriteAttribute("type", "image");
|
||||
writer.WriteAttribute("name", ctl.UniqueID);
|
||||
writer.WriteAttribute("title", loginStatus.ToolTip);
|
||||
writer.WriteAttribute("class", className);
|
||||
writer.WriteAttribute("src", loginStatus.ResolveClientUrl(loginStatus.LogoutImageUrl));
|
||||
writer.WriteAttribute("alt", loginStatus.LogoutText);
|
||||
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
|
||||
Page.ClientScript.RegisterForEventValidation(ctl.UniqueID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Control ctl = loginStatus.FindControl("ctl00");
|
||||
if (ctl != null)
|
||||
{
|
||||
writer.WriteBeginTag("a");
|
||||
writer.WriteAttribute("id", loginStatus.ClientID);
|
||||
writer.WriteAttribute("title", loginStatus.ToolTip);
|
||||
writer.WriteAttribute("class", className);
|
||||
writer.WriteAttribute("href", Page.ClientScript.GetPostBackClientHyperlink(loginStatus.FindControl("ctl00"), ""));
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Write(loginStatus.LogoutText);
|
||||
writer.WriteEndTag("a");
|
||||
Page.ClientScript.RegisterForEventValidation(ctl.UniqueID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderContents(writer);
|
||||
}
|
||||
}
|
||||
|
||||
/// ///////////////////////////////////////////////////////////////////////////////
|
||||
/// PRIVATE
|
||||
|
||||
private void RegisterScripts()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,334 @@
|
|||
// Material sourced from the bluePortal project (http://blueportal.codeplex.com).
|
||||
// Licensed under the Microsoft Public License (available at http://www.opensource.org/licenses/ms-pl.html).
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Web.Configuration;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
namespace CSSFriendly
|
||||
{
|
||||
public class MenuAdapter : System.Web.UI.WebControls.Adapters.MenuAdapter
|
||||
{
|
||||
private WebControlAdapterExtender _extender = null;
|
||||
private WebControlAdapterExtender Extender
|
||||
{
|
||||
get
|
||||
{
|
||||
if (((_extender == null) && (Control != null)) ||
|
||||
((_extender != null) && (Control != _extender.AdaptedControl)))
|
||||
{
|
||||
_extender = new WebControlAdapterExtender(Control);
|
||||
}
|
||||
|
||||
System.Diagnostics.Debug.Assert(_extender != null, "CSS Friendly adapters internal error", "Null extender instance");
|
||||
return _extender;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnInit(EventArgs e)
|
||||
{
|
||||
base.OnInit(e);
|
||||
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
RegisterScripts();
|
||||
}
|
||||
}
|
||||
|
||||
private void RegisterScripts()
|
||||
{
|
||||
Extender.RegisterScripts();
|
||||
string folderPath = WebConfigurationManager.AppSettings.Get("CSSFriendly-JavaScript-Path");
|
||||
if (String.IsNullOrEmpty(folderPath))
|
||||
{
|
||||
folderPath = "~/JavaScript";
|
||||
}
|
||||
string filePath = folderPath.EndsWith("/") ? folderPath + "MenuAdapter.js" : folderPath + "/MenuAdapter.js";
|
||||
Page.ClientScript.RegisterClientScriptInclude(GetType(), GetType().ToString(), Page.ResolveUrl(filePath));
|
||||
}
|
||||
|
||||
protected override void RenderBeginTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
Extender.RenderBeginTag(writer, "AspNet-Menu-" + Control.Orientation.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderBeginTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderEndTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
Extender.RenderEndTag(writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderEndTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderContents(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
writer.Indent++;
|
||||
BuildItems(Control.Items, true, writer);
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderContents(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildItems(MenuItemCollection items, bool isRoot, HtmlTextWriter writer)
|
||||
{
|
||||
if (items.Count > 0)
|
||||
{
|
||||
writer.WriteLine();
|
||||
|
||||
writer.WriteBeginTag("ul");
|
||||
if (isRoot)
|
||||
{
|
||||
writer.WriteAttribute("class", "AspNet-Menu");
|
||||
writer.WriteAttribute("id", Control.ClientID);
|
||||
}
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
|
||||
foreach (MenuItem item in items)
|
||||
{
|
||||
BuildItem(item, writer);
|
||||
}
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("ul");
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildItem(MenuItem item, HtmlTextWriter writer)
|
||||
{
|
||||
Menu menu = Control as Menu;
|
||||
if ((menu != null) && (item != null) && (writer != null))
|
||||
{
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("li");
|
||||
|
||||
string theClass = (item.ChildItems.Count > 0) ? "AspNet-Menu-WithChildren" : "AspNet-Menu-Leaf";
|
||||
string selectedStatusClass = GetSelectStatusClass(item);
|
||||
if (!String.IsNullOrEmpty(selectedStatusClass))
|
||||
{
|
||||
theClass += " " + selectedStatusClass;
|
||||
}
|
||||
writer.WriteAttribute("class", theClass);
|
||||
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
writer.WriteLine();
|
||||
|
||||
if (((item.Depth < menu.StaticDisplayLevels) && (menu.StaticItemTemplate != null)) ||
|
||||
((item.Depth >= menu.StaticDisplayLevels) && (menu.DynamicItemTemplate != null)))
|
||||
{
|
||||
writer.WriteBeginTag("div");
|
||||
writer.WriteAttribute("class", GetItemClass(menu, item));
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
writer.WriteLine();
|
||||
|
||||
MenuItemTemplateContainer container = new MenuItemTemplateContainer(menu.Items.IndexOf(item), item);
|
||||
if ((item.Depth < menu.StaticDisplayLevels) && (menu.StaticItemTemplate != null))
|
||||
{
|
||||
menu.StaticItemTemplate.InstantiateIn(container);
|
||||
}
|
||||
else
|
||||
{
|
||||
menu.DynamicItemTemplate.InstantiateIn(container);
|
||||
}
|
||||
container.DataBind();
|
||||
container.RenderControl(writer);
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("div");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsLink(item))
|
||||
{
|
||||
writer.WriteBeginTag("a");
|
||||
if (!String.IsNullOrEmpty(item.NavigateUrl))
|
||||
{
|
||||
writer.WriteAttribute("href", Page.Server.HtmlEncode(menu.ResolveClientUrl(item.NavigateUrl)));
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteAttribute("href", Page.ClientScript.GetPostBackClientHyperlink(menu, "b" + item.ValuePath.Replace(menu.PathSeparator.ToString(), "\\"), true));
|
||||
}
|
||||
|
||||
writer.WriteAttribute("class", GetItemClass(menu, item));
|
||||
WebControlAdapterExtender.WriteTargetAttribute(writer, item.Target);
|
||||
|
||||
if (!String.IsNullOrEmpty(item.ToolTip))
|
||||
{
|
||||
writer.WriteAttribute("title", item.ToolTip);
|
||||
}
|
||||
else if (!String.IsNullOrEmpty(menu.ToolTip))
|
||||
{
|
||||
writer.WriteAttribute("title", menu.ToolTip);
|
||||
}
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
writer.WriteLine();
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteBeginTag("span");
|
||||
writer.WriteAttribute("class", GetItemClass(menu, item));
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
writer.WriteLine();
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(item.ImageUrl))
|
||||
{
|
||||
writer.WriteBeginTag("img");
|
||||
writer.WriteAttribute("src", menu.ResolveClientUrl(item.ImageUrl));
|
||||
writer.WriteAttribute("alt", !String.IsNullOrEmpty(item.ToolTip) ? item.ToolTip : (!String.IsNullOrEmpty(menu.ToolTip) ? menu.ToolTip : item.Text));
|
||||
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
|
||||
}
|
||||
|
||||
writer.Write(item.Text);
|
||||
|
||||
if (IsLink(item))
|
||||
{
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("a");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("span");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ((item.ChildItems != null) && (item.ChildItems.Count > 0))
|
||||
{
|
||||
BuildItems(item.ChildItems, false, writer);
|
||||
}
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("li");
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsLink(MenuItem item)
|
||||
{
|
||||
return (item != null) && item.Enabled && ((!String.IsNullOrEmpty(item.NavigateUrl)) || item.Selectable);
|
||||
}
|
||||
|
||||
private string GetItemClass(Menu menu, MenuItem item)
|
||||
{
|
||||
string value = "AspNet-Menu-NonLink";
|
||||
if (item != null)
|
||||
{
|
||||
if (((item.Depth < menu.StaticDisplayLevels) && (menu.StaticItemTemplate != null)) ||
|
||||
((item.Depth >= menu.StaticDisplayLevels) && (menu.DynamicItemTemplate != null)))
|
||||
{
|
||||
value = "AspNet-Menu-Template";
|
||||
}
|
||||
else if (IsLink(item))
|
||||
{
|
||||
value = "AspNet-Menu-Link";
|
||||
}
|
||||
string selectedStatusClass = GetSelectStatusClass(item);
|
||||
if (!String.IsNullOrEmpty(selectedStatusClass))
|
||||
{
|
||||
value += " " + selectedStatusClass;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private string GetSelectStatusClass(MenuItem item)
|
||||
{
|
||||
string value = "";
|
||||
if (item.Selected)
|
||||
{
|
||||
value += " AspNet-Menu-Selected";
|
||||
}
|
||||
else if (IsChildItemSelected(item))
|
||||
{
|
||||
value += " AspNet-Menu-ChildSelected";
|
||||
}
|
||||
else if (IsParentItemSelected(item))
|
||||
{
|
||||
value += " AspNet-Menu-ParentSelected";
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private bool IsChildItemSelected(MenuItem item)
|
||||
{
|
||||
bool bRet = false;
|
||||
|
||||
if ((item != null) && (item.ChildItems != null))
|
||||
{
|
||||
bRet = IsChildItemSelected(item.ChildItems);
|
||||
}
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
private bool IsChildItemSelected(MenuItemCollection items)
|
||||
{
|
||||
bool bRet = false;
|
||||
|
||||
if (items != null)
|
||||
{
|
||||
foreach (MenuItem item in items)
|
||||
{
|
||||
if (item.Selected || IsChildItemSelected(item.ChildItems))
|
||||
{
|
||||
bRet = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
private bool IsParentItemSelected(MenuItem item)
|
||||
{
|
||||
bool bRet = false;
|
||||
|
||||
if ((item != null) && (item.Parent != null))
|
||||
{
|
||||
if (item.Parent.Selected)
|
||||
{
|
||||
bRet = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
bRet = IsParentItemSelected(item.Parent);
|
||||
}
|
||||
}
|
||||
|
||||
return bRet;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,534 @@
|
|||
// Material sourced from the bluePortal project (http://blueportal.codeplex.com).
|
||||
// Licensed under the Microsoft Public License (available at http://www.opensource.org/licenses/ms-pl.html).
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Collections;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
namespace CSSFriendly
|
||||
{
|
||||
public class PasswordRecoveryAdapter : System.Web.UI.WebControls.Adapters.WebControlAdapter
|
||||
{
|
||||
private enum State
|
||||
{
|
||||
UserName,
|
||||
VerifyingUser,
|
||||
UserLookupError,
|
||||
Question,
|
||||
VerifyingAnswer,
|
||||
AnswerLookupError,
|
||||
SendMailError,
|
||||
Success
|
||||
}
|
||||
State _state = State.UserName;
|
||||
string _currentErrorText = "";
|
||||
|
||||
private WebControlAdapterExtender _extender = null;
|
||||
private WebControlAdapterExtender Extender
|
||||
{
|
||||
get
|
||||
{
|
||||
if (((_extender == null) && (Control != null)) ||
|
||||
((_extender != null) && (Control != _extender.AdaptedControl)))
|
||||
{
|
||||
_extender = new WebControlAdapterExtender(Control);
|
||||
}
|
||||
|
||||
System.Diagnostics.Debug.Assert(_extender != null, "CSS Friendly adapters internal error", "Null extender instance");
|
||||
return _extender;
|
||||
}
|
||||
}
|
||||
|
||||
private MembershipProvider PasswordRecoveryMembershipProvider
|
||||
{
|
||||
get
|
||||
{
|
||||
MembershipProvider provider = Membership.Provider;
|
||||
PasswordRecovery passwordRecovery = Control as PasswordRecovery;
|
||||
if ((passwordRecovery != null) && (passwordRecovery.MembershipProvider != null) && (!String.IsNullOrEmpty(passwordRecovery.MembershipProvider)) && (Membership.Providers[passwordRecovery.MembershipProvider] != null))
|
||||
{
|
||||
provider = Membership.Providers[passwordRecovery.MembershipProvider];
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
|
||||
public PasswordRecoveryAdapter()
|
||||
{
|
||||
_state = State.UserName;
|
||||
_currentErrorText = "";
|
||||
}
|
||||
|
||||
/// ///////////////////////////////////////////////////////////////////////////////
|
||||
/// PROTECTED
|
||||
|
||||
protected override void OnInit(EventArgs e)
|
||||
{
|
||||
base.OnInit(e);
|
||||
|
||||
PasswordRecovery passwordRecovery = Control as PasswordRecovery;
|
||||
if (Extender.AdapterEnabled && (passwordRecovery != null))
|
||||
{
|
||||
RegisterScripts();
|
||||
passwordRecovery.AnswerLookupError += OnAnswerLookupError;
|
||||
passwordRecovery.SendMailError += OnSendMailError;
|
||||
passwordRecovery.UserLookupError += OnUserLookupError;
|
||||
passwordRecovery.VerifyingAnswer += OnVerifyingAnswer;
|
||||
passwordRecovery.VerifyingUser += OnVerifyingUser;
|
||||
_state = State.UserName;
|
||||
_currentErrorText = "";
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CreateChildControls()
|
||||
{
|
||||
base.CreateChildControls();
|
||||
|
||||
PasswordRecovery passwordRecovery = Control as PasswordRecovery;
|
||||
if (passwordRecovery != null)
|
||||
{
|
||||
if ((passwordRecovery.UserNameTemplate != null) && (passwordRecovery.UserNameTemplateContainer != null))
|
||||
{
|
||||
passwordRecovery.UserNameTemplateContainer.Controls.Clear();
|
||||
passwordRecovery.UserNameTemplate.InstantiateIn(passwordRecovery.UserNameTemplateContainer);
|
||||
passwordRecovery.UserNameTemplateContainer.DataBind();
|
||||
}
|
||||
|
||||
if ((passwordRecovery.QuestionTemplate != null) && (passwordRecovery.QuestionTemplateContainer != null))
|
||||
{
|
||||
passwordRecovery.QuestionTemplateContainer.Controls.Clear();
|
||||
passwordRecovery.QuestionTemplate.InstantiateIn(passwordRecovery.QuestionTemplateContainer);
|
||||
passwordRecovery.QuestionTemplateContainer.DataBind();
|
||||
}
|
||||
|
||||
if ((passwordRecovery.SuccessTemplate != null) && (passwordRecovery.SuccessTemplateContainer != null))
|
||||
{
|
||||
passwordRecovery.SuccessTemplateContainer.Controls.Clear();
|
||||
passwordRecovery.SuccessTemplate.InstantiateIn(passwordRecovery.SuccessTemplateContainer);
|
||||
passwordRecovery.SuccessTemplateContainer.DataBind();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnAnswerLookupError(object sender, EventArgs e)
|
||||
{
|
||||
_state = State.AnswerLookupError;
|
||||
PasswordRecovery passwordRecovery = Control as PasswordRecovery;
|
||||
if (passwordRecovery != null)
|
||||
{
|
||||
_currentErrorText = passwordRecovery.GeneralFailureText;
|
||||
if (!String.IsNullOrEmpty(passwordRecovery.QuestionFailureText))
|
||||
{
|
||||
_currentErrorText = passwordRecovery.QuestionFailureText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnSendMailError(object sender, SendMailErrorEventArgs e)
|
||||
{
|
||||
if (!e.Handled)
|
||||
{
|
||||
_state = State.SendMailError;
|
||||
_currentErrorText = e.Exception.Message;
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnUserLookupError(object sender, EventArgs e)
|
||||
{
|
||||
_state = State.UserLookupError;
|
||||
PasswordRecovery passwordRecovery = Control as PasswordRecovery;
|
||||
if (passwordRecovery != null)
|
||||
{
|
||||
_currentErrorText = passwordRecovery.GeneralFailureText;
|
||||
if (!String.IsNullOrEmpty(passwordRecovery.UserNameFailureText))
|
||||
{
|
||||
_currentErrorText = passwordRecovery.UserNameFailureText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnVerifyingAnswer(object sender, LoginCancelEventArgs e)
|
||||
{
|
||||
_state = State.VerifyingAnswer;
|
||||
}
|
||||
|
||||
protected void OnVerifyingUser(object sender, LoginCancelEventArgs e)
|
||||
{
|
||||
_state = State.VerifyingUser;
|
||||
}
|
||||
|
||||
protected override void RenderBeginTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
Extender.RenderBeginTag(writer, "AspNet-PasswordRecovery");
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderBeginTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPreRender(EventArgs e)
|
||||
{
|
||||
base.OnPreRender(e);
|
||||
|
||||
PasswordRecovery passwordRecovery = Control as PasswordRecovery;
|
||||
if (passwordRecovery != null)
|
||||
{
|
||||
string provider = passwordRecovery.MembershipProvider;
|
||||
}
|
||||
|
||||
// By this time we have finished doing our event processing. That means that if errors have
|
||||
// occurred, the event handlers (OnAnswerLookupError, OnSendMailError or
|
||||
// OnUserLookupError) will have been called. So, if we were, for example, verifying the
|
||||
// user and didn't cause an error then we know we can move on to the next step, getting
|
||||
// the answer to the security question... if the membership system demands it.
|
||||
|
||||
switch (_state)
|
||||
{
|
||||
case State.AnswerLookupError:
|
||||
// Leave the state alone because we hit an error.
|
||||
break;
|
||||
case State.Question:
|
||||
// Leave the state alone. Render a form to get the answer to the security question.
|
||||
_currentErrorText = "";
|
||||
break;
|
||||
case State.SendMailError:
|
||||
// Leave the state alone because we hit an error.
|
||||
break;
|
||||
case State.Success:
|
||||
// Leave the state alone. Render a concluding message.
|
||||
_currentErrorText = "";
|
||||
break;
|
||||
case State.UserLookupError:
|
||||
// Leave the state alone because we hit an error.
|
||||
break;
|
||||
case State.UserName:
|
||||
// Leave the state alone. Render a form to get the user name.
|
||||
_currentErrorText = "";
|
||||
break;
|
||||
case State.VerifyingAnswer:
|
||||
// Success! We did not encounter an error while verifying the answer to the security question.
|
||||
_state = State.Success;
|
||||
_currentErrorText = "";
|
||||
break;
|
||||
case State.VerifyingUser:
|
||||
// We have a valid user. We did not encounter an error while verifying the user.
|
||||
if (PasswordRecoveryMembershipProvider.RequiresQuestionAndAnswer)
|
||||
{
|
||||
_state = State.Question;
|
||||
}
|
||||
else
|
||||
{
|
||||
_state = State.Success;
|
||||
}
|
||||
_currentErrorText = "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderEndTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
Extender.RenderEndTag(writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderEndTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderContents(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
PasswordRecovery passwordRecovery = Control as PasswordRecovery;
|
||||
if (passwordRecovery != null)
|
||||
{
|
||||
if ((_state == State.UserName) || (_state == State.UserLookupError))
|
||||
{
|
||||
if ((passwordRecovery.UserNameTemplate != null) && (passwordRecovery.UserNameTemplateContainer != null))
|
||||
{
|
||||
foreach (Control c in passwordRecovery.UserNameTemplateContainer.Controls)
|
||||
{
|
||||
c.RenderControl(writer);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteTitlePanel(writer, passwordRecovery);
|
||||
WriteInstructionPanel(writer, passwordRecovery);
|
||||
WriteHelpPanel(writer, passwordRecovery);
|
||||
WriteUserPanel(writer, passwordRecovery);
|
||||
if (_state == State.UserLookupError)
|
||||
{
|
||||
WriteFailurePanel(writer, passwordRecovery);
|
||||
}
|
||||
WriteSubmitPanel(writer, passwordRecovery);
|
||||
}
|
||||
}
|
||||
else if ((_state == State.Question) || (_state == State.AnswerLookupError))
|
||||
{
|
||||
if ((passwordRecovery.QuestionTemplate != null) && (passwordRecovery.QuestionTemplateContainer != null))
|
||||
{
|
||||
foreach (Control c in passwordRecovery.QuestionTemplateContainer.Controls)
|
||||
{
|
||||
c.RenderControl(writer);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteTitlePanel(writer, passwordRecovery);
|
||||
WriteInstructionPanel(writer, passwordRecovery);
|
||||
WriteHelpPanel(writer, passwordRecovery);
|
||||
WriteUserPanel(writer, passwordRecovery);
|
||||
WriteQuestionPanel(writer, passwordRecovery);
|
||||
WriteAnswerPanel(writer, passwordRecovery);
|
||||
if (_state == State.AnswerLookupError)
|
||||
{
|
||||
WriteFailurePanel(writer, passwordRecovery);
|
||||
}
|
||||
WriteSubmitPanel(writer, passwordRecovery);
|
||||
}
|
||||
}
|
||||
else if (_state == State.SendMailError)
|
||||
{
|
||||
WriteFailurePanel(writer, passwordRecovery);
|
||||
}
|
||||
else if (_state == State.Success)
|
||||
{
|
||||
if ((passwordRecovery.SuccessTemplate != null) && (passwordRecovery.SuccessTemplateContainer != null))
|
||||
{
|
||||
foreach (Control c in passwordRecovery.SuccessTemplateContainer.Controls)
|
||||
{
|
||||
c.RenderControl(writer);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteSuccessTextPanel(writer, passwordRecovery);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// We should never get here.
|
||||
System.Diagnostics.Debug.Fail("The PasswordRecovery control adapter was asked to render a state that it does not expect.");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderContents(writer);
|
||||
}
|
||||
}
|
||||
|
||||
/// ///////////////////////////////////////////////////////////////////////////////
|
||||
/// PRIVATE
|
||||
|
||||
private void RegisterScripts()
|
||||
{
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// Step 1: user name
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
private void WriteTitlePanel(HtmlTextWriter writer, PasswordRecovery passwordRecovery)
|
||||
{
|
||||
if ((_state == State.UserName) || (_state == State.UserLookupError))
|
||||
{
|
||||
if (!String.IsNullOrEmpty(passwordRecovery.UserNameTitleText))
|
||||
{
|
||||
string className = (passwordRecovery.TitleTextStyle != null) && (!String.IsNullOrEmpty(passwordRecovery.TitleTextStyle.CssClass)) ? passwordRecovery.TitleTextStyle.CssClass + " " : "";
|
||||
className += "AspNet-PasswordRecovery-UserName-TitlePanel";
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, className);
|
||||
WebControlAdapterExtender.WriteSpan(writer, "", passwordRecovery.UserNameTitleText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
else if ((_state == State.Question) || (_state == State.AnswerLookupError))
|
||||
{
|
||||
if (!String.IsNullOrEmpty(passwordRecovery.QuestionTitleText))
|
||||
{
|
||||
string className = (passwordRecovery.TitleTextStyle != null) && (!String.IsNullOrEmpty(passwordRecovery.TitleTextStyle.CssClass)) ? passwordRecovery.TitleTextStyle.CssClass + " " : "";
|
||||
className += "AspNet-PasswordRecovery-Question-TitlePanel";
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, className);
|
||||
WebControlAdapterExtender.WriteSpan(writer, "", passwordRecovery.QuestionTitleText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteInstructionPanel(HtmlTextWriter writer, PasswordRecovery passwordRecovery)
|
||||
{
|
||||
if ((_state == State.UserName) || (_state == State.UserLookupError))
|
||||
{
|
||||
if (!String.IsNullOrEmpty(passwordRecovery.UserNameInstructionText))
|
||||
{
|
||||
string className = (passwordRecovery.InstructionTextStyle != null) && (!String.IsNullOrEmpty(passwordRecovery.InstructionTextStyle.CssClass)) ? passwordRecovery.InstructionTextStyle.CssClass + " " : "";
|
||||
className += "AspNet-PasswordRecovery-UserName-InstructionPanel";
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, className);
|
||||
WebControlAdapterExtender.WriteSpan(writer, "", passwordRecovery.UserNameInstructionText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
else if ((_state == State.Question) || (_state == State.AnswerLookupError))
|
||||
{
|
||||
if (!String.IsNullOrEmpty(passwordRecovery.QuestionInstructionText))
|
||||
{
|
||||
string className = (passwordRecovery.InstructionTextStyle != null) && (!String.IsNullOrEmpty(passwordRecovery.InstructionTextStyle.CssClass)) ? passwordRecovery.InstructionTextStyle.CssClass + " " : "";
|
||||
className += "AspNet-PasswordRecovery-Question-InstructionPanel";
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, className);
|
||||
WebControlAdapterExtender.WriteSpan(writer, "", passwordRecovery.QuestionInstructionText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteFailurePanel(HtmlTextWriter writer, PasswordRecovery passwordRecovery)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(_currentErrorText))
|
||||
{
|
||||
string className = (passwordRecovery.FailureTextStyle != null) && (!String.IsNullOrEmpty(passwordRecovery.FailureTextStyle.CssClass)) ? passwordRecovery.FailureTextStyle.CssClass + " " : "";
|
||||
className += "AspNet-PasswordRecovery-FailurePanel";
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, className);
|
||||
WebControlAdapterExtender.WriteSpan(writer, "", _currentErrorText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteHelpPanel(HtmlTextWriter writer, PasswordRecovery passwordRecovery)
|
||||
{
|
||||
if ((!String.IsNullOrEmpty(passwordRecovery.HelpPageIconUrl)) || (!String.IsNullOrEmpty(passwordRecovery.HelpPageText)))
|
||||
{
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-PasswordRecovery-HelpPanel");
|
||||
WebControlAdapterExtender.WriteImage(writer, passwordRecovery.HelpPageIconUrl, "Help");
|
||||
WebControlAdapterExtender.WriteLink(writer, passwordRecovery.HyperLinkStyle.CssClass, passwordRecovery.HelpPageUrl, "Help", passwordRecovery.HelpPageText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteUserPanel(HtmlTextWriter writer, PasswordRecovery passwordRecovery)
|
||||
{
|
||||
if ((_state == State.UserName) || (_state == State.UserLookupError))
|
||||
{
|
||||
Control container = passwordRecovery.UserNameTemplateContainer;
|
||||
TextBox textBox = (container != null) ? container.FindControl("UserName") as TextBox : null;
|
||||
RequiredFieldValidator rfv = (textBox != null) ? container.FindControl("UserNameRequired") as RequiredFieldValidator : null;
|
||||
string id = (rfv != null) ? container.ID + "_" + textBox.ID : "";
|
||||
if (!String.IsNullOrEmpty(id))
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(textBox.UniqueID);
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-PasswordRecovery-UserName-UserPanel");
|
||||
Extender.WriteTextBox(writer, false, passwordRecovery.LabelStyle.CssClass, passwordRecovery.UserNameLabelText, passwordRecovery.TextBoxStyle.CssClass, id, passwordRecovery.UserName);
|
||||
WebControlAdapterExtender.WriteRequiredFieldValidator(writer, rfv, passwordRecovery.ValidatorTextStyle.CssClass, "UserName", passwordRecovery.UserNameRequiredErrorMessage);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
else if ((_state == State.Question) || (_state == State.AnswerLookupError))
|
||||
{
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-PasswordRecovery-Question-UserPanel");
|
||||
Extender.WriteReadOnlyTextBox(writer, passwordRecovery.LabelStyle.CssClass, passwordRecovery.UserNameLabelText, passwordRecovery.TextBoxStyle.CssClass, passwordRecovery.UserName);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteSubmitPanel(HtmlTextWriter writer, PasswordRecovery passwordRecovery)
|
||||
{
|
||||
if ((_state == State.UserName) || (_state == State.UserLookupError))
|
||||
{
|
||||
Control container = passwordRecovery.UserNameTemplateContainer;
|
||||
string id = (container != null) ? container.ID + "_Submit" : "Submit";
|
||||
|
||||
string idWithType = WebControlAdapterExtender.MakeIdWithButtonType("Submit", passwordRecovery.SubmitButtonType);
|
||||
Control btn = (container != null) ? container.FindControl(idWithType) as Control : null;
|
||||
|
||||
if (btn != null)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(btn.UniqueID);
|
||||
|
||||
PostBackOptions options = new PostBackOptions(btn, "", "", false, false, false, false, true, passwordRecovery.UniqueID);
|
||||
string javascript = "javascript:" + Page.ClientScript.GetPostBackEventReference(options);
|
||||
javascript = Page.Server.HtmlEncode(javascript);
|
||||
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-PasswordRecovery-UserName-SubmitPanel");
|
||||
Extender.WriteSubmit(writer, passwordRecovery.SubmitButtonType, passwordRecovery.SubmitButtonStyle.CssClass, id, passwordRecovery.SubmitButtonImageUrl, javascript, passwordRecovery.SubmitButtonText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
else if ((_state == State.Question) || (_state == State.AnswerLookupError))
|
||||
{
|
||||
Control container = passwordRecovery.QuestionTemplateContainer;
|
||||
string id = (container != null) ? container.ID + "_Submit" : "Submit";
|
||||
string idWithType = WebControlAdapterExtender.MakeIdWithButtonType("Submit", passwordRecovery.SubmitButtonType);
|
||||
Control btn = (container != null) ? container.FindControl(idWithType) as Control : null;
|
||||
|
||||
if (btn != null)
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(btn.UniqueID);
|
||||
|
||||
PostBackOptions options = new PostBackOptions(btn, "", "", false, false, false, false, true, passwordRecovery.UniqueID);
|
||||
string javascript = "javascript:" + Page.ClientScript.GetPostBackEventReference(options);
|
||||
javascript = Page.Server.HtmlEncode(javascript);
|
||||
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-PasswordRecovery-Question-SubmitPanel");
|
||||
Extender.WriteSubmit(writer, passwordRecovery.SubmitButtonType, passwordRecovery.SubmitButtonStyle.CssClass, id, passwordRecovery.SubmitButtonImageUrl, javascript, passwordRecovery.SubmitButtonText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// Step 2: question
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
private void WriteQuestionPanel(HtmlTextWriter writer, PasswordRecovery passwordRecovery)
|
||||
{
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-PasswordRecovery-QuestionPanel");
|
||||
Extender.WriteReadOnlyTextBox(writer, passwordRecovery.LabelStyle.CssClass, passwordRecovery.QuestionLabelText, passwordRecovery.TextBoxStyle.CssClass, passwordRecovery.Question);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
|
||||
private void WriteAnswerPanel(HtmlTextWriter writer, PasswordRecovery passwordRecovery)
|
||||
{
|
||||
Control container = passwordRecovery.QuestionTemplateContainer;
|
||||
TextBox textBox = (container != null) ? container.FindControl("Answer") as TextBox : null;
|
||||
RequiredFieldValidator rfv = (textBox != null) ? container.FindControl("AnswerRequired") as RequiredFieldValidator : null;
|
||||
string id = (rfv != null) ? container.ID + "_" + textBox.ID : "";
|
||||
if (!String.IsNullOrEmpty(id))
|
||||
{
|
||||
Page.ClientScript.RegisterForEventValidation(textBox.UniqueID);
|
||||
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-PasswordRecovery-AnswerPanel");
|
||||
Extender.WriteTextBox(writer, false, passwordRecovery.LabelStyle.CssClass, passwordRecovery.AnswerLabelText, passwordRecovery.TextBoxStyle.CssClass, id, "");
|
||||
WebControlAdapterExtender.WriteRequiredFieldValidator(writer, rfv, passwordRecovery.ValidatorTextStyle.CssClass, "Answer", passwordRecovery.AnswerRequiredErrorMessage);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// Step 3: success
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
private void WriteSuccessTextPanel(HtmlTextWriter writer, PasswordRecovery passwordRecovery)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(passwordRecovery.SuccessText))
|
||||
{
|
||||
string className = (passwordRecovery.SuccessTextStyle != null) && (!String.IsNullOrEmpty(passwordRecovery.SuccessTextStyle.CssClass)) ? passwordRecovery.SuccessTextStyle.CssClass + " " : "";
|
||||
className += "AspNet-PasswordRecovery-SuccessTextPanel";
|
||||
WebControlAdapterExtender.WriteBeginDiv(writer, className);
|
||||
WebControlAdapterExtender.WriteSpan(writer, "", passwordRecovery.SuccessText);
|
||||
WebControlAdapterExtender.WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,697 @@
|
|||
// Material sourced from the bluePortal project (http://blueportal.codeplex.com).
|
||||
// Licensed under the Microsoft Public License (available at http://www.opensource.org/licenses/ms-pl.html).
|
||||
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Web;
|
||||
using System.Web.Configuration;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
using System.Reflection;
|
||||
|
||||
namespace CSSFriendly
|
||||
{
|
||||
public class TreeViewAdapter : System.Web.UI.WebControls.Adapters.HierarchicalDataBoundControlAdapter, IPostBackEventHandler, IPostBackDataHandler
|
||||
{
|
||||
private WebControlAdapterExtender _extender = null;
|
||||
private WebControlAdapterExtender Extender
|
||||
{
|
||||
get
|
||||
{
|
||||
if (((_extender == null) && (Control != null)) ||
|
||||
((_extender != null) && (Control != _extender.AdaptedControl)))
|
||||
{
|
||||
_extender = new WebControlAdapterExtender(Control);
|
||||
}
|
||||
|
||||
System.Diagnostics.Debug.Assert(_extender != null, "CSS Friendly adapters internal error", "Null extender instance");
|
||||
return _extender;
|
||||
}
|
||||
}
|
||||
|
||||
private int _checkboxIndex = 1;
|
||||
private HiddenField _viewState = null;
|
||||
private bool _updateViewState = false;
|
||||
private string _newViewState = "";
|
||||
|
||||
public TreeViewAdapter()
|
||||
{
|
||||
if (_viewState == null)
|
||||
{
|
||||
_viewState = new HiddenField();
|
||||
}
|
||||
}
|
||||
|
||||
// Implementation of IPostBackDataHandler
|
||||
public virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual void RaisePostDataChangedEvent()
|
||||
{
|
||||
TreeView treeView = Control as TreeView;
|
||||
if (treeView != null)
|
||||
{
|
||||
TreeNodeCollection items = treeView.Nodes;
|
||||
_checkboxIndex = 1;
|
||||
UpdateCheckmarks(items);
|
||||
}
|
||||
}
|
||||
|
||||
// Implementation of IPostBackEventHandler
|
||||
public void RaisePostBackEvent(string eventArgument)
|
||||
{
|
||||
TreeView treeView = Control as TreeView;
|
||||
if (treeView != null)
|
||||
{
|
||||
TreeNodeCollection items = treeView.Nodes;
|
||||
if (!String.IsNullOrEmpty(eventArgument))
|
||||
{
|
||||
if (eventArgument.StartsWith("s") || eventArgument.StartsWith("e"))
|
||||
{
|
||||
string selectedNodeValuePath = eventArgument.Substring(1).Replace("\\", "/");
|
||||
TreeNode selectedNode = treeView.FindNode(selectedNodeValuePath);
|
||||
if (selectedNode != null)
|
||||
{
|
||||
bool bSelectedNodeChanged = selectedNode != treeView.SelectedNode;
|
||||
ClearSelectedNode(items);
|
||||
selectedNode.Selected = true; // does not raise the SelectedNodeChanged event so we have to do it manually (below).
|
||||
if (eventArgument.StartsWith("e"))
|
||||
{
|
||||
selectedNode.Expanded = true;
|
||||
}
|
||||
|
||||
if (bSelectedNodeChanged)
|
||||
{
|
||||
Extender.RaiseAdaptedEvent("SelectedNodeChanged", new EventArgs());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (eventArgument.StartsWith("p"))
|
||||
{
|
||||
string parentNodeValuePath = eventArgument.Substring(1).Replace("\\", "/");
|
||||
TreeNode parentNode = treeView.FindNode(parentNodeValuePath);
|
||||
if ((parentNode != null) && ((parentNode.ChildNodes == null) || (parentNode.ChildNodes.Count == 0)))
|
||||
{
|
||||
parentNode.Expanded = true; // Raises the TreeNodePopulate event
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override Object SaveAdapterViewState()
|
||||
{
|
||||
string retStr = "";
|
||||
TreeView treeView = Control as TreeView;
|
||||
if ((treeView != null) && (_viewState != null))
|
||||
{
|
||||
if ((_viewState != null) && (Page != null) && (Page.Form != null) && (!Page.Form.Controls.Contains(_viewState)))
|
||||
{
|
||||
Panel panel = new Panel();
|
||||
panel.Controls.Add(_viewState);
|
||||
Page.Form.Controls.Add(panel);
|
||||
string script = "document.getElementById('" + _viewState.ClientID + "').value = GetViewState__AspNetTreeView('" + Control.ClientID + "');";
|
||||
Page.ClientScript.RegisterOnSubmitStatement(GetType(), GetType().ToString(), script);
|
||||
}
|
||||
retStr = _viewState.UniqueID + "|" + ComposeViewState(treeView.Nodes, "");
|
||||
}
|
||||
return retStr;
|
||||
}
|
||||
|
||||
protected override void LoadAdapterViewState(Object state)
|
||||
{
|
||||
TreeView treeView = Control as TreeView;
|
||||
string oldViewState = state as String;
|
||||
if ((treeView != null) && (oldViewState != null) && (oldViewState.Split('|').Length == 2))
|
||||
{
|
||||
string hiddenInputName = oldViewState.Split('|')[0];
|
||||
string oldExpansionState = oldViewState.Split('|')[1];
|
||||
if (!String.IsNullOrEmpty(Page.Request.Form[hiddenInputName]))
|
||||
{
|
||||
_newViewState = Page.Request.Form[hiddenInputName];
|
||||
_updateViewState = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnInit(EventArgs e)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
_updateViewState = false;
|
||||
_newViewState = "";
|
||||
|
||||
TreeView treeView = Control as TreeView;
|
||||
if (treeView != null)
|
||||
{
|
||||
treeView.EnableClientScript = false;
|
||||
}
|
||||
}
|
||||
|
||||
base.OnInit(e);
|
||||
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
RegisterScripts();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
base.OnLoad(e);
|
||||
|
||||
TreeView treeView = Control as TreeView;
|
||||
if (Extender.AdapterEnabled && _updateViewState && (treeView != null))
|
||||
{
|
||||
treeView.CollapseAll();
|
||||
ExpandToState(treeView.Nodes, _newViewState);
|
||||
_updateViewState = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void RegisterScripts()
|
||||
{
|
||||
Extender.RegisterScripts();
|
||||
string folderPath = WebConfigurationManager.AppSettings.Get("CSSFriendly-JavaScript-Path");
|
||||
if (String.IsNullOrEmpty(folderPath))
|
||||
{
|
||||
folderPath = "~/JavaScript";
|
||||
}
|
||||
string filePath = folderPath.EndsWith("/") ? folderPath + "TreeViewAdapter.js" : folderPath + "/TreeViewAdapter.js";
|
||||
Page.ClientScript.RegisterClientScriptInclude(GetType(), GetType().ToString(), Page.ResolveUrl(filePath));
|
||||
}
|
||||
|
||||
protected override void RenderBeginTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
Extender.RenderBeginTag(writer, "AspNet-TreeView");
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderBeginTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderEndTag(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
Extender.RenderEndTag(writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderEndTag(writer);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderContents(HtmlTextWriter writer)
|
||||
{
|
||||
if (Extender.AdapterEnabled)
|
||||
{
|
||||
TreeView treeView = Control as TreeView;
|
||||
if (treeView != null)
|
||||
{
|
||||
writer.Indent++;
|
||||
_checkboxIndex = 1;
|
||||
BuildItems(treeView.Nodes, true, true, writer);
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RenderContents(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildItems(TreeNodeCollection items, bool isRoot, bool isExpanded, HtmlTextWriter writer)
|
||||
{
|
||||
if (items.Count > 0)
|
||||
{
|
||||
writer.WriteLine();
|
||||
|
||||
writer.WriteBeginTag("ul");
|
||||
|
||||
if (isRoot)
|
||||
{
|
||||
writer.WriteAttribute("id", Control.ClientID);
|
||||
}
|
||||
if (!isExpanded)
|
||||
{
|
||||
writer.WriteAttribute("class", "AspNet-TreeView-Hide");
|
||||
}
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
|
||||
foreach (TreeNode item in items)
|
||||
{
|
||||
BuildItem(item, writer);
|
||||
}
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("ul");
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildItem(TreeNode item, HtmlTextWriter writer)
|
||||
{
|
||||
TreeView treeView = Control as TreeView;
|
||||
if ((treeView != null) && (item != null) && (writer != null))
|
||||
{
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("li");
|
||||
writer.WriteAttribute("class", GetNodeClass(item));
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
writer.WriteLine();
|
||||
|
||||
if (IsExpandable(item))
|
||||
{
|
||||
WriteNodeExpander(treeView, item, writer);
|
||||
}
|
||||
|
||||
if (IsCheckbox(treeView, item))
|
||||
{
|
||||
WriteNodeCheckbox(treeView, item, writer);
|
||||
}
|
||||
else if (IsLink(item))
|
||||
{
|
||||
WriteNodeLink(treeView, item, writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteNodePlain(treeView, item, writer);
|
||||
}
|
||||
|
||||
if (HasChildren(item))
|
||||
{
|
||||
BuildItems(item.ChildNodes, false, (item.Expanded == true), writer);
|
||||
}
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("li");
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteNodeExpander(TreeView treeView, TreeNode item, HtmlTextWriter writer)
|
||||
{
|
||||
writer.WriteBeginTag("span");
|
||||
writer.WriteAttribute("class", ((item.Expanded == true) ? "AspNet-TreeView-Collapse" : "AspNet-TreeView-Expand"));
|
||||
if (HasChildren(item))
|
||||
{
|
||||
writer.WriteAttribute("onclick", "ExpandCollapse__AspNetTreeView(this)");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteAttribute("onclick", Page.ClientScript.GetPostBackEventReference(treeView, "p" + (Page.Server.HtmlEncode(item.ValuePath)).Replace("/", "\\"), true));
|
||||
}
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Write(" ");
|
||||
writer.WriteEndTag("span");
|
||||
writer.WriteLine();
|
||||
}
|
||||
|
||||
private void WriteNodeImage(TreeView treeView, TreeNode item, HtmlTextWriter writer)
|
||||
{
|
||||
string imgSrc = GetImageSrc(treeView, item);
|
||||
if (!String.IsNullOrEmpty(imgSrc))
|
||||
{
|
||||
writer.WriteBeginTag("img");
|
||||
writer.WriteAttribute("src", treeView.ResolveClientUrl(imgSrc));
|
||||
writer.WriteAttribute("alt", !String.IsNullOrEmpty(item.ToolTip) ? item.ToolTip : (!String.IsNullOrEmpty(treeView.ToolTip) ? treeView.ToolTip : item.Text));
|
||||
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteNodeCheckbox(TreeView treeView, TreeNode item, HtmlTextWriter writer)
|
||||
{
|
||||
writer.WriteBeginTag("input");
|
||||
writer.WriteAttribute("type", "checkbox");
|
||||
writer.WriteAttribute("id", treeView.ClientID + "n" + _checkboxIndex.ToString() + "CheckBox");
|
||||
writer.WriteAttribute("name", treeView.UniqueID + "n" + _checkboxIndex.ToString() + "CheckBox");
|
||||
|
||||
if (!String.IsNullOrEmpty(treeView.Attributes["OnClientClickedCheckbox"]))
|
||||
{
|
||||
writer.WriteAttribute("onclick", treeView.Attributes["OnClientClickedCheckbox"]);
|
||||
}
|
||||
|
||||
if (item.Checked)
|
||||
{
|
||||
writer.WriteAttribute("checked", "checked");
|
||||
}
|
||||
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
|
||||
|
||||
if (!String.IsNullOrEmpty(item.Text))
|
||||
{
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("label");
|
||||
writer.WriteAttribute("for", treeView.ClientID + "n" + _checkboxIndex.ToString() + "CheckBox");
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Write(item.Text);
|
||||
writer.WriteEndTag("label");
|
||||
}
|
||||
|
||||
_checkboxIndex++;
|
||||
}
|
||||
|
||||
|
||||
private void WriteNodeLink(TreeView treeView, TreeNode item, HtmlTextWriter writer)
|
||||
{
|
||||
writer.WriteBeginTag("a");
|
||||
|
||||
if (!String.IsNullOrEmpty(item.NavigateUrl))
|
||||
{
|
||||
writer.WriteAttribute("href", Extender.ResolveUrl(item.NavigateUrl));
|
||||
}
|
||||
else
|
||||
{
|
||||
string codePrefix = "";
|
||||
if (item.SelectAction == TreeNodeSelectAction.Select)
|
||||
{
|
||||
codePrefix = "s";
|
||||
}
|
||||
else if (item.SelectAction == TreeNodeSelectAction.SelectExpand)
|
||||
{
|
||||
codePrefix = "e";
|
||||
}
|
||||
else if (item.PopulateOnDemand)
|
||||
{
|
||||
codePrefix = "p";
|
||||
}
|
||||
writer.WriteAttribute("href", Page.ClientScript.GetPostBackClientHyperlink(treeView, codePrefix + (Page.Server.HtmlEncode(item.ValuePath)).Replace("/", "\\"), true));
|
||||
}
|
||||
|
||||
WebControlAdapterExtender.WriteTargetAttribute(writer, item.Target);
|
||||
|
||||
if (!String.IsNullOrEmpty(item.ToolTip))
|
||||
{
|
||||
writer.WriteAttribute("title", item.ToolTip);
|
||||
}
|
||||
else if (!String.IsNullOrEmpty(treeView.ToolTip))
|
||||
{
|
||||
writer.WriteAttribute("title", treeView.ToolTip);
|
||||
}
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
writer.WriteLine();
|
||||
|
||||
WriteNodeImage(treeView, item, writer);
|
||||
writer.Write(item.Text);
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("a");
|
||||
}
|
||||
|
||||
private void WriteNodePlain(TreeView treeView, TreeNode item, HtmlTextWriter writer)
|
||||
{
|
||||
writer.WriteBeginTag("span");
|
||||
if (IsExpandable(item))
|
||||
{
|
||||
writer.WriteAttribute("class", "AspNet-TreeView-ClickableNonLink");
|
||||
writer.WriteAttribute("onclick", "ExpandCollapse__AspNetTreeView(this.parentNode.getElementsByTagName('span')[0])");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteAttribute("class", "AspNet-TreeView-NonLink");
|
||||
}
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
writer.WriteLine();
|
||||
|
||||
WriteNodeImage(treeView, item, writer);
|
||||
writer.Write(item.Text);
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("span");
|
||||
}
|
||||
|
||||
private void UpdateCheckmarks(TreeNodeCollection items)
|
||||
{
|
||||
TreeView treeView = Control as TreeView;
|
||||
if ((treeView != null) && (items != null))
|
||||
{
|
||||
foreach (TreeNode item in items)
|
||||
{
|
||||
if (IsCheckbox(treeView, item))
|
||||
{
|
||||
string name = treeView.UniqueID + "n" + _checkboxIndex.ToString() + "CheckBox";
|
||||
bool bIsNowChecked = (Page.Request.Form[name] != null);
|
||||
if (item.Checked != bIsNowChecked)
|
||||
{
|
||||
item.Checked = bIsNowChecked;
|
||||
Extender.RaiseAdaptedEvent("TreeNodeCheckChanged", new TreeNodeEventArgs(item));
|
||||
}
|
||||
_checkboxIndex++;
|
||||
}
|
||||
|
||||
if (HasChildren(item))
|
||||
{
|
||||
UpdateCheckmarks(item.ChildNodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsLink(TreeNode item)
|
||||
{
|
||||
return (item != null) && ((!String.IsNullOrEmpty(item.NavigateUrl)) || item.PopulateOnDemand || (item.SelectAction == TreeNodeSelectAction.Select) || (item.SelectAction == TreeNodeSelectAction.SelectExpand));
|
||||
}
|
||||
|
||||
private bool IsCheckbox(TreeView treeView, TreeNode item)
|
||||
{
|
||||
bool bItemCheckBoxDisallowed = (item.ShowCheckBox != null) && (item.ShowCheckBox.Value == false);
|
||||
bool bItemCheckBoxWanted = (item.ShowCheckBox != null) && (item.ShowCheckBox.Value == true);
|
||||
bool bTreeCheckBoxWanted =
|
||||
(treeView.ShowCheckBoxes == TreeNodeTypes.All) ||
|
||||
((treeView.ShowCheckBoxes == TreeNodeTypes.Leaf) && (!IsExpandable(item))) ||
|
||||
((treeView.ShowCheckBoxes == TreeNodeTypes.Parent) && (IsExpandable(item))) ||
|
||||
((treeView.ShowCheckBoxes == TreeNodeTypes.Root) && (item.Depth == 0));
|
||||
|
||||
return (!bItemCheckBoxDisallowed) && (bItemCheckBoxWanted || bTreeCheckBoxWanted);
|
||||
}
|
||||
|
||||
private string GetNodeClass(TreeNode item)
|
||||
{
|
||||
string value = "AspNet-TreeView-Leaf";
|
||||
if (item != null)
|
||||
{
|
||||
if (item.Depth == 0)
|
||||
{
|
||||
if (IsExpandable(item))
|
||||
{
|
||||
value = "AspNet-TreeView-Root";
|
||||
}
|
||||
else
|
||||
{
|
||||
value = "AspNet-TreeView-Root AspNet-TreeView-Leaf";
|
||||
}
|
||||
}
|
||||
else if (IsExpandable(item))
|
||||
{
|
||||
value = "AspNet-TreeView-Parent";
|
||||
}
|
||||
|
||||
if (item.Selected)
|
||||
{
|
||||
value += " AspNet-TreeView-Selected";
|
||||
}
|
||||
else if (IsChildNodeSelected(item))
|
||||
{
|
||||
value += " AspNet-TreeView-ChildSelected";
|
||||
}
|
||||
else if (IsParentNodeSelected(item))
|
||||
{
|
||||
value += " AspNet-TreeView-ParentSelected";
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private string GetImageSrc(TreeView treeView, TreeNode item)
|
||||
{
|
||||
string imgSrc = "";
|
||||
|
||||
if ((treeView != null) && (item != null))
|
||||
{
|
||||
imgSrc = item.ImageUrl;
|
||||
|
||||
if (String.IsNullOrEmpty(imgSrc))
|
||||
{
|
||||
if (item.Depth == 0)
|
||||
{
|
||||
if ((treeView.RootNodeStyle != null) && (!String.IsNullOrEmpty(treeView.RootNodeStyle.ImageUrl)))
|
||||
{
|
||||
imgSrc = treeView.RootNodeStyle.ImageUrl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!IsExpandable(item))
|
||||
{
|
||||
if ((treeView.LeafNodeStyle != null) && (!String.IsNullOrEmpty(treeView.LeafNodeStyle.ImageUrl)))
|
||||
{
|
||||
imgSrc = treeView.LeafNodeStyle.ImageUrl;
|
||||
}
|
||||
}
|
||||
else if ((treeView.ParentNodeStyle != null) && (!String.IsNullOrEmpty(treeView.ParentNodeStyle.ImageUrl)))
|
||||
{
|
||||
imgSrc = treeView.ParentNodeStyle.ImageUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((String.IsNullOrEmpty(imgSrc)) && (treeView.LevelStyles != null) && (treeView.LevelStyles.Count > item.Depth))
|
||||
{
|
||||
if (!String.IsNullOrEmpty(treeView.LevelStyles[item.Depth].ImageUrl))
|
||||
{
|
||||
imgSrc = treeView.LevelStyles[item.Depth].ImageUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return imgSrc;
|
||||
}
|
||||
|
||||
private bool HasChildren(TreeNode item)
|
||||
{
|
||||
return ((item != null) && ((item.ChildNodes != null) && (item.ChildNodes.Count > 0)));
|
||||
}
|
||||
|
||||
private bool IsExpandable(TreeNode item)
|
||||
{
|
||||
return (HasChildren(item) || ((item != null) && item.PopulateOnDemand));
|
||||
}
|
||||
|
||||
private void ClearSelectedNode(TreeNodeCollection nodes)
|
||||
{
|
||||
if (nodes != null)
|
||||
{
|
||||
foreach (TreeNode node in nodes)
|
||||
{
|
||||
if (node.Selected)
|
||||
{
|
||||
node.Selected = false;
|
||||
}
|
||||
if (node.ChildNodes != null)
|
||||
{
|
||||
ClearSelectedNode(node.ChildNodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsChildNodeSelected(TreeNode item)
|
||||
{
|
||||
bool bRet = false;
|
||||
|
||||
if ((item != null) && (item.ChildNodes != null))
|
||||
{
|
||||
bRet = IsChildNodeSelected(item.ChildNodes);
|
||||
}
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
private bool IsChildNodeSelected(TreeNodeCollection nodes)
|
||||
{
|
||||
bool bRet = false;
|
||||
|
||||
if (nodes != null)
|
||||
{
|
||||
foreach (TreeNode node in nodes)
|
||||
{
|
||||
if (node.Selected || IsChildNodeSelected(node.ChildNodes))
|
||||
{
|
||||
bRet = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
private bool IsParentNodeSelected(TreeNode item)
|
||||
{
|
||||
bool bRet = false;
|
||||
|
||||
if ((item != null) && (item.Parent != null))
|
||||
{
|
||||
if (item.Parent.Selected)
|
||||
{
|
||||
bRet = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
bRet = IsParentNodeSelected(item.Parent);
|
||||
}
|
||||
}
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
private string ComposeViewState(TreeNodeCollection nodes, string state)
|
||||
{
|
||||
if (nodes != null)
|
||||
{
|
||||
foreach (TreeNode node in nodes)
|
||||
{
|
||||
state += (node.Expanded == true) ? "e" : "n";
|
||||
state = ComposeViewState(node.ChildNodes, state);
|
||||
}
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
private string ExpandToState(TreeNodeCollection nodes, string state)
|
||||
{
|
||||
if ((nodes != null) && (!String.IsNullOrEmpty(state)))
|
||||
{
|
||||
foreach (TreeNode node in nodes)
|
||||
{
|
||||
if (IsExpandable(node))
|
||||
{
|
||||
bool bExpand = (state[0] == 'e');
|
||||
state = state.Substring(1);
|
||||
if (bExpand)
|
||||
{
|
||||
node.Expand();
|
||||
state = ExpandToState(node.ChildNodes, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
static public void ExpandToDepth(TreeNodeCollection nodes, int expandDepth)
|
||||
{
|
||||
if (nodes != null)
|
||||
{
|
||||
foreach (TreeNode node in nodes)
|
||||
{
|
||||
if (node.Depth < expandDepth)
|
||||
{
|
||||
node.Expand();
|
||||
ExpandToDepth(node.ChildNodes, expandDepth);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,598 @@
|
|||
// Material sourced from the bluePortal project (http://blueportal.codeplex.com).
|
||||
// Licensed under the Microsoft Public License (available at http://www.opensource.org/licenses/ms-pl.html).
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Reflection;
|
||||
using System.Web;
|
||||
using System.Web.Configuration;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.Adapters;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.Adapters;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
namespace CSSFriendly
|
||||
{
|
||||
public class WebControlAdapterExtender
|
||||
{
|
||||
private WebControl _adaptedControl = null;
|
||||
public WebControl AdaptedControl
|
||||
{
|
||||
get
|
||||
{
|
||||
System.Diagnostics.Debug.Assert(_adaptedControl != null, "CSS Friendly adapters internal error", "No control has been defined for the adapter extender");
|
||||
return _adaptedControl;
|
||||
}
|
||||
}
|
||||
|
||||
public bool AdapterEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
bool bReturn = true; // normally the adapters are enabled
|
||||
|
||||
// Individual controls can use the expando property called AdapterEnabled
|
||||
// as a way to turn the adapters off.
|
||||
// <asp:TreeView runat="server" AdapterEnabled="false" />
|
||||
if ((AdaptedControl != null) &&
|
||||
(!String.IsNullOrEmpty(AdaptedControl.Attributes["AdapterEnabled"])) &&
|
||||
(AdaptedControl.Attributes["AdapterEnabled"].IndexOf("false", StringComparison.OrdinalIgnoreCase) == 0))
|
||||
{
|
||||
bReturn = false;
|
||||
}
|
||||
|
||||
return bReturn;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _disableAutoAccessKey = false; // used when dealing with things like read-only textboxes that should not have access keys
|
||||
public bool AutoAccessKey
|
||||
{
|
||||
get
|
||||
{
|
||||
// Individual controls can use the expando property called AdapterEnabled
|
||||
// as a way to turn on/off the heurisitic for automatically setting the AccessKey
|
||||
// attribute in the rendered HTML. The default is shown below in the initialization
|
||||
// of the bReturn variable.
|
||||
// <asp:TreeView runat="server" AutoAccessKey="false" />
|
||||
|
||||
bool bReturn = true; // by default, the adapter will make access keys are available
|
||||
if (_disableAutoAccessKey ||
|
||||
((AdaptedControl != null) &&
|
||||
(!String.IsNullOrEmpty(AdaptedControl.Attributes["AutoAccessKey"])) &&
|
||||
(AdaptedControl.Attributes["AutoAccessKey"].IndexOf("false", StringComparison.OrdinalIgnoreCase) == 0)))
|
||||
{
|
||||
bReturn = false;
|
||||
}
|
||||
|
||||
return bReturn;
|
||||
}
|
||||
}
|
||||
|
||||
public WebControlAdapterExtender(WebControl adaptedControl)
|
||||
{
|
||||
_adaptedControl = adaptedControl;
|
||||
}
|
||||
|
||||
public void RegisterScripts()
|
||||
{
|
||||
string folderPath = WebConfigurationManager.AppSettings.Get("CSSFriendly-JavaScript-Path");
|
||||
if (String.IsNullOrEmpty(folderPath))
|
||||
{
|
||||
folderPath = "~/JavaScript";
|
||||
}
|
||||
string filePath = folderPath.EndsWith("/") ? folderPath + "AdapterUtils.js" : folderPath + "/AdapterUtils.js";
|
||||
AdaptedControl.Page.ClientScript.RegisterClientScriptInclude(GetType(), GetType().ToString(), AdaptedControl.Page.ResolveUrl(filePath));
|
||||
}
|
||||
|
||||
public string ResolveUrl(string url)
|
||||
{
|
||||
string urlToResolve = url;
|
||||
int nPound = url.LastIndexOf("#");
|
||||
int nSlash = url.LastIndexOf("/");
|
||||
if ((nPound > -1) && (nSlash > -1) && ((nSlash + 1) == nPound))
|
||||
{
|
||||
// We have been given a somewhat strange URL. It has a foreward slash (/) immediately followed
|
||||
// by a pound sign (#) like this xxx/#yyy. This sort of oddly shaped URL is what you get when
|
||||
// you use named anchors instead of pages in the url attribute of a sitemapnode in an ASP.NET
|
||||
// sitemap like this:
|
||||
//
|
||||
// <siteMapNode url="#Introduction" title="Introduction" description="Introduction" />
|
||||
//
|
||||
// The intend of the sitemap author is clearly to create a link to a named anchor in the page
|
||||
// that looks like these:
|
||||
//
|
||||
// <a id="Introduction"></a> (XHTML 1.1 Strict compliant)
|
||||
// <a name="Introduction"></a> (more old fashioned but quite common in many pages)
|
||||
//
|
||||
// However, the sitemap interpretter in ASP.NET doesn't understand url values that start with
|
||||
// a pound. It prepends the current site's path in front of it before making it into a link
|
||||
// (typically for a TreeView or Menu). We'll undo that problem, however, by converting this
|
||||
// sort of oddly shaped URL back into what was intended: a simple reference to a named anchor
|
||||
// that is expected to be within the current page.
|
||||
|
||||
urlToResolve = url.Substring(nPound);
|
||||
}
|
||||
else
|
||||
{
|
||||
urlToResolve = AdaptedControl.ResolveClientUrl(urlToResolve);
|
||||
}
|
||||
|
||||
// And, just to be safe, we'll make sure there aren't any troublesome characters in whatever URL
|
||||
// we have decided to use at this point.
|
||||
string newUrl = AdaptedControl.Page.Server.HtmlEncode(urlToResolve);
|
||||
|
||||
return newUrl;
|
||||
}
|
||||
|
||||
public void RaiseAdaptedEvent(string eventName, EventArgs e)
|
||||
{
|
||||
string attr = "OnAdapted" + eventName;
|
||||
if ((AdaptedControl != null) && (!String.IsNullOrEmpty(AdaptedControl.Attributes[attr])))
|
||||
{
|
||||
string delegateName = AdaptedControl.Attributes[attr];
|
||||
Control methodOwner = AdaptedControl.Parent;
|
||||
MethodInfo method = methodOwner.GetType().GetMethod(delegateName);
|
||||
if (method == null)
|
||||
{
|
||||
methodOwner = AdaptedControl.Page;
|
||||
method = methodOwner.GetType().GetMethod(delegateName);
|
||||
}
|
||||
if (method != null)
|
||||
{
|
||||
object[] args = new object[2];
|
||||
args[0] = AdaptedControl;
|
||||
args[1] = e;
|
||||
method.Invoke(methodOwner, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RenderBeginTag(HtmlTextWriter writer, string cssClass)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(AdaptedControl.Attributes["CssSelectorClass"]))
|
||||
{
|
||||
WriteBeginDiv(writer, AdaptedControl.Attributes["CssSelectorClass"]);
|
||||
}
|
||||
|
||||
WriteBeginDiv(writer, cssClass);
|
||||
}
|
||||
|
||||
public void RenderEndTag(HtmlTextWriter writer)
|
||||
{
|
||||
WriteEndDiv(writer);
|
||||
|
||||
if (!String.IsNullOrEmpty(AdaptedControl.Attributes["CssSelectorClass"]))
|
||||
{
|
||||
WriteEndDiv(writer);
|
||||
}
|
||||
}
|
||||
|
||||
static public void RemoveProblemChildren(Control ctrl, List<ControlRestorationInfo> stashedControls)
|
||||
{
|
||||
RemoveProblemTypes(ctrl.Controls, stashedControls);
|
||||
}
|
||||
|
||||
static public void RemoveProblemTypes(ControlCollection coll, List<ControlRestorationInfo> stashedControls)
|
||||
{
|
||||
foreach (Control ctrl in coll)
|
||||
{
|
||||
if (typeof(RequiredFieldValidator).IsAssignableFrom(ctrl.GetType()) ||
|
||||
typeof(CompareValidator).IsAssignableFrom(ctrl.GetType()) ||
|
||||
typeof(RegularExpressionValidator).IsAssignableFrom(ctrl.GetType()) ||
|
||||
typeof(ValidationSummary).IsAssignableFrom(ctrl.GetType()))
|
||||
{
|
||||
ControlRestorationInfo cri = new ControlRestorationInfo(ctrl, coll);
|
||||
stashedControls.Add(cri);
|
||||
coll.Remove(ctrl);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ctrl.HasControls())
|
||||
{
|
||||
RemoveProblemTypes(ctrl.Controls, stashedControls);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public void RestoreProblemChildren(List<ControlRestorationInfo> stashedControls)
|
||||
{
|
||||
foreach (ControlRestorationInfo cri in stashedControls)
|
||||
{
|
||||
cri.Restore();
|
||||
}
|
||||
}
|
||||
|
||||
public string MakeChildId(string postfix)
|
||||
{
|
||||
return AdaptedControl.ClientID + "_" + postfix;
|
||||
}
|
||||
|
||||
static public string MakeNameFromId(string id)
|
||||
{
|
||||
string name = "";
|
||||
for (int i=0; i<id.Length; i++)
|
||||
{
|
||||
char thisChar = id[i];
|
||||
char prevChar = ((i - 1) > -1) ? id[i - 1] : ' ';
|
||||
char nextChar = ((i + 1) < id.Length) ? id[i + 1] : ' ';
|
||||
if (thisChar == '_')
|
||||
{
|
||||
if (prevChar == '_')
|
||||
{
|
||||
name += "_";
|
||||
}
|
||||
else if (nextChar == '_')
|
||||
{
|
||||
name += "$_";
|
||||
}
|
||||
else
|
||||
{
|
||||
name += "$";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
name += thisChar;
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
static public string MakeIdWithButtonType(string id, ButtonType type)
|
||||
{
|
||||
string idWithType = id;
|
||||
switch (type)
|
||||
{
|
||||
case ButtonType.Button:
|
||||
idWithType += "Button";
|
||||
break;
|
||||
case ButtonType.Image:
|
||||
idWithType += "ImageButton";
|
||||
break;
|
||||
case ButtonType.Link:
|
||||
idWithType += "LinkButton";
|
||||
break;
|
||||
}
|
||||
return idWithType;
|
||||
}
|
||||
|
||||
public string MakeChildName(string postfix)
|
||||
{
|
||||
return MakeNameFromId(MakeChildId(postfix));
|
||||
}
|
||||
|
||||
static public void WriteBeginDiv(HtmlTextWriter writer, string className)
|
||||
{
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("div");
|
||||
if (!String.IsNullOrEmpty(className))
|
||||
{
|
||||
writer.WriteAttribute("class", className);
|
||||
}
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Indent++;
|
||||
}
|
||||
|
||||
static public void WriteEndDiv(HtmlTextWriter writer)
|
||||
{
|
||||
writer.Indent--;
|
||||
writer.WriteLine();
|
||||
writer.WriteEndTag("div");
|
||||
}
|
||||
|
||||
static public void WriteSpan(HtmlTextWriter writer, string className, string content)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(content))
|
||||
{
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("span");
|
||||
if (!String.IsNullOrEmpty(className))
|
||||
{
|
||||
writer.WriteAttribute("class", className);
|
||||
}
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Write(content);
|
||||
writer.WriteEndTag("span");
|
||||
}
|
||||
}
|
||||
|
||||
static public void WriteImage(HtmlTextWriter writer, string url, string alt)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(url))
|
||||
{
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("img");
|
||||
writer.WriteAttribute("src", url);
|
||||
writer.WriteAttribute("alt", alt);
|
||||
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
|
||||
}
|
||||
}
|
||||
|
||||
static public void WriteLink(HtmlTextWriter writer, string className, string url, string title, string content)
|
||||
{
|
||||
if ((!String.IsNullOrEmpty(url)) && (!String.IsNullOrEmpty(content)))
|
||||
{
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("a");
|
||||
if (!String.IsNullOrEmpty(className))
|
||||
{
|
||||
writer.WriteAttribute("class", className);
|
||||
}
|
||||
writer.WriteAttribute("href", url);
|
||||
writer.WriteAttribute("title", title);
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Write(content);
|
||||
writer.WriteEndTag("a");
|
||||
}
|
||||
}
|
||||
|
||||
// Can't be static because it uses MakeChildId
|
||||
public void WriteLabel(HtmlTextWriter writer, string className, string text, string forId)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(text))
|
||||
{
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("label");
|
||||
writer.WriteAttribute("for", MakeChildId(forId));
|
||||
if (!String.IsNullOrEmpty(className))
|
||||
{
|
||||
writer.WriteAttribute("class", className);
|
||||
}
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
|
||||
if (AutoAccessKey)
|
||||
{
|
||||
writer.WriteBeginTag("em");
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Write(text[0].ToString());
|
||||
writer.WriteEndTag("em");
|
||||
if (!String.IsNullOrEmpty(text))
|
||||
{
|
||||
writer.Write(text.Substring(1));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(text);
|
||||
}
|
||||
|
||||
writer.WriteEndTag("label");
|
||||
}
|
||||
}
|
||||
|
||||
// Can't be static because it uses MakeChildId
|
||||
public void WriteTextBox(HtmlTextWriter writer, bool isPassword, string labelClassName, string labelText, string inputClassName, string id, string value)
|
||||
{
|
||||
WriteLabel(writer, labelClassName, labelText, id);
|
||||
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("input");
|
||||
writer.WriteAttribute("type", isPassword ? "password" : "text");
|
||||
if (!String.IsNullOrEmpty(inputClassName))
|
||||
{
|
||||
writer.WriteAttribute("class", inputClassName);
|
||||
}
|
||||
writer.WriteAttribute("id", MakeChildId(id));
|
||||
writer.WriteAttribute("name", MakeChildName(id));
|
||||
writer.WriteAttribute("value", value);
|
||||
if (AutoAccessKey && (!String.IsNullOrEmpty(labelText)))
|
||||
{
|
||||
writer.WriteAttribute("accesskey", labelText[0].ToString().ToLower());
|
||||
}
|
||||
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
|
||||
}
|
||||
|
||||
// Can't be static because it uses MakeChildId
|
||||
public void WriteReadOnlyTextBox(HtmlTextWriter writer, string labelClassName, string labelText, string inputClassName, string value)
|
||||
{
|
||||
bool oldDisableAutoAccessKey = _disableAutoAccessKey;
|
||||
_disableAutoAccessKey = true;
|
||||
|
||||
WriteLabel(writer, labelClassName, labelText, "");
|
||||
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("input");
|
||||
writer.WriteAttribute("readonly", "true");
|
||||
if (!String.IsNullOrEmpty(inputClassName))
|
||||
{
|
||||
writer.WriteAttribute("class", inputClassName);
|
||||
}
|
||||
writer.WriteAttribute("value", value);
|
||||
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
|
||||
|
||||
_disableAutoAccessKey = oldDisableAutoAccessKey;
|
||||
}
|
||||
|
||||
// Can't be static because it uses MakeChildId
|
||||
public void WriteCheckBox(HtmlTextWriter writer, string labelClassName, string labelText, string inputClassName, string id, bool isChecked)
|
||||
{
|
||||
writer.WriteLine();
|
||||
writer.WriteBeginTag("input");
|
||||
writer.WriteAttribute("type", "checkbox");
|
||||
if (!String.IsNullOrEmpty(inputClassName))
|
||||
{
|
||||
writer.WriteAttribute("class", inputClassName);
|
||||
}
|
||||
writer.WriteAttribute("id", MakeChildId(id));
|
||||
writer.WriteAttribute("name", MakeChildName(id));
|
||||
if (isChecked)
|
||||
{
|
||||
writer.WriteAttribute("checked", "checked");
|
||||
}
|
||||
if (AutoAccessKey && (!String.IsNullOrEmpty(labelText)))
|
||||
{
|
||||
writer.WriteAttribute("accesskey", labelText[0].ToString());
|
||||
}
|
||||
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
|
||||
|
||||
WriteLabel(writer, labelClassName, labelText, id);
|
||||
}
|
||||
|
||||
// Can't be static because it uses MakeChildId
|
||||
public void WriteSubmit(HtmlTextWriter writer, ButtonType buttonType, string className, string id, string imageUrl, string javascript, string text)
|
||||
{
|
||||
writer.WriteLine();
|
||||
|
||||
string idWithType = id;
|
||||
|
||||
switch (buttonType)
|
||||
{
|
||||
case ButtonType.Button:
|
||||
writer.WriteBeginTag("input");
|
||||
writer.WriteAttribute("type", "submit");
|
||||
writer.WriteAttribute("value", text);
|
||||
idWithType += "Button";
|
||||
break;
|
||||
case ButtonType.Image:
|
||||
writer.WriteBeginTag("input");
|
||||
writer.WriteAttribute("type", "image");
|
||||
writer.WriteAttribute("src", imageUrl);
|
||||
idWithType += "ImageButton";
|
||||
break;
|
||||
case ButtonType.Link:
|
||||
writer.WriteBeginTag("a");
|
||||
idWithType += "LinkButton";
|
||||
break;
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(className))
|
||||
{
|
||||
writer.WriteAttribute("class", className);
|
||||
}
|
||||
writer.WriteAttribute("id", MakeChildId(idWithType));
|
||||
writer.WriteAttribute("name", MakeChildName(idWithType));
|
||||
|
||||
if (!String.IsNullOrEmpty(javascript))
|
||||
{
|
||||
string pureJS = javascript;
|
||||
if (pureJS.StartsWith("javascript:"))
|
||||
{
|
||||
pureJS = pureJS.Substring("javascript:".Length);
|
||||
}
|
||||
switch (buttonType)
|
||||
{
|
||||
case ButtonType.Button:
|
||||
writer.WriteAttribute("onclick", pureJS);
|
||||
break;
|
||||
case ButtonType.Image:
|
||||
writer.WriteAttribute("onclick", pureJS);
|
||||
break;
|
||||
case ButtonType.Link:
|
||||
writer.WriteAttribute("href", javascript);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (buttonType == ButtonType.Link)
|
||||
{
|
||||
writer.Write(HtmlTextWriter.TagRightChar);
|
||||
writer.Write(text);
|
||||
writer.WriteEndTag("a");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
|
||||
}
|
||||
}
|
||||
|
||||
static public void WriteRequiredFieldValidator(HtmlTextWriter writer, RequiredFieldValidator rfv, string className, string controlToValidate, string msg)
|
||||
{
|
||||
if (rfv != null)
|
||||
{
|
||||
rfv.CssClass = className;
|
||||
rfv.ControlToValidate = controlToValidate;
|
||||
rfv.ErrorMessage = msg;
|
||||
rfv.RenderControl(writer);
|
||||
}
|
||||
}
|
||||
|
||||
static public void WriteRegularExpressionValidator(HtmlTextWriter writer, RegularExpressionValidator rev, string className, string controlToValidate, string msg, string expression)
|
||||
{
|
||||
if (rev != null)
|
||||
{
|
||||
rev.CssClass = className;
|
||||
rev.ControlToValidate = controlToValidate;
|
||||
rev.ErrorMessage = msg;
|
||||
rev.ValidationExpression = expression;
|
||||
rev.RenderControl(writer);
|
||||
}
|
||||
}
|
||||
|
||||
static public void WriteCompareValidator(HtmlTextWriter writer, CompareValidator cv, string className, string controlToValidate, string msg, string controlToCompare)
|
||||
{
|
||||
if (cv != null)
|
||||
{
|
||||
cv.CssClass = className;
|
||||
cv.ControlToValidate = controlToValidate;
|
||||
cv.ErrorMessage = msg;
|
||||
cv.ControlToCompare = controlToCompare;
|
||||
cv.RenderControl(writer);
|
||||
}
|
||||
}
|
||||
|
||||
static public void WriteTargetAttribute(HtmlTextWriter writer, string targetValue)
|
||||
{
|
||||
if ((writer != null) && (!String.IsNullOrEmpty(targetValue)))
|
||||
{
|
||||
// If the targetValue is _blank then we have an opportunity to use attributes other than "target"
|
||||
// which allows us to be compliant at the XHTML 1.1 Strict level. Specifically, we can use a combination
|
||||
// of "onclick" and "onkeypress" to achieve what we want to achieve when we used to render
|
||||
// target='blank'.
|
||||
//
|
||||
// If the targetValue is other than _blank then we fall back to using the "target" attribute.
|
||||
// This is a heuristic that can be refined over time.
|
||||
if (targetValue.Equals("_blank", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
string js = "window.open(this.href, '_blank', ''); return false;";
|
||||
writer.WriteAttribute("onclick", js);
|
||||
writer.WriteAttribute("onkeypress", js);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteAttribute("target", targetValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ControlRestorationInfo
|
||||
{
|
||||
private Control _ctrl = null;
|
||||
public Control Control
|
||||
{
|
||||
get { return _ctrl; }
|
||||
}
|
||||
|
||||
private ControlCollection _coll = null;
|
||||
public ControlCollection Collection
|
||||
{
|
||||
get { return _coll; }
|
||||
}
|
||||
|
||||
public bool IsValid
|
||||
{
|
||||
get { return (Control != null) && (Collection != null); }
|
||||
}
|
||||
|
||||
public ControlRestorationInfo(Control ctrl, ControlCollection coll)
|
||||
{
|
||||
_ctrl = ctrl;
|
||||
_coll = coll;
|
||||
}
|
||||
|
||||
public void Restore()
|
||||
{
|
||||
if (IsValid)
|
||||
{
|
||||
_coll.Add(_ctrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 43 B |
|
@ -0,0 +1,52 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.WebPortal
|
||||
{
|
||||
public class ContentPane
|
||||
{
|
||||
private string id;
|
||||
private List<PageModule> modules = new List<PageModule>();
|
||||
|
||||
public string Id
|
||||
{
|
||||
get { return this.id; }
|
||||
set { this.id = value; }
|
||||
}
|
||||
|
||||
public List<PageModule> Modules
|
||||
{
|
||||
get { return this.modules; }
|
||||
set { this.modules = value; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
namespace WebsitePanel.WebPortal.Code.Controls
|
||||
{
|
||||
public class DesktopValidationEventArgs : EventArgs
|
||||
{
|
||||
private bool contextIsValid;
|
||||
|
||||
public bool ContextIsValid
|
||||
{
|
||||
get { return contextIsValid; }
|
||||
set { contextIsValid = value; }
|
||||
}
|
||||
}
|
||||
|
||||
public class DesktopContextValidator : CustomValidator
|
||||
{
|
||||
public event EventHandler<DesktopValidationEventArgs> EvaluatingContext;
|
||||
|
||||
protected override bool ControlPropertiesValid()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool EvaluateIsValid()
|
||||
{
|
||||
//
|
||||
DesktopValidationEventArgs args = new DesktopValidationEventArgs();
|
||||
//
|
||||
if (EvaluatingContext != null)
|
||||
{
|
||||
// trying evaluate manual context
|
||||
EvaluatingContext(this, args);
|
||||
//
|
||||
return args.ContextIsValid;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.WebPortal
|
||||
{
|
||||
public class ModuleControl
|
||||
{
|
||||
private string iconFile;
|
||||
private string src;
|
||||
private string key;
|
||||
private string title;
|
||||
private ModuleControlType controlType;
|
||||
|
||||
public string Src
|
||||
{
|
||||
get { return this.src; }
|
||||
set { this.src = value; }
|
||||
}
|
||||
|
||||
public string Key
|
||||
{
|
||||
get { return this.key; }
|
||||
set { this.key = value; }
|
||||
}
|
||||
|
||||
public string Title
|
||||
{
|
||||
get { return this.title; }
|
||||
set { this.title = value; }
|
||||
}
|
||||
|
||||
public ModuleControlType ControlType
|
||||
{
|
||||
get { return this.controlType; }
|
||||
set { this.controlType = value; }
|
||||
}
|
||||
|
||||
public string IconFile
|
||||
{
|
||||
get { return this.iconFile; }
|
||||
set { this.iconFile = value; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
namespace WebsitePanel.WebPortal
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for ModuleActionSecurityLevel
|
||||
/// </summary>
|
||||
public enum ModuleControlType
|
||||
{
|
||||
View,
|
||||
Edit
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.WebPortal
|
||||
{
|
||||
public class ModuleDefinition
|
||||
{
|
||||
private string id;
|
||||
private ModuleControl defaultControl;
|
||||
private Dictionary<string, ModuleControl> controls = new Dictionary<string, ModuleControl>();
|
||||
|
||||
public string Id
|
||||
{
|
||||
get { return this.id; }
|
||||
set { this.id = value; }
|
||||
}
|
||||
|
||||
public ModuleControl DefaultControl
|
||||
{
|
||||
get { return this.defaultControl; }
|
||||
set { this.defaultControl = value; }
|
||||
}
|
||||
|
||||
public Dictionary<string, ModuleControl> Controls
|
||||
{
|
||||
get { return this.controls; }
|
||||
}
|
||||
}
|
||||
}
|
127
WebsitePanel/Sources/WebsitePanel.WebPortal/Code/PageModule.cs
Normal file
127
WebsitePanel/Sources/WebsitePanel.WebPortal/Code/PageModule.cs
Normal file
|
@ -0,0 +1,127 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Xml;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.WebPortal
|
||||
{
|
||||
public class PageModule
|
||||
{
|
||||
private int moduleId;
|
||||
private string title;
|
||||
private string moduleDefinitionID;
|
||||
private string iconFile;
|
||||
private string containerSrc;
|
||||
private string adminContainerSrc;
|
||||
private List<string> viewRoles = new List<string>();
|
||||
private List<string> editRoles = new List<string>();
|
||||
private Hashtable settings = new Hashtable();
|
||||
private XmlDocument xmlModuleData = new XmlDocument();
|
||||
private PortalPage page;
|
||||
|
||||
public string ModuleDefinitionID
|
||||
{
|
||||
get { return this.moduleDefinitionID; }
|
||||
set { this.moduleDefinitionID = value; }
|
||||
}
|
||||
|
||||
public string IconFile
|
||||
{
|
||||
get { return this.iconFile; }
|
||||
set { this.iconFile = value; }
|
||||
}
|
||||
|
||||
public string ContainerSrc
|
||||
{
|
||||
get { return this.containerSrc; }
|
||||
set { this.containerSrc = value; }
|
||||
}
|
||||
|
||||
public string AdminContainerSrc
|
||||
{
|
||||
get { return this.adminContainerSrc; }
|
||||
set { this.adminContainerSrc = value; }
|
||||
}
|
||||
|
||||
public List<string> ViewRoles
|
||||
{
|
||||
get { return this.viewRoles; }
|
||||
}
|
||||
|
||||
public List<string> EditRoles
|
||||
{
|
||||
get { return this.editRoles; }
|
||||
}
|
||||
|
||||
public Hashtable Settings
|
||||
{
|
||||
get { return this.settings; }
|
||||
}
|
||||
|
||||
public string Title
|
||||
{
|
||||
get { return this.title; }
|
||||
set { this.title = value; }
|
||||
}
|
||||
|
||||
public int ModuleId
|
||||
{
|
||||
get { return this.moduleId; }
|
||||
set { this.moduleId = value; }
|
||||
}
|
||||
|
||||
public PortalPage Page
|
||||
{
|
||||
get { return this.page; }
|
||||
set { this.page = value; }
|
||||
}
|
||||
|
||||
public XmlNodeList SelectNodes(string xpath)
|
||||
{
|
||||
if(xmlModuleData.DocumentElement == null)
|
||||
return null;
|
||||
|
||||
return xmlModuleData.DocumentElement.SelectNodes(xpath);
|
||||
}
|
||||
|
||||
public void LoadXmlModuleData(string xml)
|
||||
{
|
||||
try
|
||||
{
|
||||
xmlModuleData.LoadXml(xml);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Configuration;
|
||||
|
||||
namespace WebsitePanel.WebPortal
|
||||
{
|
||||
public abstract class PageTitleProvider
|
||||
{
|
||||
private static PageTitleProvider _instance;
|
||||
public static PageTitleProvider Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance != null)
|
||||
return _instance;
|
||||
|
||||
try
|
||||
{
|
||||
_instance = (PageTitleProvider)Activator.CreateInstance(Type.GetType(
|
||||
ConfigurationManager.AppSettings["WebPortal.PageTitleProvider"]));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Could not create '{0}' page title provider", ex);
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract string ProcessPageTitle(string title);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,387 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Configuration;
|
||||
using System.Globalization;
|
||||
using System.Web;
|
||||
using System.Web.Caching;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
using System.Xml;
|
||||
|
||||
namespace WebsitePanel.WebPortal
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for ModuleDefinitions
|
||||
/// </summary>
|
||||
public class PortalConfiguration
|
||||
{
|
||||
private const string ROLES_DELIMITERS = ";,";
|
||||
private const string APP_DATA_FOLDER = "~/App_Data";
|
||||
private const string THEMES_FOLDER = "~/App_Themes";
|
||||
private const string MODULES_PATTERN = "*_Modules.config";
|
||||
private const string PAGES_PATTERN = "*_Pages.config";
|
||||
private const string SITE_SETTINGS_FILE = "SiteSettings.config";
|
||||
private const string MODULE_DEFINITIONS_KEY = "PortalModuleDefinitionsCacheKey";
|
||||
private const string SITE_STRUCTURE_KEY = "SiteStructureCacheKey";
|
||||
private const string SITE_SETTINGS_KEY = "SiteSettingsCacheKey";
|
||||
|
||||
public static Dictionary<string, ModuleDefinition> ModuleDefinitions
|
||||
{
|
||||
get
|
||||
{
|
||||
Dictionary<string, ModuleDefinition> modules =
|
||||
(Dictionary<string, ModuleDefinition>)HttpContext.Current.Cache[MODULE_DEFINITIONS_KEY];
|
||||
if (modules == null)
|
||||
{
|
||||
// create list
|
||||
modules = new Dictionary<string, ModuleDefinition>();
|
||||
|
||||
// load modules
|
||||
string appData = HttpContext.Current.Server.MapPath(APP_DATA_FOLDER);
|
||||
FileInfo[] files = new DirectoryInfo(appData).GetFiles(MODULES_PATTERN);
|
||||
|
||||
foreach (FileInfo file in files)
|
||||
LoadModulesFromXml(modules, file.FullName);
|
||||
|
||||
// place to cache
|
||||
HttpContext.Current.Cache.Insert(MODULE_DEFINITIONS_KEY, modules,
|
||||
new System.Web.Caching.CacheDependency(appData));
|
||||
|
||||
}
|
||||
return modules;
|
||||
}
|
||||
}
|
||||
|
||||
public static SiteStructure Site
|
||||
{
|
||||
get
|
||||
{
|
||||
SiteStructure site =
|
||||
(SiteStructure)HttpContext.Current.Cache[SITE_STRUCTURE_KEY];
|
||||
if (site == null)
|
||||
{
|
||||
// create list
|
||||
site = new SiteStructure();
|
||||
|
||||
// load pages
|
||||
string appData = HttpContext.Current.Server.MapPath(APP_DATA_FOLDER);
|
||||
FileInfo[] files = new DirectoryInfo(appData).GetFiles(PAGES_PATTERN);
|
||||
|
||||
foreach (FileInfo file in files)
|
||||
LoadPagesFromXml(site, file.FullName);
|
||||
|
||||
// place to cache
|
||||
HttpContext.Current.Cache.Insert(SITE_STRUCTURE_KEY, site,
|
||||
new System.Web.Caching.CacheDependency(appData));
|
||||
|
||||
}
|
||||
return site;
|
||||
}
|
||||
}
|
||||
|
||||
public static SiteSettings SiteSettings
|
||||
{
|
||||
get
|
||||
{
|
||||
SiteSettings settings =
|
||||
(SiteSettings)HttpContext.Current.Cache[SITE_SETTINGS_KEY];
|
||||
if (settings == null)
|
||||
{
|
||||
// create list
|
||||
settings = new SiteSettings();
|
||||
|
||||
// load pages
|
||||
string appData = HttpContext.Current.Server.MapPath(APP_DATA_FOLDER);
|
||||
string path = Path.Combine(appData, SITE_SETTINGS_FILE);
|
||||
|
||||
// load site settings
|
||||
XmlDocument xml = new XmlDocument();
|
||||
xml.Load(path);
|
||||
|
||||
XmlNodeList nodes = xml.SelectNodes("SiteSettings/*");
|
||||
|
||||
foreach(XmlNode node in nodes)
|
||||
{
|
||||
settings[node.LocalName] = node.InnerText;
|
||||
}
|
||||
|
||||
// place to cache
|
||||
HttpContext.Current.Cache.Insert(SITE_SETTINGS_KEY, settings,
|
||||
new System.Web.Caching.CacheDependency(path));
|
||||
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool SaveSiteSettings()
|
||||
{
|
||||
// load pages
|
||||
string appData = HttpContext.Current.Server.MapPath(APP_DATA_FOLDER);
|
||||
string path = Path.Combine(appData, SITE_SETTINGS_FILE);
|
||||
|
||||
try
|
||||
{
|
||||
// build and save site settings
|
||||
XmlDocument xml = new XmlDocument();
|
||||
|
||||
XmlElement root = xml.CreateElement("SiteSettings");
|
||||
xml.AppendChild(root);
|
||||
|
||||
foreach (string keyName in SiteSettings.AllKeys)
|
||||
{
|
||||
XmlElement elem = xml.CreateElement(keyName);
|
||||
elem.InnerText = SiteSettings[keyName];
|
||||
|
||||
root.AppendChild(elem);
|
||||
}
|
||||
|
||||
xml.Save(path);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void LoadModulesFromXml(Dictionary<string, ModuleDefinition> modules, string path)
|
||||
{
|
||||
// open xml document
|
||||
XmlDocument xml = new XmlDocument();
|
||||
xml.Load(path);
|
||||
|
||||
// select nodes
|
||||
XmlNodeList xmlModules = xml.SelectNodes("ModuleDefinitions/ModuleDefinition");
|
||||
foreach (XmlNode xmlModule in xmlModules)
|
||||
{
|
||||
ModuleDefinition module = new ModuleDefinition();
|
||||
if (xmlModule.Attributes["id"] == null)
|
||||
throw new Exception(String.Format("Module ID is not specified. File: {0}, Node: {1}",
|
||||
path, xmlModule.OuterXml));
|
||||
|
||||
module.Id = xmlModule.Attributes["id"].Value.ToLower(CultureInfo.InvariantCulture);
|
||||
modules.Add(module.Id, module);
|
||||
|
||||
// controls
|
||||
XmlNodeList xmlControls = xmlModule.SelectNodes("Controls/Control");
|
||||
foreach (XmlNode xmlControl in xmlControls)
|
||||
{
|
||||
ModuleControl control = new ModuleControl();
|
||||
if (xmlControl.Attributes["icon"] != null)
|
||||
control.IconFile = xmlControl.Attributes["icon"].Value;
|
||||
|
||||
if(xmlControl.Attributes["key"] != null)
|
||||
control.Key = xmlControl.Attributes["key"].Value.ToLower(CultureInfo.InvariantCulture);
|
||||
|
||||
if (xmlControl.Attributes["src"] == null)
|
||||
throw new Exception(String.Format("Control 'src' is not specified. File: {0}, Node: {1}",
|
||||
path, xmlControl.ParentNode.OuterXml));
|
||||
control.Src = xmlControl.Attributes["src"].Value;
|
||||
|
||||
if (xmlControl.Attributes["title"] == null)
|
||||
throw new Exception(String.Format("Control 'title' is not specified. File: {0}, Node: {1}",
|
||||
path, xmlControl.ParentNode.OuterXml));
|
||||
control.Title = xmlControl.Attributes["title"].Value;
|
||||
|
||||
if (xmlControl.Attributes["type"] != null)
|
||||
control.ControlType = (ModuleControlType)Enum.Parse(typeof(ModuleControlType), xmlControl.Attributes["type"].Value, true);
|
||||
else
|
||||
control.ControlType = ModuleControlType.View;
|
||||
|
||||
if (String.IsNullOrEmpty(control.Key))
|
||||
module.DefaultControl = control;
|
||||
|
||||
module.Controls.Add(control.Key, control);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void LoadPagesFromXml(SiteStructure site, string path)
|
||||
{
|
||||
// open xml document
|
||||
XmlDocument xml = new XmlDocument();
|
||||
xml.Load(path);
|
||||
|
||||
// select nodes
|
||||
XmlNodeList xmlPages = xml.SelectNodes("Pages/Page");
|
||||
|
||||
// process includes
|
||||
ProcessXmlIncludes(xml, path);
|
||||
|
||||
// parse root nodes
|
||||
ParsePagesRecursively(path, site, xmlPages, null);
|
||||
}
|
||||
|
||||
private static void ProcessXmlIncludes(XmlDocument xml, string parentPath)
|
||||
{
|
||||
// working dir
|
||||
string path = Path.GetDirectoryName(parentPath);
|
||||
|
||||
// get all <includes>
|
||||
XmlNodeList nodes = xml.SelectNodes("//include");
|
||||
foreach (XmlNode node in nodes)
|
||||
{
|
||||
if (node.Attributes["file"] == null)
|
||||
continue;
|
||||
|
||||
string incPath = Path.Combine(path, node.Attributes["file"].Value);
|
||||
XmlDocument inc = new XmlDocument();
|
||||
inc.Load(incPath);
|
||||
|
||||
XmlElement incNode = xml.CreateElement(inc.DocumentElement.Name);
|
||||
incNode.InnerXml = inc.DocumentElement.InnerXml;
|
||||
|
||||
// replace original node
|
||||
node.ParentNode.ReplaceChild(incNode, node);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ParsePagesRecursively(string path, SiteStructure site, XmlNodeList xmlPages, PortalPage parentPage)
|
||||
{
|
||||
foreach (XmlNode xmlPage in xmlPages)
|
||||
{
|
||||
PortalPage page = new PortalPage();
|
||||
page.ParentPage = parentPage;
|
||||
|
||||
// page properties
|
||||
if (xmlPage.Attributes["name"] == null)
|
||||
throw new Exception(String.Format("Page name is not specified. File: {0}, Node: {1}",
|
||||
path, xmlPage.OuterXml));
|
||||
page.Name = xmlPage.Attributes["name"].Value;
|
||||
|
||||
if (xmlPage.Attributes["roles"] == null)
|
||||
page.Roles.Add("*");
|
||||
else
|
||||
page.Roles.AddRange(xmlPage.Attributes["roles"].Value.Split(ROLES_DELIMITERS.ToCharArray()));
|
||||
|
||||
page.Enabled = (xmlPage.Attributes["enabled"] != null) ? Boolean.Parse(xmlPage.Attributes["enabled"].Value) : true;
|
||||
page.Hidden = (xmlPage.Attributes["hidden"] != null) ? Boolean.Parse(xmlPage.Attributes["hidden"].Value) : false;
|
||||
page.SkinSrc = (xmlPage.Attributes["skin"] != null) ? xmlPage.Attributes["skin"].Value : null;
|
||||
page.AdminSkinSrc = (xmlPage.Attributes["adminskin"] != null) ? xmlPage.Attributes["adminskin"].Value : null;
|
||||
|
||||
if (xmlPage.Attributes["url"] != null)
|
||||
page.Url = xmlPage.Attributes["url"].Value;
|
||||
|
||||
if (xmlPage.Attributes["target"] != null)
|
||||
page.Target = xmlPage.Attributes["target"].Value;
|
||||
|
||||
// content panes
|
||||
XmlNodeList xmlContentPanes = xmlPage.SelectNodes("Content");
|
||||
foreach (XmlNode xmlContentPane in xmlContentPanes)
|
||||
{
|
||||
ContentPane pane = new ContentPane();
|
||||
if (xmlContentPane.Attributes["id"] == null)
|
||||
throw new Exception(String.Format("ContentPane ID is not specified. File: {0}, Node: {1}",
|
||||
path, xmlContentPane.ParentNode.OuterXml));
|
||||
pane.Id = xmlContentPane.Attributes["id"].Value;
|
||||
page.ContentPanes.Add(pane.Id, pane);
|
||||
|
||||
// page modules
|
||||
XmlNodeList xmlModules = xmlContentPane.SelectNodes("Module");
|
||||
foreach (XmlNode xmlModule in xmlModules)
|
||||
{
|
||||
PageModule module = new PageModule();
|
||||
module.ModuleId = site.Modules.Count + 1;
|
||||
module.Page = page;
|
||||
site.Modules.Add(module.ModuleId, module);
|
||||
|
||||
if (xmlModule.Attributes["moduleDefinitionID"] == null)
|
||||
throw new Exception(String.Format("ModuleDefinition ID is not specified. File: {0}, Node: {1}",
|
||||
path, xmlModule.ParentNode.OuterXml));
|
||||
module.ModuleDefinitionID = xmlModule.Attributes["moduleDefinitionID"].Value.ToLower(CultureInfo.InvariantCulture);
|
||||
|
||||
if (xmlModule.Attributes["title"] != null)
|
||||
module.Title = xmlModule.Attributes["title"].Value;
|
||||
|
||||
if (xmlModule.Attributes["icon"] != null)
|
||||
module.IconFile = xmlModule.Attributes["icon"].Value;
|
||||
|
||||
if (xmlModule.Attributes["container"] != null)
|
||||
module.ContainerSrc = xmlModule.Attributes["container"].Value;
|
||||
|
||||
if (xmlModule.Attributes["admincontainer"] != null)
|
||||
module.AdminContainerSrc = xmlModule.Attributes["admincontainer"].Value;
|
||||
|
||||
if (xmlModule.Attributes["viewRoles"] == null)
|
||||
module.ViewRoles.Add("*");
|
||||
else
|
||||
module.ViewRoles.AddRange(xmlModule.Attributes["viewRoles"].Value.Split(ROLES_DELIMITERS.ToCharArray()));
|
||||
|
||||
if (xmlModule.Attributes["editRoles"] == null)
|
||||
module.EditRoles.Add("*");
|
||||
else
|
||||
module.EditRoles.AddRange(xmlModule.Attributes["editRoles"].Value.Split(ROLES_DELIMITERS.ToCharArray()));
|
||||
|
||||
// settings
|
||||
XmlNodeList xmlSettings = xmlModule.SelectNodes("Settings/Add");
|
||||
foreach (XmlNode xmlSetting in xmlSettings)
|
||||
{
|
||||
module.Settings[xmlSetting.Attributes["name"].Value] = xmlSetting.Attributes["value"].Value;
|
||||
}
|
||||
|
||||
XmlNode xmlModuleData = xmlModule.SelectSingleNode("ModuleData");
|
||||
if (xmlModuleData != null)
|
||||
{
|
||||
// check reference
|
||||
if (xmlModuleData.Attributes["ref"] != null)
|
||||
{
|
||||
// load referenced module data
|
||||
xmlModuleData = xmlModule.OwnerDocument.SelectSingleNode(
|
||||
"Pages/ModulesData/ModuleData[@id='" + xmlModuleData.Attributes["ref"].Value + "']");
|
||||
}
|
||||
module.LoadXmlModuleData(xmlModuleData.OuterXml);
|
||||
}
|
||||
|
||||
pane.Modules.Add(module);
|
||||
}
|
||||
}
|
||||
|
||||
// add page to te array
|
||||
if (parentPage != null)
|
||||
parentPage.Pages.Add(page);
|
||||
|
||||
site.Pages.Add(page);
|
||||
|
||||
// process children
|
||||
XmlNodeList xmlChildPages = xmlPage.SelectNodes("Pages/Page");
|
||||
ParsePagesRecursively(path, site, xmlChildPages, page);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
|
||||
namespace WebsitePanel.WebPortal
|
||||
{
|
||||
public class PortalControlBase : UserControl
|
||||
{
|
||||
private Control containerControl;
|
||||
private PageModule module;
|
||||
public PageModule Module
|
||||
{
|
||||
get { return module; }
|
||||
set { module = value; }
|
||||
}
|
||||
|
||||
public Control ContainerControl
|
||||
{
|
||||
get { return containerControl; }
|
||||
set { containerControl = value; }
|
||||
}
|
||||
|
||||
protected int ModuleID
|
||||
{
|
||||
get { return module.ModuleId; }
|
||||
}
|
||||
|
||||
protected Hashtable ModuleSettings
|
||||
{
|
||||
get { return module.Settings; }
|
||||
}
|
||||
|
||||
public string EditUrl(string controlKey)
|
||||
{
|
||||
return EditUrl(null, null, controlKey);
|
||||
}
|
||||
|
||||
public string EditUrl(string keyName, string keyValue, string controlKey)
|
||||
{
|
||||
return EditUrl(keyName, keyValue, controlKey, null);
|
||||
}
|
||||
|
||||
public string EditUrl(string keyName, string keyValue, string controlKey, params string[] additionalParams)
|
||||
{
|
||||
List<string> url = new List<string>();
|
||||
|
||||
string pageId = Request[DefaultPage.PAGE_ID_PARAM];
|
||||
|
||||
if (!String.IsNullOrEmpty(pageId))
|
||||
url.Add(String.Concat(DefaultPage.PAGE_ID_PARAM, "=", pageId));
|
||||
|
||||
url.Add(String.Concat(DefaultPage.MODULE_ID_PARAM, "=", ModuleID));
|
||||
url.Add(String.Concat(DefaultPage.CONTROL_ID_PARAM, "=", controlKey));
|
||||
|
||||
if (!String.IsNullOrEmpty(keyName) && !String.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
url.Add(String.Concat(keyName, "=", keyValue));
|
||||
}
|
||||
|
||||
if (additionalParams != null)
|
||||
{
|
||||
foreach(string additionalParam in additionalParams)
|
||||
url.Add(additionalParam);
|
||||
}
|
||||
|
||||
return "~/Default.aspx?" + String.Join("&", url.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
112
WebsitePanel/Sources/WebsitePanel.WebPortal/Code/PortalPage.cs
Normal file
112
WebsitePanel/Sources/WebsitePanel.WebPortal/Code/PortalPage.cs
Normal file
|
@ -0,0 +1,112 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.WebPortal
|
||||
{
|
||||
public class PortalPage
|
||||
{
|
||||
private string name;
|
||||
private bool enabled;
|
||||
private bool hidden;
|
||||
private string adminSkinSrc;
|
||||
private string skinSrc;
|
||||
private List<string> roles = new List<string>();
|
||||
private List<PortalPage> pages = new List<PortalPage>();
|
||||
private PortalPage parentPage;
|
||||
private Dictionary<string, ContentPane> contentPanes = new Dictionary<string, ContentPane>();
|
||||
private string url;
|
||||
private string target;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return this.name; }
|
||||
set { this.name = value; }
|
||||
}
|
||||
|
||||
public List<string> Roles
|
||||
{
|
||||
get { return this.roles; }
|
||||
}
|
||||
|
||||
public List<PortalPage> Pages
|
||||
{
|
||||
get { return this.pages; }
|
||||
}
|
||||
|
||||
public PortalPage ParentPage
|
||||
{
|
||||
get { return this.parentPage; }
|
||||
set { this.parentPage = value; }
|
||||
}
|
||||
|
||||
public string SkinSrc
|
||||
{
|
||||
get { return this.skinSrc; }
|
||||
set { this.skinSrc = value; }
|
||||
}
|
||||
|
||||
public string AdminSkinSrc
|
||||
{
|
||||
get { return this.adminSkinSrc; }
|
||||
set { this.adminSkinSrc = value; }
|
||||
}
|
||||
|
||||
public Dictionary<string, ContentPane> ContentPanes
|
||||
{
|
||||
get { return this.contentPanes; }
|
||||
}
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get { return this.enabled; }
|
||||
set { this.enabled = value; }
|
||||
}
|
||||
|
||||
public bool Hidden
|
||||
{
|
||||
get { return this.hidden; }
|
||||
set { this.hidden = value; }
|
||||
}
|
||||
|
||||
public string Url
|
||||
{
|
||||
get { return this.url; }
|
||||
set { this.url = value; }
|
||||
}
|
||||
|
||||
public string Target
|
||||
{
|
||||
get { return this.target; }
|
||||
set { this.target = value; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Configuration;
|
||||
|
||||
namespace WebsitePanel.WebPortal
|
||||
{
|
||||
public abstract class PortalThemeProvider
|
||||
{
|
||||
private static PortalThemeProvider _instance;
|
||||
public static PortalThemeProvider Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance != null)
|
||||
return _instance;
|
||||
|
||||
try
|
||||
{
|
||||
_instance = (PortalThemeProvider)Activator.CreateInstance(Type.GetType(
|
||||
ConfigurationManager.AppSettings["WebPortal.ThemeProvider"]));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Could not create '{0}' theme provider", ex);
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract string GetTheme();
|
||||
}
|
||||
}
|
882
WebsitePanel/Sources/WebsitePanel.WebPortal/Code/PortalUtils.cs
Normal file
882
WebsitePanel/Sources/WebsitePanel.WebPortal/Code/PortalUtils.cs
Normal file
|
@ -0,0 +1,882 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Security.Principal;
|
||||
using System.Resources;
|
||||
using System.Configuration;
|
||||
using System.Collections.Specialized;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Compilation;
|
||||
using System.Web.Configuration;
|
||||
using System.Web.UI;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Net;
|
||||
using System.Net.Mail;
|
||||
|
||||
using Microsoft.Web.Services3;
|
||||
using WebsitePanel.EnterpriseServer;
|
||||
using WebsitePanel.WebPortal;
|
||||
|
||||
namespace WebsitePanel.Portal
|
||||
{
|
||||
public class PortalUtils
|
||||
{
|
||||
public const string SharedResourcesFile = "SharedResources.ascx.resx";
|
||||
public const string CONFIG_FOLDER = "~/App_Data/";
|
||||
public const string SUPPORTED_THEMES_FILE = "SupportedThemes.config";
|
||||
public const string SUPPORTED_LOCALES_FILE = "SupportedLocales.config";
|
||||
public const string USER_ID_PARAM = "UserID";
|
||||
public const string SPACE_ID_PARAM = "SpaceID";
|
||||
public const string SEARCH_QUERY_PARAM = "Query";
|
||||
|
||||
public static string CultureCookieName
|
||||
{
|
||||
get { return PortalConfiguration.SiteSettings["CultureCookieName"]; }
|
||||
}
|
||||
|
||||
public static string ThemeCookieName
|
||||
{
|
||||
get { return PortalConfiguration.SiteSettings["ThemeCookieName"]; }
|
||||
}
|
||||
|
||||
public static System.Globalization.CultureInfo CurrentCulture
|
||||
{
|
||||
get { return GetCurrentCulture(); }
|
||||
}
|
||||
|
||||
public static System.Globalization.CultureInfo CurrentUICulture
|
||||
{
|
||||
get { return GetCurrentCulture(); }
|
||||
}
|
||||
|
||||
public static string CurrentTheme
|
||||
{
|
||||
get { return GetCurrentTheme(); }
|
||||
}
|
||||
|
||||
internal static string GetCurrentTheme()
|
||||
{
|
||||
string theme = (string) HttpContext.Current.Items[ThemeCookieName];
|
||||
|
||||
if (theme == null)
|
||||
{
|
||||
HttpCookie cookie = HttpContext.Current.Request.Cookies[ThemeCookieName];
|
||||
if (cookie != null)
|
||||
{
|
||||
theme = cookie.Value;
|
||||
|
||||
if (!String.IsNullOrEmpty(theme))
|
||||
{
|
||||
HttpContext.Current.Items[ThemeCookieName] = theme;
|
||||
return theme;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string appData = HttpContext.Current.Server.MapPath(CONFIG_FOLDER);
|
||||
string path = Path.Combine(appData, SUPPORTED_THEMES_FILE);
|
||||
|
||||
XmlTextReader reader = new XmlTextReader(path);
|
||||
reader.XmlResolver = null;
|
||||
reader.WhitespaceHandling = WhitespaceHandling.None;
|
||||
reader.MoveToContent();
|
||||
if (reader.Name != null)
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (reader.NodeType == XmlNodeType.Element)
|
||||
{
|
||||
if (reader.HasAttributes)
|
||||
{
|
||||
reader.MoveToFirstAttribute();
|
||||
theme = reader.Value;
|
||||
return theme;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return String.IsNullOrEmpty(theme) ? "Default" : theme;
|
||||
}
|
||||
|
||||
public static void SetCurrentTheme(string theme)
|
||||
{
|
||||
// theme
|
||||
if (!String.IsNullOrEmpty(theme))
|
||||
{
|
||||
HttpCookie cookieTheme = new HttpCookie(ThemeCookieName, theme);
|
||||
cookieTheme.Expires = DateTime.Now.AddMonths(2);
|
||||
HttpContext.Current.Response.Cookies.Add(cookieTheme);
|
||||
}
|
||||
}
|
||||
|
||||
internal static System.Globalization.CultureInfo GetCurrentCulture()
|
||||
{
|
||||
System.Globalization.CultureInfo ci = (System.Globalization.CultureInfo)
|
||||
HttpContext.Current.Items[CultureCookieName];
|
||||
|
||||
if (ci == null)
|
||||
{
|
||||
HttpCookie localeCrumb = HttpContext.Current.Request.Cookies[CultureCookieName];
|
||||
if (localeCrumb != null)
|
||||
{
|
||||
ci = System.Globalization.CultureInfo.CreateSpecificCulture(localeCrumb.Value);
|
||||
|
||||
if (ci != null)
|
||||
{
|
||||
HttpContext.Current.Items[CultureCookieName] = ci;
|
||||
return ci;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
return ci;
|
||||
|
||||
return System.Threading.Thread.CurrentThread.CurrentCulture;
|
||||
}
|
||||
|
||||
public static string AdminEmail
|
||||
{
|
||||
get { return PortalConfiguration.SiteSettings["AdminEmail"]; }
|
||||
}
|
||||
|
||||
public static string FromEmail
|
||||
{
|
||||
get { return PortalConfiguration.SiteSettings["FromEmail"]; }
|
||||
}
|
||||
|
||||
public static void SendMail(string from, string to, string bcc, string subject, string body)
|
||||
{
|
||||
// Command line argument must the the SMTP host.
|
||||
SmtpClient client = new SmtpClient();
|
||||
|
||||
// set SMTP client settings
|
||||
client.Host = PortalConfiguration.SiteSettings["SmtpHost"];
|
||||
client.Port = Int32.Parse(PortalConfiguration.SiteSettings["SmtpPort"]);
|
||||
string smtpUsername = PortalConfiguration.SiteSettings["SmtpUsername"];
|
||||
string smtpPassword = PortalConfiguration.SiteSettings["SmtpPassword"];
|
||||
if (String.IsNullOrEmpty(smtpUsername))
|
||||
{
|
||||
client.Credentials = new NetworkCredential(smtpUsername, smtpPassword);
|
||||
}
|
||||
|
||||
// create message
|
||||
MailMessage message = new MailMessage(from, to);
|
||||
message.Body = body;
|
||||
message.BodyEncoding = System.Text.Encoding.UTF8;
|
||||
message.IsBodyHtml = false;
|
||||
message.Subject = subject;
|
||||
message.SubjectEncoding = System.Text.Encoding.UTF8;
|
||||
if (!String.IsNullOrEmpty(bcc))
|
||||
message.Bcc.Add(bcc);
|
||||
|
||||
// send message
|
||||
try
|
||||
{
|
||||
client.Send(message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Clean up.
|
||||
message.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static void UserSignOut()
|
||||
{
|
||||
FormsAuthentication.SignOut();
|
||||
HttpContext.Current.Response.Redirect(LoginRedirectUrl);
|
||||
}
|
||||
|
||||
public static MenuItem GetSpaceMenuItem(string menuItemKey)
|
||||
{
|
||||
MenuItem item = new MenuItem();
|
||||
item.Value = menuItemKey;
|
||||
|
||||
menuItemKey = String.Concat("Space", menuItemKey);
|
||||
|
||||
PortalPage page = PortalConfiguration.Site.Pages[menuItemKey];
|
||||
|
||||
if (page != null)
|
||||
item.NavigateUrl = DefaultPage.GetPageUrl(menuItemKey);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
private static FormsAuthenticationTicket AuthTicket
|
||||
{
|
||||
get
|
||||
{
|
||||
FormsAuthenticationTicket authTicket = (FormsAuthenticationTicket)HttpContext.Current.Items[FormsAuthentication.FormsCookieName];
|
||||
|
||||
if (authTicket == null)
|
||||
{
|
||||
// original code
|
||||
HttpCookie authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
|
||||
// workaround for cases when AuthTicket is required before round-trip
|
||||
if (authCookie == null || String.IsNullOrEmpty(authCookie.Value))
|
||||
authCookie = HttpContext.Current.Response.Cookies[FormsAuthentication.FormsCookieName];
|
||||
//
|
||||
if (authCookie != null)
|
||||
{
|
||||
authTicket = FormsAuthentication.Decrypt(authCookie.Value);
|
||||
HttpContext.Current.Items[FormsAuthentication.FormsCookieName] = authTicket;
|
||||
}
|
||||
}
|
||||
|
||||
return authTicket;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetAuthTicket(FormsAuthenticationTicket ticket, bool persistent)
|
||||
{
|
||||
// issue authentication cookie
|
||||
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName);
|
||||
authCookie.Domain = FormsAuthentication.CookieDomain;
|
||||
authCookie.Secure = FormsAuthentication.RequireSSL;
|
||||
authCookie.Path = FormsAuthentication.FormsCookiePath;
|
||||
authCookie.Value = FormsAuthentication.Encrypt(ticket);
|
||||
|
||||
if (persistent)
|
||||
authCookie.Expires = DateTime.Now.AddMonths(1);
|
||||
|
||||
HttpContext.Current.Response.Cookies.Add(authCookie);
|
||||
}
|
||||
|
||||
public static string ApplicationPath
|
||||
{
|
||||
get
|
||||
{
|
||||
if (HttpContext.Current.Request.ApplicationPath == "/")
|
||||
return "";
|
||||
else
|
||||
return HttpContext.Current.Request.ApplicationPath;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetSharedLocalizedString(string moduleName, string resourceKey)
|
||||
{
|
||||
string className = SharedResourcesFile.Replace(".resx", "");
|
||||
|
||||
if (!String.IsNullOrEmpty(moduleName))
|
||||
className = String.Concat(moduleName, "_", className);
|
||||
|
||||
return (string)HttpContext.GetGlobalResourceObject(className, resourceKey);
|
||||
}
|
||||
|
||||
public static string GetCurrentPageId()
|
||||
{
|
||||
return HttpContext.Current.Request["pid"];
|
||||
}
|
||||
|
||||
public static bool PageExists(string pageId)
|
||||
{
|
||||
return PortalConfiguration.Site.Pages[pageId] != null;
|
||||
}
|
||||
|
||||
public static string GetLocalizedPageName(string pageId)
|
||||
{
|
||||
return DefaultPage.GetLocalizedPageName(pageId);
|
||||
}
|
||||
|
||||
public static int AuthenticateUser(string username, string password, string ipAddress,
|
||||
bool rememberLogin, string preferredLocale, string theme)
|
||||
{
|
||||
esAuthentication authService = new esAuthentication();
|
||||
ConfigureEnterpriseServerProxy(authService, false);
|
||||
|
||||
try
|
||||
{
|
||||
int authResult = authService.AuthenticateUser(username, password, ipAddress);
|
||||
|
||||
if (authResult < 0)
|
||||
{
|
||||
return authResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
UserInfo user = authService.GetUserByUsernamePassword(username, password, ipAddress);
|
||||
if (user != null)
|
||||
{
|
||||
// issue authentication ticket
|
||||
FormsAuthenticationTicket ticket = CreateAuthTicket(user.Username, user.Password, user.Role, rememberLogin);
|
||||
SetAuthTicket(ticket, rememberLogin);
|
||||
|
||||
CompleteUserLogin(username, rememberLogin, preferredLocale, theme);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
private static int GetAuthenticationFormsTimeout()
|
||||
{
|
||||
//default
|
||||
int retValue = 30;
|
||||
try
|
||||
{
|
||||
AuthenticationSection authenticationSection = WebConfigurationManager.GetSection("system.web/authentication") as AuthenticationSection;
|
||||
if (authenticationSection != null)
|
||||
{
|
||||
FormsAuthenticationConfiguration fac = authenticationSection.Forms;
|
||||
retValue = (int) Math.Truncate(fac.Timeout.TotalMinutes);
|
||||
}
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
return retValue;
|
||||
}
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
private static FormsAuthenticationTicket CreateAuthTicket(string username, string password,
|
||||
UserRole role, bool persistent)
|
||||
{
|
||||
return new FormsAuthenticationTicket(
|
||||
1,
|
||||
username,
|
||||
DateTime.Now,
|
||||
DateTime.Now.AddMinutes(GetAuthenticationFormsTimeout()),
|
||||
persistent,
|
||||
String.Concat(password, Environment.NewLine, Enum.GetName(typeof(UserRole), role))
|
||||
);
|
||||
}
|
||||
|
||||
public static int ChangeUserPassword(int userId, string newPassword)
|
||||
{
|
||||
// load user account
|
||||
esUsers usersService = new esUsers();
|
||||
ConfigureEnterpriseServerProxy(usersService, true);
|
||||
|
||||
try
|
||||
{
|
||||
UserInfo user = usersService.GetUserById(userId);
|
||||
|
||||
// change WebsitePanel account password
|
||||
int result = usersService.ChangeUserPassword(userId, newPassword);
|
||||
if (result < 0)
|
||||
return result;
|
||||
|
||||
// change auth cookie
|
||||
if (String.Compare(user.Username, AuthTicket.Name, true) == 0)
|
||||
{
|
||||
FormsAuthenticationTicket ticket = CreateAuthTicket(user.Username, newPassword, user.Role, AuthTicket.IsPersistent);
|
||||
SetAuthTicket(ticket, AuthTicket.IsPersistent);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
public static int UpdateUserAccount(UserInfo user)
|
||||
{
|
||||
return UpdateUserAccount(null, user);
|
||||
}
|
||||
|
||||
public static int UpdateUserAccount(string taskId, UserInfo user)
|
||||
{
|
||||
esUsers usersService = new esUsers();
|
||||
ConfigureEnterpriseServerProxy(usersService, true);
|
||||
|
||||
try
|
||||
{
|
||||
// update user in WebsitePanel
|
||||
return usersService.UpdateUserTask(taskId, user);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
public static int AddUserAccount(List<string> log, UserInfo user, bool sendLetter)
|
||||
{
|
||||
esUsers usersService = new esUsers();
|
||||
ConfigureEnterpriseServerProxy(usersService, true);
|
||||
|
||||
try
|
||||
{
|
||||
// add user to WebsitePanel server
|
||||
return usersService.AddUser(user, sendLetter);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
public static int DeleteUserAccount(int userId)
|
||||
{
|
||||
esUsers usersService = new esUsers();
|
||||
ConfigureEnterpriseServerProxy(usersService, true);
|
||||
|
||||
try
|
||||
{
|
||||
// add user to WebsitePanel server
|
||||
return usersService.DeleteUser(userId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
public static int ChangeUserStatus(int userId, UserStatus status)
|
||||
{
|
||||
esUsers usersService = new esUsers();
|
||||
ConfigureEnterpriseServerProxy(usersService, true);
|
||||
|
||||
try
|
||||
{
|
||||
// add user to WebsitePanel server
|
||||
return usersService.ChangeUserStatus(userId, status);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
public static UserInfo GetCurrentUser()
|
||||
{
|
||||
UserInfo user = null;
|
||||
|
||||
if (AuthTicket != null)
|
||||
{
|
||||
esUsers usersService = new esUsers();
|
||||
ConfigureEnterpriseServerProxy(usersService);
|
||||
|
||||
user = usersService.GetUserByUsername(AuthTicket.Name);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
private static void CompleteUserLogin(string username, bool rememberLogin,
|
||||
string preferredLocale, string theme)
|
||||
{
|
||||
// store last successful username in the cookie
|
||||
HttpCookie cookie = new HttpCookie("WebsitePanelLogin", username);
|
||||
cookie.Expires = DateTime.Now.AddDays(7);
|
||||
HttpContext.Current.Response.Cookies.Add(cookie);
|
||||
|
||||
// set language
|
||||
SetCurrentLanguage(preferredLocale);
|
||||
|
||||
// set theme
|
||||
SetCurrentTheme(theme);
|
||||
|
||||
// remember me
|
||||
if (rememberLogin)
|
||||
HttpContext.Current.Response.Cookies[FormsAuthentication.FormsCookieName].Expires = DateTime.Now.AddMonths(1);
|
||||
}
|
||||
|
||||
public static void SetCurrentLanguage(string preferredLocale)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(preferredLocale))
|
||||
{
|
||||
HttpCookie localeCrumb = new HttpCookie(CultureCookieName, preferredLocale);
|
||||
localeCrumb.Expires = DateTime.Now.AddMonths(2);
|
||||
HttpContext.Current.Response.Cookies.Add(localeCrumb);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ConfigureEnterpriseServerProxy(WebServicesClientProtocol proxy)
|
||||
{
|
||||
ConfigureEnterpriseServerProxy(proxy, true);
|
||||
}
|
||||
|
||||
public static void ConfigureEnterpriseServerProxy(WebServicesClientProtocol proxy, bool applyPolicy)
|
||||
{
|
||||
// load ES properties
|
||||
string serverUrl = PortalConfiguration.SiteSettings["EnterpriseServer"];
|
||||
|
||||
EnterpriseServerProxyConfigurator cnfg = new EnterpriseServerProxyConfigurator();
|
||||
cnfg.EnterpriseServerUrl = serverUrl;
|
||||
|
||||
// create assertion
|
||||
if (applyPolicy)
|
||||
{
|
||||
if (AuthTicket != null)
|
||||
{
|
||||
cnfg.Username = AuthTicket.Name;
|
||||
cnfg.Password = AuthTicket.UserData.Substring(0, AuthTicket.UserData.IndexOf(Environment.NewLine));
|
||||
}
|
||||
}
|
||||
|
||||
cnfg.Configure(proxy);
|
||||
}
|
||||
|
||||
public static XmlNode GetModuleContentNode(WebPortalControlBase module)
|
||||
{
|
||||
XmlNodeList nodes = module.Module.SelectNodes("Content");
|
||||
return nodes.Count > 0 ? nodes[0] : null;
|
||||
}
|
||||
|
||||
public static XmlNodeList GetModuleMenuItems(WebPortalControlBase module)
|
||||
{
|
||||
return module.Module.SelectNodes("MenuItem");
|
||||
}
|
||||
|
||||
public static string FormatIconImageUrl(string url)
|
||||
{
|
||||
return url;
|
||||
}
|
||||
|
||||
public static string FormatIconLinkUrl(object url)
|
||||
{
|
||||
return DefaultPage.GetPageUrl(url.ToString());
|
||||
}
|
||||
|
||||
public static string GetThemedImage(string imageUrl)
|
||||
{
|
||||
Page page = (Page)HttpContext.Current.Handler;
|
||||
return page.ResolveUrl("~/App_Themes/" + page.Theme + "/Images/" + imageUrl);
|
||||
}
|
||||
|
||||
public static string GetThemedIcon(string iconUrl)
|
||||
{
|
||||
Page page = (Page)HttpContext.Current.Handler;
|
||||
return page.ResolveUrl("~/App_Themes/" + page.Theme + "/" + iconUrl);
|
||||
}
|
||||
|
||||
public static void LoadStatesDropDownList(DropDownList list, string countryCode)
|
||||
{
|
||||
string xmlFilePath = HttpContext.Current.Server.MapPath(CONFIG_FOLDER + "CountryStates.config");
|
||||
list.Items.Clear();
|
||||
if (File.Exists(xmlFilePath))
|
||||
{
|
||||
try
|
||||
{
|
||||
XmlDocument xmlDoc = new XmlDocument();
|
||||
xmlDoc.Load(xmlFilePath);
|
||||
|
||||
List<ListItem> items = new List<ListItem>();
|
||||
|
||||
XmlNodeList xmlNodes = xmlDoc.SelectNodes("//State[@countryCode='" + countryCode + "']");
|
||||
foreach (XmlElement xmlNode in xmlNodes)
|
||||
{
|
||||
string nodeName = xmlNode.GetAttribute("name");
|
||||
string nodeKey = xmlNode.GetAttribute("key");
|
||||
|
||||
items.Add(new ListItem(nodeName, nodeKey));
|
||||
}
|
||||
|
||||
list.Items.AddRange(items.ToArray());
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadCountriesDropDownList(DropDownList list, string countryToSelect)
|
||||
{
|
||||
string countriesPath = HttpContext.Current.Server.MapPath(CONFIG_FOLDER + "Countries.config");
|
||||
|
||||
if (File.Exists(countriesPath))
|
||||
{
|
||||
try
|
||||
{
|
||||
XmlDocument xmlCountriesDoc = new XmlDocument();
|
||||
xmlCountriesDoc.Load(countriesPath);
|
||||
|
||||
List<ListItem> items = new List<ListItem>();
|
||||
|
||||
XmlNodeList xmlCountries = xmlCountriesDoc.SelectNodes("//Country");
|
||||
foreach (XmlElement xmlCountry in xmlCountries)
|
||||
{
|
||||
string countryName = xmlCountry.GetAttribute("name");
|
||||
string countryKey = xmlCountry.GetAttribute("key");
|
||||
|
||||
if (String.Compare(countryKey, countryToSelect) == 0)
|
||||
{
|
||||
ListItem li = new ListItem(countryName, countryKey);
|
||||
li.Selected = true;
|
||||
items.Add(li);
|
||||
}
|
||||
else
|
||||
items.Add(new ListItem(countryName, countryKey));
|
||||
}
|
||||
|
||||
list.Items.AddRange(items.ToArray());
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void LoadCultureDropDownList(DropDownList list)
|
||||
{
|
||||
string localesPath = HttpContext.Current.Server.MapPath(CONFIG_FOLDER + "SupportedLocales.config");
|
||||
|
||||
if (File.Exists(localesPath))
|
||||
{
|
||||
|
||||
string localeToSelect = CurrentCulture.Name;
|
||||
|
||||
try
|
||||
{
|
||||
XmlDocument xmlLocalesDoc = new XmlDocument();
|
||||
xmlLocalesDoc.Load(localesPath);
|
||||
|
||||
XmlNodeList xmlLocales = xmlLocalesDoc.SelectNodes("//Locale");
|
||||
for (int i = 0; i < xmlLocales.Count; i++)
|
||||
{
|
||||
XmlElement xmlLocale = (XmlElement) xmlLocales[i];
|
||||
|
||||
string localeName = xmlLocale.GetAttribute("name");
|
||||
string localeKey = xmlLocale.GetAttribute("key");
|
||||
|
||||
list.Items.Add(new ListItem(localeName, localeKey));
|
||||
}
|
||||
|
||||
|
||||
HttpCookie localeCrumb = HttpContext.Current.Request.Cookies[CultureCookieName];
|
||||
if (localeCrumb != null)
|
||||
{
|
||||
ListItem item = list.Items.FindByValue(localeToSelect);
|
||||
if (item != null)
|
||||
item.Selected = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (list.Items.Count > 0 && list.Items[0] != null)
|
||||
{
|
||||
SetCurrentLanguage(list.Items[0].Value);
|
||||
HttpContext.Current.Response.Redirect(HttpContext.Current.Request.Url.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadThemesDropDownList(DropDownList list)
|
||||
{
|
||||
string localesPath = HttpContext.Current.Server.MapPath(CONFIG_FOLDER + "SupportedThemes.config");
|
||||
|
||||
if (File.Exists(localesPath))
|
||||
{
|
||||
string themeToSelect = CurrentTheme;
|
||||
|
||||
try
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.Load(localesPath);
|
||||
|
||||
XmlNodeList xmlThemes = doc.SelectNodes("//Theme");
|
||||
for (int i = 0; i < xmlThemes.Count; i++)
|
||||
{
|
||||
XmlElement xmlTheme = (XmlElement)xmlThemes[i];
|
||||
string themeName = xmlTheme.GetAttribute("name");
|
||||
string themeTitle = xmlTheme.GetAttribute("title");
|
||||
|
||||
list.Items.Add(new ListItem(themeTitle, themeName));
|
||||
|
||||
if (String.Compare(themeName, themeToSelect) == 0)
|
||||
list.Items[i].Selected = true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Navigation Routines
|
||||
public static string LoginRedirectUrl
|
||||
{
|
||||
get { return DefaultPage.GetPageUrl(PortalConfiguration.SiteSettings["DefaultPage"]); }
|
||||
}
|
||||
|
||||
public static string GetUserHomePageUrl(int userId)
|
||||
{
|
||||
string userHomePageId = PortalConfiguration.SiteSettings["UserHomePage"];
|
||||
return userId > 0 ? NavigatePageURL(userHomePageId, USER_ID_PARAM, userId.ToString())
|
||||
: NavigatePageURL(userHomePageId);
|
||||
}
|
||||
|
||||
public static string GetUserCustomersPageId()
|
||||
{
|
||||
return PortalConfiguration.SiteSettings["UserCustomersPage"];
|
||||
}
|
||||
|
||||
public static string GetUsersSearchPageId()
|
||||
{
|
||||
return PortalConfiguration.SiteSettings["UsersSearchPage"];
|
||||
}
|
||||
|
||||
public static string GetSpacesSearchPageId()
|
||||
{
|
||||
return PortalConfiguration.SiteSettings["SpacesSearchPage"];
|
||||
}
|
||||
|
||||
public static string GetNestedSpacesPageId()
|
||||
{
|
||||
return PortalConfiguration.SiteSettings["NestedSpacesPage"];
|
||||
}
|
||||
|
||||
public static string GetSpaceHomePageUrl(int spaceId)
|
||||
{
|
||||
string spaceHomePageId = PortalConfiguration.SiteSettings["SpaceHomePage"];
|
||||
return spaceId > -1 ? NavigatePageURL(spaceHomePageId, SPACE_ID_PARAM, spaceId.ToString())
|
||||
: NavigatePageURL(spaceHomePageId);
|
||||
}
|
||||
|
||||
public static string GetLoggedUserAccountPageUrl()
|
||||
{
|
||||
return NavigatePageURL(PortalConfiguration.SiteSettings["LoggedUserAccountPage"]);
|
||||
}
|
||||
|
||||
public static string NavigateURL()
|
||||
{
|
||||
return NavigateURL(null, null);
|
||||
}
|
||||
|
||||
public static string NavigatePageURL(string pageId)
|
||||
{
|
||||
return NavigatePageURL(pageId, null, null, new string[] { });
|
||||
}
|
||||
|
||||
public static string NavigateURL(string keyName, string keyValue, params string[] additionalParams)
|
||||
{
|
||||
return NavigatePageURL(HttpContext.Current.Request[DefaultPage.PAGE_ID_PARAM], keyName, keyValue, additionalParams);
|
||||
}
|
||||
|
||||
public static string NavigatePageURL(string pageId, string keyName, string keyValue, params string[] additionalParams)
|
||||
{
|
||||
string navigateUrl = DefaultPage.DEFAULT_PAGE;
|
||||
|
||||
List<string> urlBuilder = new List<string>();
|
||||
|
||||
// add page id parameter
|
||||
if (!String.IsNullOrEmpty(pageId))
|
||||
urlBuilder.Add(String.Concat(DefaultPage.PAGE_ID_PARAM, "=", pageId));
|
||||
|
||||
// add specified key
|
||||
if (!String.IsNullOrEmpty(keyName) && !String.IsNullOrEmpty(keyValue))
|
||||
urlBuilder.Add(String.Concat(keyName, "=", keyValue));
|
||||
|
||||
// load additional params
|
||||
if (additionalParams != null)
|
||||
{
|
||||
string controlId = null;
|
||||
string moduleDefinitionId = null;
|
||||
//
|
||||
foreach (string paramStr in additionalParams)
|
||||
{
|
||||
if (paramStr.StartsWith("ctl=", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
// ensure page exists and avoid unnecessary exceptions throw
|
||||
if (PortalConfiguration.Site.Pages.ContainsKey(pageId))
|
||||
{
|
||||
string[] pair = paramStr.Split('=');
|
||||
controlId = pair[1];
|
||||
}
|
||||
|
||||
}
|
||||
else if (paramStr.StartsWith("moduleDefId=", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
// ensure page exists and avoid unnecessary exceptions throw
|
||||
if (PortalConfiguration.Site.Pages.ContainsKey(pageId))
|
||||
{
|
||||
string[] pair = paramStr.Split('=');
|
||||
moduleDefinitionId = pair[1];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
urlBuilder.Add(paramStr);
|
||||
}
|
||||
if (!String.IsNullOrEmpty(moduleDefinitionId) && !String.IsNullOrEmpty(controlId))
|
||||
{
|
||||
// 1. Read module controls first information first
|
||||
foreach (ModuleDefinition md in PortalConfiguration.ModuleDefinitions.Values)
|
||||
{
|
||||
if (String.Equals(md.Id, moduleDefinitionId, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
// 2. Lookup for module control
|
||||
foreach (ModuleControl mc in md.Controls.Values)
|
||||
{
|
||||
// 3. Compare against ctl parameter value
|
||||
if (mc.Key.Equals(controlId, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
// 4. Lookup for module id
|
||||
foreach (int pmKey in PortalConfiguration.Site.Modules.Keys)
|
||||
{
|
||||
PageModule pm = PortalConfiguration.Site.Modules[pmKey];
|
||||
if (String.Equals(pm.ModuleDefinitionID, md.Id,
|
||||
StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
// 5. Append module id parameter
|
||||
urlBuilder.Add("mid=" + pmKey);
|
||||
goto End;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
End:
|
||||
if (urlBuilder.Count > 0)
|
||||
navigateUrl += String.Concat("?", String.Join("&", urlBuilder.ToArray()));
|
||||
|
||||
return navigateUrl;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
//
|
||||
*/
|
|
@ -0,0 +1,55 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.WebPortal
|
||||
{
|
||||
public class SiteSettings
|
||||
{
|
||||
private NameValueCollection _settings;
|
||||
|
||||
public string this[string settingName]
|
||||
{
|
||||
get { return _settings[settingName]; }
|
||||
set { _settings[settingName] = value; }
|
||||
}
|
||||
|
||||
public string[] AllKeys
|
||||
{
|
||||
get { return _settings.AllKeys; }
|
||||
}
|
||||
|
||||
public SiteSettings()
|
||||
{
|
||||
_settings = new NameValueCollection();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.WebPortal
|
||||
{
|
||||
public class SiteStructure
|
||||
{
|
||||
private PageCollection pages = new PageCollection();
|
||||
private Dictionary<int, PageModule> modules = new Dictionary<int, PageModule>();
|
||||
|
||||
public PageCollection Pages
|
||||
{
|
||||
get { return this.pages; }
|
||||
}
|
||||
|
||||
public Dictionary<int, PageModule> Modules
|
||||
{
|
||||
get { return this.modules; }
|
||||
}
|
||||
}
|
||||
|
||||
public class PageCollection : NameObjectCollectionBase
|
||||
{
|
||||
public PortalPage this[string name]
|
||||
{
|
||||
get { return (PortalPage)BaseGet(name); }
|
||||
set { BaseAdd(name, value); }
|
||||
}
|
||||
|
||||
public PortalPage[] Values
|
||||
{
|
||||
get { return (PortalPage[])BaseGetAllValues(typeof(PortalPage)); }
|
||||
}
|
||||
|
||||
public bool ContainsKey(string key)
|
||||
{
|
||||
return BaseGet(key) != null;
|
||||
}
|
||||
|
||||
public void Add(PortalPage page)
|
||||
{
|
||||
BaseAdd(page.Name, page);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Resources;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using System.Web.Compilation;
|
||||
using System.Web.UI;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.Portal
|
||||
{
|
||||
public class WebPortalControlBase : WebsitePanel.WebPortal.PortalControlBase
|
||||
{
|
||||
protected Hashtable Settings
|
||||
{
|
||||
get { return base.ModuleSettings; }
|
||||
}
|
||||
|
||||
public string GetThemedImage(string imageUrl)
|
||||
{
|
||||
return PortalUtils.GetThemedImage(imageUrl);
|
||||
}
|
||||
|
||||
public string GetSharedLocalizedString(string moduleName, string resourceKey)
|
||||
{
|
||||
return PortalUtils.GetSharedLocalizedString(moduleName, resourceKey);
|
||||
}
|
||||
|
||||
public string GetLocalizedString(string resourceKey)
|
||||
{
|
||||
return (string)GetLocalResourceObject(resourceKey);
|
||||
}
|
||||
|
||||
public string NavigateURL()
|
||||
{
|
||||
return PortalUtils.NavigateURL();
|
||||
}
|
||||
|
||||
public string NavigateURL(string keyName, string keyValue, params string[] additionalParams)
|
||||
{
|
||||
return PortalUtils.NavigateURL(keyName, keyValue, additionalParams);
|
||||
}
|
||||
|
||||
public string NavigatePageURL(string pageId, string keyName, string keyValue, params string[] additionalParams)
|
||||
{
|
||||
return PortalUtils.NavigatePageURL(pageId, keyName, keyValue, additionalParams);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,262 @@
|
|||
// Copyright (c) 2011, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
|
||||
namespace WebsitePanel.WebPortal
|
||||
{
|
||||
public class WebsitePanelSiteMapProvider : SiteMapProvider
|
||||
{
|
||||
private const string DEFAULT_PAGE_URL = "~/Default.aspx?pid=";
|
||||
private const string ROOT_NODE_KEY = "wsp_root";
|
||||
private const string PAGE_ID_PARAM = "pid";
|
||||
|
||||
private SiteMapProvider parentSiteMapProvider = null;
|
||||
|
||||
public WebsitePanelSiteMapProvider()
|
||||
{
|
||||
}
|
||||
|
||||
// Implement the CurrentNode property.
|
||||
public override SiteMapNode CurrentNode
|
||||
{
|
||||
get
|
||||
{
|
||||
// page id
|
||||
string pid = GetCurrentPageID();
|
||||
|
||||
// find page by id
|
||||
if (PortalConfiguration.Site.Pages.ContainsKey(pid))
|
||||
{
|
||||
return CreateNodeFromPage(PortalConfiguration.Site.Pages[pid]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Implement the RootNode property.
|
||||
public override SiteMapNode RootNode
|
||||
{
|
||||
get { return new SiteMapNode(this, ROOT_NODE_KEY, "", ""); }
|
||||
}
|
||||
|
||||
// Implement the ParentProvider property.
|
||||
public override SiteMapProvider ParentProvider
|
||||
{
|
||||
get { return parentSiteMapProvider; }
|
||||
set { parentSiteMapProvider = value; }
|
||||
}
|
||||
|
||||
// Implement the RootProvider property.
|
||||
public override SiteMapProvider RootProvider
|
||||
{
|
||||
get
|
||||
{
|
||||
// If the current instance belongs to a provider hierarchy, it
|
||||
// cannot be the RootProvider. Rely on the ParentProvider.
|
||||
if (this.ParentProvider != null)
|
||||
{
|
||||
return ParentProvider.RootProvider;
|
||||
}
|
||||
// If the current instance does not have a ParentProvider, it is
|
||||
// not a child in a hierarchy, and can be the RootProvider.
|
||||
else
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Implement the FindSiteMapNode method.
|
||||
public override SiteMapNode FindSiteMapNode(string rawUrl)
|
||||
{
|
||||
int idx = rawUrl.IndexOf("?pid=");
|
||||
if (idx == -1)
|
||||
return null;
|
||||
|
||||
// page id
|
||||
string pid = null;
|
||||
int ampIdx = rawUrl.IndexOf("&", idx);
|
||||
pid = (ampIdx == -1) ? rawUrl.Substring(idx + 5) : rawUrl.Substring(idx + 5, ampIdx - idx - 5);
|
||||
|
||||
// find page by id
|
||||
if (PortalConfiguration.Site.Pages.ContainsKey(pid))
|
||||
{
|
||||
return CreateNodeFromPage(PortalConfiguration.Site.Pages[pid]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Implement the GetChildNodes method.
|
||||
public override SiteMapNodeCollection GetChildNodes(SiteMapNode node)
|
||||
{
|
||||
// pid
|
||||
string pid = node.Key;
|
||||
|
||||
SiteMapNodeCollection children = new SiteMapNodeCollection();
|
||||
|
||||
if (PortalConfiguration.Site.Pages.ContainsKey(pid))
|
||||
{
|
||||
// fill collection
|
||||
foreach (PortalPage page in PortalConfiguration.Site.Pages[pid].Pages)
|
||||
{
|
||||
if (page.Hidden)
|
||||
continue;
|
||||
|
||||
SiteMapNode childNode = CreateNodeFromPage(page);
|
||||
if (childNode != null)
|
||||
children.Add(childNode);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// check if this is a root node
|
||||
if (node.Key == ROOT_NODE_KEY)
|
||||
{
|
||||
foreach (PortalPage page in PortalConfiguration.Site.Pages.Values)
|
||||
{
|
||||
if (page.ParentPage == null && !page.Hidden)
|
||||
{
|
||||
SiteMapNode childNode = CreateNodeFromPage(page);
|
||||
if (childNode != null)
|
||||
children.Add(childNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
protected override SiteMapNode GetRootNodeCore()
|
||||
{
|
||||
return RootNode;
|
||||
}
|
||||
|
||||
// Implement the GetParentNode method.
|
||||
public override SiteMapNode GetParentNode(SiteMapNode node)
|
||||
{
|
||||
string pid = node.Key;
|
||||
if (pid == ROOT_NODE_KEY)
|
||||
return null;
|
||||
|
||||
// find page
|
||||
if (PortalConfiguration.Site.Pages.ContainsKey(pid))
|
||||
{
|
||||
PortalPage page = PortalConfiguration.Site.Pages[pid];
|
||||
if (page.ParentPage != null)
|
||||
return CreateNodeFromPage(page.ParentPage);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Implement the ProviderBase.Initialize property.
|
||||
// Initialize is used to initialize the state that the Provider holds, but
|
||||
// not actually build the site map.
|
||||
public override void Initialize(string name, NameValueCollection attributes)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
base.Initialize(name, attributes);
|
||||
}
|
||||
}
|
||||
|
||||
private SiteMapNode CreateNodeFromPage(PortalPage page)
|
||||
{
|
||||
string url = String.IsNullOrEmpty(page.Url) ? DEFAULT_PAGE_URL + page.Name : page.Url;
|
||||
|
||||
string localizedName = DefaultPage.GetLocalizedPageName(page.Name);
|
||||
|
||||
NameValueCollection attrs = new NameValueCollection();
|
||||
attrs["target"] = page.Target;
|
||||
|
||||
SiteMapNode node = new SiteMapNode(this, page.Name,
|
||||
url,
|
||||
localizedName,
|
||||
localizedName, page.Roles, attrs, null, null);
|
||||
|
||||
if (!page.Enabled)
|
||||
node.Url = "";
|
||||
|
||||
if (IsNodeAccessibleToUser(HttpContext.Current, node))
|
||||
{
|
||||
return node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool IsNodeAccessibleToUser(HttpContext context, SiteMapNode node)
|
||||
{
|
||||
if (node == null)
|
||||
{
|
||||
throw new ArgumentNullException("node");
|
||||
}
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException("context");
|
||||
}
|
||||
if (!this.SecurityTrimmingEnabled)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (node.Roles != null)
|
||||
{
|
||||
return DefaultPage.IsAccessibleToUser(HttpContext.Current, node.Roles);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Private helper methods
|
||||
// Get the URL of the currently displayed page.
|
||||
private string GetCurrentPageID()
|
||||
{
|
||||
try
|
||||
{
|
||||
// The current HttpContext.
|
||||
HttpContext currentContext = HttpContext.Current;
|
||||
if (currentContext != null)
|
||||
{
|
||||
return (currentContext.Request[PAGE_ID_PARAM] != null) ? currentContext.Request[PAGE_ID_PARAM] : "";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("HttpContext.Current is Invalid");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new NotSupportedException("This provider requires a valid context.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue