Inheritance: RockPage
示例#1
0
        /// <summary>
        /// Raises the <see cref="E:Init" /> event.
        /// </summary>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            Rock.Web.UI.DialogPage dialogPage = this.Page as Rock.Web.UI.DialogPage;
            if (dialogPage != null)
            {
                dialogPage.OnSave += new EventHandler <EventArgs>(masterPage_OnSave);
            }

            try
            {
                int   blockId = Convert.ToInt32(PageParameter("BlockId"));
                Block _block  = new BlockService(new RockContext()).Get(blockId);

                if (_block.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson))
                {
                    phAttributes.Controls.Clear();
                    phAdvancedAttributes.Controls.Clear();

                    _block.LoadAttributes();
                    if (_block.Attributes != null)
                    {
                        foreach (var attributeCategory in Rock.Attribute.Helper.GetAttributeCategories(_block))
                        {
                            if (attributeCategory.Category != null && attributeCategory.Category.Name.Equals("customsetting", StringComparison.OrdinalIgnoreCase))
                            {
                            }
                            else if (attributeCategory.Category != null && attributeCategory.Category.Name.Equals("advanced", StringComparison.OrdinalIgnoreCase))
                            {
                                Rock.Attribute.Helper.AddEditControls(
                                    string.Empty, attributeCategory.Attributes.Select(a => a.Key).ToList(),
                                    _block, phAdvancedAttributes, string.Empty, !Page.IsPostBack, new List <string>());
                            }
                            else
                            {
                                Rock.Attribute.Helper.AddEditControls(
                                    attributeCategory.Category != null ? attributeCategory.Category.Name : string.Empty,
                                    attributeCategory.Attributes.Select(a => a.Key).ToList(),
                                    _block, phAttributes, string.Empty, !Page.IsPostBack, new List <string>());
                            }
                        }
                    }
                }
                else
                {
                    DisplayError("You are not authorized to edit this block", null);
                }
            }
            catch (SystemException ex)
            {
                DisplayError(ex.Message, "<pre>" + ex.StackTrace + "</pre>");
            }

            base.OnInit(e);
        }
        /// <summary>
        /// Raises the <see cref="E:Init" /> event.
        /// </summary>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            try
            {
                int?blockId = PageParameter("BlockId").AsIntegerOrNull();
                if (!blockId.HasValue)
                {
                    return;
                }

                var _block = BlockCache.Get(blockId.Value);

                Rock.Web.UI.DialogPage dialogPage = this.Page as Rock.Web.UI.DialogPage;
                if (dialogPage != null)
                {
                    dialogPage.OnSave  += new EventHandler <EventArgs>(masterPage_OnSave);
                    dialogPage.Title    = _block.BlockType.Name;
                    dialogPage.SubTitle = string.Format("{0} / Id: {1}", _block.BlockType.Category, blockId);
                }

                if (_block.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson))
                {
                    var blockTypeId = _block.BlockTypeId;
                    var blockType   = BlockTypeCache.Get(blockTypeId);
                    if (blockType != null && !blockType.IsInstancePropertiesVerified)
                    {
                        using (var rockContext = new RockContext())
                        {
                            var  blockCompiledType = _block.BlockType.GetCompiledType();
                            int? blockEntityTypeId = EntityTypeCache.Get(typeof(Block)).Id;
                            bool attributesUpdated = Rock.Attribute.Helper.UpdateAttributes(blockCompiledType, blockEntityTypeId, "BlockTypeId", blockTypeId.ToString(), rockContext);
                            BlockTypeCache.Get(blockTypeId).MarkInstancePropertiesVerified(true);
                        }
                    }
                }
                else
                {
                    DisplayError("You are not authorized to edit this block", null);
                }
            }
            catch (SystemException ex)
            {
                DisplayError(ex.Message, "<pre>" + HttpUtility.HtmlEncode(ex.StackTrace) + "</pre>");
            }

            base.OnInit(e);

            LoadCustomSettingsTabs();
        }
示例#3
0
        /// <summary>
        /// Raises the <see cref="E:Init" /> event.
        /// </summary>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            Rock.Web.UI.DialogPage dialogPage = this.Page as Rock.Web.UI.DialogPage;
            if (dialogPage != null)
            {
                dialogPage.OnSave += new EventHandler <EventArgs>(masterPage_OnSave);
            }

            try
            {
                int   blockId = Convert.ToInt32(PageParameter("BlockId"));
                Block _block  = new BlockService(new RockContext()).Get(blockId);

                if (_block.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson))
                {
                    var blockType = BlockTypeCache.Read(_block.BlockTypeId);
                    if (blockType != null && !blockType.IsInstancePropertiesVerified)
                    {
                        System.Web.UI.Control control = Page.LoadControl(blockType.Path);
                        if (control is RockBlock)
                        {
                            using (var rockContext = new RockContext())
                            {
                                var rockBlock         = control as RockBlock;
                                int?blockEntityTypeId = EntityTypeCache.Read(typeof(Block)).Id;
                                Rock.Attribute.Helper.UpdateAttributes(rockBlock.GetType(), blockEntityTypeId, "BlockTypeId", blockType.Id.ToString(), rockContext);
                            }

                            blockType.IsInstancePropertiesVerified = true;
                        }
                    }

                    phAttributes.Controls.Clear();
                    phAdvancedAttributes.Controls.Clear();

                    _block.LoadAttributes();
                    if (_block.Attributes != null)
                    {
                        foreach (var attributeCategory in Rock.Attribute.Helper.GetAttributeCategories(_block))
                        {
                            if (attributeCategory.Category != null && attributeCategory.Category.Name.Equals("customsetting", StringComparison.OrdinalIgnoreCase))
                            {
                            }
                            else if (attributeCategory.Category != null && attributeCategory.Category.Name.Equals("advanced", StringComparison.OrdinalIgnoreCase))
                            {
                                Rock.Attribute.Helper.AddEditControls(
                                    string.Empty, attributeCategory.Attributes.Select(a => a.Key).ToList(),
                                    _block, phAdvancedAttributes, string.Empty, !Page.IsPostBack, new List <string>());
                            }
                            else
                            {
                                Rock.Attribute.Helper.AddEditControls(
                                    attributeCategory.Category != null ? attributeCategory.Category.Name : string.Empty,
                                    attributeCategory.Attributes.Select(a => a.Key).ToList(),
                                    _block, phAttributes, string.Empty, !Page.IsPostBack, new List <string>());
                            }
                        }
                    }
                }
                else
                {
                    DisplayError("You are not authorized to edit this block", null);
                }
            }
            catch (SystemException ex)
            {
                DisplayError(ex.Message, "<pre>" + HttpUtility.HtmlEncode(ex.StackTrace) + "</pre>");
            }

            base.OnInit(e);
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            Rock.Web.UI.DialogPage dialogPage = this.Page as Rock.Web.UI.DialogPage;
            if (dialogPage != null)
            {
                dialogPage.ValidationGroup = this.BlockValidationGroup;
            }

            valSummaryTop.ValidationGroup = this.BlockValidationGroup;

            // Set the validation group on any custom settings providers.
            SetValidationGroup(CustomSettingsProviders.Values.ToArray(), this.BlockValidationGroup);

            int?blockId = PageParameter("BlockId").AsIntegerOrNull();

            if (!blockId.HasValue)
            {
                return;
            }

            var       _block = BlockCache.Get(blockId.Value);
            SiteCache _site  = null;

            // Get site info from Page -> Layout -> Site
            if (_block.Page.IsNotNull())
            {
                _site = SiteCache.Get(_block.Page.SiteId);
            }
            else if (_block.Layout.IsNotNull())
            {
                _site = SiteCache.Get(_block.Layout.SiteId);
            }
            else if (_block.SiteId.HasValue)
            {
                _site = SiteCache.Get(_block.SiteId.Value);
            }

            // Change Pre/Post text labels if this is a mobile block
            if (_site.IsNotNull() && _site.SiteType == SiteType.Mobile)
            {
                cePostHtml.Label = "Post-XAML";
                cePreHtml.Label  = "Pre-XAML";
            }

            var blockControlType = _block.BlockType.GetCompiledType();

            this.ShowCustomGridColumns = typeof(Rock.Web.UI.ICustomGridColumns).IsAssignableFrom(blockControlType);
            this.ShowCustomGridOptions = typeof(Rock.Web.UI.ICustomGridOptions).IsAssignableFrom(blockControlType);
            this.ShowMobileOptions     = _block.Attributes.Any(a => a.Value.Categories.Any(c => c.Name == "custommobile"));

            if (!Page.IsPostBack && _block.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson))
            {
                if (_block.Attributes != null)
                {
                    avcAdvancedAttributes.IncludedCategoryNames = new string[] { "advanced" };
                    avcAdvancedAttributes.AddEditControls(_block);

                    avcMobileAttributes.IncludedCategoryNames = new string[] { "custommobile" };
                    avcMobileAttributes.AddEditControls(_block);

                    avcAttributes.ExcludedCategoryNames = new string[] { "advanced", "customsetting", "custommobile" };
                    avcAttributes.AddEditControls(_block);
                }

                foreach (var kvp in CustomSettingsProviders)
                {
                    kvp.Key.ReadSettingsFromEntity(_block, kvp.Value);
                }

                rptProperties.DataSource = GetTabs(_block.BlockType);
                rptProperties.DataBind();

                tbBlockName.Text = _block.Name;
                tbCssClass.Text  = _block.CssClass;
                cePreHtml.Text   = _block.PreHtml;
                cePostHtml.Text  = _block.PostHtml;

                // Hide the Cache duration block for now;
                tbCacheDuration.Visible = false;
                //tbCacheDuration.Text = _block.OutputCacheDuration.ToString();

                pwCustomGridColumns.Visible   = this.ShowCustomGridColumns;
                tglEnableStickyHeader.Visible = this.ShowCustomGridOptions;

                if (this.ShowCustomGridColumns)
                {
                    CustomGridColumnsConfigState = _block.GetAttributeValue(CustomGridColumnsConfig.AttributeKey).FromJsonOrNull <CustomGridColumnsConfig>() ?? new CustomGridColumnsConfig();
                    BindCustomColumnsConfig();
                }
                else
                {
                    CustomGridColumnsConfigState = null;
                }

                if (this.ShowCustomGridOptions)
                {
                    tglEnableStickyHeader.Checked            = _block.GetAttributeValue(CustomGridOptionsConfig.EnableStickyHeadersAttributeKey).AsBoolean();
                    tglEnableDefaultWorkflowLauncher.Checked = _block.GetAttributeValue(CustomGridOptionsConfig.EnableDefaultWorkflowLauncherAttributeKey).AsBoolean();

                    CustomActionsConfigState = _block.GetAttributeValue(CustomGridOptionsConfig.CustomActionsConfigsAttributeKey).FromJsonOrNull <List <CustomActionConfig> >();
                    BindCustomActionsConfig();
                }
                else
                {
                    CustomActionsConfigState = null;
                }

                ShowSelectedPane();
            }

            base.OnLoad(e);
        }