Exemplo n.º 1
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";
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
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";
        }
Exemplo n.º 4
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();
        }