protected override void OnInit(EventArgs e)
        {
            Rock.Web.UI.DialogMasterPage masterPage = this.Page.Master as Rock.Web.UI.DialogMasterPage;
            if (masterPage != null)
            {
                masterPage.OnSave += new EventHandler <EventArgs>(masterPage_OnSave);
            }

            try
            {
                int pageId = Convert.ToInt32(PageParameter("Page"));
                _page = Rock.Web.Cache.Page.Read(pageId);

                if (_page.Authorized("Configure", CurrentUser))
                {
                    var attributeControls = Rock.Attribute.Helper.GetEditControls(_page, !Page.IsPostBack);
                    foreach (HtmlGenericControl fs in attributeControls)
                    {
                        phAttributes.Controls.Add(fs);
                    }
                }
                else
                {
                    DisplayError("You are not authorized to edit this page");
                }
            }
            catch (SystemException ex)
            {
                DisplayError(ex.Message);
            }

            base.OnInit(e);
        }
Example #2
0
        protected override void OnInit(EventArgs e)
        {
            Rock.Web.UI.DialogMasterPage masterPage = this.Page.Master as Rock.Web.UI.DialogMasterPage;
            if (masterPage != null)
            {
                masterPage.OnSave += new EventHandler <EventArgs>(masterPage_OnSave);
            }

            try
            {
                int pageId = Convert.ToInt32(PageParameter("Page"));
                _page = Rock.Web.Cache.PageCache.Read(pageId);

                if (_page.IsAuthorized("Administrate", CurrentPerson))
                {
                    phAttributes.Controls.Clear();
                    Rock.Attribute.Helper.AddEditControls(_page, phAttributes, !Page.IsPostBack);

                    List <string> blockContexts = new List <string>();
                    foreach (var block in _page.Blocks)
                    {
                        var blockControl = TemplateControl.LoadControl(block.BlockType.Path) as Rock.Web.UI.RockBlock;
                        if (blockControl != null)
                        {
                            blockControl.CurrentPage  = _page;
                            blockControl.CurrentBlock = block;
                            foreach (var context in blockControl.ContextTypesRequired)
                            {
                                if (!blockContexts.Contains(context))
                                {
                                    blockContexts.Add(context);
                                }
                            }
                        }
                    }

                    phContextPanel.Visible = blockContexts.Count > 0;

                    int i = 0;
                    foreach (string context in blockContexts)
                    {
                        var tbContext = new LabeledTextBox();
                        tbContext.ID        = string.Format("context_{0}", i++);
                        tbContext.Required  = true;
                        tbContext.LabelText = context;

                        if (_page.PageContexts.ContainsKey(context))
                        {
                            tbContext.Text = _page.PageContexts[context];
                        }

                        phContext.Controls.Add(tbContext);
                    }
                }
                else
                {
                    DisplayError("You are not authorized to edit this page");
                }
            }
            catch (SystemException ex)
            {
                DisplayError(ex.Message);
            }

            base.OnInit(e);
        }