protected void AddColumns( ContentChannel channel) { // Remove all columns gContentChannelItems.Columns.Clear(); if ( channel != null ) { // Add Title column var titleField = new BoundField(); titleField.DataField = "Title"; titleField.HeaderText = "Title"; titleField.SortExpression = "Title"; gContentChannelItems.Columns.Add( titleField ); // Add Attribute columns int entityTypeId = EntityTypeCache.Read( typeof( Rock.Model.ContentChannelItem ) ).Id; string channelId = channel.Id.ToString(); string channelTypeId = channel.ContentChannelTypeId.ToString(); foreach ( var attribute in new AttributeService( new RockContext() ).Queryable() .Where( a => a.EntityTypeId == entityTypeId && a.IsGridColumn && ( ( a.EntityTypeQualifierColumn.Equals( "ContentChannelTypeId", StringComparison.OrdinalIgnoreCase ) && a.EntityTypeQualifierValue.Equals( channelTypeId ) ) || ( a.EntityTypeQualifierColumn.Equals( "ContentChannelId", StringComparison.OrdinalIgnoreCase ) && a.EntityTypeQualifierValue.Equals( channelId ) ) ) ) .OrderBy( a => a.Order ) .ThenBy( a => a.Name ) ) { string dataFieldExpression = attribute.Key; bool columnExists = gContentChannelItems.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; } gContentChannelItems.Columns.Add( boundField ); } } // Add Start column var startField = new DateTimeField(); startField.DataField = "StartDateTime"; startField.HeaderText = channel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ? "Start" : "Date"; startField.SortExpression = "StartDateTime"; gContentChannelItems.Columns.Add( startField ); // Expire column if ( channel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ) { var expireField = new DateTimeField(); expireField.DataField = "ExpireDateTime"; expireField.HeaderText = "Expire"; expireField.SortExpression = "ExpireDateTime"; gContentChannelItems.Columns.Add( expireField ); } // Priority column var priorityField = new BoundField(); priorityField.DataField = "Priority"; priorityField.HeaderText = "Priority"; priorityField.SortExpression = "Priority"; priorityField.DataFormatString = "{0:N0}"; priorityField.ItemStyle.HorizontalAlign = HorizontalAlign.Right; gContentChannelItems.Columns.Add( priorityField ); // Status column if ( channel.RequiresApproval ) { var statusField = new BoundField(); gContentChannelItems.Columns.Add( statusField ); statusField.DataField = "Status"; statusField.HeaderText = "Status"; statusField.SortExpression = "Status"; statusField.HtmlEncode = false; } bool canEditChannel = channel.IsAuthorized( Rock.Security.Authorization.EDIT, CurrentPerson ); gContentChannelItems.Actions.ShowAdd = canEditChannel; gContentChannelItems.IsDeleteEnabled = canEditChannel; if ( canEditChannel ) { var deleteField = new DeleteField(); gContentChannelItems.Columns.Add( deleteField ); deleteField.Click += gContentChannelItems_Delete; } } }
/// <summary> /// Shows the detail. /// </summary> /// <param name="contentChannelId">The content channel identifier.</param> public void ShowDetail(int contentChannelId) { ContentChannel contentChannel = null; cbIndexChannel.Visible = IndexContainer.IndexingEnabled; bool editAllowed = IsUserAuthorized(Authorization.EDIT); var rockContext = new RockContext(); if (!contentChannelId.Equals(0)) { contentChannel = GetContentChannel(contentChannelId); if (contentChannel != null) { editAllowed = editAllowed || contentChannel.IsAuthorized(Authorization.EDIT, CurrentPerson); } pdAuditDetails.SetEntity(contentChannel, ResolveRockUrl("~")); } if (contentChannel == null) { contentChannel = new ContentChannel { Id = 0 }; contentChannel.ChildContentChannels = new List <ContentChannel>(); // hide the panel drawer that show created and last modified dates pdAuditDetails.Visible = false; } if (contentChannel != null && contentChannel.IsAuthorized(Authorization.VIEW, CurrentPerson)) { hfId.Value = contentChannel.Id.ToString(); bool readOnly = false; nbEditModeMessage.Text = string.Empty; if (!editAllowed) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(ContentChannel.FriendlyTypeName); } if (readOnly) { lbEdit.Visible = false; ShowReadonlyDetails(contentChannel); } else { lbEdit.Visible = true; if (contentChannel.Id > 0) { ShowReadonlyDetails(contentChannel); } else { ShowEditDetails(contentChannel); } } btnSecurity.Visible = contentChannel.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson); btnSecurity.Title = contentChannel.Name; btnSecurity.EntityId = contentChannel.Id; lbSave.Visible = !readOnly; } else { nbEditModeMessage.Text = EditModeMessage.NotAuthorizedToView(ContentChannel.FriendlyTypeName); pnlEditDetails.Visible = false; fieldsetViewSummary.Visible = false; } }
protected void AddDynamicControls( ContentChannel channel) { // Remove all columns gContentChannelItems.Columns.Clear(); phAttributeFilters.Controls.Clear(); if ( channel != null ) { // Add Title column var titleField = new BoundField(); titleField.DataField = "Title"; titleField.HeaderText = "Title"; titleField.SortExpression = "Title"; gContentChannelItems.Columns.Add( titleField ); // Add Attribute columns int entityTypeId = EntityTypeCache.Read( typeof( Rock.Model.ContentChannelItem ) ).Id; string channelId = channel.Id.ToString(); string channelTypeId = channel.ContentChannelTypeId.ToString(); foreach ( var attribute in AvailableAttributes ) { var control = attribute.FieldType.Field.FilterControl( attribute.QualifierValues, "filter_" + attribute.Id.ToString(), false, Rock.Reporting.FilterMode.SimpleFilter ); if ( control != null ) { if ( control is IRockControl ) { var rockControl = (IRockControl)control; rockControl.Label = attribute.Name; rockControl.Help = attribute.Description; phAttributeFilters.Controls.Add( control ); } else { var wrapper = new RockControlWrapper(); wrapper.ID = control.ID + "_wrapper"; wrapper.Label = attribute.Name; wrapper.Controls.Add( control ); phAttributeFilters.Controls.Add( wrapper ); } string savedValue = gfFilter.GetUserPreference( MakeKeyUniqueToChannel( channel.Id, attribute.Key ) ); if ( !string.IsNullOrWhiteSpace( savedValue ) ) { try { var values = JsonConvert.DeserializeObject<List<string>>( savedValue ); attribute.FieldType.Field.SetFilterValues( control, attribute.QualifierValues, values ); } catch { // intentionally ignore } } } string dataFieldExpression = attribute.Key; bool columnExists = gContentChannelItems.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; boundField.ItemStyle.HorizontalAlign = attribute.FieldType.Field.AlignValue; gContentChannelItems.Columns.Add( boundField ); } } if ( channel.ContentChannelType.IncludeTime ) { // Add Start column var startField = new DateTimeField(); startField.DataField = "StartDateTime"; startField.HeaderText = channel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ? "Start" : "Date"; startField.SortExpression = "StartDateTime"; gContentChannelItems.Columns.Add( startField ); // Expire column if ( channel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ) { var expireField = new DateTimeField(); expireField.DataField = "ExpireDateTime"; expireField.HeaderText = "Expire"; expireField.SortExpression = "ExpireDateTime"; gContentChannelItems.Columns.Add( expireField ); } } else { // Add Start column var startField = new DateField(); startField.DataField = "StartDateTime"; startField.HeaderText = channel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ? "Start" : "Date"; startField.SortExpression = "StartDateTime"; gContentChannelItems.Columns.Add( startField ); // Expire column if ( channel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ) { var expireField = new DateField(); expireField.DataField = "ExpireDateTime"; expireField.HeaderText = "Expire"; expireField.SortExpression = "ExpireDateTime"; gContentChannelItems.Columns.Add( expireField ); } } // Priority column var priorityField = new BoundField(); priorityField.DataField = "Priority"; priorityField.HeaderText = "Priority"; priorityField.SortExpression = "Priority"; priorityField.DataFormatString = "{0:N0}"; priorityField.ItemStyle.HorizontalAlign = HorizontalAlign.Right; gContentChannelItems.Columns.Add( priorityField ); // Status column if ( channel.RequiresApproval ) { var statusField = new BoundField(); gContentChannelItems.Columns.Add( statusField ); statusField.DataField = "Status"; statusField.HeaderText = "Status"; statusField.SortExpression = "Status"; statusField.HtmlEncode = false; } // Add occurrences Count column var occurrencesField = new BoolField(); occurrencesField.DataField = "Occurrences"; occurrencesField.HeaderText = "Event Occurrences"; gContentChannelItems.Columns.Add( occurrencesField ); bool canEditChannel = channel.IsAuthorized( Rock.Security.Authorization.EDIT, CurrentPerson ); gContentChannelItems.Actions.ShowAdd = canEditChannel; gContentChannelItems.IsDeleteEnabled = canEditChannel; if ( canEditChannel ) { var deleteField = new DeleteField(); gContentChannelItems.Columns.Add( deleteField ); deleteField.Click += gContentChannelItems_Delete; } } }
protected void AddDynamicControls(ContentChannel channel) { // Remove all columns gContentChannelItems.Columns.Clear(); phAttributeFilters.Controls.Clear(); if (channel != null) { // Add Title column var titleField = new BoundField(); titleField.DataField = "Title"; titleField.HeaderText = "Title"; titleField.SortExpression = "Title"; gContentChannelItems.Columns.Add(titleField); // Add Attribute columns int entityTypeId = EntityTypeCache.Read(typeof(Rock.Model.ContentChannelItem)).Id; string channelId = channel.Id.ToString(); string channelTypeId = channel.ContentChannelTypeId.ToString(); foreach (var attribute in AvailableAttributes) { var control = attribute.FieldType.Field.FilterControl(attribute.QualifierValues, "filter_" + attribute.Id.ToString(), false, Rock.Reporting.FilterMode.SimpleFilter); if (control != null) { if (control is IRockControl) { var rockControl = (IRockControl)control; rockControl.Label = attribute.Name; rockControl.Help = attribute.Description; phAttributeFilters.Controls.Add(control); } else { var wrapper = new RockControlWrapper(); wrapper.ID = control.ID + "_wrapper"; wrapper.Label = attribute.Name; wrapper.Controls.Add(control); phAttributeFilters.Controls.Add(wrapper); } string savedValue = gfFilter.GetUserPreference(MakeKeyUniqueToChannel(channel.Id, attribute.Key)); if (!string.IsNullOrWhiteSpace(savedValue)) { try { var values = JsonConvert.DeserializeObject <List <string> >(savedValue); attribute.FieldType.Field.SetFilterValues(control, attribute.QualifierValues, values); } catch { // intentionally ignore } } } string dataFieldExpression = attribute.Key; bool columnExists = gContentChannelItems.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; boundField.ItemStyle.HorizontalAlign = attribute.FieldType.Field.AlignValue; gContentChannelItems.Columns.Add(boundField); } } if (channel.ContentChannelType.IncludeTime) { // Add Start column var startField = new DateTimeField(); startField.DataField = "StartDateTime"; startField.HeaderText = channel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ? "Start" : "Date"; startField.SortExpression = "StartDateTime"; gContentChannelItems.Columns.Add(startField); // Expire column if (channel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange) { var expireField = new DateTimeField(); expireField.DataField = "ExpireDateTime"; expireField.HeaderText = "Expire"; expireField.SortExpression = "ExpireDateTime"; gContentChannelItems.Columns.Add(expireField); } } else { // Add Start column var startField = new DateField(); startField.DataField = "StartDateTime"; startField.HeaderText = channel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ? "Start" : "Date"; startField.SortExpression = "StartDateTime"; gContentChannelItems.Columns.Add(startField); // Expire column if (channel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange) { var expireField = new DateField(); expireField.DataField = "ExpireDateTime"; expireField.HeaderText = "Expire"; expireField.SortExpression = "ExpireDateTime"; gContentChannelItems.Columns.Add(expireField); } } // Priority column var priorityField = new BoundField(); priorityField.DataField = "Priority"; priorityField.HeaderText = "Priority"; priorityField.SortExpression = "Priority"; priorityField.DataFormatString = "{0:N0}"; priorityField.ItemStyle.HorizontalAlign = HorizontalAlign.Right; gContentChannelItems.Columns.Add(priorityField); // Status column if (channel.RequiresApproval) { var statusField = new BoundField(); gContentChannelItems.Columns.Add(statusField); statusField.DataField = "Status"; statusField.HeaderText = "Status"; statusField.SortExpression = "Status"; statusField.HtmlEncode = false; } // Add occurrences Count column var occurrencesField = new BoolField(); occurrencesField.DataField = "Occurrences"; occurrencesField.HeaderText = "Event Occurrences"; gContentChannelItems.Columns.Add(occurrencesField); // Add Created By column var createdByPersonNameField = new BoundField(); createdByPersonNameField.DataField = "CreatedByPersonName"; createdByPersonNameField.HeaderText = "Created By"; createdByPersonNameField.HtmlEncode = false; gContentChannelItems.Columns.Add(createdByPersonNameField); bool canEditChannel = channel.IsAuthorized(Rock.Security.Authorization.EDIT, CurrentPerson); gContentChannelItems.Actions.ShowAdd = canEditChannel; gContentChannelItems.IsDeleteEnabled = canEditChannel; if (canEditChannel) { var deleteField = new DeleteField(); gContentChannelItems.Columns.Add(deleteField); deleteField.Click += gContentChannelItems_Delete; } } }
protected void AddColumns(ContentChannel channel) { // Remove all columns gContentChannelItems.Columns.Clear(); if (channel != null) { // Add Title column var titleField = new BoundField(); titleField.DataField = "Title"; titleField.HeaderText = "Title"; titleField.SortExpression = "Title"; gContentChannelItems.Columns.Add(titleField); // Add Attribute columns int entityTypeId = EntityTypeCache.Read(typeof(Rock.Model.ContentChannelItem)).Id; string channelId = channel.Id.ToString(); string channelTypeId = channel.ContentChannelTypeId.ToString(); foreach (var attribute in new AttributeService(new RockContext()).Queryable() .Where(a => a.EntityTypeId == entityTypeId && a.IsGridColumn && (( a.EntityTypeQualifierColumn.Equals("ContentChannelTypeId", StringComparison.OrdinalIgnoreCase) && a.EntityTypeQualifierValue.Equals(channelTypeId) ) || ( a.EntityTypeQualifierColumn.Equals("ContentChannelId", StringComparison.OrdinalIgnoreCase) && a.EntityTypeQualifierValue.Equals(channelId) ))) .OrderBy(a => a.Order) .ThenBy(a => a.Name)) { string dataFieldExpression = attribute.Key; bool columnExists = gContentChannelItems.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; } gContentChannelItems.Columns.Add(boundField); } } // Add Start column var startField = new DateTimeField(); startField.DataField = "StartDateTime"; startField.HeaderText = channel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ? "Start" : "Date"; startField.SortExpression = "StartDateTime"; gContentChannelItems.Columns.Add(startField); // Expire column if (channel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange) { var expireField = new DateTimeField(); expireField.DataField = "ExpireDateTime"; expireField.HeaderText = "Expire"; expireField.SortExpression = "ExpireDateTime"; gContentChannelItems.Columns.Add(expireField); } // Priority column var priorityField = new BoundField(); priorityField.DataField = "Priority"; priorityField.HeaderText = "Priority"; priorityField.SortExpression = "Priority"; priorityField.DataFormatString = "{0:N0}"; priorityField.ItemStyle.HorizontalAlign = HorizontalAlign.Right; gContentChannelItems.Columns.Add(priorityField); // Status column if (channel.RequiresApproval) { var statusField = new BoundField(); gContentChannelItems.Columns.Add(statusField); statusField.DataField = "Status"; statusField.HeaderText = "Status"; statusField.SortExpression = "Status"; statusField.HtmlEncode = false; } bool canEditChannel = channel.IsAuthorized(Rock.Security.Authorization.EDIT, CurrentPerson); gContentChannelItems.Actions.ShowAdd = canEditChannel; gContentChannelItems.IsDeleteEnabled = canEditChannel; if (canEditChannel) { var deleteField = new DeleteField(); gContentChannelItems.Columns.Add(deleteField); deleteField.Click += gContentChannelItems_Delete; } } }
/// <summary> /// Shows the detail. /// </summary> /// <param name="contentChannelId">The marketing campaign ad type identifier.</param> public void ShowDetail(int contentChannelId) { ContentChannel contentChannel = null; bool editAllowed = IsUserAuthorized(Authorization.EDIT); var rockContext = new RockContext(); if (!contentChannelId.Equals(0)) { contentChannel = GetContentChannel(contentChannelId); if (contentChannel != null) { editAllowed = editAllowed || contentChannel.IsAuthorized(Authorization.EDIT, CurrentPerson); } } if (contentChannel == null) { contentChannel = new ContentChannel { Id = 0 }; } if (contentChannel != null && contentChannel.IsAuthorized(Authorization.VIEW, CurrentPerson)) { hfId.Value = contentChannel.Id.ToString(); bool readOnly = false; nbEditModeMessage.Text = string.Empty; if (!editAllowed) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(ContentChannel.FriendlyTypeName); } if (readOnly) { lbEdit.Visible = false; ShowReadonlyDetails(contentChannel); } else { lbEdit.Visible = true; if (contentChannel.Id > 0) { ShowReadonlyDetails(contentChannel); } else { ShowEditDetails(contentChannel); } } lbSave.Visible = !readOnly; } else { nbEditModeMessage.Text = EditModeMessage.NotAuthorizedToView(ContentChannel.FriendlyTypeName); pnlEditDetails.Visible = false; fieldsetViewSummary.Visible = false; } }