Ejemplo n.º 1
0
        protected void rgHtmlFragments_Edit(int contentId)
        {
            pnlList.Visible = false;
            pnlEdit.Visible = true;

            var hc = new HtmlContentService(new RockContext()).Get(contentId);

            hfHTMLContentGUID.Value = hc.Guid.ToString();

            rtbBlockId.Text = hc.BlockId.ToString();

            var context = HttpUtility.ParseQueryString(hc.EntityValue);

            rtbContextName.Text = context["ContextName"];

            context.Remove("ContextName");
            rtbContextParameter.Text = context.ToString();

            rtbVersion.Text = hc.Version.ToString();

            dtpStartTime.SelectedDateTime = hc.StartDateTime;
            dtpExpire.SelectedDateTime    = hc.ExpireDateTime;

            rcbApproved.Checked = hc.IsApproved;

            if (htmlEditor.Visible)
            {
                htmlEditor.Text = hc.Content;
            }
            else
            {
                ceHtml.Text = hc.Content;
            }
        }
Ejemplo n.º 2
0
        protected void lbSaveAs_Click(object sender, EventArgs e)
        {
            var hc = new HtmlContent();

            hc.BlockId        = rtbBlockId.Text.AsIntegerOrNull() ?? BlockId;
            hc.EntityValue    = rtbContextParameter.Text + (string.IsNullOrWhiteSpace(rtbContextName.Text) ? "" : ("&ContextName=" + rtbContextName.Text));
            hc.Version        = rtbVersion.Text.AsInteger();
            hc.StartDateTime  = dtpStartTime.SelectedDateTime;
            hc.ExpireDateTime = dtpExpire.SelectedDateTime;
            hc.IsApproved     = rcbApproved.Checked;
            if (hc.IsApproved)
            {
                hc.ApprovedDateTime = DateTime.Now;
            }
            if (htmlEditor.Visible)
            {
                hc.Content = htmlEditor.Text;
            }
            else
            {
                hc.Content = ceHtml.Text;
            }

            var rockContext = new RockContext();
            var hcServ      = new HtmlContentService(rockContext);

            hcServ.Add(hc);
            rockContext.SaveChanges();

            pnlList.Visible = true;
            pnlEdit.Visible = false;
            BindGrid();
        }
Ejemplo n.º 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var replacedId    = "";
        var replacedImage = "";

        var lastMessageSeries = new ContentChannelService(new RockContext())
                                .Get(MessageSeriesContentChannelGuid)
                                .Items
                                .Where(i => i.StartDateTime < DateTime.Now)
                                .OrderByDescending(i => i.StartDateTime)
                                .FirstOrDefault();

        if (lastMessageSeries != null)
        {
            replacedId = lastMessageSeries.Id.ToString();
            lastMessageSeries.LoadAttributes();
            replacedImage = lastMessageSeries.GetAttributeValue("SmallSeriesFeatureImage") ?? "";
        }

        var rootPageId = RockPage.Site.DefaultPageId;
        var menuData   = new HtmlContentService(new RockContext()).Queryable()
                         .Where(h => h.Block.Page.ParentPageId == rootPageId && h.Block.Page.InternalName != "support-pages")
                         .Select(h => new
        {
            h.Block.Page.Id,
            h.Block.Page.PageTitle,
            HtmlContent = h.Content.Replace("{{seriesid}}", replacedId).Replace("{{seriesimage}}", replacedImage)
        });

        rptMenuLinks.DataSource = rptMenuDivs.DataSource = menuData.ToList();
        rptMenuLinks.DataBind();
        rptMenuDivs.DataBind();
    }
        public void UpdateContents(int blockId, [FromBody] HtmlContents htmlContents)
        {
            // Enable proxy creation since security is being checked and need to navigate parent authorities
            SetProxyCreation(true);

            var person = GetPerson();

            var block = new BlockService((RockContext)Service.Context).Get(blockId);

            if (block != null && block.IsAuthorized(Rock.Security.Authorization.EDIT, person))
            {
                var htmlContentService = (HtmlContentService)Service;
                var htmlContent        = htmlContentService.GetActiveContent(blockId, htmlContents.EntityValue);
                if (htmlContent != null)
                {
                    htmlContent.Content = htmlContents.Content;
                    if (!System.Web.HttpContext.Current.Items.Contains("CurrentPerson"))
                    {
                        System.Web.HttpContext.Current.Items.Add("CurrentPerson", person);
                    }

                    Service.Context.SaveChanges();

                    HtmlContentService.FlushCachedContent(blockId, htmlContents.EntityValue);
                }
            }
        }
Ejemplo n.º 5
0
        private void ShowView()
        {
            string entityValue = EntityValue();
            string html        = "";

            int    cacheDuration = Int32.Parse(AttributeValue("CacheDuration"));
            string cachedContent = GetCacheItem(entityValue) as string;

            // if content not cached load it from DB
            if (cachedContent == null)
            {
                Rock.CMS.HtmlContent content = new HtmlContentService().GetActiveContent(BlockInstance.Id, entityValue);

                if (content != null)
                {
                    html = content.Content;

                    // cache content
                    if (cacheDuration > 0)
                    {
                        AddCacheItem(entityValue, html, cacheDuration);
                    }
                }
            }
            else
            {
                html = cachedContent;
            }

            // add content to the content window
            lPreText.Text     = AttributeValue("PreText");
            lHtmlContent.Text = html;
            lPostText.Text    = AttributeValue("PostText");
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Checks HtmlContent model for legacy lava and outputs SQL to correct it
        /// Fields evaluated: Content
        /// </summary>
        public void CheckHtmlContent()
        {
            RockContext        rockContext        = new RockContext();
            HtmlContentService htmlContentService = new HtmlContentService(rockContext);

            foreach (HtmlContent htmlContent in htmlContentService.Queryable().ToList())
            {
                // don't change if modified
                if (htmlContent.ModifiedDateTime != null)
                {
                    continue;
                }

                bool isUpdated = false;

                htmlContent.Content = ReplaceUnformatted(htmlContent.Content, ref isUpdated);
                htmlContent.Content = ReplaceUrl(htmlContent.Content, ref isUpdated);
                htmlContent.Content = ReplaceGlobal(htmlContent.Content, ref isUpdated);
                htmlContent.Content = ReplaceDotNotation(htmlContent.Content, ref isUpdated);

                if (isUpdated)
                {
                    string sql = $"UPDATE [HtmlContent] SET [Content] = '{htmlContent.Content.Replace( "'", "''" )}' WHERE [Guid] = '{htmlContent.Guid}';";
                    _sqlUpdateScripts.Add(sql);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Handles the Click event of the SelectVersion control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs"/> instance containing the event data.</param>
        protected void SelectVersion_Click(object sender, Rock.Web.UI.Controls.RowEventArgs e)
        {
            HtmlContent htmlContent = new HtmlContentService(new RockContext()).Get(e.RowKeyId);

            pnlVersionGrid.Visible = false;
            pnlEdit.Visible        = true;
            ShowEditDetail(htmlContent);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the maximum version that this HtmlContent block
        /// </summary>
        /// <returns></returns>
        private int?GetMaxVersionOfHtmlContent()
        {
            string entityValue = this.EntityValue();
            int?   maxVersion  = new HtmlContentService(new RockContext()).Queryable()
                                 .Where(c => c.BlockId == this.BlockId && c.EntityValue == entityValue)
                                 .Select(c => (int?)c.Version).Max();

            return(maxVersion);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Shows the view.
        /// </summary>
        protected void ShowView()
        {
            mdEdit.Hide();
            pnlEditModel.Visible = false;
            upnlHtmlContent.Update();

            // prevent htmlEditor from using viewstate when not needed
            pnlEdit.EnableViewState = false;

            pnlEdit.Visible        = false;
            pnlVersionGrid.Visible = false;
            string entityValue = EntityValue();
            string html        = string.Empty;

            string cachedContent = GetCacheItem(entityValue) as string;

            // if content not cached load it from DB
            if (cachedContent == null)
            {
                HtmlContent content = new HtmlContentService(new RockContext()).GetActiveContent(this.BlockId, entityValue);

                if (content != null)
                {
                    var mergeFields = Rock.Web.Cache.GlobalAttributesCache.GetMergeFields(CurrentPerson);
                    if (CurrentPerson != null)
                    {
                        mergeFields.Add("Person", CurrentPerson);
                    }

                    html = content.Content.ResolveMergeFields(mergeFields);
                }
                else
                {
                    html = string.Empty;
                }

                // Resolve any dynamic url references
                string appRoot   = ResolveRockUrl("~/");
                string themeRoot = ResolveRockUrl("~~/");
                html = html.Replace("~~/", themeRoot).Replace("~/", appRoot);

                // cache content
                int cacheDuration = GetAttributeValue("CacheDuration").AsInteger() ?? 0;
                if (cacheDuration > 0)
                {
                    AddCacheItem(entityValue, html, cacheDuration);
                }
            }
            else
            {
                html = cachedContent;
            }

            // add content to the content window
            lHtmlContent.Text = html;
        }
        /// <summary>
        /// Handles the RowSelected event of the gContentList control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void gContentList_RowSelected(object sender, RowEventArgs e)
        {
            var htmlContent = new HtmlContentService(new RockContext()).Get(e.RowKeyId);

            if (htmlContent != null)
            {
                lPreviewHtml.Text = htmlContent.Content;
                mdPreview.Show();
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Handles the Click event of the lbEdit 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 lbEdit_Click(object sender, EventArgs e)
        {
            // only enable viewstate for htmlEditor when needed (it is really big)
            pnlEdit.EnableViewState = true;

            pnlEdit.Visible        = true;
            pnlVersionGrid.Visible = false;
            mdEdit.Show();

            bool useCodeEditor = GetAttributeValue("UseCodeEditor").AsBoolean();

            ceHtml.Visible     = useCodeEditor;
            htmlEditor.Visible = !useCodeEditor;

            htmlEditor.Toolbar = HtmlEditor.ToolbarConfig.Full;

            // if the current user can't approve their own edits, set the approval to Not-Approved when they change something
            if (!IsUserAuthorized("Approve"))
            {
                string onchangeScriptFormat = @"
   $('#{0}').removeClass('label label-success label-danger').addClass('label label-danger');
   $('#{0}').text('Not-Approved');
   $('#{1}').val('false');
   $('#{2}').val('');
   $('#{3}').hide();";

                string onchangeScript = string.Format(onchangeScriptFormat, lblApprovalStatus.ClientID, hfApprovalStatus.ClientID, hfApprovalStatusPersonId.ClientID, lblApprovalStatusPerson.ClientID);

                htmlEditor.OnChangeScript = onchangeScript;
                ceHtml.OnChangeScript     = onchangeScript;
            }

            htmlEditor.MergeFields.Clear();
            htmlEditor.MergeFields.Add("GlobalAttribute");

            bool supportsVersioning = GetAttributeValue("SupportVersions").AsBoolean();
            bool requireApproval    = GetAttributeValue("RequireApproval").AsBoolean();

            lVersion.Visible           = supportsVersioning;
            lbShowVersionGrid.Visible  = supportsVersioning;
            cbOverwriteVersion.Visible = supportsVersioning;
            cbOverwriteVersion.Checked = false;

            // RequireApproval only applies if SupportsVersioning=True
            upnlApproval.Visible = supportsVersioning && requireApproval;
            lbApprove.Enabled    = IsUserAuthorized("Approve");
            lbDeny.Enabled       = IsUserAuthorized("Approve");

            string      entityValue = EntityValue();
            HtmlContent htmlContent = new HtmlContentService().GetActiveContent(this.BlockId, entityValue);

            ShowEditDetail(htmlContent);
        }
Ejemplo n.º 12
0
        protected void lbEdit_Click(object sender, EventArgs e)
        {
            HtmlContentService service = new HtmlContentService();

            Rock.Model.HtmlContent content = service.GetActiveContent(CurrentBlock.Id, EntityValue());
            if (content == null)
            {
                content = new Rock.Model.HtmlContent();
            }

            if (_supportVersioning)
            {
                phCurrentVersion.Visible    = true;
                pnlVersioningHeader.Visible = true;
                cbOverwriteVersion.Visible  = true;

                hfVersion.Value   = content.Version.ToString();
                lVersion.Text     = content.Version.ToString();
                tbStartDate.Text  = content.StartDateTime.HasValue ? content.StartDateTime.Value.ToShortDateString() : string.Empty;
                tbExpireDate.Text = content.ExpireDateTime.HasValue ? content.ExpireDateTime.Value.ToShortDateString() : string.Empty;

                if (_requireApproval)
                {
                    cbApprove.Checked = content.IsApproved;
                    cbApprove.Enabled = IsUserAuthorized("Approve");
                    cbApprove.Visible = true;
                }
                else
                {
                    cbApprove.Visible = false;
                }
            }
            else
            {
                phCurrentVersion.Visible    = false;
                pnlVersioningHeader.Visible = false;
                cbOverwriteVersion.Visible  = false;
            }

            edtHtmlContent.Toolbar = "RockCustomConfigFull";
            edtHtmlContent.Text    = content.Content;
            mpeContent.Show();
            edtHtmlContent.Visible      = true;
            HtmlContentModified         = false;
            edtHtmlContent.TextChanged += edtHtmlContent_TextChanged;

            BindGrid();

            hfAction.Value = "Edit";
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Handles the BlockUpdated event of the HtmlContentDetail 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 HtmlContentDetail_BlockUpdated(object sender, EventArgs e)
        {
            bool supportsVersioning = GetAttributeValue("SupportVersions").AsBoolean();
            bool requireApproval    = GetAttributeValue("RequireApproval").AsBoolean();

            if (requireApproval && !supportsVersioning)
            {
                SetAttributeValue("SupportVersions", "true");
                SaveAttributeValues();
            }

            HtmlContentService.FlushCachedContent(this.BlockId, EntityValue());

            ShowView();
        }
Ejemplo n.º 14
0
        private void BindGrid()
        {
            var HtmlService = new HtmlContentService();
            var content     = HtmlService.GetContent(CurrentBlock.Id, EntityValue());

            var personService   = new Rock.Model.PersonService();
            var versionAudits   = new Dictionary <int, Rock.Model.Audit>();
            var modifiedPersons = new Dictionary <int, string>();

            foreach (var version in content)
            {
                var lastAudit = HtmlService.Audits(version)
                                .Where(a => a.AuditType == Rock.Model.AuditType.Add ||
                                       a.AuditType == Rock.Model.AuditType.Modify)
                                .OrderByDescending(h => h.DateTime)
                                .FirstOrDefault();
                if (lastAudit != null)
                {
                    versionAudits.Add(version.Id, lastAudit);
                }
            }

            foreach (var audit in versionAudits.Values)
            {
                if (audit.PersonId.HasValue && !modifiedPersons.ContainsKey(audit.PersonId.Value))
                {
                    var modifiedPerson = personService.Get(audit.PersonId.Value, true);
                    modifiedPersons.Add(audit.PersonId.Value, modifiedPerson != null ? modifiedPerson.FullName : string.Empty);
                }
            }

            var versions = content.
                           Select(v => new
            {
                v.Id,
                v.Version,
                v.Content,
                ModifiedDateTime = versionAudits.ContainsKey(v.Id) ? versionAudits[v.Id].DateTime.ToElapsedString() : string.Empty,
                ModifiedByPerson = versionAudits.ContainsKey(v.Id) && versionAudits[v.Id].PersonId.HasValue ? modifiedPersons[versionAudits[v.Id].PersonId.Value] : string.Empty,
                Approved         = v.IsApproved,
                ApprovedByPerson = v.ApprovedByPerson != null ? v.ApprovedByPerson.FullName : "",
                v.StartDateTime,
                v.ExpireDateTime
            }).ToList();

            rGrid.DataSource = versions;
            rGrid.DataBind();
        }
Ejemplo n.º 15
0
        protected void lbEdit_Click(object sender, EventArgs e)
        {
            HtmlContentService service = new HtmlContentService();

            Rock.CMS.HtmlContent content = service.GetActiveContent(BlockInstance.Id, EntityValue());
            if (content == null)
            {
                content = new Rock.CMS.HtmlContent();
            }

            if (_supportVersioning)
            {
                phCurrentVersion.Visible    = true;
                pnlVersioningHeader.Visible = true;
                cbOverwriteVersion.Visible  = true;

                hfVersion.Value   = content.Version.ToString();
                lVersion.Text     = content.Version.ToString();
                tbStartDate.Text  = content.StartDateTime.HasValue ? content.StartDateTime.Value.ToShortDateString() : string.Empty;
                tbExpireDate.Text = content.ExpireDateTime.HasValue ? content.ExpireDateTime.Value.ToShortDateString() : string.Empty;

                if (_requireApproval)
                {
                    cbApprove.Checked = content.Approved;
                    cbApprove.Enabled = UserAuthorized("Approve");
                    cbApprove.Visible = true;
                }
                else
                {
                    cbApprove.Visible = false;
                }
            }
            else
            {
                phCurrentVersion.Visible    = false;
                pnlVersioningHeader.Visible = false;
                cbOverwriteVersion.Visible  = false;
            }

            txtHtmlContentEditor.Text = content.Content;

            BindGrid();

            hfAction.Value = "Edit";
        }
Ejemplo n.º 16
0
        protected void lbSave_Click(object sender, EventArgs e)
        {
            var rockContext = new RockContext();
            var hc          = new HtmlContentService(rockContext).Get(hfHTMLContentGUID.Value.AsGuid());

            if (hc != null)
            {
                var oldBlockId = hc.BlockId;
                hc.BlockId = rtbBlockId.Text.AsIntegerOrNull() ?? BlockId;
                var oldEntityValue = hc.EntityValue;
                hc.EntityValue    = rtbContextParameter.Text + (String.IsNullOrWhiteSpace(rtbContextName.Text) ? "" : ("&ContextName=" + rtbContextName.Text));
                hc.Version        = rtbVersion.Text.AsInteger();
                hc.StartDateTime  = dtpStartTime.SelectedDateTime;
                hc.ExpireDateTime = dtpExpire.SelectedDateTime;

                if (!hc.IsApproved && rcbApproved.Checked)
                {
                    hc.ApprovedDateTime = DateTime.Now;
                }
                else if (!rcbApproved.Checked)
                {
                    hc.ApprovedDateTime = null;
                }
                hc.IsApproved = rcbApproved.Checked;
                if (htmlEditor.Visible)
                {
                    hc.Content = htmlEditor.Text;
                }
                else
                {
                    hc.Content = ceHtml.Text;
                }

                rockContext.SaveChanges();
                HtmlContentService.FlushCachedContent(oldBlockId, oldEntityValue);
                HtmlContentService.FlushCachedContent(hc.BlockId, hc.EntityValue);
            }
            pnlList.Visible = true;
            pnlEdit.Visible = false;
            BindGrid();
        }
Ejemplo n.º 17
0
        private void BindGrid()
        {
            HtmlContentService service = new HtmlContentService();

            var versions = service.GetContent(BlockInstance.Id, EntityValue()).
                           Select(v => new
            {
                v.Id,
                v.Version,
                v.Content,
                ModifiedDateTime = v.ModifiedDateTime.ToElapsedString(),
                ModifiedByPerson = v.ModifiedByPerson != null ? v.ModifiedByPerson.FullName : "",
                v.Approved,
                ApprovedByPerson = v.ApprovedByPerson != null ? v.ApprovedByPerson.FullName : "",
                v.StartDateTime,
                v.ExpireDateTime
            }).ToList();

            rGrid.DataSource = versions;
            rGrid.DataBind();
        }
        /// <summary>
        /// Handles the CheckChanged event of the gContentList IsApproved field.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gContentList_CheckedChanged(object sender, RowEventArgs e)
        {
            bool cannotApprove = true;

            if (e.RowKeyValue != null)
            {
                var rockContext        = new RockContext();
                var htmlContentService = new HtmlContentService(rockContext);
                var htmlContent        = htmlContentService.Get(e.RowKeyId);

                if (htmlContent != null)
                {
                    cannotApprove = false;

                    // if it was approved, set it to unapproved... otherwise
                    if (htmlContent.IsApproved)
                    {
                        htmlContent.IsApproved = false;
                        htmlContent.ApprovedByPersonAliasId = null;
                        htmlContent.ApprovedDateTime        = null;
                    }
                    else
                    {
                        htmlContent.IsApproved = true;
                        htmlContent.ApprovedByPersonAliasId = CurrentPersonAliasId;
                        htmlContent.ApprovedDateTime        = RockDateTime.Now;
                    }

                    rockContext.SaveChanges();
                    HtmlContentService.FlushCachedContent(htmlContent.BlockId, htmlContent.EntityValue);
                }

                BindGrid();
            }

            if (cannotApprove)
            {
                mdGridWarning.Show("Unable to approve this HTML Content", ModalAlertType.Warning);
            }
        }
Ejemplo n.º 19
0
        private void ShowView()
        {
            string entityValue = EntityValue();
            string html        = "";

            string cachedContent = GetCacheItem(entityValue) as string;

            // if content not cached load it from DB
            if (cachedContent == null)
            {
                Rock.Model.HtmlContent content = new HtmlContentService().GetActiveContent(CurrentBlock.Id, entityValue);

                if (content != null)
                {
                    html = content.Content;
                }
                else
                {
                    html = string.Empty;
                }

                // cache content
                int cacheDuration = 0;
                if (Int32.TryParse(GetAttributeValue("CacheDuration"), out cacheDuration) && cacheDuration > 0)
                {
                    AddCacheItem(entityValue, html, cacheDuration);
                }
            }
            else
            {
                html = cachedContent;
            }

            // add content to the content window
            lPreText.Text     = GetAttributeValue("PreText");
            lHtmlContent.Text = html;
            lPostText.Text    = GetAttributeValue("PostText");
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var htmlContentService = new HtmlContentService(new RockContext());
            var content            = htmlContentService.GetContent(this.BlockId, EntityValue()).OrderByDescending(a => a.Version).ThenByDescending(a => a.ModifiedDateTime).ToList();

            var versions = content.Select(v =>
                                          new
            {
                v.Id,
                v.Version,
                VersionText      = "Version " + v.Version.ToString(),
                ModifiedDateTime = "(" + v.ModifiedDateTime.ToElapsedString() + ")",
                ModifiedByPerson = v.ModifiedByPersonAlias != null ? v.ModifiedByPersonAlias.Person : null,
                Approved         = v.IsApproved,
                ApprovedByPerson = v.ApprovedByPerson,
                v.StartDateTime,
                v.ExpireDateTime
            }).ToList();

            gVersions.DataSource  = versions;
            gVersions.GridRebind += gVersions_GridRebind;
            gVersions.DataBind();
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var htmlContentService = new HtmlContentService();
            var content            = htmlContentService.GetContent(this.BlockId, EntityValue());

            var versions = content.Select(v =>
                                          new
            {
                v.Id,
                v.Version,
                VersionText      = "Version " + v.Version.ToString(),
                ModifiedDateTime = "(" + v.LastModifiedDateTime.ToElapsedString() + ")",
                ModifiedByPerson = v.LastModifiedPerson,
                Approved         = v.IsApproved,
                ApprovedByPerson = v.ApprovedByPerson,
                v.StartDateTime,
                v.ExpireDateTime
            }).ToList();

            gVersions.DataSource  = versions;
            gVersions.GridRebind += gVersions_GridRebind;
            gVersions.DataBind();
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Handles the CheckChanged event of the gContentList IsApproved field.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gContentList_CheckedChanged(object sender, RowEventArgs e)
        {
            bool cannotApprove = true;

            if (e.RowKeyValue != null)
            {
                var htmlContentService = new HtmlContentService();
                var htmlContent        = htmlContentService.Get((int)e.RowKeyValue);

                if (htmlContent != null)
                {
                    cannotApprove = false;
                    // if it was approved, set it to unapproved... otherwise
                    if (htmlContent.IsApproved)
                    {
                        htmlContent.IsApproved         = false;
                        htmlContent.ApprovedByPersonId = null;
                        htmlContent.ApprovedDateTime   = null;
                    }
                    else
                    {
                        htmlContent.IsApproved         = true;
                        htmlContent.ApprovedByPersonId = CurrentPersonId;
                        htmlContent.ApprovedDateTime   = DateTime.Now;
                    }

                    htmlContentService.Save(htmlContent, CurrentPersonId);
                }

                BindGrid();
            }

            if (cannotApprove)
            {
                mdGridWarning.Show("Unable to approve this HTML Content", ModalAlertType.Warning);
            }
        }
Ejemplo n.º 23
0
        protected void BindGrid()
        {
            SortProperty sortProp = rgHtmlFragments.SortProperty;

            var HtmlContents = new HtmlContentService(new RockContext()).Queryable().Where(hc => hc.BlockId == BlockId || (hc.EntityValue != null && hc.EntityValue != "")).ToList().Select(hc =>
            {
                var context = HttpUtility.ParseQueryString(hc.EntityValue);
                var cName   = context["ContextName"];
                context.Remove("ContextName");
                var cParams = context.ToString();
                return(new
                {
                    Id = hc.Id,
                    BlockId = hc.BlockId,
                    ContextName = cName,
                    ContextParameters = cParams,
                    Version = hc.Version,
                    IsApproved = hc.IsApproved,
                    ApprovedDateTime = hc.ApprovedDateTime,
                    StartDateTime = hc.StartDateTime,
                    ExpireDateTime = hc.ExpireDateTime
                });
            }).AsQueryable();


            if (sortProp != null)
            {
                rgHtmlFragments.DataSource = HtmlContents.Sort(sortProp).ToList();
            }
            else
            {
                rgHtmlFragments.DataSource = HtmlContents.OrderBy("Version").OrderBy("ContextName").ToList();
            }
            rgHtmlFragments.DataKeyNames = new String[] { "Id" };
            rgHtmlFragments.DataBind();
        }
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var rockContext = new RockContext();

            int    entityTypeIdBlock   = EntityTypeCache.Read(typeof(Rock.Model.Block), true, rockContext).Id;
            string entityTypeQualifier = BlockTypeCache.Read(Rock.SystemGuid.BlockType.HTML_CONTENT.AsGuid(), rockContext).Id.ToString();
            var    htmlContentService  = new HtmlContentService(rockContext);
            var    attributeValueQry   = new AttributeValueService(rockContext).Queryable()
                                         .Where(a => a.Attribute.Key == "RequireApproval" && a.Attribute.EntityTypeId == entityTypeIdBlock)
                                         .Where(a => a.Attribute.EntityTypeQualifierColumn == "BlockTypeId" && a.Attribute.EntityTypeQualifierValue == entityTypeQualifier)
                                         .Where(a => a.Value == "True")
                                         .Select(a => a.EntityId);

            var qry = htmlContentService.Queryable().Where(a => attributeValueQry.Contains(a.BlockId));

            // Filter by approved/unapproved
            if (ddlApprovedFilter.SelectedIndex > -1)
            {
                if (ddlApprovedFilter.SelectedValue.ToLower() == "unapproved")
                {
                    qry = qry.Where(a => a.IsApproved == false);
                }
                else if (ddlApprovedFilter.SelectedValue.ToLower() == "approved")
                {
                    qry = qry.Where(a => a.IsApproved == true);
                }
            }

            // Filter by the person that approved the content
            if (_canApprove)
            {
                int?personId = gContentListFilter.GetUserPreference("Approved By").AsIntegerOrNull();
                if (personId.HasValue)
                {
                    qry = qry.Where(a => a.ApprovedByPersonAliasId.HasValue && a.ApprovedByPersonAlias.PersonId == personId);
                }
            }

            SortProperty sortProperty = gContentList.SortProperty;

            if (sortProperty != null)
            {
                qry = qry.Sort(sortProperty);
            }
            else
            {
                qry = qry.OrderByDescending(a => a.ModifiedDateTime);
            }

            var selectQry = qry.Select(a => new
            {
                a.Id,
                SiteName = a.Block.PageId.HasValue ? a.Block.Page.Layout.Site.Name : a.Block.Layout.Site.Name,
                PageName = a.Block.Page.InternalName,
                a.ModifiedDateTime,
                a.IsApproved,
                ApprovedDateTime = a.IsApproved ? a.ApprovedDateTime : null,
                ApprovedByPerson = a.IsApproved ? a.ApprovedByPersonAlias.Person : null,
                BlockPageId      = a.Block.PageId,
                BlockLayoutId    = a.Block.LayoutId,
            });

            // Filter by Site
            if (ddlSiteFilter.SelectedIndex > 0)
            {
                if (ddlSiteFilter.SelectedValue.ToLower() != "all")
                {
                    selectQry = selectQry.Where(h => h.SiteName == ddlSiteFilter.SelectedValue);
                }
            }

            gContentList.DataSource = selectQry.ToList();
            gContentList.DataBind();
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Handles the Click event of the lbSave 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 lbSave_Click(object sender, EventArgs e)
        {
            bool supportVersioning = GetAttributeValue("SupportVersions").AsBoolean();
            bool requireApproval   = GetAttributeValue("RequireApproval").AsBoolean();


            var rockContext = new RockContext();
            HtmlContentService htmlContentService = new HtmlContentService(rockContext);

            // get settings
            string entityValue = EntityValue();

            // get current content
            int         version     = hfVersion.ValueAsInt();
            HtmlContent htmlContent = htmlContentService.GetByBlockIdAndEntityValueAndVersion(this.BlockId, entityValue, version);

            // get the content depending on which mode we are in (codeeditor or ckeditor)
            string newContent = ceHtml.Visible ? ceHtml.Text : htmlEditor.Text;

            //// create a new record only in the following situations:
            ////   - this is the first time this htmlcontent block got content (new block and edited for the first time)
            ////   - the content was changed, versioning is enabled, and OverwriteVersion is not checked

            // if the existing content changed, and the overwrite option was not checked, create a new version
            if (htmlContent != null)
            {
                // Editing existing content. Check if content has changed
                if (htmlContent.Content != newContent)
                {
                    // The content has changed (different than database). Check if versioning is enabled
                    if (supportVersioning && !cbOverwriteVersion.Checked)
                    {
                        //// versioning is enabled, and they didn't choose to overwrite
                        //// set to null so that we'll create a new record
                        htmlContent = null;
                    }
                }
            }

            // if a record doesn't exist then create one
            if (htmlContent == null)
            {
                htmlContent             = new HtmlContent();
                htmlContent.BlockId     = this.BlockId;
                htmlContent.EntityValue = entityValue;

                if (supportVersioning)
                {
                    int?maxVersion = GetMaxVersionOfHtmlContent();

                    htmlContent.Version = maxVersion.HasValue ? maxVersion.Value + 1 : 1;
                }
                else
                {
                    htmlContent.Version = 1;
                }

                htmlContentService.Add(htmlContent);
            }

            htmlContent.StartDateTime  = drpDateRange.LowerValue;
            htmlContent.ExpireDateTime = drpDateRange.UpperValue;
            bool currentUserCanApprove = IsUserAuthorized("Approve");

            if (!requireApproval)
            {
                // if this block doesn't require Approval, mark it as approved
                htmlContent.IsApproved         = true;
                htmlContent.ApprovedByPersonId = this.CurrentPersonId;
                htmlContent.ApprovedDateTime   = RockDateTime.Now;
            }
            else
            {
                // if this block requires Approval, mark it as approved if the ApprovalStatus is still approved, or if the current user can approve
                htmlContent.IsApproved = (hfApprovalStatus.Value.AsBoolean()) || currentUserCanApprove;
                if (htmlContent.IsApproved)
                {
                    int?personId = hfApprovalStatusPersonId.Value.AsInteger(false);
                    if (!personId.HasValue)
                    {
                        // if it wasn't approved, but the current user can approve, make the current user the approver
                        if (currentUserCanApprove)
                        {
                            personId = this.CurrentPersonId;
                        }
                    }

                    if (personId.HasValue)
                    {
                        htmlContent.ApprovedByPersonId = personId;
                        htmlContent.ApprovedDateTime   = RockDateTime.Now;
                    }
                }
            }

            htmlContent.Content = newContent;

            if (rockContext.SaveChanges() > 0)
            {
                // flush cache content
                this.FlushCacheItem(entityValue);

                ShowView();
            }
            else
            {
                // TODO: service.ErrorMessages;
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var htmlContentService = new HtmlContentService();
            var htmlContent        = htmlContentService.Queryable();

            string pageName = "";
            string siteName = "";
            var    htmlList = new List <HtmlApproval>();

            foreach (var content in htmlContent)
            {
                content.Block.LoadAttributes();
                var blah = content.Block.GetAttributeValue("RequireApproval");
                if (!string.IsNullOrEmpty(blah) && blah.ToLower() == "true")
                {
                    var pageService = new PageService();
                    if (content.Block.PageId != null)
                    {
                        var page = pageService.Get((int)content.Block.PageId);
                        if (page != null)
                        {
                            pageName = page.InternalName;
                            while (page.ParentPageId != null)
                            {
                                page = pageService.Get((int)page.ParentPageId);
                            }
                            var siteService = new SiteService();
                            siteName = siteService.GetByDefaultPageId(page.Id).Select(s => s.Name).FirstOrDefault();
                        }
                    }

                    var htmlApprovalClass = new HtmlApproval();
                    htmlApprovalClass.SiteName           = siteName;
                    htmlApprovalClass.PageName           = pageName;
                    htmlApprovalClass.Block              = content.Block;
                    htmlApprovalClass.BlockId            = content.BlockId;
                    htmlApprovalClass.Content            = content.Content;
                    htmlApprovalClass.Id                 = content.Id;
                    htmlApprovalClass.IsApproved         = content.IsApproved;
                    htmlApprovalClass.ApprovedByPerson   = content.ApprovedByPerson;
                    htmlApprovalClass.ApprovedByPersonId = content.ApprovedByPersonId;
                    htmlApprovalClass.ApprovedDateTime   = content.ApprovedDateTime;

                    htmlList.Add(htmlApprovalClass);
                }
            }

            // Filter by Site
            if (ddlSiteFilter.SelectedIndex > 0)
            {
                if (ddlSiteFilter.SelectedValue.ToLower() != "all")
                {
                    htmlList = htmlList.Where(h => h.SiteName == ddlSiteFilter.SelectedValue).ToList();
                }
            }

            // Filter by approved/unapproved
            if (ddlApprovedFilter.SelectedIndex > -1)
            {
                if (ddlApprovedFilter.SelectedValue.ToLower() == "unapproved")
                {
                    htmlList = htmlList.Where(a => a.IsApproved == false).ToList();
                }
                else if (ddlApprovedFilter.SelectedValue.ToLower() == "approved")
                {
                    htmlList = htmlList.Where(a => a.IsApproved == true).ToList();
                }
            }

            // Filter by the person that approved the content
            if (_canApprove)
            {
                int personId = 0;
                if (int.TryParse(gContentListFilter.GetUserPreference("Approved By"), out personId) && personId != 0)
                {
                    htmlList = htmlList.Where(a => a.ApprovedByPersonId.HasValue && a.ApprovedByPersonId.Value == personId).ToList();
                }
            }

            SortProperty sortProperty = gContentList.SortProperty;

            if (sortProperty != null)
            {
                gContentList.DataSource = htmlList.AsQueryable().Sort(sortProperty).ToList();
            }
            else
            {
                gContentList.DataSource = htmlList.OrderBy(h => h.Id).ToList();
            }

            gContentList.DataBind();
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Handles the Click event of the lbQuickEdit control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        // Disable QuickEdit for v7
        //protected void lbQuickEdit_Click( object sender, EventArgs e )
        //{
        //    ShowSettings();
        //}

        /// <summary>
        /// Handles the Click event of the lbSave 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 lbSave_Click(object sender, EventArgs e)
        {
            bool supportVersioning = GetAttributeValue("SupportVersions").AsBoolean();
            bool requireApproval   = GetAttributeValue("RequireApproval").AsBoolean();

            var rockContext = new RockContext();
            HtmlContentService htmlContentService = new HtmlContentService(rockContext);

            // get settings
            string entityValue = EntityValue();

            // get current content
            int         version     = hfVersion.ValueAsInt();
            HtmlContent htmlContent = htmlContentService.GetByBlockIdAndEntityValueAndVersion(this.BlockId, entityValue, version);

            string newContent = htmlEditor.Text;

            // check if the new content is valid
            // NOTE: This is a limited check that will only warn of invalid HTML the first
            // time a user clicks the save button. Any errors encountered on the second runthrough
            // are assumed to be intentional.
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(newContent);

            if (doc.ParseErrors.Count() > 0 && !nbInvalidHtml.Visible)
            {
                var           reasons = doc.ParseErrors.Select(r => r.Reason).ToList();
                StringBuilder sb      = new StringBuilder();
                sb.AppendLine("Warning: The HTML has the following errors:<ul>");
                foreach (var reason in reasons)
                {
                    sb.AppendLine(String.Format("<li>{0}</li>", reason.EncodeHtml()));
                }
                sb.AppendLine("</ul> <br/> If you wish to save anyway, click the save button again.");
                nbInvalidHtml.Text    = sb.ToString();
                nbInvalidHtml.Visible = true;
                return;
            }

            //// create a new record only in the following situations:
            ////   - this is the first time this htmlcontent block got content (new block and edited for the first time)
            ////   - the content was changed, versioning is enabled, and OverwriteVersion is not checked

            // if the existing content changed, and the overwrite option was not checked, create a new version
            if (htmlContent != null)
            {
                // Editing existing content. Check if content has changed
                if (htmlContent.Content != newContent)
                {
                    // The content has changed (different than database). Check if versioning is enabled
                    if (supportVersioning && !cbOverwriteVersion.Checked)
                    {
                        //// versioning is enabled, and they didn't choose to overwrite
                        //// set to null so that we'll create a new record
                        htmlContent = null;
                    }
                }
            }

            // if a record doesn't exist then create one
            if (htmlContent == null)
            {
                htmlContent             = new HtmlContent();
                htmlContent.BlockId     = this.BlockId;
                htmlContent.EntityValue = entityValue;

                if (supportVersioning)
                {
                    int?maxVersion = GetMaxVersionOfHtmlContent();

                    htmlContent.Version = maxVersion.HasValue ? maxVersion.Value + 1 : 1;
                }
                else
                {
                    htmlContent.Version = 1;
                }

                htmlContentService.Add(htmlContent);
            }

            htmlContent.StartDateTime  = drpDateRange.LowerValue;
            htmlContent.ExpireDateTime = drpDateRange.UpperValue;
            bool currentUserCanApprove = IsUserAuthorized("Approve");

            if (!requireApproval)
            {
                // if this block doesn't require Approval, mark it as approved
                htmlContent.IsApproved = true;
                htmlContent.ApprovedByPersonAliasId = CurrentPersonAliasId;
                htmlContent.ApprovedDateTime        = RockDateTime.Now;
            }
            else
            {
                // since this content requires Approval, mark it as approved ONLY if the current user can approve
                // and they set the hfApprovalStatus flag to true.
                if (currentUserCanApprove && hfApprovalStatus.Value.AsBoolean())
                {
                    htmlContent.IsApproved = true;
                    htmlContent.ApprovedByPersonAliasId = CurrentPersonAliasId;
                    htmlContent.ApprovedDateTime        = RockDateTime.Now;
                }
                else
                {
                    // if the content has changed
                    if (htmlContent.Content != newContent)
                    {
                        nbApprovalRequired.Visible = true;
                        htmlContent.IsApproved     = false;
                    }
                }
            }

            htmlContent.Content = newContent;

            rockContext.SaveChanges();

            // flush cache content
            HtmlContentService.FlushCachedContent(htmlContent.BlockId, htmlContent.EntityValue);

            ShowView();
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Shows the view.
        /// </summary>
        protected void ShowView()
        {
            mdEdit.Hide();
            pnlEditModel.Visible = false;
            upnlHtmlContent.Update();

            // prevent htmlEditor from using viewstate when not needed
            pnlEdit.EnableViewState = false;

            pnlEdit.Visible        = false;
            pnlVersionGrid.Visible = false;
            string entityValue = EntityValue();
            string html        = string.Empty;

            string cachedContent = HtmlContentService.GetCachedContent(this.BlockId, entityValue);

            // if content not cached load it from DB
            if (cachedContent == null)
            {
                using (var rockContext = new RockContext())
                {
                    var         htmlContentService = new HtmlContentService(rockContext);
                    HtmlContent content            = htmlContentService.GetActiveContent(this.BlockId, entityValue);

                    if (content != null)
                    {
                        bool enableDebug = GetAttributeValue("EnableDebug").AsBoolean();

                        if (content.Content.HasMergeFields() || enableDebug)
                        {
                            var mergeFields = Rock.Web.Cache.GlobalAttributesCache.GetMergeFields(CurrentPerson);
                            if (CurrentPerson != null)
                            {
                                // TODO: When support for "Person" is not supported anymore (should use "CurrentPerson" instead), remove this line
                                mergeFields.Add("Person", CurrentPerson);
                                mergeFields.Add("CurrentPerson", CurrentPerson);
                            }

                            mergeFields.Add("Campuses", CampusCache.All());
                            mergeFields.Add("PageParameter", PageParameters());
                            mergeFields.Add("CurrentPage", GetPageProperties());

                            var contextObjects = new Dictionary <string, object>();
                            foreach (var contextEntityType in RockPage.GetContextEntityTypes())
                            {
                                var contextEntity = RockPage.GetCurrentContext(contextEntityType);
                                if (contextEntity != null && contextEntity is DotLiquid.ILiquidizable)
                                {
                                    var type = Type.GetType(contextEntityType.AssemblyName ?? contextEntityType.Name);
                                    if (type != null)
                                    {
                                        contextObjects.Add(type.Name, contextEntity);
                                    }
                                }
                            }

                            if (contextObjects.Any())
                            {
                                mergeFields.Add("Context", contextObjects);
                            }

                            mergeFields.Add("RockVersion", Rock.VersionInfo.VersionInfo.GetRockProductVersionNumber());
                            mergeFields.Add("CurrentPersonCanEdit", IsUserAuthorized(Authorization.EDIT));
                            mergeFields.Add("CurrentPersonCanAdministrate", IsUserAuthorized(Authorization.ADMINISTRATE));

                            html = content.Content.ResolveMergeFields(mergeFields);

                            // show merge fields if enable debug true
                            if (enableDebug && IsUserAuthorized(Authorization.EDIT))
                            {
                                // TODO: When support for "Person" is not supported anymore (should use "CurrentPerson" instead), remove this line
                                mergeFields.Remove("Person");
                                html += mergeFields.lavaDebugInfo();
                            }
                        }
                        else
                        {
                            html = content.Content;
                        }
                    }
                    else
                    {
                        html = string.Empty;
                    }
                }

                // Resolve any dynamic url references
                string appRoot   = ResolveRockUrl("~/");
                string themeRoot = ResolveRockUrl("~~/");
                html = html.Replace("~~/", themeRoot).Replace("~/", appRoot);

                // cache content
                int cacheDuration = GetAttributeValue("CacheDuration").AsInteger();
                if (cacheDuration > 0)
                {
                    HtmlContentService.AddCachedContent(this.BlockId, entityValue, html, cacheDuration);
                }
            }
            else
            {
                html = cachedContent;
            }

            // add content to the content window
            lHtmlContent.Text = html;
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Shows the settings.
        /// </summary>
        /// <exception cref="System.NotImplementedException"></exception>
        protected override void ShowSettings()
        {
            // only enable viewstate for htmlEditor when needed (it is really big)
            pnlEdit.EnableViewState = true;

            pnlEdit.Visible        = true;
            pnlVersionGrid.Visible = false;
            pnlEditModel.Visible   = true;
            upnlHtmlContent.Update();
            mdEdit.Show();

            bool useCodeEditor = GetAttributeValue("UseCodeEditor").AsBoolean();

            ceHtml.Visible     = useCodeEditor;
            htmlEditor.Visible = !useCodeEditor;

            htmlEditor.Toolbar = HtmlEditor.ToolbarConfig.Full;

            // if the current user can't approve their own edits, set the approval to Not-Approved when they change something
            if (!IsUserAuthorized("Approve"))
            {
                string onchangeScriptFormat = @"
   $('#{0}').removeClass('label label-success label-danger').addClass('label label-danger');
   $('#{0}').text('Not-Approved');
   $('#{1}').val('false');
   $('#{2}').val('');
   $('#{3}').hide();";

                string onchangeScript = string.Format(onchangeScriptFormat, lblApprovalStatus.ClientID, hfApprovalStatus.ClientID, hfApprovalStatusPersonId.ClientID, lblApprovalStatusPerson.ClientID);

                htmlEditor.OnChangeScript = onchangeScript;
                ceHtml.OnChangeScript     = onchangeScript;
            }

            htmlEditor.MergeFields.Clear();
            htmlEditor.MergeFields.Add("GlobalAttribute");
            htmlEditor.MergeFields.Add("CurrentPerson^Rock.Model.Person|Current Person");
            htmlEditor.MergeFields.Add("Campuses");
            htmlEditor.MergeFields.Add("PageParameter");
            htmlEditor.MergeFields.Add("RockVersion");
            htmlEditor.MergeFields.Add("Date");
            htmlEditor.MergeFields.Add("Time");
            htmlEditor.MergeFields.Add("DayOfWeek");

            ceHtml.MergeFields.Clear();
            ceHtml.MergeFields.Add("GlobalAttribute");
            ceHtml.MergeFields.Add("CurrentPerson^Rock.Model.Person|Current Person");
            ceHtml.MergeFields.Add("Campuses");
            ceHtml.MergeFields.Add("RockVersion");
            ceHtml.MergeFields.Add("PageParameter");
            ceHtml.MergeFields.Add("Date");
            ceHtml.MergeFields.Add("Time");
            ceHtml.MergeFields.Add("DayOfWeek");

            var contextObjects = new Dictionary <string, object>();

            foreach (var contextEntityType in RockPage.GetContextEntityTypes())
            {
                var contextEntity = RockPage.GetCurrentContext(contextEntityType);
                if (contextEntity != null && contextEntity is Rock.Lava.ILiquidizable)
                {
                    var type = Type.GetType(contextEntityType.AssemblyName ?? contextEntityType.Name);
                    if (type != null)
                    {
                        string mergeField = string.Format("Context.{0}^{1}|Current {0} (Context)|Context", type.Name, type.FullName);
                        htmlEditor.MergeFields.Add(mergeField);
                        ceHtml.MergeFields.Add(mergeField);
                    }
                }
            }

            string documentRoot = GetAttributeValue("DocumentRootFolder");
            string imageRoot    = GetAttributeValue("ImageRootFolder");

            htmlEditor.UserSpecificRoot   = GetAttributeValue("UserSpecificFolders").AsBoolean();
            htmlEditor.DocumentFolderRoot = documentRoot;
            htmlEditor.ImageFolderRoot    = imageRoot;

            bool supportsVersioning = GetAttributeValue("SupportVersions").AsBoolean();
            bool requireApproval    = GetAttributeValue("RequireApproval").AsBoolean();

            lVersion.Visible           = supportsVersioning;
            lbShowVersionGrid.Visible  = supportsVersioning;
            cbOverwriteVersion.Visible = supportsVersioning;
            cbOverwriteVersion.Checked = false;

            // RequireApproval only applies if SupportsVersioning=True
            upnlApproval.Visible = supportsVersioning && requireApproval;
            lbApprove.Enabled    = IsUserAuthorized("Approve");
            lbDeny.Enabled       = IsUserAuthorized("Approve");

            string      entityValue = EntityValue();
            HtmlContent htmlContent = new HtmlContentService(new RockContext()).GetActiveContent(this.BlockId, entityValue);

            // set Height of editors
            if (supportsVersioning && requireApproval)
            {
                ceHtml.EditorHeight = "280";
                htmlEditor.Height   = 280;
            }
            else if (supportsVersioning)
            {
                ceHtml.EditorHeight = "350";
                htmlEditor.Height   = 350;
            }
            else
            {
                ceHtml.EditorHeight = "380";
                htmlEditor.Height   = 380;
            }

            ShowEditDetail(htmlContent);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Shows the view.
        /// </summary>
        protected void ShowView()
        {
            mdEdit.Hide();
            pnlEditModel.Visible = false;
            upnlHtmlContent.Update();

            // prevent htmlEditor from using viewstate when not needed
            pnlEdit.EnableViewState = false;

            pnlEdit.Visible        = false;
            pnlVersionGrid.Visible = false;
            string entityValue = EntityValue();
            string html        = string.Empty;

            int    cacheDuration = GetAttributeValue("CacheDuration").AsInteger();
            string cachedContent = null;

            // only load from the cache if a cacheDuration was specified
            if (cacheDuration > 0)
            {
                cachedContent = HtmlContentService.GetCachedContent(this.BlockId, entityValue);
            }

            // if content not cached load it from DB
            if (cachedContent == null)
            {
                using (var rockContext = new RockContext())
                {
                    var         htmlContentService = new HtmlContentService(rockContext);
                    HtmlContent content            = htmlContentService.GetActiveContent(this.BlockId, entityValue);

                    if (content != null)
                    {
                        if (content.Content.HasMergeFields())
                        {
                            var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, this.CurrentPerson);
                            mergeFields.Add("CurrentPage", this.PageCache);

                            if (CurrentPerson != null)
                            {
                                // TODO: When support for "Person" is not supported anymore (should use "CurrentPerson" instead), remove this line
                                mergeFields.AddOrIgnore("Person", CurrentPerson);
                            }

                            mergeFields.Add("RockVersion", Rock.VersionInfo.VersionInfo.GetRockProductVersionNumber());
                            mergeFields.Add("CurrentPersonCanEdit", IsUserAuthorized(Authorization.EDIT));
                            mergeFields.Add("CurrentPersonCanAdministrate", IsUserAuthorized(Authorization.ADMINISTRATE));

                            html = content.Content.ResolveMergeFields(mergeFields, GetAttributeValue("EnabledLavaCommands"));
                        }
                        else
                        {
                            html = content.Content;
                        }
                    }
                    else
                    {
                        html = string.Empty;
                    }
                }

                // Resolve any dynamic url references
                string appRoot   = ResolveRockUrl("~/");
                string themeRoot = ResolveRockUrl("~~/");
                html = html.Replace("~~/", themeRoot).Replace("~/", appRoot);

                // cache content
                if (cacheDuration > 0)
                {
                    HtmlContentService.AddCachedContent(this.BlockId, entityValue, html, cacheDuration);
                }
            }
            else
            {
                html = cachedContent;
            }

            // add content to the content window
            lHtmlContent.Text = html;
        }