using System; using System.Linq; using System.Web.UI; using System.Web.UI.WebControls; using AjaxControlToolkit; using CMS.ExtendedControls; using CMS.GlobalHelper; using CMS.PortalControls; using CMS.PortalEngine; using CMS.SettingsProvider; public partial class CMSWebParts_Layouts_Tabs : CMSAbstractLayoutWebPart { #region "Variables" private TabContainer tabs = null; #endregion #region "Public properties" /// /// Number of tabs. /// public int Tabs { get { return ValidationHelper.GetInteger(GetValue("Tabs"), 2); } set { SetValue("Tabs", value); } } /// /// Tab headers. /// public string TabHeaders { get { return ValidationHelper.GetString(GetValue("TabHeaders"), ""); } set { SetValue("TabHeaders", value); } } /// /// Active tab index. /// public int ActiveTabIndex { get { return ValidationHelper.GetInteger(GetValue("ActiveTabIndex"), 0); } set { SetValue("ActiveTabIndex", value); } } /// /// Hide empty tabs /// public bool HideEmptyTabs { get { return ValidationHelper.GetBoolean(GetValue("HideEmptyTabs"), false); } set { SetValue("HideEmptyTabs", value); } } /// /// Hide if no tabs are visible /// public bool HideIfNoTabsVisible { get { return ValidationHelper.GetBoolean(GetValue("HideIfNoTabsVisible"), true); } set { SetValue("HideIfNoTabsVisible", value); } } /// /// Tab strip placement. /// public string TabStripPlacement { get { return ValidationHelper.GetString(GetValue("TabStripPlacement"), "top"); } set { SetValue("TabStripPlacement", value); } } /// /// Width. /// public string Width { get { return ValidationHelper.GetString(GetValue("Width"), ""); } set { SetValue("Width", value); } } /// /// Height. /// public string Height { get { return ValidationHelper.GetString(GetValue("Height"), ""); } set { SetValue("Height", value); } } /// /// Tabs CSS class. /// public string TabsCSSClass { get { return ValidationHelper.GetString(GetValue("TabsCSSClass"), ""); } set { SetValue("TabsCSSClass", value); } } /// /// Scrollbars. /// public string Scrollbars { get { return ValidationHelper.GetString(GetValue("Scrollbars"), ""); } set { SetValue("Scrollbars", value); } } #endregion #region "Page events" /// /// Render event handler /// protected override void Render(HtmlTextWriter writer) { if (HideIfNoTabsVisible) { // Check if some tab is visible Visible = tabs.Tabs.Cast().Any(tab => tab.Visible); } if(Visible) { const string preventFocusLoadScript = @" Sys.Extended.UI.TabContainer.prototype._app_onload = function (sender, e) { if (this._cachedActiveTabIndex != -1) { this.set_activeTabIndex(this._cachedActiveTabIndex); this._cachedActiveTabIndex = -1; var activeTab = this.get_tabs()[this._activeTabIndex]; if (activeTab) { activeTab._wasLoaded = true; /*** CMS ***/ // Disable focus on active tab //activeTab._setFocus(activeTab); /*** END CMS ***/ } } this._loaded = true; } "; // Register script preventing focusing active tab (caused scrolling to tab container - e.g. to the bottom of the page) ScriptHelper.RegisterStartupScript(this, typeof(string), "preventTabFocus", preventFocusLoadScript, true); } base.Render(writer); } #endregion #region "Methods" /// /// Prepares the layout of the web part. /// protected override void PrepareLayout() { StartLayout(); Append(""); Append(""); switch (ViewMode) { case ViewModeEnum.Design: case ViewModeEnum.DesignDisabled: { Append(""); } break; } Append(""); // Resizers if (AllowDesignMode) { // Width resizer Append(""); // Height resizer Append(""); Append(""); } Append(""); } // Tab headers string[] headers = TextHelper.EnsureLineEndings(TabHeaders, "\n").Split('\n'); if ((ActiveTabIndex >= 1) && (ActiveTabIndex <= Tabs)) { tabs.ActiveTabIndex = ActiveTabIndex - 1; } bool hideEmpty = HideEmptyTabs; for (int i = 1; i <= Tabs; i++) { // Create new tab CMSTabPanel tab = new CMSTabPanel(); tab.ID = "tab" + i; // Prepare the header string header = null; if (headers.Length >= i) { header = ResHelper.LocalizeString(headers[i - 1]); } if (String.IsNullOrEmpty(header)) { header = "Tab " + i; } tab.HeaderText = header; tab.HideIfZoneEmpty = hideEmpty; tabs.Tabs.Add(tab); tab.WebPartZone = AddZone(ID + "_" + i, header, tab); } // Setup the tabs tabs.ScrollBars = ControlsHelper.GetScrollbarsEnum(Scrollbars); if (!String.IsNullOrEmpty(TabsCSSClass)) { tabs.CssClass = TabsCSSClass; } tabs.TabStripPlacement = GetTabStripPlacement(TabStripPlacement); if (!String.IsNullOrEmpty(Height)) { tabs.Height = new Unit(Height); } if (IsDesign) { // Footer if (AllowDesignMode) { Append(""); } Append("
"); // Add header container AddHeaderContainer(); Append("
"); } else { Append(">"); } // Add the tabs tabs = new TabContainer(); tabs.ID = "tabs"; AddControl(tabs); if (IsDesign) { Append(" 
  
"); Append("
"); // Pane actions if (Tabs > 1) { AppendRemoveAction(ResHelper.GetString("Layout.RemoveTab"), "Tabs"); Append(" "); } AppendAddAction(ResHelper.GetString("Layout.AddTab"), "Tabs"); Append("
"); } Append(""); FinishLayout(); } /// /// Gets the tab strip placement based on the string representation /// /// Placement protected TabStripPlacement GetTabStripPlacement(string placement) { switch (placement.ToLowerCSafe()) { case "bottom": return AjaxControlToolkit.TabStripPlacement.Bottom; case "bottomright": return AjaxControlToolkit.TabStripPlacement.BottomRight; case "topright": return AjaxControlToolkit.TabStripPlacement.TopRight; default: return AjaxControlToolkit.TabStripPlacement.Top; } } #endregion }