using System; using System.Data; using System.Collections; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CMS.PortalControls; using CMS.GlobalHelper; using CMS.CMSHelper; using CMS.SettingsProvider; public partial class CMSWebParts_Layouts_Wizard_WizardHeader : CMSAbstractWebPart { #region "Variables" /// /// Flag if the controls were already loaded /// protected bool loaded = false; #endregion #region "Properties" /// /// Header text /// public string HeaderText { get { return ValidationHelper.GetString(this.GetValue("HeaderText"), "Step {0} of {1}"); } set { this.SetValue("HeaderText", value); } } /// /// Header icon /// public string Icon { get { return ValidationHelper.GetString(this.GetValue("Icon"), ""); } set { this.SetValue("Icon", value); } } /// /// Description text /// public string InfoText { get { return ValidationHelper.GetString(this.GetValue("InfoText"), ""); } set { this.SetValue("InfoText", value); } } #endregion #region "Methods" /// /// Init event handler /// protected override void OnInit(EventArgs e) { base.OnInit(e); // Register the events ComponentEvents.RequestEvents.RegisterForComponentEvent(this.WebPartID, ComponentEvents.STEP_LOADED, StepLoaded); } /// /// Content loaded event handler /// public override void OnContentLoaded() { base.OnContentLoaded(); SetupControl(); } /// /// Initializes the control properties /// protected void SetupControl() { if (this.StopProcessing) { // Do not process } else { if (!RequestHelper.IsPostBack()) { ReloadTexts(null, false); } } } /// /// Reloads the texts of the control /// /// Step event arguments /// If true, the load is forced protected void ReloadTexts(StepEventArgs e, bool forceLoad) { if (loaded && !forceLoad) { return; } loaded = true; // Setup the default texts string header = this.HeaderText; string info = this.InfoText; string icon = this.Icon; int current = 1; int steps = 1; if (e != null) { // Use custom header if (e.StepHeader != null) { header = e.StepHeader; } // Use custom info if (e.StepInfo != null) { info = e.StepInfo; } // Use custom icon if (e.StepIcon != null) { icon = e.StepIcon; } current = e.CurrentStep; steps = e.Steps; } // Format the header {0} = current step index, {1} = total number of steps header = String.Format(header, current, steps); info = String.Format(info, current, steps); icon = String.Format(icon, current, steps); this.ltlHeader.Text = header; this.ltlInfo.Text = info; this.imgIcon.ImageUrl = icon; } /// /// Fired when the step is loaded /// protected void StepLoaded(object sender, EventArgs e) { StepEventArgs args = (StepEventArgs)e; ReloadTexts(args, true); } protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); // Show / display components this.plcHeader.Visible = !String.IsNullOrEmpty(ltlHeader.Text); this.plcInfo.Visible = !String.IsNullOrEmpty(ltlInfo.Text); this.plcIcon.Visible = !String.IsNullOrEmpty(imgIcon.ImageUrl); } /// /// Reloads the control data /// public override void ReloadData() { base.ReloadData(); SetupControl(); } #endregion }