/// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
        {
            LavaShortcode lavaShortcode;
            var           rockContext          = new RockContext();
            var           lavaShortCodeService = new LavaShortcodeService(rockContext);

            int lavaShortCode = hfLavaShortcodeId.ValueAsInt();

            if (lavaShortCodeService.Queryable().Any(a => a.TagName == tbTagName.Text && a.Id != lavaShortCode))
            {
                Page.ModelState.AddModelError("DuplicateTag", "Tag with the same name is already in use.");
                return;
            }

            if (lavaShortCode == 0)
            {
                lavaShortcode = new LavaShortcode();
                lavaShortCodeService.Add(lavaShortcode);
            }
            else
            {
                lavaShortcode = lavaShortCodeService.Get(lavaShortCode);
            }

            lavaShortcode.Name                = tbLavaShortcodeName.Text;
            lavaShortcode.IsActive            = cbIsActive.Checked;
            lavaShortcode.Description         = tbDescription.Text;
            lavaShortcode.Documentation       = htmlDocumentation.Text;
            lavaShortcode.TagType             = rblTagType.SelectedValueAsEnum <TagType>();
            lavaShortcode.TagName             = tbTagName.Text;
            lavaShortcode.Markup              = ceMarkup.Text;
            lavaShortcode.Parameters          = kvlParameters.Value;
            lavaShortcode.EnabledLavaCommands = String.Join(",", lcpLavaCommands.SelectedLavaCommands);

            rockContext.SaveChanges();

            // unregister shortcode
            if (hfOriginalTagName.Value.IsNotNullOrWhiteSpace())
            {
                Template.UnregisterShortcode(hfOriginalTagName.Value);
            }

            // register shortcode
            if (lavaShortcode.TagType == TagType.Block)
            {
                Template.RegisterShortcode <DynamicShortcodeBlock>(lavaShortcode.TagName);
            }
            else
            {
                Template.RegisterShortcode <DynamicShortcodeInline>(lavaShortcode.TagName);
            }

            // (bug fix) Now we have to clear the entire LavaTemplateCache because it's possible that some other
            // usage of this shortcode is cached with a key we can't predict.
            LavaTemplateCache.Clear();

            NavigateToParentPage();
        }
示例#2
0
        /// <summary>
        /// Handles the Click event of the btnDelete 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 btnDelete_Click(object sender, EventArgs e)
        {
            LinkButton   btn           = ( LinkButton )sender;
            RepeaterItem item          = ( RepeaterItem )btn.NamingContainer;
            HiddenField  hfShortcodeId = ( HiddenField )item.FindControl("hfShortcodeId");

            var rockContext = new RockContext();
            LavaShortcodeService lavaShortcodeService = new LavaShortcodeService(rockContext);
            LavaShortcode        lavaShortcode        = lavaShortcodeService.Get(hfShortcodeId.ValueAsInt());

            if (lavaShortcode != null)
            {
                // unregister the shortcode
                Template.UnregisterShortcode(lavaShortcode.TagName);

                lavaShortcodeService.Delete(lavaShortcode);
                rockContext.SaveChanges();
            }

            LoadShortcodes();
        }
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
        {
            LavaShortcode lavaShortcode;
            var           rockContext          = new RockContext();
            var           lavaShortCodeService = new LavaShortcodeService(rockContext);

            int lavaShortCode = hfLavaShortcodeId.ValueAsInt();

            if (lavaShortCodeService.Queryable().Any(a => a.TagName == tbTagName.Text && a.Id != lavaShortCode))
            {
                Page.ModelState.AddModelError("DuplicateTag", "Tag with the same name is already in use.");
                return;
            }

            if (lavaShortCode == 0)
            {
                lavaShortcode = new LavaShortcode();
                lavaShortCodeService.Add(lavaShortcode);
            }
            else
            {
                lavaShortcode = lavaShortCodeService.Get(lavaShortCode);
            }

            var oldTagName = hfOriginalTagName.Value;

            lavaShortcode.Name                = tbLavaShortcodeName.Text;
            lavaShortcode.IsActive            = cbIsActive.Checked;
            lavaShortcode.Description         = tbDescription.Text;
            lavaShortcode.Documentation       = htmlDocumentation.Text;
            lavaShortcode.TagType             = rblTagType.SelectedValueAsEnum <TagType>();
            lavaShortcode.TagName             = tbTagName.Text.Trim();
            lavaShortcode.Markup              = ceMarkup.Text;
            lavaShortcode.Parameters          = kvlParameters.Value;
            lavaShortcode.EnabledLavaCommands = String.Join(",", lcpLavaCommands.SelectedLavaCommands);

            rockContext.SaveChanges();

            if (LavaService.RockLiquidIsEnabled)
            {
                // unregister shortcode
                if (oldTagName.IsNotNullOrWhiteSpace())
                {
                    Template.UnregisterShortcode(oldTagName);
                }

                // Register the new shortcode definition. Note that RockLiquid shortcode tags are case-sensitive.
                if (lavaShortcode.TagType == TagType.Block)
                {
                    Template.RegisterShortcode <Rock.Lava.Shortcodes.DynamicShortcodeBlock>(lavaShortcode.TagName);
                }
                else
                {
                    Template.RegisterShortcode <Rock.Lava.Shortcodes.DynamicShortcodeInline>(lavaShortcode.TagName);
                }

                // (bug fix) Now we have to clear the entire LavaTemplateCache because it's possible that some other
                // usage of this shortcode is cached with a key we can't predict.
#pragma warning disable CS0618 // Type or member is obsolete
                // This obsolete code can be deleted when support for the DotLiquid Lava implementation is removed.
                LavaTemplateCache.Clear();
#pragma warning restore CS0618 // Type or member is obsolete
            }

            if (oldTagName.IsNotNullOrWhiteSpace())
            {
                LavaService.DeregisterShortcode(oldTagName);
            }

            // Register the new shortcode definition.
            LavaService.RegisterShortcode(lavaShortcode.TagName, (shortcodeName) => WebsiteLavaShortcodeProvider.GetShortcodeDefinition(shortcodeName));

            LavaService.ClearTemplateCache();

            NavigateToParentPage();
        }