using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using AjaxControlToolkit; using CMS.Controls; using CMS.GlobalHelper; using CMS.PortalControls; using CMS.PortalEngine; public partial class CMSWebParts_Layouts_Accordion : CMSAbstractLayoutWebPart { #region "Public properties" /// /// Number of panes. /// public int Panes { get { return ValidationHelper.GetInteger(GetValue("Panes"), 2); } set { SetValue("Panes", value); } } /// /// Pane headers. /// public string PaneHeaders { get { return ValidationHelper.GetString(GetValue("PaneHeaders"), ""); } set { SetValue("PaneHeaders", value); } } /// /// Active pane index. /// public int ActivePaneIndex { get { return ValidationHelper.GetInteger(GetValue("ActivePaneIndex"), -1); } set { SetValue("ActivePaneIndex", value); } } /// /// Require opened pane. /// public bool RequireOpenedPane { get { return ValidationHelper.GetBoolean(GetValue("RequireOpenedPane"), false); } set { SetValue("RequireOpenedPane", value); } } /// /// Width. /// public string Width { get { return ValidationHelper.GetString(GetValue("Width"), ""); } set { SetValue("Width", value); } } /// /// Header CSS class. /// public string HeaderCSSClass { get { return ValidationHelper.GetString(GetValue("HeaderCSSClass"), ""); } set { SetValue("HeaderCSSClass", value); } } /// /// Selected header CSS class. /// public string SelectedHeaderCSSClass { get { return ValidationHelper.GetString(GetValue("SelectedHeaderCSSClass"), ""); } set { SetValue("SelectedHeaderCSSClass", value); } } /// /// Content CSS class. /// public string ContentCSSClass { get { return ValidationHelper.GetString(GetValue("ContentCSSClass"), ""); } set { SetValue("ContentCSSClass", value); } } /// /// Fade transitions. /// public bool FadeTransitions { get { return ValidationHelper.GetBoolean(GetValue("FadeTransitions"), false); } set { SetValue("FadeTransitions", value); } } /// /// Transition duration (ms). /// public int TransitionDuration { get { return ValidationHelper.GetInteger(GetValue("TransitionDuration"), 500); } set { SetValue("TransitionDuration", value); } } #endregion #region "Methods" /// /// Prepares the layout of the web part. /// protected override void PrepareLayout() { StartLayout(); Append(""); Append(""); if (ViewMode == ViewModeEnum.Design) { Append(""); } Append(""); if (AllowDesignMode) { // Width resizer Append(""); } Append(""); } // Pane headers string[] headers = TextHelper.EnsureLineEndings(PaneHeaders, "\n").Split('\n'); for (int i = 1; i <= Panes; i++) { // Create new pane AccordionPane pane = new AccordionPane(); pane.ID = "pane" + i; // Prepare the header string header = null; if (headers.Length >= i) { header = ResHelper.LocalizeString(headers[i - 1]); } if (String.IsNullOrEmpty(header)) { header = "Pane " + i; } pane.Header = new TextTransformationTemplate(header); acc.Panes.Add(pane); AddZone(ID + "_" + i, header, pane.ContentContainer); } // Setup the accordion if ((ActivePaneIndex >= 1) && (ActivePaneIndex <= acc.Panes.Count)) { acc.SelectedIndex = ActivePaneIndex - 1; } acc.ContentCssClass = ContentCSSClass; acc.HeaderCssClass = HeaderCSSClass; acc.HeaderSelectedCssClass = SelectedHeaderCSSClass; acc.FadeTransitions = FadeTransitions; acc.TransitionDuration = TransitionDuration; acc.RequireOpenedPane = RequireOpenedPane; // If no active pane is selected and doesn't require opened one, do not preselect any if (!acc.RequireOpenedPane && (ActivePaneIndex < 0)) { acc.SelectedIndex = -1; } if (IsDesign) { if (AllowDesignMode) { Append(""); } Append("
"); // Add header container AddHeaderContainer(); Append("
"); } else { Append(">"); } // Add the tabs Accordion acc = new Accordion(); acc.ID = "acc"; AddControl(acc); if (IsDesign) { Append(" 
"); // Pane actions Append("
"); if (Panes > 1) { AppendRemoveAction(ResHelper.GetString("Layout.RemoveLastPane"), "Panes"); Append(" "); } AppendAddAction(ResHelper.GetString("Layout.AddPane"), "Panes"); Append("
"); } Append(""); FinishLayout(); } #endregion }