/// <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)
        {
            var rockContext = new RockContext();
            ContentChannelItem contentItem = GetContentItem(rockContext);

            if (contentItem != null && contentItem.IsAuthorized(Authorization.EDIT, CurrentPerson))
            {
                contentItem.Title   = tbTitle.Text;
                contentItem.Content = contentItem.ContentChannel.ContentControlType == ContentControlType.HtmlEditor ?
                                      htmlContent.Text : ceContent.Text;
                contentItem.Priority       = nbPriority.Text.AsInteger();
                contentItem.StartDateTime  = dtpStart.SelectedDateTime ?? RockDateTime.Now;
                contentItem.ExpireDateTime = (contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange) ?
                                             dtpExpire.SelectedDateTime : null;

                int newStatusID = hfStatus.Value.AsIntegerOrNull() ?? contentItem.Status.ConvertToInt();
                int oldStatusId = contentItem.Status.ConvertToInt();
                if (newStatusID != oldStatusId && contentItem.IsAuthorized(Authorization.APPROVE, CurrentPerson))
                {
                    contentItem.Status = hfStatus.Value.ConvertToEnum <ContentChannelItemStatus>(ContentChannelItemStatus.PendingApproval);
                    if (contentItem.Status == ContentChannelItemStatus.PendingApproval)
                    {
                        contentItem.ApprovedDateTime        = null;
                        contentItem.ApprovedByPersonAliasId = null;
                    }
                    else
                    {
                        contentItem.ApprovedDateTime        = RockDateTime.Now;
                        contentItem.ApprovedByPersonAliasId = CurrentPersonAliasId;
                    }
                }

                contentItem.LoadAttributes(rockContext);
                Rock.Attribute.Helper.GetEditValues(phAttributes, contentItem);

                if (!Page.IsValid || !contentItem.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                rockContext.WrapTransaction(() =>
                {
                    rockContext.SaveChanges();
                    contentItem.SaveAttributeValues(rockContext);
                });

                ReturnToParentPage();
            }
        }
示例#2
0
        private void ShowApproval(ContentChannelItem contentItem)
        {
            if (contentItem != null &&
                contentItem.ContentChannel != null &&
                contentItem.ContentChannel.RequiresApproval)
            {
                if (contentItem.IsAuthorized(Authorization.APPROVE, CurrentPerson))
                {
                    pnlStatus.Visible = true;

                    PendingCss  = contentItem.Status == ContentChannelItemStatus.PendingApproval ? "btn-default active" : "btn-default";
                    ApprovedCss = contentItem.Status == ContentChannelItemStatus.Approved ? "btn-success active" : "btn-default";
                    DeniedCss   = contentItem.Status == ContentChannelItemStatus.Denied ? "btn-danger active" : "btn-default";
                }
                else
                {
                    pnlStatus.Visible = false;
                }

                hfStatus.Value = contentItem.Status.ConvertToInt().ToString();
            }
            else
            {
                hfStatus.Value    = ContentChannelItemStatus.Approved.ToString();
                pnlStatus.Visible = false;
                divStatus.Visible = false;
            }
        }
示例#3
0
        public void ShowDetail(int contentItemId, int?contentChannelId)
        {
            bool canEdit = IsUserAuthorized(Authorization.EDIT);

            hfId.Value        = contentItemId.ToString();
            hfChannelId.Value = contentChannelId.HasValue ? contentChannelId.Value.ToString() : string.Empty;

            ContentChannelItem contentItem = GetContentItem();

            if (contentItem != null &&
                contentItem.ContentChannelType != null &&
                contentItem.ContentChannel != null &&
                (canEdit || contentItem.IsAuthorized(Authorization.EDIT, CurrentPerson)))
            {
                ShowApproval(contentItem);

                pnlEditDetails.Visible = true;

                hfId.Value        = contentItem.Id.ToString();
                hfChannelId.Value = contentItem.ContentChannelId.ToString();

                string cssIcon = contentItem.ContentChannel.IconCssClass;
                if (string.IsNullOrWhiteSpace(cssIcon))
                {
                    cssIcon = "fa fa-certificate";
                }
                lIcon.Text = string.Format("<i class='{0}'></i>", cssIcon);

                string title = contentItem.Id > 0 ?
                               ActionTitle.Edit(ContentChannelItem.FriendlyTypeName) :
                               ActionTitle.Add(ContentChannelItem.FriendlyTypeName);
                lTitle.Text = title.FormatAsHtmlTitle();

                hlContentChannel.Text = contentItem.ContentChannel.Name;
                hlStatus.Text         = contentItem.Status.ConvertToString();

                hlStatus.LabelType = LabelType.Default;
                switch (contentItem.Status)
                {
                case ContentChannelItemStatus.Approved: hlStatus.LabelType = LabelType.Success; break;

                case ContentChannelItemStatus.Denied: hlStatus.LabelType = LabelType.Danger; break;

                case ContentChannelItemStatus.PendingApproval: hlStatus.LabelType = LabelType.Warning; break;

                default: hlStatus.LabelType = LabelType.Default; break;
                }

                var statusDetail = new System.Text.StringBuilder();
                if (contentItem.ApprovedByPersonAlias != null && contentItem.ApprovedByPersonAlias.Person != null)
                {
                    statusDetail.AppendFormat("by {0} ", contentItem.ApprovedByPersonAlias.Person.FullName);
                }
                if (contentItem.ApprovedDateTime.HasValue)
                {
                    statusDetail.AppendFormat("on {0} at {1}", contentItem.ApprovedDateTime.Value.ToShortDateString(),
                                              contentItem.ApprovedDateTime.Value.ToShortTimeString());
                }
                hlStatus.ToolTip = statusDetail.ToString();

                tbTitle.Text = contentItem.Title;

                if (contentItem.ContentChannel.ContentControlType == ContentControlType.HtmlEditor)
                {
                    ceContent.Visible   = false;
                    htmlContent.Visible = true;
                    htmlContent.Text    = contentItem.Content;
                    htmlContent.MergeFields.Clear();
                    htmlContent.MergeFields.Add("GlobalAttribute");
                    htmlContent.MergeFields.Add("Rock.Model.ContentChannelItem|Current Item");
                    htmlContent.MergeFields.Add("Rock.Model.Person|Current Person");
                    htmlContent.MergeFields.Add("Campuses");
                    htmlContent.MergeFields.Add("RockVersion");

                    if (!string.IsNullOrWhiteSpace(contentItem.ContentChannel.RootImageDirectory))
                    {
                        htmlContent.DocumentFolderRoot = contentItem.ContentChannel.RootImageDirectory;
                        htmlContent.ImageFolderRoot    = contentItem.ContentChannel.RootImageDirectory;
                    }
                }
                else
                {
                    htmlContent.Visible = false;
                    ceContent.Visible   = true;
                    ceContent.Text      = contentItem.Content;
                    ceContent.MergeFields.Clear();
                    ceContent.MergeFields.Add("GlobalAttribute");
                    ceContent.MergeFields.Add("Rock.Model.ContentChannelItem|Current Item");
                    ceContent.MergeFields.Add("Rock.Model.Person|Current Person");
                    ceContent.MergeFields.Add("Campuses");
                    ceContent.MergeFields.Add("RockVersion");
                }

                if (contentItem.ContentChannelType.IncludeTime)
                {
                    dpStart.Visible   = false;
                    dpExpire.Visible  = false;
                    dtpStart.Visible  = true;
                    dtpExpire.Visible = contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange;

                    dtpStart.SelectedDateTime  = contentItem.StartDateTime;
                    dtpStart.Label             = contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ? "Start" : "Active";
                    dtpExpire.SelectedDateTime = contentItem.ExpireDateTime;
                }
                else
                {
                    dpStart.Visible   = true;
                    dpExpire.Visible  = contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange;
                    dtpStart.Visible  = false;
                    dtpExpire.Visible = false;

                    dpStart.SelectedDate  = contentItem.StartDateTime.Date;
                    dpStart.Label         = contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ? "Start" : "Active";
                    dpExpire.SelectedDate = contentItem.ExpireDateTime.HasValue ? contentItem.ExpireDateTime.Value.Date : (DateTime?)null;
                }

                nbPriority.Text    = contentItem.Priority.ToString();
                nbPriority.Visible = !contentItem.ContentChannelType.DisablePriority;

                contentItem.LoadAttributes();
                phAttributes.Controls.Clear();
                Rock.Attribute.Helper.AddEditControls(contentItem, phAttributes, true, BlockValidationGroup);

                phOccurrences.Controls.Clear();
                foreach (var occurrence in contentItem.EventItemOccurrences
                         .Where(o => o.EventItemOccurrence != null)
                         .Select(o => o.EventItemOccurrence))
                {
                    var qryParams = new Dictionary <string, string> {
                        { "EventItemOccurrenceId", occurrence.Id.ToString() }
                    };
                    string url          = LinkedPageUrl("EventOccurrencePage", qryParams);
                    var    hlOccurrence = new HighlightLabel();
                    hlOccurrence.LabelType = LabelType.Info;
                    hlOccurrence.ID        = string.Format("hlOccurrence_{0}", occurrence.Id);
                    hlOccurrence.Text      = string.Format("<a href='{0}'>{1}</a>", url, occurrence.ToString());
                    phOccurrences.Controls.Add(hlOccurrence);
                }
            }
            else
            {
                nbEditModeMessage.Text = EditModeMessage.NotAuthorizedToEdit(ContentChannelItem.FriendlyTypeName);
                pnlEditDetails.Visible = false;
            }
        }
示例#4
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)
        {
            var rockContext = new RockContext();
            ContentChannelItem contentItem = GetContentItem(rockContext);

            if (contentItem != null && contentItem.IsAuthorized(Authorization.EDIT, CurrentPerson))
            {
                contentItem.Title   = tbTitle.Text;
                contentItem.Content = contentItem.ContentChannel.ContentControlType == ContentControlType.HtmlEditor ?
                                      htmlContent.Text : ceContent.Text;
                contentItem.Priority = nbPriority.Text.AsInteger();
                if (contentItem.ContentChannelType.IncludeTime)
                {
                    contentItem.StartDateTime  = dtpStart.SelectedDateTime ?? RockDateTime.Now;
                    contentItem.ExpireDateTime = (contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange) ?
                                                 dtpExpire.SelectedDateTime : null;
                }
                else
                {
                    contentItem.StartDateTime  = dpStart.SelectedDate ?? RockDateTime.Today;
                    contentItem.ExpireDateTime = (contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange) ?
                                                 dpExpire.SelectedDate : null;
                }

                int newStatusID = hfStatus.Value.AsIntegerOrNull() ?? contentItem.Status.ConvertToInt();
                int oldStatusId = contentItem.Status.ConvertToInt();
                if (newStatusID != oldStatusId && contentItem.IsAuthorized(Authorization.APPROVE, CurrentPerson))
                {
                    contentItem.Status = hfStatus.Value.ConvertToEnum <ContentChannelItemStatus>(ContentChannelItemStatus.PendingApproval);
                    if (contentItem.Status == ContentChannelItemStatus.PendingApproval)
                    {
                        contentItem.ApprovedDateTime        = null;
                        contentItem.ApprovedByPersonAliasId = null;
                    }
                    else
                    {
                        contentItem.ApprovedDateTime        = RockDateTime.Now;
                        contentItem.ApprovedByPersonAliasId = CurrentPersonAliasId;
                    }
                }

                contentItem.LoadAttributes(rockContext);
                Rock.Attribute.Helper.GetEditValues(phAttributes, contentItem);

                if (!Page.IsValid || !contentItem.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                rockContext.WrapTransaction(() =>
                {
                    rockContext.SaveChanges();
                    contentItem.SaveAttributeValues(rockContext);

                    int?eventItemOccurrenceId = PageParameter("EventItemOccurrenceId").AsIntegerOrNull();
                    if (eventItemOccurrenceId.HasValue)
                    {
                        var occurrenceChannelItemService = new EventItemOccurrenceChannelItemService(rockContext);
                        var occurrenceChannelItem        = occurrenceChannelItemService
                                                           .Queryable()
                                                           .Where(c =>
                                                                  c.ContentChannelItemId == contentItem.Id &&
                                                                  c.EventItemOccurrenceId == eventItemOccurrenceId.Value)
                                                           .FirstOrDefault();

                        if (occurrenceChannelItem == null)
                        {
                            occurrenceChannelItem = new EventItemOccurrenceChannelItem();
                            occurrenceChannelItem.ContentChannelItemId  = contentItem.Id;
                            occurrenceChannelItem.EventItemOccurrenceId = eventItemOccurrenceId.Value;
                            occurrenceChannelItemService.Add(occurrenceChannelItem);
                            rockContext.SaveChanges();
                        }
                    }
                });

                ReturnToParentPage();
            }
        }
        private void ShowApproval( ContentChannelItem contentItem )
        {
            if ( contentItem != null &&
                contentItem.ContentChannel != null &&
                contentItem.ContentChannel.RequiresApproval )
            {

                if ( contentItem.IsAuthorized( Authorization.APPROVE, CurrentPerson ) )
                {
                    pnlStatus.Visible = true;

                    PendingCss = contentItem.Status == ContentChannelItemStatus.PendingApproval ? "btn-default active" : "btn-default";
                    ApprovedCss = contentItem.Status == ContentChannelItemStatus.Approved ? "btn-success active" : "btn-default";
                    DeniedCss = contentItem.Status == ContentChannelItemStatus.Denied ? "btn-danger active" : "btn-default";
                }
                else
                {
                    pnlStatus.Visible = false;
                }

                hfStatus.Value = contentItem.Status.ConvertToInt().ToString();
            }
            else
            {
                hfStatus.Value = ContentChannelItemStatus.Approved.ToString();
                pnlStatus.Visible = false;
                divStatus.Visible = false;
            }
        }
示例#6
0
        public void ShowDetail(int contentItemId, int?contentChannelId)
        {
            bool canEdit = IsUserAuthorized(Authorization.EDIT);

            hfId.Value        = contentItemId.ToString();
            hfChannelId.Value = contentChannelId.HasValue ? contentChannelId.Value.ToString() : string.Empty;

            ContentChannelItem contentItem = GetContentItem();

            if (contentItem == null)
            {
                // this block requires a valid ContentChannel in order to know which channel the ContentChannelItem belongs to, so if ContentChannel wasn't specified, don't show this block
                this.Visible = false;
                return;
            }

            if (contentItem.ContentChannel.IsTaggingEnabled)
            {
                taglTags.EntityTypeId = EntityTypeCache.Read(typeof(ContentChannelItem)).Id;
                taglTags.CategoryGuid = (contentItem.ContentChannel != null && contentItem.ContentChannel.ItemTagCategory != null) ?
                                        contentItem.ContentChannel.ItemTagCategory.Guid : (Guid?)null;
                taglTags.EntityGuid = contentItem.Guid;
                taglTags.DelaySave  = true;
                taglTags.GetTagValues(CurrentPersonId);
                rcwTags.Visible = true;
            }
            else
            {
                rcwTags.Visible = false;
            }

            pdAuditDetails.SetEntity(contentItem, ResolveRockUrl("~"));

            if (contentItem != null &&
                contentItem.ContentChannelType != null &&
                contentItem.ContentChannel != null &&
                (canEdit || contentItem.IsAuthorized(Authorization.EDIT, CurrentPerson)))
            {
                hfIsDirty.Value = "false";

                ShowApproval(contentItem);

                pnlEditDetails.Visible = true;

                // show/hide the delete button
                lbDelete.Visible = (GetAttributeValue("ShowDeleteButton").AsBoolean() && contentItem.Id != 0);

                hfId.Value        = contentItem.Id.ToString();
                hfChannelId.Value = contentItem.ContentChannelId.ToString();

                string cssIcon = contentItem.ContentChannel.IconCssClass;
                if (string.IsNullOrWhiteSpace(cssIcon))
                {
                    cssIcon = "fa fa-certificate";
                }
                lIcon.Text = string.Format("<i class='{0}'></i>", cssIcon);

                string title = contentItem.Id > 0 ?
                               ActionTitle.Edit(ContentChannelItem.FriendlyTypeName) :
                               ActionTitle.Add(ContentChannelItem.FriendlyTypeName);
                lTitle.Text = title.FormatAsHtmlTitle();

                hlContentChannel.Text = contentItem.ContentChannel.Name;

                hlStatus.Visible = contentItem.ContentChannel.RequiresApproval && !contentItem.ContentChannelType.DisableStatus;

                hlStatus.Text = contentItem.Status.ConvertToString();

                hlStatus.LabelType = LabelType.Default;
                switch (contentItem.Status)
                {
                case ContentChannelItemStatus.Approved: hlStatus.LabelType = LabelType.Success; break;

                case ContentChannelItemStatus.Denied: hlStatus.LabelType = LabelType.Danger; break;

                case ContentChannelItemStatus.PendingApproval: hlStatus.LabelType = LabelType.Warning; break;

                default: hlStatus.LabelType = LabelType.Default; break;
                }

                var statusDetail = new System.Text.StringBuilder();
                if (contentItem.ApprovedByPersonAlias != null && contentItem.ApprovedByPersonAlias.Person != null)
                {
                    statusDetail.AppendFormat("by {0} ", contentItem.ApprovedByPersonAlias.Person.FullName);
                }
                if (contentItem.ApprovedDateTime.HasValue)
                {
                    statusDetail.AppendFormat("on {0} at {1}", contentItem.ApprovedDateTime.Value.ToShortDateString(),
                                              contentItem.ApprovedDateTime.Value.ToShortTimeString());
                }
                hlStatus.ToolTip = statusDetail.ToString();

                tbTitle.Text = contentItem.Title;

                htmlContent.Visible = !contentItem.ContentChannelType.DisableContentField;
                htmlContent.Text    = contentItem.Content;
                htmlContent.MergeFields.Clear();
                htmlContent.MergeFields.Add("GlobalAttribute");
                htmlContent.MergeFields.Add("Rock.Model.ContentChannelItem|Current Item");
                htmlContent.MergeFields.Add("Rock.Model.Person|Current Person");
                htmlContent.MergeFields.Add("Campuses");
                htmlContent.MergeFields.Add("RockVersion");

                if (!string.IsNullOrWhiteSpace(contentItem.ContentChannel.RootImageDirectory))
                {
                    htmlContent.DocumentFolderRoot = contentItem.ContentChannel.RootImageDirectory;
                    htmlContent.ImageFolderRoot    = contentItem.ContentChannel.RootImageDirectory;
                }

                htmlContent.StartInCodeEditorMode = contentItem.ContentChannel.ContentControlType == ContentControlType.CodeEditor;

                if (contentItem.ContentChannelType.IncludeTime)
                {
                    dpStart.Visible   = false;
                    dpExpire.Visible  = false;
                    dtpStart.Visible  = contentItem.ContentChannelType.DateRangeType != ContentChannelDateType.NoDates;
                    dtpExpire.Visible = contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange;

                    dtpStart.SelectedDateTime  = contentItem.StartDateTime;
                    dtpStart.Label             = contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ? "Start" : "Active";
                    dtpExpire.SelectedDateTime = contentItem.ExpireDateTime;
                }
                else
                {
                    dpStart.Visible   = contentItem.ContentChannelType.DateRangeType != ContentChannelDateType.NoDates;
                    dpExpire.Visible  = contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange;
                    dtpStart.Visible  = false;
                    dtpExpire.Visible = false;

                    dpStart.SelectedDate  = contentItem.StartDateTime.Date;
                    dpStart.Label         = contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ? "Start" : "Active";
                    dpExpire.SelectedDate = contentItem.ExpireDateTime.HasValue ? contentItem.ExpireDateTime.Value.Date : (DateTime?)null;
                }

                nbPriority.Text    = contentItem.Priority.ToString();
                nbPriority.Visible = !contentItem.ContentChannelType.DisablePriority;

                contentItem.LoadAttributes();
                phAttributes.Controls.Clear();
                Rock.Attribute.Helper.AddEditControls(contentItem, phAttributes, true, BlockValidationGroup, 2);

                phOccurrences.Controls.Clear();
                foreach (var occurrence in contentItem.EventItemOccurrences
                         .Where(o => o.EventItemOccurrence != null)
                         .Select(o => o.EventItemOccurrence))
                {
                    var qryParams = new Dictionary <string, string> {
                        { "EventItemOccurrenceId", occurrence.Id.ToString() }
                    };
                    string url          = LinkedPageUrl("EventOccurrencePage", qryParams);
                    var    hlOccurrence = new HighlightLabel();
                    hlOccurrence.LabelType = LabelType.Info;
                    hlOccurrence.ID        = string.Format("hlOccurrence_{0}", occurrence.Id);
                    hlOccurrence.Text      = string.Format("<a href='{0}'><i class='fa fa-calendar-o'></i> {1}</a>", url, occurrence.ToString());
                    phOccurrences.Controls.Add(hlOccurrence);
                }

                bool canHaveChildren = contentItem.Id > 0 && contentItem.ContentChannel.ChildContentChannels.Any();
                bool canHaveParents  = contentItem.Id > 0 && contentItem.ContentChannel.ParentContentChannels.Any();

                pnlChildrenParents.Visible = canHaveChildren || canHaveParents;
                phPills.Visible            = canHaveChildren && canHaveParents;
                if (canHaveChildren && !canHaveParents)
                {
                    lChildrenParentsTitle.Text = "<i class='fa fa-arrow-circle-down'></i> Child Items";
                }

                if (!canHaveChildren && canHaveParents)
                {
                    lChildrenParentsTitle.Text = "<i class='fa fa-arrow-circle-up'></i> Parent Items";
                    divParentItems.AddCssClass("active");
                }

                if (canHaveChildren)
                {
                    BindChildItemsGrid(contentItem);
                }

                if (canHaveParents)
                {
                    BindParentItemsGrid(contentItem);
                }
            }
            else
            {
                nbEditModeMessage.Text = EditModeMessage.NotAuthorizedToEdit(ContentChannelItem.FriendlyTypeName);
                pnlEditDetails.Visible = false;
            }
        }
        public void ShowDetail(int contentItemId, int?contentChannelId)
        {
            bool canEdit = IsUserAuthorized(Authorization.EDIT);

            hfId.Value        = contentItemId.ToString();
            hfChannelId.Value = contentChannelId.HasValue ? contentChannelId.Value.ToString() : string.Empty;

            ContentChannelItem contentItem = GetContentItem();

            if (contentItem != null &&
                contentItem.ContentChannelType != null &&
                contentItem.ContentChannel != null &&
                (canEdit || contentItem.IsAuthorized(Authorization.EDIT, CurrentPerson)))
            {
                ShowApproval(contentItem);

                pnlEditDetails.Visible = true;

                hfId.Value        = contentItem.Id.ToString();
                hfChannelId.Value = contentItem.ContentChannelId.ToString();

                string cssIcon = contentItem.ContentChannel.IconCssClass;
                if (string.IsNullOrWhiteSpace(cssIcon))
                {
                    cssIcon = "fa fa-certificate";
                }
                lIcon.Text = string.Format("<i class='{0}'></i>", cssIcon);

                string title = contentItem.Id > 0 ?
                               ActionTitle.Edit(ContentChannelItem.FriendlyTypeName) :
                               ActionTitle.Add(ContentChannelItem.FriendlyTypeName);
                lTitle.Text = title.FormatAsHtmlTitle();

                hlContentChannel.Text = contentItem.ContentChannel.Name;
                hlStatus.Text         = contentItem.Status.ConvertToString();

                hlStatus.LabelType = LabelType.Default;
                if (contentItem.Status == ContentChannelItemStatus.Approved)
                {
                    hlStatus.LabelType = LabelType.Success;
                }
                else if (contentItem.Status == ContentChannelItemStatus.Denied)
                {
                    hlStatus.LabelType = LabelType.Danger;
                }
                if (contentItem.Status != ContentChannelItemStatus.PendingApproval)
                {
                    var statusDetail = new System.Text.StringBuilder();
                    if (contentItem.ApprovedByPersonAlias != null && contentItem.ApprovedByPersonAlias.Person != null)
                    {
                        statusDetail.AppendFormat("by {0} ", contentItem.ApprovedByPersonAlias.Person.FullName);
                    }
                    if (contentItem.ApprovedDateTime.HasValue)
                    {
                        statusDetail.AppendFormat("on {0} at {1}", contentItem.ApprovedDateTime.Value.ToShortDateString(),
                                                  contentItem.ApprovedDateTime.Value.ToShortTimeString());
                    }
                    hlStatus.ToolTip = statusDetail.ToString();
                }

                tbTitle.Text = contentItem.Title;

                if (contentItem.ContentChannel.ContentControlType == ContentControlType.HtmlEditor)
                {
                    ceContent.Visible   = false;
                    htmlContent.Visible = true;
                    htmlContent.Text    = contentItem.Content;
                    htmlContent.MergeFields.Clear();
                    htmlContent.MergeFields.Add("GlobalAttribute");
                    htmlContent.MergeFields.Add("Rock.Model.ContentChannelItem|Current Item");
                    htmlContent.MergeFields.Add("Rock.Model.Person|Current Person");
                    htmlContent.MergeFields.Add("Campuses");
                    htmlContent.MergeFields.Add("RockVersion");

                    if (!string.IsNullOrWhiteSpace(contentItem.ContentChannel.RootImageDirectory))
                    {
                        htmlContent.DocumentFolderRoot = contentItem.ContentChannel.RootImageDirectory;
                        htmlContent.ImageFolderRoot    = contentItem.ContentChannel.RootImageDirectory;
                    }
                }
                else
                {
                    htmlContent.Visible = false;
                    ceContent.Visible   = true;
                    ceContent.Text      = contentItem.Content;
                    ceContent.MergeFields.Clear();
                    ceContent.MergeFields.Add("GlobalAttribute");
                    ceContent.MergeFields.Add("Rock.Model.ContentChannelItem|Current Item");
                    ceContent.MergeFields.Add("Rock.Model.Person|Current Person");
                    ceContent.MergeFields.Add("Campuses");
                    ceContent.MergeFields.Add("RockVersion");
                }

                dtpStart.SelectedDateTime  = contentItem.StartDateTime;
                dtpStart.Label             = contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ? "Start" : "Active";
                dtpExpire.SelectedDateTime = contentItem.ExpireDateTime;
                dtpExpire.Visible          = contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange;
                nbPriority.Text            = contentItem.Priority.ToString();
                nbPriority.Visible         = !contentItem.ContentChannelType.DisablePriority;

                contentItem.LoadAttributes();
                phAttributes.Controls.Clear();
                Rock.Attribute.Helper.AddEditControls(contentItem, phAttributes, true, BlockValidationGroup);
            }
            else
            {
                nbEditModeMessage.Text = EditModeMessage.NotAuthorizedToEdit(ContentChannelItem.FriendlyTypeName);
                pnlEditDetails.Visible = false;
            }
        }
示例#8
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)
        {
            var rockContext = new RockContext();
            ContentChannelItem contentItem = GetContentItem(rockContext);

            if (contentItem != null &&
                (IsUserAuthorized(Authorization.EDIT) || contentItem.IsAuthorized(Authorization.EDIT, CurrentPerson)))
            {
                contentItem.Title    = tbTitle.Text;
                contentItem.Content  = htmlContent.Text;
                contentItem.Priority = nbPriority.Text.AsInteger();

                // If this is a new item and the channel is manually sorted then we need to set the order to the next number
                if (contentItem.Id == 0 && new ContentChannelService(rockContext).IsManuallySorted(contentItem.ContentChannelId))
                {
                    contentItem.Order = new ContentChannelItemService(rockContext).GetNextItemOrderValueForContentChannel(contentItem.ContentChannelId);
                }

                if (contentItem.ContentChannelType.IncludeTime)
                {
                    contentItem.StartDateTime  = dtpStart.SelectedDateTime ?? RockDateTime.Now;
                    contentItem.ExpireDateTime = (contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange) ?
                                                 dtpExpire.SelectedDateTime : null;
                }
                else
                {
                    contentItem.StartDateTime  = dpStart.SelectedDate ?? RockDateTime.Today;
                    contentItem.ExpireDateTime = (contentItem.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange) ?
                                                 dpExpire.SelectedDate : null;
                }

                if (contentItem.ContentChannelType.DisableStatus)
                {
                    // if DisableStatus == True, just set the status to Approved
                    contentItem.Status = ContentChannelItemStatus.Approved;
                }
                else
                {
                    int newStatusID = hfStatus.Value.AsIntegerOrNull() ?? contentItem.Status.ConvertToInt();
                    int oldStatusId = contentItem.Status.ConvertToInt();
                    if (newStatusID != oldStatusId && contentItem.IsAuthorized(Authorization.APPROVE, CurrentPerson))
                    {
                        contentItem.Status = hfStatus.Value.ConvertToEnum <ContentChannelItemStatus>(ContentChannelItemStatus.PendingApproval);
                        if (contentItem.Status == ContentChannelItemStatus.PendingApproval)
                        {
                            contentItem.ApprovedDateTime        = null;
                            contentItem.ApprovedByPersonAliasId = null;
                        }
                        else
                        {
                            contentItem.ApprovedDateTime        = RockDateTime.Now;
                            contentItem.ApprovedByPersonAliasId = CurrentPersonAliasId;
                        }
                    }

                    // remove approved status if they do not have approve access when editing
                    if (!contentItem.IsAuthorized(Authorization.APPROVE, CurrentPerson))
                    {
                        contentItem.ApprovedDateTime        = null;
                        contentItem.ApprovedByPersonAliasId = null;
                        contentItem.Status = ContentChannelItemStatus.PendingApproval;
                    }
                }

                contentItem.LoadAttributes(rockContext);
                Rock.Attribute.Helper.GetEditValues(phAttributes, contentItem);

                if (!Page.IsValid || !contentItem.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                rockContext.WrapTransaction(() =>
                {
                    rockContext.SaveChanges();
                    contentItem.SaveAttributeValues(rockContext);

                    if (contentItem.ContentChannel.IsTaggingEnabled)
                    {
                        taglTags.EntityGuid = contentItem.Guid;
                        taglTags.SaveTagValues(CurrentPersonAlias);
                    }

                    int?eventItemOccurrenceId = PageParameter("EventItemOccurrenceId").AsIntegerOrNull();
                    if (eventItemOccurrenceId.HasValue)
                    {
                        var occurrenceChannelItemService = new EventItemOccurrenceChannelItemService(rockContext);
                        var occurrenceChannelItem        = occurrenceChannelItemService
                                                           .Queryable()
                                                           .Where(c =>
                                                                  c.ContentChannelItemId == contentItem.Id &&
                                                                  c.EventItemOccurrenceId == eventItemOccurrenceId.Value)
                                                           .FirstOrDefault();

                        if (occurrenceChannelItem == null)
                        {
                            occurrenceChannelItem = new EventItemOccurrenceChannelItem();
                            occurrenceChannelItem.ContentChannelItemId  = contentItem.Id;
                            occurrenceChannelItem.EventItemOccurrenceId = eventItemOccurrenceId.Value;
                            occurrenceChannelItemService.Add(occurrenceChannelItem);
                            rockContext.SaveChanges();
                        }
                    }
                });

                ReturnToParentPage();
            }
        }