/// <summary> /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering. /// </summary> protected override void CreateChildControls() { Controls.Clear(); _hfExpanded = new HiddenFieldWithClass(); Controls.Add(_hfExpanded); _hfExpanded.ID = this.ID + "_hfExpanded"; _hfExpanded.CssClass = "filter-expanded"; _hfExpanded.Value = "False"; _hfActivityTypeGuid = new HiddenField(); Controls.Add(_hfActivityTypeGuid); _hfActivityTypeGuid.ID = this.ID + "_hfActivityTypeGuid"; _lblActivityTypeName = new Label(); Controls.Add(_lblActivityTypeName); _lblActivityTypeName.ClientIDMode = ClientIDMode.Static; _lblActivityTypeName.ID = this.ID + "_lblActivityTypeName"; _lblActivityTypeDescription = new Label(); Controls.Add(_lblActivityTypeDescription); _lblActivityTypeDescription.ClientIDMode = ClientIDMode.Static; _lblActivityTypeDescription.ID = this.ID + "_lblActivityTypeDescription"; _lblInactive = new Label(); Controls.Add(_lblInactive); _lblInactive.ClientIDMode = ClientIDMode.Static; _lblInactive.ID = this.ID + "_lblInactive"; _lblInactive.CssClass = "pull-right"; _lblInactive.Text = "<span class='label label-danger'>Inactive</span>"; _lbDeleteActivityType = new LinkButton(); Controls.Add(_lbDeleteActivityType); _lbDeleteActivityType.CausesValidation = false; _lbDeleteActivityType.ID = this.ID + "_lbDeleteActivityType"; _lbDeleteActivityType.CssClass = "btn btn-xs btn-square btn-danger js-activity-delete"; _lbDeleteActivityType.Click += lbDeleteActivityType_Click; _lbDeleteActivityType.Controls.Add(new LiteralControl { Text = "<i class='fa fa-times'></i>" }); _sbSecurity = new SecurityButton(); Controls.Add(_sbSecurity); _sbSecurity.ID = this.ID + "_sbSecurity"; _sbSecurity.Attributes["class"] = "btn btn-security btn-xs security pull-right"; _sbSecurity.EntityTypeId = EntityTypeCache.Get(typeof(Rock.Model.WorkflowActivityType)).Id; _cbActivityTypeIsActive = new RockCheckBox { Text = "Active" }; Controls.Add(_cbActivityTypeIsActive); _cbActivityTypeIsActive.ID = this.ID + "_cbActivityTypeIsActive"; string checkboxScriptFormat = @" javascript: if ($(this).is(':checked')) {{ $('#{0}').hide(); $('#{1}').removeClass('workflow-activity-inactive'); }} else {{ $('#{0}').show(); $('#{1}').addClass('workflow-activity-inactive'); }} "; _cbActivityTypeIsActive.InputAttributes.Add("onclick", string.Format(checkboxScriptFormat, _lblInactive.ID, this.ID + "_section")); _tbActivityTypeName = new RockTextBox(); Controls.Add(_tbActivityTypeName); _tbActivityTypeName.ID = this.ID + "_tbActivityTypeName"; _tbActivityTypeName.Label = "Name"; _tbActivityTypeName.Required = true; _tbActivityTypeName.Attributes["onblur"] = string.Format("javascript: $('#{0}').text($(this).val());", _lblActivityTypeName.ID); _tbActivityTypeDescription = new RockTextBox(); Controls.Add(_tbActivityTypeDescription); _tbActivityTypeDescription.ID = this.ID + "_tbActivityTypeDescription"; _tbActivityTypeDescription.Label = "Description"; _tbActivityTypeDescription.TextMode = TextBoxMode.MultiLine; _tbActivityTypeDescription.Rows = 2; _tbActivityTypeDescription.Attributes["onblur"] = string.Format("javascript: $('#{0}').text($(this).val());", _lblActivityTypeDescription.ID); _cbActivityTypeIsActivatedWithWorkflow = new RockCheckBox { Text = "Activated with Workflow" }; Controls.Add(_cbActivityTypeIsActivatedWithWorkflow); _cbActivityTypeIsActivatedWithWorkflow.ID = this.ID + "_cbActivityTypeIsActivatedWithWorkflow"; checkboxScriptFormat = @" javascript: if ($(this).is(':checked')) {{ $('#{0}').addClass('activated-with-workflow'); }} else {{ $('#{0}').removeClass('activated-with-workflow'); }} "; _cbActivityTypeIsActivatedWithWorkflow.InputAttributes.Add("onclick", string.Format(checkboxScriptFormat, this.ID + "_section")); _lbAddActionType = new LinkButton(); Controls.Add(_lbAddActionType); _lbAddActionType.ID = this.ID + "_lbAddAction"; _lbAddActionType.CssClass = "btn btn-xs btn-action add-action"; _lbAddActionType.Click += lbAddActionType_Click; _lbAddActionType.CausesValidation = false; _lbAddActionType.Controls.Add(new LiteralControl { Text = "<i class='fa fa-plus'></i> Add Action" }); _pwAttributes = new PanelWidget(); Controls.Add(_pwAttributes); _pwAttributes.ID = this.ID + "_pwAttributes"; _pwAttributes.Title = "Activity Attributes"; _pwAttributes.CssClass = "attribute-panel"; _gAttributes = new Grid(); _pwAttributes.Controls.Add(_gAttributes); _gAttributes.ID = this.ID + "_gAttributes"; _gAttributes.AllowPaging = false; _gAttributes.DisplayType = GridDisplayType.Light; _gAttributes.RowItemText = "Activity Attribute"; _gAttributes.AddCssClass("attribute-grid"); _gAttributes.DataKeyNames = new string[] { "Guid" }; _gAttributes.Actions.ShowAdd = true; _gAttributes.Actions.AddClick += gAttributes_Add; _gAttributes.GridRebind += gAttributes_Rebind; _gAttributes.GridReorder += gAttributes_Reorder; _gAttributes.ShowActionsInHeader = false; var reorderField = new ReorderField(); _gAttributes.Columns.Add(reorderField); var nameField = new BoundField(); nameField.DataField = "Name"; nameField.HeaderText = "Attribute"; _gAttributes.Columns.Add(nameField); var descField = new BoundField(); descField.DataField = "Description"; descField.HeaderText = "Description"; _gAttributes.Columns.Add(descField); var fieldTypeField = new BoundField(); fieldTypeField.DataField = "FieldType"; fieldTypeField.HeaderText = "Field Type"; _gAttributes.Columns.Add(fieldTypeField); var reqField = new BoolField(); reqField.DataField = "IsRequired"; reqField.HeaderText = "Required"; _gAttributes.Columns.Add(reqField); var editField = new EditField(); editField.Click += gAttributes_Edit; _gAttributes.Columns.Add(editField); var delField = new DeleteField(); delField.Click += gAttributes_Delete; _gAttributes.Columns.Add(delField); }
/// <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 ) { PanelWidget panelWidget = new PanelWidget(); panelWidget.ID = string.Format( "reportFieldWidget_{0}", reportFieldGuid.ToString( "N" ) ); panelWidget.ShowDeleteButton = true; panelWidget.DeleteClick += FieldsPanelWidget_DeleteClick; panelWidget.ShowReorderIcon = true; panelWidget.Expanded = showExpanded; Label lbFields = new Label(); lbFields.Text = "Field Type"; RockDropDownList ddlFields = new RockDropDownList(); panelWidget.Controls.Add( ddlFields ); ddlFields.ID = panelWidget.ID + "_ddlFields"; ddlFields.AutoPostBack = true; ddlFields.SelectedIndexChanged += ddlFields_SelectedIndexChanged; panelWidget.HeaderControls = new Control[2] { lbFields, ddlFields }; this.LoadFieldsDropDown( ddlFields ); RockCheckBox showInGridCheckBox = new RockCheckBox(); showInGridCheckBox.ID = panelWidget.ID + "_showInGridCheckBox"; showInGridCheckBox.Text = "Show in Grid"; panelWidget.Controls.Add( showInGridCheckBox ); RockTextBox columnHeaderTextTextBox = new RockTextBox(); columnHeaderTextTextBox.ID = panelWidget.ID + "_columnHeaderTextTextBox"; columnHeaderTextTextBox.Label = "Column Label"; columnHeaderTextTextBox.CssClass = "js-column-header-textbox"; panelWidget.Controls.Add( columnHeaderTextTextBox ); phReportFields.Controls.Add( panelWidget ); CreateFieldTypeSpecificControls( reportFieldType, fieldSelection, panelWidget ); if ( setReportFieldValues ) { PopulateFieldPanelWidget( panelWidget, reportField, reportFieldType, fieldSelection ); } }
/// <summary> /// Creates the data select controls. /// </summary> /// <param name="reportFieldType">Type of the report field.</param> /// <param name="fieldSelection">The field selection.</param> /// <param name="panelWidget">The panel widget.</param> private void CreateFieldTypeSpecificControls( ReportFieldType reportFieldType, string fieldSelection, PanelWidget panelWidget ) { PlaceHolder phDataSelectControls = panelWidget.ControlsOfTypeRecursive<PlaceHolder>().FirstOrDefault( a => a.ID == panelWidget.ID + "_phDataSelectControls" ); if ( phDataSelectControls == null ) { phDataSelectControls = new PlaceHolder(); phDataSelectControls.ID = panelWidget.ID + "_phDataSelectControls"; panelWidget.Controls.Add( phDataSelectControls ); } phDataSelectControls.Controls.Clear(); if ( reportFieldType == ReportFieldType.DataSelectComponent ) { string dataSelectComponentTypeName = EntityTypeCache.Read( fieldSelection.AsInteger() ).GetEntityType().FullName; DataSelectComponent dataSelectComponent = Rock.Reporting.DataSelectContainer.GetComponent( dataSelectComponentTypeName ); if ( dataSelectComponent != null ) { var dataSelectControls = dataSelectComponent.CreateChildControls( phDataSelectControls ); } } }
private void BuildAttributes( RockContext rockContext, bool setValues = false ) { var selectedCategories = new List<CategoryCache>(); foreach ( string categoryGuid in GetAttributeValue( "AttributeCategories" ).SplitDelimitedValues() ) { var category = CategoryCache.Read( categoryGuid.AsGuid(), rockContext ); if ( category != null ) { selectedCategories.Add( category ); } } int categoryIndex = 0; foreach( var category in selectedCategories.OrderBy( c => c.Name ) ) { var pw = new PanelWidget(); if ( categoryIndex % 2 == 0) { phAttributesCol1.Controls.Add( pw ); } else { phAttributesCol2.Controls.Add( pw ); } pw.ID = "pwAttributes_" + category.Id.ToString(); categoryIndex++; if ( !string.IsNullOrWhiteSpace( category.IconCssClass ) ) { pw.TitleIconCssClass = category.IconCssClass; } pw.Title = category.Name; var orderedAttributeList = new AttributeService( rockContext ).GetByCategoryId( category.Id ) .OrderBy( a => a.Order ).ThenBy( a => a.Name ); foreach ( var attribute in orderedAttributeList ) { if ( attribute.IsAuthorized( Authorization.EDIT, CurrentPerson ) ) { var attributeCache = AttributeCache.Read( attribute.Id ); string clientId = string.Format( "{0}_attribute_field_{1}", pw.ClientID, attribute.Id ); bool controlEnabled = SelectedFields.Contains( clientId, StringComparer.OrdinalIgnoreCase ); string iconCss = controlEnabled ? "fa-check-circle-o" : "fa-circle-o"; string labelText = string.Format( "<span class='js-select-item'><i class='fa {0}'></i></span> {1}", iconCss, attributeCache.Name ); Control control = attributeCache.AddControl( pw.Controls, string.Empty, string.Empty, setValues, true, false, labelText ); if ( !( control is RockCheckBox ) ) { var webControl = control as WebControl; if ( webControl != null ) { webControl.Enabled = controlEnabled; } } } } } }
/// <summary> /// Populates the field panel widget. /// </summary> /// <param name="panelWidget">The panel widget.</param> /// <param name="reportField">The report field.</param> /// <param name="reportFieldType">Type of the report field.</param> /// <param name="fieldSelection">The field selection.</param> private void PopulateFieldPanelWidget( PanelWidget panelWidget, ReportField reportField, ReportFieldType reportFieldType, string fieldSelection ) { int entityTypeId = etpEntityType.SelectedEntityTypeId ?? 0; if ( entityTypeId == 0 ) { return; } string defaultColumnHeaderText = null; DataSelectComponent dataSelectComponent = null; bool fieldDefined = false; switch ( reportFieldType ) { case ReportFieldType.Property: var entityType = EntityTypeCache.Read( entityTypeId ).GetEntityType(); var entityField = EntityHelper.GetEntityFields( entityType ).FirstOrDefault( a => a.Name == fieldSelection ); if ( entityField != null ) { defaultColumnHeaderText = entityField.Title; fieldDefined = true; } break; case ReportFieldType.Attribute: var attribute = AttributeCache.Read( fieldSelection.AsGuid() ); if ( attribute != null ) { defaultColumnHeaderText = attribute.Name; fieldDefined = true; } break; case ReportFieldType.DataSelectComponent: string dataSelectComponentTypeName = EntityTypeCache.Read( fieldSelection.AsInteger() ).GetEntityType().FullName; dataSelectComponent = Rock.Reporting.DataSelectContainer.GetComponent( dataSelectComponentTypeName ); if ( dataSelectComponent != null ) { defaultColumnHeaderText = dataSelectComponent.ColumnHeaderText; fieldDefined = true; } break; } if ( !fieldDefined ) { // return if we can't determine field return; } RockDropDownList ddlFields = panelWidget.ControlsOfTypeRecursive<RockDropDownList>().FirstOrDefault( a => a.ID == panelWidget.ID + "_ddlFields" ); if ( reportField.ReportFieldType == ReportFieldType.Attribute ) { ddlFields.SelectedValue = string.Format( "{0}|{1}", reportField.ReportFieldType, reportField.Selection ); } else if ( reportField.ReportFieldType == ReportFieldType.Property ) { ddlFields.SelectedValue = string.Format( "{0}|{1}", reportField.ReportFieldType, reportField.Selection ); } else if ( reportField.ReportFieldType == ReportFieldType.DataSelectComponent ) { ddlFields.SelectedValue = string.Format( "{0}|{1}", reportField.ReportFieldType, dataSelectComponent.TypeId ); } string fieldTitle = string.IsNullOrWhiteSpace( reportField.ColumnHeaderText ) ? defaultColumnHeaderText : reportField.ColumnHeaderText; panelWidget.Title = fieldTitle; RockCheckBox showInGridCheckBox = panelWidget.ControlsOfTypeRecursive<RockCheckBox>().FirstOrDefault( a => a.ID == panelWidget.ID + "_showInGridCheckBox" ); showInGridCheckBox.Checked = reportField.ShowInGrid; RockTextBox columnHeaderTextTextBox = panelWidget.ControlsOfTypeRecursive<RockTextBox>().FirstOrDefault( a => a.ID == panelWidget.ID + "_columnHeaderTextTextBox" ); columnHeaderTextTextBox.Text = string.IsNullOrWhiteSpace( reportField.ColumnHeaderText ) ? defaultColumnHeaderText : reportField.ColumnHeaderText; if ( dataSelectComponent != null ) { PlaceHolder phDataSelectControls = panelWidget.ControlsOfTypeRecursive<PlaceHolder>().FirstOrDefault( a => a.ID == panelWidget.ID + "_phDataSelectControls" ); if ( phDataSelectControls != null ) { var dataSelectControls = phDataSelectControls.Controls.OfType<Control>().ToArray(); dataSelectComponent.SetSelection( dataSelectControls, reportField.Selection ?? string.Empty ); } } }
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" } ); 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" } ); } 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; } }
/// <summary> /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering. /// </summary> protected override void CreateChildControls() { Controls.Clear(); _hfExpanded = new HiddenFieldWithClass(); Controls.Add( _hfExpanded ); _hfExpanded.ID = this.ID + "_hfExpanded"; _hfExpanded.CssClass = "filter-expanded"; _hfExpanded.Value = "False"; _hfActivityTypeGuid = new HiddenField(); Controls.Add( _hfActivityTypeGuid ); _hfActivityTypeGuid.ID = this.ID + "_hfActivityTypeGuid"; _lblActivityTypeName = new Label(); Controls.Add( _lblActivityTypeName ); _lblActivityTypeName.ClientIDMode = ClientIDMode.Static; _lblActivityTypeName.ID = this.ID + "_lblActivityTypeName"; _lblActivityTypeDescription = new Label(); Controls.Add( _lblActivityTypeDescription ); _lblActivityTypeDescription.ClientIDMode = ClientIDMode.Static; _lblActivityTypeDescription.ID = this.ID + "_lblActivityTypeDescription"; _lblInactive = new Label(); Controls.Add( _lblInactive ); _lblInactive.ClientIDMode = ClientIDMode.Static; _lblInactive.ID = this.ID + "_lblInactive"; _lblInactive.CssClass = "pull-right"; _lblInactive.Text = "<span class='label label-danger'>Inactive</span>"; _lbDeleteActivityType = new LinkButton(); Controls.Add( _lbDeleteActivityType ); _lbDeleteActivityType.CausesValidation = false; _lbDeleteActivityType.ID = this.ID + "_lbDeleteActivityType"; _lbDeleteActivityType.CssClass = "btn btn-xs btn-danger js-activity-delete"; _lbDeleteActivityType.Click += lbDeleteActivityType_Click; _lbDeleteActivityType.Controls.Add( new LiteralControl { Text = "<i class='fa fa-times'></i>" } ); _sbSecurity = new SecurityButton(); Controls.Add( _sbSecurity ); _sbSecurity.ID = this.ID + "_sbSecurity"; _sbSecurity.Attributes["class"] = "btn btn-security btn-xs security pull-right"; _sbSecurity.EntityTypeId = EntityTypeCache.Read( typeof( Rock.Model.WorkflowActivityType ) ).Id; _cbActivityTypeIsActive = new RockCheckBox { Text = "Active" }; Controls.Add( _cbActivityTypeIsActive ); _cbActivityTypeIsActive.ID = this.ID + "_cbActivityTypeIsActive"; string checkboxScriptFormat = @" javascript: if ($(this).is(':checked')) {{ $('#{0}').hide(); $('#{1}').removeClass('workflow-activity-inactive'); }} else {{ $('#{0}').show(); $('#{1}').addClass('workflow-activity-inactive'); }} "; _cbActivityTypeIsActive.InputAttributes.Add( "onclick", string.Format( checkboxScriptFormat, _lblInactive.ID, this.ID + "_section" ) ); _tbActivityTypeName = new RockTextBox(); Controls.Add( _tbActivityTypeName ); _tbActivityTypeName.ID = this.ID + "_tbActivityTypeName"; _tbActivityTypeName.Label = "Name"; _tbActivityTypeName.Required = true; _tbActivityTypeName.Attributes["onblur"] = string.Format( "javascript: $('#{0}').text($(this).val());", _lblActivityTypeName.ID ); _tbActivityTypeDescription = new RockTextBox(); Controls.Add( _tbActivityTypeDescription ); _tbActivityTypeDescription.ID = this.ID + "_tbActivityTypeDescription"; _tbActivityTypeDescription.Label = "Description"; _tbActivityTypeDescription.TextMode = TextBoxMode.MultiLine; _tbActivityTypeDescription.Rows = 2; _tbActivityTypeDescription.Attributes["onblur"] = string.Format( "javascript: $('#{0}').text($(this).val());", _lblActivityTypeDescription.ID ); _cbActivityTypeIsActivatedWithWorkflow = new RockCheckBox { Text = "Activated with Workflow" }; Controls.Add( _cbActivityTypeIsActivatedWithWorkflow ); _cbActivityTypeIsActivatedWithWorkflow.ID = this.ID + "_cbActivityTypeIsActivatedWithWorkflow"; checkboxScriptFormat = @" javascript: if ($(this).is(':checked')) {{ $('#{0}').addClass('activated-with-workflow'); }} else {{ $('#{0}').removeClass('activated-with-workflow'); }} "; _cbActivityTypeIsActivatedWithWorkflow.InputAttributes.Add( "onclick", string.Format( checkboxScriptFormat, this.ID + "_section" ) ); _lbAddActionType = new LinkButton(); Controls.Add( _lbAddActionType ); _lbAddActionType.ID = this.ID + "_lbAddAction"; _lbAddActionType.CssClass = "btn btn-xs btn-action"; _lbAddActionType.Click += lbAddActionType_Click; _lbAddActionType.CausesValidation = false; _lbAddActionType.Controls.Add( new LiteralControl { Text = "<i class='fa fa-plus'></i> Add Action" } ); _pwAttributes = new PanelWidget(); Controls.Add( _pwAttributes ); _pwAttributes.ID = this.ID + "_pwAttributes"; _pwAttributes.Title = "Activity Attributes"; _pwAttributes.CssClass = "attribute-panel"; _gAttributes = new Grid(); _pwAttributes.Controls.Add( _gAttributes ); _gAttributes.ID = this.ID + "_gAttributes"; _gAttributes.AllowPaging = false; _gAttributes.DisplayType = GridDisplayType.Light; _gAttributes.RowItemText = "Activity Attribute"; _gAttributes.AddCssClass( "attribute-grid" ); _gAttributes.DataKeyNames = new string[] { "Guid" }; _gAttributes.Actions.ShowAdd = true; _gAttributes.Actions.AddClick += gAttributes_Add; _gAttributes.GridRebind += gAttributes_Rebind; _gAttributes.GridReorder += gAttributes_Reorder; var reorderField = new ReorderField(); _gAttributes.Columns.Add( reorderField ); var nameField = new BoundField(); nameField.DataField = "Name"; nameField.HeaderText = "Attribute"; _gAttributes.Columns.Add( nameField ); var descField = new BoundField(); descField.DataField = "Description"; descField.HeaderText = "Description"; _gAttributes.Columns.Add( descField ); var fieldTypeField = new BoundField(); fieldTypeField.DataField = "FieldType"; fieldTypeField.HeaderText = "Field Type"; _gAttributes.Columns.Add( fieldTypeField ); var reqField = new BoolField(); reqField.DataField = "IsRequired"; reqField.HeaderText = "Required"; _gAttributes.Columns.Add( reqField ); var editField = new EditField(); editField.Click += gAttributes_Edit; _gAttributes.Columns.Add( editField ); var delField = new DeleteField(); delField.Click += gAttributes_Delete; _gAttributes.Columns.Add( delField ); }
/// <summary> /// Creates the child controls. /// </summary> /// <returns></returns> public override Control[] CreateChildControls( Type entityType, FilterField filterControl ) { rp = new RegistrationTemplatePicker(); rp.ID = filterControl.ID + "_rp"; rp.Label = "RegistrationTemplate(s)"; rp.CssClass = "js-group-picker"; rp.AllowMultiSelect = true; rp.Help = "Select the registration templates that you want the registrants for. Leaving this blank will not restrict results to a registration template."; filterControl.Controls.Add( rp ); cbIncludeInactiveRegistrationInstances = new RockCheckBox(); cbIncludeInactiveRegistrationInstances.ID = filterControl.ID + "_cbIncludeInactiveRegistrationInstances"; cbIncludeInactiveRegistrationInstances.Text = "Include Inactive Registration Instances"; cbIncludeInactiveRegistrationInstances.CssClass = "js-include-inactive-groups"; cbIncludeInactiveRegistrationInstances.AutoPostBack = true; filterControl.Controls.Add( cbIncludeInactiveRegistrationInstances ); PanelWidget pwAdvanced = new PanelWidget(); filterControl.Controls.Add( pwAdvanced ); pwAdvanced.ID = filterControl.ID + "_pwAttributes"; pwAdvanced.Title = "Advanced Filters"; pwAdvanced.CssClass = "advanced-panel"; SlidingDateRangePicker registeredOnDateRangePicker = new SlidingDateRangePicker(); registeredOnDateRangePicker.ID = pwAdvanced.ID + "_addedOnDateRangePicker"; registeredOnDateRangePicker.AddCssClass( "js-sliding-date-range" ); registeredOnDateRangePicker.Label = "Date Registered:"; registeredOnDateRangePicker.Help = "Select the date range that the person was registered. Leaving this blank will not restrict results to a date range."; pwAdvanced.Controls.Add( registeredOnDateRangePicker ); return new Control[4] { rp, cbIncludeInactiveRegistrationInstances, registeredOnDateRangePicker, pwAdvanced }; }
/// <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> /// Creates the child controls. /// </summary> /// <returns></returns> public override Control[] CreateChildControls( Type entityType, FilterField filterControl ) { gp = new GroupPicker(); gp.ID = filterControl.ID + "_gp"; gp.Label = "Group(s)"; gp.SelectItem += gp_SelectItem; gp.CssClass = "js-group-picker"; gp.AllowMultiSelect = true; filterControl.Controls.Add( gp ); cbChildGroups = new RockCheckBox(); cbChildGroups.ID = filterControl.ID + "_cbChildsGroups"; cbChildGroups.Text = "Include Child Group(s)"; cbChildGroups.CssClass = "js-include-child-groups"; cbChildGroups.AutoPostBack = true; cbChildGroups.CheckedChanged += gp_SelectItem; filterControl.Controls.Add( cbChildGroups ); cbIncludeSelectedGroup = new RockCheckBox(); cbIncludeSelectedGroup.ID = filterControl.ID + "_cbIncludeSelectedGroup"; cbIncludeSelectedGroup.Text = "Include Selected Group(s)"; cbIncludeSelectedGroup.CssClass = "js-include-selected-groups"; cbIncludeSelectedGroup.AutoPostBack = true; cbIncludeSelectedGroup.CheckedChanged += gp_SelectItem; filterControl.Controls.Add( cbIncludeSelectedGroup ); cbChildGroupsPlusDescendants = new RockCheckBox(); cbChildGroupsPlusDescendants.ID = filterControl.ID + "_cbChildGroupsPlusDescendants"; cbChildGroupsPlusDescendants.Text = "Include All Descendants(s)"; cbChildGroupsPlusDescendants.CssClass = "js-include-child-groups-descendants"; cbChildGroupsPlusDescendants.AutoPostBack = true; cbChildGroupsPlusDescendants.CheckedChanged += gp_SelectItem; filterControl.Controls.Add( cbChildGroupsPlusDescendants ); cbIncludeInactiveGroups = new RockCheckBox(); cbIncludeInactiveGroups.ID = filterControl.ID + "_cbIncludeInactiveGroups"; cbIncludeInactiveGroups.Text = "Include Inactive Groups"; cbIncludeInactiveGroups.CssClass = "js-include-inactive-groups"; cbIncludeInactiveGroups.AutoPostBack = true; cbIncludeInactiveGroups.CheckedChanged += gp_SelectItem; filterControl.Controls.Add( cbIncludeInactiveGroups ); cblRole = new RockCheckBoxList(); cblRole.Label = "with Group Member Role(s) (optional)"; cblRole.ID = filterControl.ID + "_cblRole"; cblRole.CssClass = "js-roles"; cblRole.Visible = false; filterControl.Controls.Add( cblRole ); RockDropDownList ddlGroupMemberStatus = new RockDropDownList(); ddlGroupMemberStatus.CssClass = "js-group-member-status"; ddlGroupMemberStatus.ID = filterControl.ID + "_ddlGroupMemberStatus"; ddlGroupMemberStatus.Label = "with Group Member Status"; ddlGroupMemberStatus.Help = "Select a specific group member status to only include group members with that status. Leaving this blank will return all members."; ddlGroupMemberStatus.BindToEnum<GroupMemberStatus>( true ); ddlGroupMemberStatus.SetValue( GroupMemberStatus.Active.ConvertToInt() ); filterControl.Controls.Add( ddlGroupMemberStatus ); PanelWidget pwAdvanced = new PanelWidget(); filterControl.Controls.Add( pwAdvanced ); pwAdvanced.ID = filterControl.ID + "_pwAttributes"; pwAdvanced.Title = "Advanced Filters"; pwAdvanced.CssClass = "advanced-panel"; SlidingDateRangePicker addedOnDateRangePicker = new SlidingDateRangePicker(); addedOnDateRangePicker.ID = pwAdvanced.ID + "_addedOnDateRangePicker"; addedOnDateRangePicker.AddCssClass( "js-sliding-date-range" ); addedOnDateRangePicker.Label = "Date Added:"; addedOnDateRangePicker.Help = "Select the date range that the person was added to the group. Leaving this blank will not restrict results to a date range."; pwAdvanced.Controls.Add( addedOnDateRangePicker ); return new Control[9] { gp, cbChildGroups, cbIncludeSelectedGroup, cbChildGroupsPlusDescendants, cblRole, ddlGroupMemberStatus, cbIncludeInactiveGroups, addedOnDateRangePicker, pwAdvanced }; }
/// <summary> /// Creates the data select controls. /// </summary> /// <param name="reportFieldType">Type of the report field.</param> /// <param name="fieldSelection">The field selection.</param> /// <param name="panelWidget">The panel widget.</param> /// <param name="rockContext">The rock context.</param> private void CreateFieldTypeSpecificControls( ReportFieldType reportFieldType, string fieldSelection, PanelWidget panelWidget, RockContext rockContext ) { PlaceHolder phDataSelectControls = panelWidget.ControlsOfTypeRecursive<PlaceHolder>().FirstOrDefault( a => a.ID == panelWidget.ID + "_phDataSelectControls" ); if ( phDataSelectControls == null ) { phDataSelectControls = new PlaceHolder(); phDataSelectControls.ID = panelWidget.ID + "_phDataSelectControls"; panelWidget.Controls.Add( phDataSelectControls ); } phDataSelectControls.Controls.Clear(); if ( reportFieldType == ReportFieldType.DataSelectComponent ) { var dataSelectComponent = GetDataSelectComponent( rockContext, fieldSelection.AsInteger() ); if ( dataSelectComponent != null ) { dataSelectComponent.CreateChildControls( phDataSelectControls ); } } }
private void BuildAttributes( bool setValues ) { var rockContext = new RockContext(); var selectedCategories = new List<CategoryCache>(); foreach ( string categoryGuid in GetAttributeValue( "AttributeCategories" ).SplitDelimitedValues() ) { var category = CategoryCache.Read( categoryGuid.AsGuid(), rockContext ); if ( category != null ) { selectedCategories.Add( category ); } } int categoryIndex = 0; foreach( var category in selectedCategories.OrderBy( c => c.Name ) ) { var pw = new PanelWidget(); pw.ID = "pwAttributes_" + category.Id.ToString(); if ( categoryIndex % 2 == 0) { phAttributesCol1.Controls.Add( pw ); } else { phAttributesCol2.Controls.Add( pw ); } categoryIndex++; if ( !string.IsNullOrWhiteSpace( category.IconCssClass ) ) { pw.TitleIconCssClass = category.IconCssClass; } pw.Title = category.Name; var orderedAttributeList = new AttributeService( rockContext ).GetByCategoryId( category.Id ) .OrderBy( a => a.Order ).ThenBy( a => a.Name ); foreach ( var attribute in orderedAttributeList ) { if ( attribute.IsAuthorized( Authorization.EDIT, CurrentPerson ) ) { var attributeCache = AttributeCache.Read( attribute.Id ); attributeCache.AddControl( pw.Controls, string.Empty, string.Empty, setValues, true, false ); } } } }
/// <summary> /// Selecteds the field type supports sorting. /// </summary> /// <param name="panelWidget">The panel widget.</param> /// <returns></returns> private bool SelectedFieldTypeSupportsSorting( PanelWidget panelWidget ) { try { string ddlFieldsId = panelWidget.ID + "_ddlFields"; RockDropDownList ddlFields = phReportFields.ControlsOfTypeRecursive<RockDropDownList>().First( a => a.ID == ddlFieldsId ); bool fieldSupportsSorting = true; var fieldTypeSelection = GetSelectedFieldTypeSelection( ddlFields ); if ( fieldTypeSelection != null ) { if ( fieldTypeSelection.ReportFieldType == ReportFieldType.DataSelectComponent ) { var entityTypeId = fieldTypeSelection.FieldSelection.AsIntegerOrNull(); if ( entityTypeId.HasValue ) { var dataSelectComponent = this.GetDataSelectComponent( new RockContext(), entityTypeId.Value ); if ( dataSelectComponent != null ) { if ( dataSelectComponent.SortProperties( string.Empty ) == string.Empty ) { fieldSupportsSorting = false; } } } } } return fieldSupportsSorting; } catch { // if an exception occurred, ignore and assume it supports sorting return true; } }
/// <summary> /// Populates the field panel widget. /// </summary> /// <param name="panelWidget">The panel widget.</param> /// <param name="reportField">The report field.</param> /// <param name="reportFieldType">Type of the report field.</param> /// <param name="fieldSelection">The field selection.</param> /// <param name="rockContext">The rock context.</param> private void PopulateFieldPanelWidget( PanelWidget panelWidget, ReportField reportField, ReportFieldType reportFieldType, string fieldSelection, RockContext rockContext ) { int entityTypeId = etpEntityType.SelectedEntityTypeId ?? 0; if ( entityTypeId == 0 ) { return; } string defaultColumnHeaderText = null; DataSelectComponent dataSelectComponent = null; bool fieldDefined = false; switch ( reportFieldType ) { case ReportFieldType.Property: var entityType = EntityTypeCache.Read( entityTypeId, rockContext ).GetEntityType(); var entityField = EntityHelper.GetEntityFields( entityType ).FirstOrDefault( a => a.Name == fieldSelection ); if ( entityField != null ) { defaultColumnHeaderText = entityField.Title; fieldDefined = true; } break; case ReportFieldType.Attribute: var attribute = AttributeCache.Read( fieldSelection.AsGuid(), rockContext ); if ( attribute != null ) { defaultColumnHeaderText = attribute.Name; fieldDefined = true; } break; case ReportFieldType.DataSelectComponent: dataSelectComponent = this.GetDataSelectComponent( rockContext, fieldSelection.AsInteger() ); if ( dataSelectComponent != null ) { defaultColumnHeaderText = dataSelectComponent.ColumnHeaderText; fieldDefined = true; } break; } // Show the common field properties. string fieldTitle = string.IsNullOrWhiteSpace( reportField.ColumnHeaderText ) ? defaultColumnHeaderText : reportField.ColumnHeaderText; panelWidget.Title = fieldTitle; RockCheckBox showInGridCheckBox = panelWidget.ControlsOfTypeRecursive<RockCheckBox>().FirstOrDefault( a => a.ID == panelWidget.ID + "_showInGridCheckBox" ); showInGridCheckBox.Checked = reportField.ShowInGrid; RockTextBox columnHeaderTextTextBox = panelWidget.ControlsOfTypeRecursive<RockTextBox>().FirstOrDefault( a => a.ID == panelWidget.ID + "_columnHeaderTextTextBox" ); columnHeaderTextTextBox.Text = string.IsNullOrWhiteSpace( reportField.ColumnHeaderText ) ? defaultColumnHeaderText : reportField.ColumnHeaderText; // Show settings that are specific to the field type. if ( !fieldDefined ) { // return if we can't determine field return; } RockDropDownList ddlFields = panelWidget.ControlsOfTypeRecursive<RockDropDownList>().FirstOrDefault( a => a.ID == panelWidget.ID + "_ddlFields" ); if ( reportField.ReportFieldType == ReportFieldType.Attribute ) { var selectedValue = string.Format( "{0}|{1}", reportField.ReportFieldType, reportField.Selection ); if ( ddlFields.Items.OfType<ListItem>().Any( a => a.Value == selectedValue ) ) { ddlFields.SelectedValue = selectedValue; } else { // if this EntityField is not available for the current person, but this reportField already has it configured, let them keep it var attribute = AttributeCache.Read( fieldSelection.AsGuid(), rockContext ); ddlFields.Items.Add( new ListItem( attribute.Name, selectedValue ) ); ddlFields.SelectedValue = selectedValue; } } else if ( reportField.ReportFieldType == ReportFieldType.Property ) { ddlFields.SelectedValue = string.Format( "{0}|{1}", reportField.ReportFieldType, reportField.Selection ); } else if ( reportField.ReportFieldType == ReportFieldType.DataSelectComponent ) { ddlFields.SelectedValue = string.Format( "{0}|{1}", reportField.ReportFieldType, dataSelectComponent.TypeId ); } if ( dataSelectComponent != null ) { PlaceHolder phDataSelectControls = panelWidget.ControlsOfTypeRecursive<PlaceHolder>().FirstOrDefault( a => a.ID == panelWidget.ID + "_phDataSelectControls" ); if ( phDataSelectControls != null ) { var dataSelectControls = phDataSelectControls.Controls.OfType<Control>().ToArray(); dataSelectComponent.SetSelection( dataSelectControls, reportField.Selection ?? string.Empty ); } } }