Esempio n. 1
0
        protected void btnSave_Click( object sender, EventArgs e )
        {
            if ( UserAuthorized( "Edit" ) || UserAuthorized( "Configure" ) )
            {
                Rock.CMS.HtmlContent content = null;
                HtmlContentService service = new HtmlContentService();

                // get settings
                string entityValue = EntityValue();

                // get current  content
                int version = 0;
                if ( !Int32.TryParse( hfVersion.Value, out version ) )
                    version = 0;
                content = service.GetByBlockIdAndEntityValueAndVersion( BlockInstance.Id, entityValue, version );

                // if the existing content changed, and the overwrite option was not checked, create a new version
                if ( content != null &&
                    _supportVersioning &&
                    content.Content != txtHtmlContentEditor.Text &&
                    !cbOverwriteVersion.Checked )
                    content = null;

                // if a record doesn't exist then  create one
                if ( content == null )
                {
                    content = new Rock.CMS.HtmlContent();
                    content.BlockId = BlockInstance.Id;
                    content.EntityValue = entityValue;

                    if ( _supportVersioning )
                    {
                        int? maxVersion = service.Queryable().
                            Where( c => c.BlockId == BlockInstance.Id &&
                                c.EntityValue == entityValue ).
                            Select( c => ( int? )c.Version ).Max();

                        content.Version = maxVersion.HasValue ? maxVersion.Value + 1 : 1;
                    }
                    else
                        content.Version = 0;

                    service.Add( content, CurrentPersonId );
                }

                if ( _supportVersioning )
                {
                    DateTime startDate;
                    if ( DateTime.TryParse( tbStartDate.Text, out startDate ) )
                        content.StartDateTime = startDate;
                    else
                        content.StartDateTime = null;

                    DateTime expireDate;
                    if ( DateTime.TryParse( tbExpireDate.Text, out expireDate ) )
                        content.ExpireDateTime = expireDate;
                    else
                        content.ExpireDateTime = null;
                }
                else
                {
                    content.StartDateTime = null;
                    content.ExpireDateTime = null;
                }

                if ( !_requireApproval || UserAuthorized( "Approve" ) )
                {
                    content.Approved = !_requireApproval || cbApprove.Checked;
                    if ( content.Approved )
                    {
                        content.ApprovedByPersonId = CurrentPersonId;
                        content.ApprovedDateTime = DateTime.Now;
                    }
                }

                content.Content = txtHtmlContentEditor.Text;

                service.Save( content, CurrentPersonId );

                // flush cache content
                this.FlushCacheItem( entityValue );

            }

            ShowView();
        }
Esempio n. 2
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();
        }
Esempio n. 3
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" );
        }
Esempio n. 4
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";
        }