private void BuildDynamicControls() { // Get all the accounts grouped by campus if ( _campusAccounts == null ) { using ( var rockContext = new RockContext() ) { _campusAccounts = new Dictionary<int, Dictionary<int, string>>(); Guid contributionGuid = Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION.AsGuid(); var contributionAccountIds = new FinancialTransactionDetailService( rockContext ) .Queryable().AsNoTracking() .Where( d => d.Transaction != null && d.Transaction.TransactionTypeValue != null && d.Transaction.TransactionTypeValue.Guid.Equals( contributionGuid ) ) .Select( d => d.AccountId ) .Distinct() .ToList(); foreach ( var campusAccounts in new FinancialAccountService( rockContext ) .Queryable().AsNoTracking() .Where( a => a.IsActive && contributionAccountIds.Contains( a.Id ) ) .GroupBy( a => a.CampusId ?? 0 ) .Select( c => new { CampusId = c.Key, Accounts = c.OrderBy( a => a.Name ).Select( a => new { a.Id, a.Name } ).ToList() } ) ) { _campusAccounts.Add( campusAccounts.CampusId, new Dictionary<int, string>() ); foreach ( var account in campusAccounts.Accounts ) { _campusAccounts[campusAccounts.CampusId].Add( account.Id, account.Name ); } } } } phAccounts.Controls.Clear(); foreach( var campusId in _campusAccounts ) { var cbList = new RockCheckBoxList(); cbList.ID = "cblAccounts" + campusId.Key.ToString(); if ( campusId.Key > 0) { var campus = CampusCache.Read( campusId.Key ); cbList.Label = campus != null ? campus.Name + " Accounts" : "Campus " + campusId.Key.ToString(); } else { cbList.Label = "Accounts"; } cbList.RepeatDirection = RepeatDirection.Vertical; cbList.DataValueField = "Key"; cbList.DataTextField = "Value"; cbList.DataSource = campusId.Value; cbList.DataBind(); phAccounts.Controls.Add( cbList ); } }
/// <summary> /// Configures the settings. /// </summary> private void ConfigureSettings() { // toggle refine search view toggle button lbRefineSearch.Visible = GetAttributeValue( "ShowRefinedSearch" ).AsBoolean(); // model selector var enabledModelIds = new List<int>(); if ( GetAttributeValue( "EnabledModels" ).IsNotNullOrWhitespace() ) { enabledModelIds = GetAttributeValue( "EnabledModels" ).Split( ',' ).Select( int.Parse ).ToList(); } var entities = EntityTypeCache.All(); var indexableEntities = entities.Where( i => i.IsIndexingSupported == true && enabledModelIds.Contains( i.Id )).ToList(); cblModelFilter.DataTextField = "FriendlyName"; cblModelFilter.DataValueField = "Id"; cblModelFilter.DataSource = indexableEntities; cblModelFilter.DataBind(); cblModelFilter.Visible = GetAttributeValue( "ShowFilters" ).AsBoolean(); // add dynamic filters if ( GetAttributeValue( "ShowRefinedSearch" ).AsBoolean() ) { foreach ( var entity in indexableEntities ) { var entityType = entity.GetEntityType(); if ( SupportsIndexFieldFiltering( entityType ) ) { var filterOptions = GetIndexFilterConfig( entityType ); RockCheckBoxList filterConfig = new RockCheckBoxList(); filterConfig.Label = filterOptions.FilterLabel; filterConfig.CssClass = "js-entity-id-" + entity.Id.ToString(); filterConfig.RepeatDirection = RepeatDirection.Horizontal; filterConfig.Attributes.Add( "entity-id", entity.Id.ToString() ); filterConfig.Attributes.Add( "entity-filter-field", filterOptions.FilterField ); filterConfig.DataSource = filterOptions.FilterValues; filterConfig.DataBind(); // set any selected values from the query string if(!string.IsNullOrWhiteSpace(PageParameter( filterOptions.FilterField ) ) ) { List<string> selectedValues = PageParameter( filterOptions.FilterField ).Split( ',' ).ToList(); foreach(ListItem item in filterConfig.Items ) { if ( selectedValues.Contains( item.Value ) ) { item.Selected = true; } } } if ( filterOptions.FilterValues.Count > 0 ) { HtmlGenericContainer filterWrapper = new HtmlGenericContainer( "div", "col-md-6" ); filterWrapper.Controls.Add( filterConfig ); phFilters.Controls.Add( filterWrapper ); } } } } // if only one model is selected then hide the type checkbox if (cblModelFilter.Items.Count == 1 ) { cblModelFilter.Visible = false; } ddlSearchType.BindToEnum<SearchType>(); ddlSearchType.SelectedValue = GetAttributeValue( "SearchType" ); // override the block setting if passed in the query string if ( !string.IsNullOrWhiteSpace( PageParameter( "SearchType" ) ) ) { ddlSearchType.SelectedValue = PageParameter( "SearchType" ); } // set setting values from query string if ( !string.IsNullOrWhiteSpace( PageParameter( "Models" ) ) ) { var queryStringModels = PageParameter( "Models" ).Split( ',' ).Select( s => s.Trim() ).ToList(); foreach ( ListItem item in cblModelFilter.Items ) { if ( queryStringModels.Contains( item.Value ) ) { item.Selected = true; } else { item.Selected = false; } } } if ( !string.IsNullOrWhiteSpace( PageParameter( "ItemsPerPage" ) ) ) { _itemsPerPage = PageParameter( "ItemsPerPage" ).AsInteger(); } if ( !string.IsNullOrWhiteSpace( PageParameter( "CurrentPage" ) ) ) { _currentPageNum = PageParameter( "CurrentPage" ).AsInteger(); } if ( !string.IsNullOrWhiteSpace( PageParameter( "RefinedSearch" ) ) ) { pnlRefineSearch.Visible = PageParameter( "RefinedSearch" ).AsBoolean(); if ( pnlRefineSearch.Visible ) { lbRefineSearch.Text = "Hide Refined Search"; } } _itemsPerPage = GetAttributeValue( "ResultsPerPage" ).AsInteger(); }
private void BuildDynamicControls() { // Get all the accounts grouped by campus if ( _campusAccounts == null ) { using ( var rockContext = new RockContext() ) { _campusAccounts = new Dictionary<int, Dictionary<int, string>>(); foreach ( var campusAccounts in new FinancialAccountService( rockContext ) .Queryable().AsNoTracking() .Where( a => a.IsActive && a.IsTaxDeductible ) .GroupBy( a => a.CampusId ?? 0 ) .Select( c => new { CampusId = c.Key, Accounts = c.OrderBy( a => a.Name ).Select( a => new { a.Id, a.Name } ).ToList() } ) ) { _campusAccounts.Add( campusAccounts.CampusId, new Dictionary<int, string>() ); foreach ( var account in campusAccounts.Accounts ) { _campusAccounts[campusAccounts.CampusId].Add( account.Id, account.Name ); } } } } phAccounts.Controls.Clear(); foreach ( var campusId in _campusAccounts ) { var cbList = new RockCheckBoxList(); cbList.ID = "cblAccounts" + campusId.Key.ToString(); if ( campusId.Key > 0 ) { var campus = CampusCache.Read( campusId.Key ); cbList.Label = campus != null ? campus.Name + " Accounts" : "Campus " + campusId.Key.ToString(); } else { cbList.Label = "Accounts"; } cbList.RepeatDirection = RepeatDirection.Vertical; cbList.DataValueField = "Key"; cbList.DataTextField = "Value"; cbList.DataSource = campusId.Value; cbList.DataBind(); phAccounts.Controls.Add( cbList ); } }