/// <summary> /// Binds the grid. /// </summary> private void BindGrids() { if (ContentChannels.Any()) { var allContentItems = new EventItemOccurrenceChannelItemService(new RockContext()) .Queryable() .Where(c => c.EventItemOccurrenceId == OccurrenceId.Value) .Select(c => c.ContentChannelItem) .ToList(); foreach (var contentChannel in ContentChannels) { var pwItems = phContentChannelGrids.FindControl(string.Format("pwItems_{0}", contentChannel.Id)) as PanelWidget; if (pwItems != null) { var gItems = pwItems.FindControl(string.Format("gItems_{0}", contentChannel.Id)) as Grid; if (gItems != null) { var contentItems = allContentItems .Where(c => c.ContentChannelId == contentChannel.Id); var items = new List <ContentChannelItem>(); foreach (var item in contentItems.ToList()) { if (item.IsAuthorized(Rock.Security.Authorization.VIEW, CurrentPerson)) { items.Add(item); } } SortProperty sortProperty = gItems.SortProperty; if (sortProperty != null) { items = items.AsQueryable().Sort(sortProperty).ToList(); } else { items = items.OrderByDescending(p => p.StartDateTime).ToList(); } gItems.ObjectList = new Dictionary <string, object>(); items.ForEach(i => gItems.ObjectList.Add(i.Id.ToString(), i)); gItems.EntityTypeId = EntityTypeCache.Read <ContentChannelItem>().Id; gItems.DataSource = items.Select(i => new { i.Id, i.Guid, i.Title, i.StartDateTime, i.ExpireDateTime, i.Priority, Status = DisplayStatus(i.Status) }).ToList(); gItems.DataBind(); } } } } }
private void CreateGrids(RockContext rockContext) { if (ContentChannels.Any()) { this.Visible = true; phContentChannelGrids.Controls.Clear(); foreach (var contentChannel in ContentChannels) { bool canEdit = UserCanEdit || contentChannel.IsAuthorized(Authorization.EDIT, CurrentPerson); string iconClass = "fa fa-bullhorn"; if (!string.IsNullOrWhiteSpace(contentChannel.IconCssClass)) { iconClass = contentChannel.IconCssClass; } var pwItems = new PanelWidget(); phContentChannelGrids.Controls.Add(pwItems); pwItems.ID = string.Format("pwItems_{0}", contentChannel.Id); pwItems.Title = string.Format("<i class='{0}'></i> {1}", iconClass, contentChannel.Name); pwItems.Expanded = ExpandedPanels.Contains(contentChannel.Id); var divItems = new HtmlGenericControl("div"); pwItems.Controls.Add(divItems); divItems.ID = string.Format("divItems_{0}", contentChannel.Id); divItems.AddCssClass("grid"); divItems.AddCssClass("grid-panel"); Grid gItems = new Grid(); divItems.Controls.Add(gItems); gItems.ID = string.Format("gItems_{0}", contentChannel.Id); gItems.DataKeyNames = new string[] { "Id" }; gItems.EmptyDataText = "No Items Found"; gItems.RowItemText = "Item"; gItems.AllowSorting = true; gItems.Actions.ShowAdd = canEdit; gItems.IsDeleteEnabled = canEdit; gItems.Actions.AddClick += gItems_Add; gItems.RowSelected += gItems_Edit; gItems.GridRebind += gItems_GridRebind; // // Add the "Link Existing Item" button. // if (OccurrenceId.HasValue) { var lbtnLinkExisting = new LinkButton(); lbtnLinkExisting.Attributes.Add("title", "Link Existing Item"); lbtnLinkExisting.CommandArgument = contentChannel.Id.ToString(); lbtnLinkExisting.CssClass = "btn btn-default btn-sm"; lbtnLinkExisting.Click += lbtnLinkExisting_Click; lbtnLinkExisting.Text = "<i class='fa fa-link'></i>"; gItems.Actions.AddCustomActionControl(lbtnLinkExisting); } gItems.Columns.Add(new RockBoundField { DataField = "Title", HeaderText = "Title", SortExpression = "Title" }); if (contentChannel.ContentChannelType.DateRangeType != ContentChannelDateType.NoDates) { RockBoundField startDateTimeField; RockBoundField expireDateTimeField; if (contentChannel.ContentChannelType.IncludeTime) { startDateTimeField = new DateTimeField(); expireDateTimeField = new DateTimeField(); } else { startDateTimeField = new DateField(); expireDateTimeField = new DateField(); } startDateTimeField.DataField = "StartDateTime"; startDateTimeField.HeaderText = contentChannel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ? "Start" : "Active"; startDateTimeField.SortExpression = "StartDateTime"; gItems.Columns.Add(startDateTimeField); expireDateTimeField.DataField = "ExpireDateTime"; expireDateTimeField.HeaderText = "Expire"; expireDateTimeField.SortExpression = "ExpireDateTime"; if (contentChannel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange) { gItems.Columns.Add(expireDateTimeField); } } if (!contentChannel.ContentChannelType.DisablePriority) { var priorityField = new RockBoundField { DataField = "Priority", HeaderText = "Priority", SortExpression = "Priority", DataFormatString = "{0:N0}", }; priorityField.ItemStyle.HorizontalAlign = HorizontalAlign.Right; gItems.Columns.Add(priorityField); } // Add attribute columns int entityTypeId = EntityTypeCache.Read(typeof(Rock.Model.ContentChannelItem)).Id; string qualifier = contentChannel.ContentChannelTypeId.ToString(); foreach (var attribute in new AttributeService(rockContext).Queryable() .Where(a => a.EntityTypeId == entityTypeId && a.IsGridColumn && a.EntityTypeQualifierColumn.Equals("ContentChannelTypeId", StringComparison.OrdinalIgnoreCase) && a.EntityTypeQualifierValue.Equals(qualifier)) .OrderBy(a => a.Order) .ThenBy(a => a.Name)) { string dataFieldExpression = attribute.Key; bool columnExists = gItems.Columns.OfType <AttributeField>().FirstOrDefault(a => a.DataField.Equals(dataFieldExpression)) != null; if (!columnExists) { AttributeField boundField = new AttributeField(); boundField.DataField = dataFieldExpression; boundField.AttributeId = attribute.Id; boundField.HeaderText = attribute.Name; var attributeCache = Rock.Web.Cache.AttributeCache.Read(attribute.Id); if (attributeCache != null) { boundField.ItemStyle.HorizontalAlign = attributeCache.FieldType.Field.AlignValue; } gItems.Columns.Add(boundField); } } if (contentChannel.RequiresApproval && !contentChannel.ContentChannelType.DisableStatus) { var statusField = new BoundField(); gItems.Columns.Add(statusField); statusField.DataField = "Status"; statusField.HeaderText = "Status"; statusField.SortExpression = "Status"; statusField.HtmlEncode = false; } var deleteField = new DeleteField(); gItems.Columns.Add(deleteField); deleteField.Click += gItems_Delete; } } else { this.Visible = false; } }
private void CreateGrids(RockContext rockContext) { if (ContentChannels.Any()) { this.Visible = true; // TODO: security bool canEdit = true; phContentChannelGrids.Controls.Clear(); foreach (var contentChannel in ContentChannels) { var pwItems = new PanelWidget(); phContentChannelGrids.Controls.Add(pwItems); pwItems.ID = string.Format("pwItems_{0}", contentChannel.Id); pwItems.Title = contentChannel.Name; pwItems.Expanded = ExpandedPanels.Contains(contentChannel.Id); var divItems = new HtmlGenericControl("div"); pwItems.Controls.Add(divItems); divItems.ID = string.Format("divItems_{0}", contentChannel.Id); divItems.AddCssClass("grid"); divItems.AddCssClass("grid-panel"); Grid gItems = new Grid(); divItems.Controls.Add(gItems); gItems.ID = string.Format("gItems_{0}", contentChannel.Id); gItems.DataKeyNames = new string[] { "Id" }; gItems.EmptyDataText = "No Items Found"; gItems.RowItemText = "Item"; gItems.AllowSorting = true; gItems.Actions.ShowAdd = canEdit; gItems.IsDeleteEnabled = canEdit; gItems.Actions.AddClick += gItems_Add; gItems.RowSelected += gItems_Edit; gItems.GridRebind += gItems_GridRebind; gItems.Columns.Add(new RockBoundField { DataField = "Title", HeaderText = "Title", SortExpression = "Title" }); if (contentChannel.ContentChannelType.IncludeTime) { gItems.Columns.Add(new DateTimeField { DataField = "StartDateTime", HeaderText = contentChannel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ? "Start" : "Active", SortExpression = "StartDateTime" }); if (contentChannel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange) { gItems.Columns.Add(new DateTimeField { DataField = "ExpireDateTime", HeaderText = "Expire", SortExpression = "ExpireDateTime" }); } } else { gItems.Columns.Add(new DateField { DataField = "StartDateTime", HeaderText = contentChannel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ? "Start" : "Active", SortExpression = "StartDateTime" }); if (contentChannel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange) { gItems.Columns.Add(new DateField { DataField = "ExpireDateTime", HeaderText = "Expire", SortExpression = "ExpireDateTime" }); } } if (!contentChannel.ContentChannelType.DisablePriority) { var priorityField = new RockBoundField { DataField = "Priority", HeaderText = "Priority", SortExpression = "Priority", DataFormatString = "{0:N0}", }; priorityField.ItemStyle.HorizontalAlign = HorizontalAlign.Right; gItems.Columns.Add(priorityField); } // Add attribute columns int entityTypeId = EntityTypeCache.Read(typeof(Rock.Model.ContentChannelItem)).Id; string qualifier = contentChannel.ContentChannelTypeId.ToString(); foreach (var attribute in new AttributeService(rockContext).Queryable() .Where(a => a.EntityTypeId == entityTypeId && a.IsGridColumn && a.EntityTypeQualifierColumn.Equals("ContentChannelTypeId", StringComparison.OrdinalIgnoreCase) && a.EntityTypeQualifierValue.Equals(qualifier)) .OrderBy(a => a.Order) .ThenBy(a => a.Name)) { string dataFieldExpression = attribute.Key; bool columnExists = gItems.Columns.OfType <AttributeField>().FirstOrDefault(a => a.DataField.Equals(dataFieldExpression)) != null; if (!columnExists) { AttributeField boundField = new AttributeField(); boundField.DataField = dataFieldExpression; boundField.HeaderText = attribute.Name; boundField.SortExpression = string.Empty; var attributeCache = Rock.Web.Cache.AttributeCache.Read(attribute.Id); if (attributeCache != null) { boundField.ItemStyle.HorizontalAlign = attributeCache.FieldType.Field.AlignValue; } gItems.Columns.Add(boundField); } } if (contentChannel.RequiresApproval) { var statusField = new BoundField(); gItems.Columns.Add(statusField); statusField.DataField = "Status"; statusField.HeaderText = "Status"; statusField.SortExpression = "Status"; statusField.HtmlEncode = false; } var deleteField = new DeleteField(); gItems.Columns.Add(deleteField); deleteField.Click += gItems_Delete; } } else { this.Visible = false; } }