using System; using CMS.GlobalHelper; using CMS.PortalEngine; using CMS.SettingsProvider; using CMS.UIControls; using CMS.DocumentEngine; public partial class CMSModules_PortalEngine_UI_WebParts_WebPartProperties_layout_menu : CMSWebPartPropertiesPage { #region "Variables" private WebPartInfo webPartInfo = null; /// /// Current page info. /// private PageInfo pi = null; /// /// Page template info. /// private PageTemplateInfo pti = null; /// /// Current web part. /// private WebPartInstance webPart = null; private string mLayoutCodeName = null; #endregion #region "Properties" /// /// Gets code name of edited layout. /// private string LayoutCodeName { get { return mLayoutCodeName ?? (mLayoutCodeName = QueryHelper.GetString("layoutcodename", String.Empty)); } set { mLayoutCodeName = value; } } #endregion #region "Page methods" protected override void OnLoad(EventArgs e) { base.OnLoad(e); CurrentMaster.DisplaySiteSelectorPanel = true; if (webpartId != "") { // Get pageinfo pi = GetPageInfo(aliasPath, templateId, cultureCode); if (pi == null) { RedirectToInformation(GetString("WebPartProperties.WebPartNotFound")); return; } // Get page template pti = pi.UsedPageTemplateInfo; if ((pti != null) && ((pti.TemplateInstance != null))) { webPart = pti.TemplateInstance.GetWebPart(instanceGuid, zoneVariantId, variantId) ?? pti.GetWebPart(webpartId); } } bool hide = false; // If the web part is not found, do not continue // Redirect to information is in main window, just hide selector if (webPart == null) { hide = true; } else { webPartInfo = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType); if (webPartInfo == null) { hide = true; } // Get the current layout name if (String.IsNullOrEmpty(LayoutCodeName)) { mLayoutCodeName = ValidationHelper.GetString(webPart.GetValue("WebPartLayout"), ""); } } if (hide) { pnlContent.Visible = false; return; } // Strings lblLayouts.Text = GetString("WebPartPropertise.LayoutList"); // Add default drop down items selectLayout.ShowDefaultItem = true; // Add new item if (CurrentUser.IsAuthorizedPerResource("CMS.Design", "EditCode")) { selectLayout.ShowNewItem = true; } // Set where condition selectLayout.WhereCondition = "WebPartLayoutWebPartID =" + webPartInfo.WebPartID; // Load layouts if (!RequestHelper.IsPostBack() && (LayoutCodeName != "")) { selectLayout.Value = LayoutCodeName; } // Reload the content page if required if (!RequestHelper.IsPostBack() || QueryHelper.GetBoolean("reload", false)) { LoadContentPage(); } } /// /// Selected index changed. /// protected void drpLayouts_Changed(object sender, EventArgs ea) { if (webPartInfo != null) { LoadContentPage(); } } /// /// Registers a script to load the layout page to the content frame. /// private void LoadContentPage() { var query = URLHelper.Url.Query; var selectedLayout = selectLayout.Value.ToString(); query = URLHelper.AddParameterToUrl(query, "layoutcodename", selectedLayout); query = URLHelper.AddParameterToUrl(query, "noreload", "true"); query = URLHelper.RemoveParameterFromUrl(query, "tabmode"); var script = ScriptHelper.GetScript(@"parent.frames['webpartpropertiescontent'].location = 'webpartproperties_layout.aspx" + query + "';"); ScriptHelper.RegisterStartupScript(Page, typeof(string), "SetWebPartLayout", script); } #endregion }