Exemple #1
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            try
            {
                int pageId = int.MinValue;
                if (int.TryParse(PageParameter("Page"), out pageId))
                {
                    _page = Rock.Web.Cache.PageCache.Read(pageId);

                    DialogMasterPage masterPage = this.Page.Master as DialogMasterPage;
                    if (masterPage != null)
                    {
                        masterPage.OnSave  += new EventHandler <EventArgs>(masterPage_OnSave);
                        masterPage.SubTitle = string.Format("Id: {0}", _page.Id);
                    }

                    if (_page.IsAuthorized("Administrate", CurrentPerson))
                    {
                        ddlMenuWhen.BindToEnum(typeof(DisplayInNavWhen));

                        phAttributes.Controls.Clear();
                        Rock.Attribute.Helper.AddEditControls(_page, phAttributes, !Page.IsPostBack);

                        var blockContexts = new Dictionary <string, string>();
                        foreach (var block in _page.Blocks)
                        {
                            var blockControl = TemplateControl.LoadControl(block.BlockType.Path) as RockBlock;
                            if (blockControl != null)
                            {
                                blockControl.SetBlock(block);
                                foreach (var context in blockControl.ContextTypesRequired)
                                {
                                    if (!blockContexts.ContainsKey(context.Name))
                                    {
                                        blockContexts.Add(context.Name, context.FriendlyName);
                                    }
                                }
                            }
                        }

                        phContextPanel.Visible = blockContexts.Count > 0;

                        foreach (var context in blockContexts)
                        {
                            var tbContext = new RockTextBox();
                            tbContext.ID       = string.Format("context_{0}", context.Key.Replace('.', '_'));
                            tbContext.Required = true;
                            tbContext.Label    = context.Value + " Parameter Name";
                            tbContext.Help     = "The page parameter name that contains the id of this context entity.";
                            if (_page.PageContexts.ContainsKey(context.Key))
                            {
                                tbContext.Text = _page.PageContexts[context.Key];
                            }

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

            base.OnInit(e);
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            DialogMasterPage masterPage = this.Page.Master as 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 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 RockTextBox();
                        tbContext.ID       = string.Format("context_{0}", i++);
                        tbContext.Required = true;
                        tbContext.Label    = 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);
        }