Ejemplo n.º 1
0
        /// <summary>
        /// Handles the Click event of the btnDeleteCustomAction control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnDeleteCustomAction_Click(object sender, EventArgs e)
        {
            SaveCustomActionsConfigToViewState();
            var index = (sender as LinkButton).CommandArgument.AsIntegerOrNull();

            if (index.HasValue)
            {
                CustomActionsConfigState.RemoveAt(index.Value);
            }

            BindCustomActionsConfig();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Handles the Click event of the lbAddCustomAction control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 protected void lbAddCustomAction_Click(object sender, EventArgs e)
 {
     SaveCustomActionsConfigToViewState();
     CustomActionsConfigState.Add(new CustomActionConfig());
     BindCustomActionsConfig();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Handles the OnSave event of the masterPage control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void masterPage_OnSave(object sender, EventArgs e)
        {
            bool reloadPage = false;
            int  blockId    = Convert.ToInt32(PageParameter("BlockId"));

            if (!Page.IsValid)
            {
                return;
            }

            var rockContext = new RockContext();

            rockContext.WrapTransaction(() =>
            {
                var blockService = new Rock.Model.BlockService(rockContext);
                var block        = blockService.Get(blockId);

                block.LoadAttributes();

                block.Name                = tbBlockName.Text;
                block.CssClass            = tbCssClass.Text;
                block.PreHtml             = cePreHtml.Text;
                block.PostHtml            = cePostHtml.Text;
                block.OutputCacheDuration = 0; //Int32.Parse( tbCacheDuration.Text );

                avcAttributes.GetEditValues(block);
                avcMobileAttributes.GetEditValues(block);
                avcAdvancedAttributes.GetEditValues(block);

                foreach (var kvp in CustomSettingsProviders)
                {
                    kvp.Key.WriteSettingsToEntity(block, kvp.Value, rockContext);
                }

                SaveCustomColumnsConfigToViewState();
                if (this.CustomGridColumnsConfigState != null && this.CustomGridColumnsConfigState.ColumnsConfig.Any())
                {
                    if (!block.Attributes.Any(a => a.Key == CustomGridColumnsConfig.AttributeKey))
                    {
                        block.Attributes.Add(CustomGridColumnsConfig.AttributeKey, null);
                    }

                    var customGridColumnsJSON = this.CustomGridColumnsConfigState.ToJson();
                    if (block.GetAttributeValue(CustomGridColumnsConfig.AttributeKey) != customGridColumnsJSON)
                    {
                        block.SetAttributeValue(CustomGridColumnsConfig.AttributeKey, customGridColumnsJSON);

                        // if the CustomColumns changed, reload the whole page so that we can avoid issues with columns changing between postbacks
                        reloadPage = true;
                    }
                }
                else
                {
                    if (block.Attributes.Any(a => a.Key == CustomGridColumnsConfig.AttributeKey))
                    {
                        if (block.GetAttributeValue(CustomGridColumnsConfig.AttributeKey) != null)
                        {
                            // if the CustomColumns were removed, reload the whole page so that we can avoid issues with columns changing between postbacks
                            reloadPage = true;
                        }

                        block.SetAttributeValue(CustomGridColumnsConfig.AttributeKey, null);
                    }
                }

                // Save the custom action configs
                SaveCustomActionsConfigToViewState();

                if (CustomActionsConfigState != null && CustomActionsConfigState.Any())
                {
                    if (!block.Attributes.Any(a => a.Key == CustomGridOptionsConfig.CustomActionsConfigsAttributeKey))
                    {
                        block.Attributes.Add(CustomGridOptionsConfig.CustomActionsConfigsAttributeKey, null);
                    }

                    var json = CustomActionsConfigState.ToJson();

                    if (block.GetAttributeValue(CustomGridOptionsConfig.CustomActionsConfigsAttributeKey) != json)
                    {
                        block.SetAttributeValue(CustomGridOptionsConfig.CustomActionsConfigsAttributeKey, json);

                        // if the actions changed, reload the whole page so that we can avoid issues with launchers changing between postbacks
                        reloadPage = true;
                    }
                }
                else
                {
                    if (block.Attributes.Any(a => a.Key == CustomGridOptionsConfig.CustomActionsConfigsAttributeKey))
                    {
                        if (block.GetAttributeValue(CustomGridOptionsConfig.CustomActionsConfigsAttributeKey) != null)
                        {
                            // if the actions were removed, reload the whole page so that we can avoid issues with launchers changing between postbacks
                            reloadPage = true;
                        }

                        block.SetAttributeValue(CustomGridOptionsConfig.CustomActionsConfigsAttributeKey, null);
                    }
                }

                if (tglEnableStickyHeader.Checked)
                {
                    if (!block.Attributes.Any(a => a.Key == CustomGridOptionsConfig.EnableStickyHeadersAttributeKey))
                    {
                        block.Attributes.Add(CustomGridOptionsConfig.EnableStickyHeadersAttributeKey, null);
                    }
                }

                if (block.GetAttributeValue(CustomGridOptionsConfig.EnableStickyHeadersAttributeKey).AsBoolean() != tglEnableStickyHeader.Checked)
                {
                    block.SetAttributeValue(CustomGridOptionsConfig.EnableStickyHeadersAttributeKey, tglEnableStickyHeader.Checked.ToTrueFalse());

                    // if EnableStickyHeaders changed, reload the page
                    reloadPage = true;
                }

                // Save the default launcher enabled setting
                var isDefaultLauncherEnabled = tglEnableDefaultWorkflowLauncher.Checked;

                if (isDefaultLauncherEnabled && !block.Attributes.Any(a => a.Key == CustomGridOptionsConfig.EnableDefaultWorkflowLauncherAttributeKey))
                {
                    block.Attributes.Add(CustomGridOptionsConfig.EnableDefaultWorkflowLauncherAttributeKey, null);
                }

                if (block.GetAttributeValue(CustomGridOptionsConfig.EnableDefaultWorkflowLauncherAttributeKey).AsBoolean() != isDefaultLauncherEnabled)
                {
                    block.SetAttributeValue(CustomGridOptionsConfig.EnableDefaultWorkflowLauncherAttributeKey, isDefaultLauncherEnabled.ToTrueFalse());

                    // since the setting changed, reload the page
                    reloadPage = true;
                }

                rockContext.SaveChanges();
                block.SaveAttributeValues(rockContext);

                // If this is a PageMenu block then we need to also flush the lava template cache for the block here.
                // Changes to the PageMenu block configuration will handle this in the PageMenu_BlockUpdated event handler,
                // but here we address the situation where child pages are modified using the "CMS Configuration | Pages" menu option.
                if (block.BlockType.Guid == Rock.SystemGuid.BlockType.PAGE_MENU.AsGuid())
                {
                    var cacheKey = string.Format("Rock:PageMenu:{0}", block.Id);

                    if (LavaService.RockLiquidIsEnabled)
                    {
#pragma warning disable CS0618 // Type or member is obsolete
                        LavaTemplateCache.Remove(cacheKey);
#pragma warning restore CS0618 // Type or member is obsolete
                    }

                    LavaService.RemoveTemplateCacheEntry(cacheKey);
                }

                StringBuilder scriptBuilder = new StringBuilder();

                if (reloadPage)
                {
                    scriptBuilder.AppendLine("window.parent.location.reload();");
                }
                else
                {
                    scriptBuilder.AppendLine(string.Format("window.parent.Rock.controls.modal.close('BLOCK_UPDATED:{0}');", blockId));
                }

                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "close-modal", scriptBuilder.ToString(), true);
            });
        }