/// <summary> /// Adds the field panel widget. /// </summary> /// <param name="reportFieldGuid">The report field unique identifier.</param> /// <param name="reportFieldType">Type of the report field.</param> /// <param name="fieldSelection">The field selection.</param> /// <param name="showExpanded">if set to <c>true</c> [show expanded].</param> /// <param name="setReportFieldValues">if set to <c>true</c> [set report field values].</param> /// <param name="reportField">The report field.</param> private void AddFieldPanelWidget( Guid reportFieldGuid, ReportFieldType reportFieldType, string fieldSelection, bool showExpanded, bool setReportFieldValues = false, ReportField reportField = null ) { int entityTypeId = ddlEntityType.SelectedValueAsInt() ?? 0; if (entityTypeId == 0) { return; } PanelWidget panelWidget = new PanelWidget(); panelWidget.ID = string.Format( "reportFieldWidget_{0}", reportFieldGuid.ToString( "N" ) ); string fieldTitle = null; DataSelectComponent dataSelectComponent = null; switch ( reportFieldType ) { case ReportFieldType.Property: var entityType = EntityTypeCache.Read( entityTypeId ).GetEntityType(); var entityField = EntityHelper.GetEntityFields( entityType ).FirstOrDefault( a => a.Name == fieldSelection ); if ( entityField != null ) { fieldTitle = entityField.Title; } break; case ReportFieldType.Attribute: var attribute = AttributeCache.Read( fieldSelection.AsInteger() ?? 0 ); if ( attribute != null ) { fieldTitle = attribute.Name; } break; case ReportFieldType.DataSelectComponent: string dataSelectComponentTypeName = EntityTypeCache.Read( fieldSelection.AsInteger() ?? 0 ).GetEntityType().FullName; dataSelectComponent = Rock.Reporting.DataSelectContainer.GetComponent( dataSelectComponentTypeName ); if ( dataSelectComponent != null ) { fieldTitle = dataSelectComponent.GetTitle( null ); } break; } if ( fieldTitle == null ) { // return if we can't determine field return; } panelWidget.Title = fieldTitle; panelWidget.ShowDeleteButton = true; panelWidget.DeleteClick += FieldsPanelWidget_DeleteClick; panelWidget.ShowReorderIcon = true; panelWidget.Expanded = showExpanded; HiddenField hfReportFieldType = new HiddenField(); hfReportFieldType.ID = panelWidget.ID + "_hfReportFieldType"; hfReportFieldType.Value = reportFieldType.ConvertToString(); panelWidget.Controls.Add( hfReportFieldType ); HiddenField hfFieldSelection = new HiddenField(); hfFieldSelection.ID = panelWidget.ID + "_hfFieldSelection"; hfFieldSelection.Value = fieldSelection; panelWidget.Controls.Add( hfFieldSelection ); RockCheckBox showInGridCheckBox = new RockCheckBox(); showInGridCheckBox.ID = panelWidget.ID + "_showInGridCheckBox"; showInGridCheckBox.Text = "Show in Grid"; if ( setReportFieldValues ) { showInGridCheckBox.Checked = reportField.ShowInGrid; } panelWidget.Controls.Add( showInGridCheckBox ); RockTextBox columnHeaderTextTextBox = new RockTextBox(); columnHeaderTextTextBox.ID = panelWidget.ID + "_columnHeaderTextTextBox"; columnHeaderTextTextBox.Label = "Column Label"; if ( setReportFieldValues ) { columnHeaderTextTextBox.Text = string.IsNullOrWhiteSpace( reportField.ColumnHeaderText ) ? fieldTitle : reportField.ColumnHeaderText; } panelWidget.Controls.Add( columnHeaderTextTextBox ); if ( dataSelectComponent != null ) { PlaceHolder phDataSelectControls = new PlaceHolder(); phDataSelectControls.ID = panelWidget.ID + "_phDataSelectControls"; panelWidget.Controls.Add( phDataSelectControls ); var dataSelectControls = dataSelectComponent.CreateChildControls( phDataSelectControls ); if ( setReportFieldValues ) { dataSelectComponent.SetSelection( dataSelectControls, reportField.Selection ); } } phReportFields.Controls.Add( panelWidget ); }
/// <summary> /// Adds the field panel widget. /// </summary> /// <param name="reportFieldGuid">The report field unique identifier.</param> /// <param name="reportFieldType">Type of the report field.</param> /// <param name="fieldSelection">The field selection.</param> /// <param name="showExpanded">if set to <c>true</c> [show expanded].</param> /// <param name="setReportFieldValues">if set to <c>true</c> [set report field values].</param> /// <param name="reportField">The report field.</param> private void AddFieldPanelWidget(Guid reportFieldGuid, ReportFieldType reportFieldType, string fieldSelection, bool showExpanded, bool setReportFieldValues = false, ReportField reportField = null) { int entityTypeId = ddlEntityType.SelectedValueAsInt() ?? 0; if (entityTypeId == 0) { return; } PanelWidget panelWidget = new PanelWidget(); panelWidget.ID = string.Format("reportFieldWidget_{0}", reportFieldGuid.ToString("N")); string fieldTitle = null; DataSelectComponent dataSelectComponent = null; switch (reportFieldType) { case ReportFieldType.Property: var entityType = EntityTypeCache.Read(entityTypeId).GetEntityType(); var entityField = EntityHelper.GetEntityFields(entityType).FirstOrDefault(a => a.Name == fieldSelection); if (entityField != null) { fieldTitle = entityField.Title; } break; case ReportFieldType.Attribute: var attribute = AttributeCache.Read(fieldSelection.AsInteger() ?? 0); if (attribute != null) { fieldTitle = attribute.Name; } break; case ReportFieldType.DataSelectComponent: string dataSelectComponentTypeName = EntityTypeCache.Read(fieldSelection.AsInteger() ?? 0).GetEntityType().FullName; dataSelectComponent = Rock.Reporting.DataSelectContainer.GetComponent(dataSelectComponentTypeName); if (dataSelectComponent != null) { fieldTitle = dataSelectComponent.GetTitle(null); } break; } if (fieldTitle == null) { // return if we can't determine field return; } panelWidget.Title = fieldTitle; panelWidget.ShowDeleteButton = true; panelWidget.DeleteClick += FieldsPanelWidget_DeleteClick; panelWidget.ShowReorderIcon = true; panelWidget.Expanded = showExpanded; HiddenField hfReportFieldType = new HiddenField(); hfReportFieldType.ID = panelWidget.ID + "_hfReportFieldType"; hfReportFieldType.Value = reportFieldType.ConvertToString(); panelWidget.Controls.Add(hfReportFieldType); HiddenField hfFieldSelection = new HiddenField(); hfFieldSelection.ID = panelWidget.ID + "_hfFieldSelection"; hfFieldSelection.Value = fieldSelection; panelWidget.Controls.Add(hfFieldSelection); RockCheckBox showInGridCheckBox = new RockCheckBox(); showInGridCheckBox.ID = panelWidget.ID + "_showInGridCheckBox"; showInGridCheckBox.Text = "Show in Grid"; if (setReportFieldValues) { showInGridCheckBox.Checked = reportField.ShowInGrid; } panelWidget.Controls.Add(showInGridCheckBox); RockTextBox columnHeaderTextTextBox = new RockTextBox(); columnHeaderTextTextBox.ID = panelWidget.ID + "_columnHeaderTextTextBox"; columnHeaderTextTextBox.Label = "Column Label"; if (setReportFieldValues) { columnHeaderTextTextBox.Text = string.IsNullOrWhiteSpace(reportField.ColumnHeaderText) ? fieldTitle : reportField.ColumnHeaderText; } panelWidget.Controls.Add(columnHeaderTextTextBox); if (dataSelectComponent != null) { PlaceHolder phDataSelectControls = new PlaceHolder(); phDataSelectControls.ID = panelWidget.ID + "_phDataSelectControls"; panelWidget.Controls.Add(phDataSelectControls); var dataSelectControls = dataSelectComponent.CreateChildControls(phDataSelectControls); if (setReportFieldValues) { dataSelectComponent.SetSelection(dataSelectControls, reportField.Selection); } } phReportFields.Controls.Add(panelWidget); }