Inheritance: System.Web.UI.WebControls.PlaceHolder, IRockControl
        /// <summary>
        /// Adds the attribute columns.
        /// </summary>
        private void AddDynamicControls()
        {
            // Clear the filter controls
            phAttributeFilters.Controls.Clear();

            if ( SearchAttributes != null )
            {
                foreach ( var attribute in SearchAttributes )
                {
                    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 );
                        }
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Adds the attribute columns.
        /// </summary>
        private void AddDynamicControls()
        {
            // Clear the filter controls
            phAttributeFilters.Controls.Clear();

            // Remove attribute columns
            foreach ( var column in gGroupMembers.Columns.OfType<AttributeField>().ToList() )
            {
                gGroupMembers.Columns.Remove( column );
            }

            if ( AvailableAttributes != null )
            {
                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 = rFilter.GetUserPreference( MakeKeyUniqueToGroup( 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 = gGroupMembers.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;
                        }

                        gGroupMembers.Columns.Add( boundField );
                    }
                }
            }

            // Add Place Elsewhere column if the group or group type has any Place Elsewhere member triggers
            if ( _group != null && _group.GroupType != null )
            {
                if ( _group.GetGroupMemberWorkflowTriggers().Where( a => a.TriggerType == GroupMemberWorkflowTriggerType.MemberPlacedElsewhere ).Any() )
                {
                    AddPlaceElsewhereColumn();
                }
            }

            // Add Link to Profile Page Column
            if ( !string.IsNullOrEmpty( GetAttributeValue( "PersonProfilePage" ) ) )
            {
                AddPersonProfileLinkColumn();
            }

            // Add delete column
            var deleteField = new DeleteField();
            gGroupMembers.Columns.Add( deleteField );
            deleteField.Click += DeleteGroupMember_Click;
        }
Beispiel #3
0
        /// <summary>
        /// Adds the filter controls and grid columns for all of the registration template's form fields
        /// that were configured to 'Show on Grid'
        /// </summary>
        private void AddDynamicRegistrantControls()
        {
            phRegistrantFormFieldFilters.Controls.Clear();

            // Remove any of the dynamic person fields
            var dynamicColumns = new List<string> {
                "PersonAlias.Person.BirthDate",
            };
            foreach ( var column in gRegistrants.Columns
                .OfType<BoundField>()
                .Where( c => dynamicColumns.Contains( c.DataField ) )
                .ToList() )
            {
                gRegistrants.Columns.Remove( column );
            }

            // Remove any of the dynamic attribute fields
            foreach ( var column in gRegistrants.Columns
                .OfType<AttributeField>()
                .ToList() )
            {
                gRegistrants.Columns.Remove( column );
            }

            // Remove the fees field
            foreach ( var column in gRegistrants.Columns
                .OfType<TemplateField>()
                .Where( c => c.HeaderText == "Fees" )
                .ToList() )
            {
                gRegistrants.Columns.Remove( column );
            }

            // Remove the delete field
            foreach ( var column in gRegistrants.Columns
                .OfType<DeleteField>()
                .ToList() )
            {
                gRegistrants.Columns.Remove( column );
            }

            if ( RegistrantFields != null )
            {
                foreach ( var field in RegistrantFields )
                {
                    if ( field.FieldSource == RegistrationFieldSource.PersonField && field.PersonFieldType.HasValue )
                    {
                        switch ( field.PersonFieldType.Value )
                        {
                            case RegistrationPersonFieldType.Campus:
                                {
                                    var ddlCampus = new RockDropDownList();
                                    ddlCampus.ID = "ddlCampus";
                                    ddlCampus.Label = "Home Campus";
                                    ddlCampus.DataValueField = "Id";
                                    ddlCampus.DataTextField = "Name";
                                    ddlCampus.DataSource = CampusCache.All();
                                    ddlCampus.DataBind();
                                    ddlCampus.Items.Insert( 0, new ListItem( "", "" ) );
                                    ddlCampus.SetValue( fRegistrants.GetUserPreference( "Home Campus" ) );
                                    phRegistrantFormFieldFilters.Controls.Add( ddlCampus );

                                    var templateField = new TemplateField();
                                    templateField.ItemTemplate = new LiteralFieldTemplate( "lCampus" );
                                    templateField.HeaderText = "Campus";
                                    gRegistrants.Columns.Add( templateField );

                                    break;
                                }

                            case RegistrationPersonFieldType.Email:
                                {
                                    var tbEmailFilter = new RockTextBox();
                                    tbEmailFilter.ID = "tbEmailFilter";
                                    tbEmailFilter.Label = "Email";
                                    tbEmailFilter.Text = fRegistrants.GetUserPreference( "Email" );
                                    phRegistrantFormFieldFilters.Controls.Add( tbEmailFilter );

                                    string dataFieldExpression = "PersonAlias.Person.Email";
                                    var emailField = new BoundField();
                                    emailField.DataField = dataFieldExpression;
                                    emailField.HeaderText = "Email";
                                    emailField.SortExpression = dataFieldExpression;
                                    gRegistrants.Columns.Add( emailField );

                                    break;
                                }

                            case RegistrationPersonFieldType.Birthdate:
                                {
                                    var drpBirthdateFilter = new DateRangePicker();
                                    drpBirthdateFilter.ID = "drpBirthdateFilter";
                                    drpBirthdateFilter.Label = "Birthdate Range";
                                    drpBirthdateFilter.DelimitedValues = fRegistrants.GetUserPreference( "Birthdate Range" );
                                    phRegistrantFormFieldFilters.Controls.Add( drpBirthdateFilter );

                                    string dataFieldExpression = "PersonAlias.Person.BirthDate";
                                    var birthdateField = new DateField();
                                    birthdateField.DataField = dataFieldExpression;
                                    birthdateField.HeaderText = "Birthdate";
                                    birthdateField.SortExpression = dataFieldExpression;
                                    gRegistrants.Columns.Add( birthdateField );

                                    break;
                                }

                            case RegistrationPersonFieldType.Gender:
                                {
                                    var ddlGenderFilter = new RockDropDownList();
                                    ddlGenderFilter.BindToEnum<Gender>( true );
                                    ddlGenderFilter.ID = "ddlGenderFilter";
                                    ddlGenderFilter.Label = "Gender";
                                    ddlGenderFilter.SetValue( fRegistrants.GetUserPreference( "Gender" ) );
                                    phRegistrantFormFieldFilters.Controls.Add( ddlGenderFilter );

                                    string dataFieldExpression = "PersonAlias.Person.Gender";
                                    var genderField = new EnumField();
                                    genderField.DataField = dataFieldExpression;
                                    genderField.HeaderText = "Gender";
                                    genderField.SortExpression = dataFieldExpression;
                                    gRegistrants.Columns.Add( genderField );

                                    break;
                                }

                            case RegistrationPersonFieldType.MaritalStatus:
                                {
                                    var ddlMaritalStatusFilter = new RockDropDownList();
                                    ddlMaritalStatusFilter.BindToDefinedType( DefinedTypeCache.Read( Rock.SystemGuid.DefinedType.PERSON_MARITAL_STATUS.AsGuid() ), true );
                                    ddlMaritalStatusFilter.ID = "ddlMaritalStatusFilter";
                                    ddlMaritalStatusFilter.Label = "Marital Status";
                                    ddlMaritalStatusFilter.SetValue( fRegistrants.GetUserPreference( "Marital Status" ) );
                                    phRegistrantFormFieldFilters.Controls.Add( ddlMaritalStatusFilter );

                                    string dataFieldExpression = "PersonAlias.Person.MaritalStatusValue.Value";
                                    var maritalStatusField = new BoundField();
                                    maritalStatusField.DataField = dataFieldExpression;
                                    maritalStatusField.HeaderText = "MaritalStatus";
                                    maritalStatusField.SortExpression = dataFieldExpression;
                                    gRegistrants.Columns.Add( maritalStatusField );

                                    break;
                                }

                            case RegistrationPersonFieldType.MobilePhone:
                                {
                                    var tbPhoneFilter = new RockTextBox();
                                    tbPhoneFilter.ID = "tbPhoneFilter";
                                    tbPhoneFilter.Label = "Phone";
                                    tbPhoneFilter.Text = fRegistrants.GetUserPreference( "Phone" );
                                    phRegistrantFormFieldFilters.Controls.Add( tbPhoneFilter );

                                    var templateField = new TemplateField();
                                    templateField.ItemTemplate = new LiteralFieldTemplate( "lPhone" );
                                    templateField.HeaderText = "Phone(s)";
                                    gRegistrants.Columns.Add( templateField );

                                    break;
                                }
                        }
                    }

                    else if ( field.Attribute != null )
                    {
                        var attribute = field.Attribute;
                        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;
                                phRegistrantFormFieldFilters.Controls.Add( control );
                            }
                            else
                            {
                                var wrapper = new RockControlWrapper();
                                wrapper.ID = control.ID + "_wrapper";
                                wrapper.Label = attribute.Name;
                                wrapper.Controls.Add( control );
                                phRegistrantFormFieldFilters.Controls.Add( wrapper );
                            }

                            string savedValue = fRegistrants.GetUserPreference( attribute.Key );
                            if ( !string.IsNullOrWhiteSpace( savedValue ) )
                            {
                                try
                                {
                                    var values = JsonConvert.DeserializeObject<List<string>>( savedValue );
                                    attribute.FieldType.Field.SetFilterValues( control, attribute.QualifierValues, values );
                                }
                                catch { }
                            }
                        }

                        string dataFieldExpression = attribute.Id.ToString() + attribute.Key;
                        bool columnExists = gRegistrants.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;
                            }

                            gRegistrants.Columns.Add( boundField );
                        }

                    }
                }
            }

            // Add fee column
            var feeField = new TemplateField();
            feeField.HeaderText = "Fees";
            feeField.ItemTemplate = new LiteralFieldTemplate( "lFees" );
            gRegistrants.Columns.Add( feeField );

            var deleteField = new DeleteField();
            gRegistrants.Columns.Add( deleteField );
            deleteField.Click += gRegistrants_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.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;
                }
            }
        }
        /// <summary>
        /// Adds the attribute columns.
        /// </summary>
        private void AddDynamicControls()
        {
            // Clear the filter controls
            phAttributeFilters.Controls.Clear();

            // Remove attribute columns
            foreach ( var column in gConnectionOpportunities.Columns.OfType<AttributeField>().ToList() )
            {
                gConnectionOpportunities.Columns.Remove( column );
            }

            if ( AvailableAttributes != null )
            {
                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 = rFilter.GetUserPreference( MakeKeyUniqueToConnectionType( attribute.Key ) );
                        if ( !string.IsNullOrWhiteSpace( savedValue ) )
                        {
                            try
                            {
                                var values = JsonConvert.DeserializeObject<List<string>>( savedValue );
                                attribute.FieldType.Field.SetFilterValues( control, attribute.QualifierValues, values );
                            }
                            catch { }
                        }
                    }

                    string dataFieldExpression = attribute.Key;
                    bool columnExists = gConnectionOpportunities.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;
                        }

                        gConnectionOpportunities.Columns.Add( boundField );
                    }
                }
            }
        }
        /// <summary>
        /// Sets the filters.
        /// </summary>
        private void SetFilters( bool setValues )
        {
            using ( var rockContext = new RockContext() )
            {
                string sessionKey = string.Format( "ConnectionSearch_{0}", this.BlockId );
                var searchSelections = Session[sessionKey] as Dictionary<string, string>;
                setValues = setValues && searchSelections != null;

                var connectionType = new ConnectionTypeService( rockContext ).Get( GetAttributeValue( "ConnectionTypeId" ).AsInteger() );

                if ( !GetAttributeValue( "DisplayNameFilter" ).AsBoolean() )
                {
                    tbSearchName.Visible = false;
                }

                if ( GetAttributeValue( "DisplayCampusFilter" ).AsBoolean() )
                {
                    cblCampus.Visible = true;
                    cblCampus.DataSource = CampusCache.All().Where(c => (c.IsActive ?? false) && c.Id != 7 && c.Id != 8);
                    cblCampus.DataBind();
                }
                else
                {
                    cblCampus.Visible = false;
                }

                if ( setValues )
                {
                    if ( searchSelections.ContainsKey( "tbSearchName" ) )
                    {
                        tbSearchName.Text = searchSelections["tbSearchName"];
                    }
                    if ( searchSelections.ContainsKey( "cblCampus" ) )
                    {
                        var selectedItems = searchSelections["cblCampus"].SplitDelimitedValues().AsIntegerList();
                        cblCampus.SetValues( selectedItems );
                    }
                }
                else if ( GetAttributeValue( "EnableCampusContext" ).AsBoolean() )
                {
                    var campusEntityType = EntityTypeCache.Read( "Rock.Model.Campus" );
                    var contextCampus = RockPage.GetCurrentContext( campusEntityType ) as Campus;

                    if ( contextCampus != null )
                    {
                        cblCampus.SetValue( contextCampus.Id.ToString() );
                    }
                }

                if ( GetAttributeValue( "DisplayAttributeFilters" ).AsBoolean() )
                {
                    // Parse the attribute filters
                    AvailableAttributes = new List<AttributeCache>();
                    if ( connectionType != null )
                    {
                        int entityTypeId = new ConnectionOpportunity().TypeId;
                        foreach ( var attributeModel in new AttributeService( new RockContext() ).Queryable()
                            .Where( a =>
                                a.EntityTypeId == entityTypeId &&
                                a.EntityTypeQualifierColumn.Equals( "ConnectionTypeId", StringComparison.OrdinalIgnoreCase ) &&
                                a.EntityTypeQualifierValue.Equals( connectionType.Id.ToString() ) &&
                                a.AllowSearch == true )
                            .OrderBy( a => a.Order )
                            .ThenBy( a => a.Name ) )
                        {
                            AvailableAttributes.Add( AttributeCache.Read( attributeModel ) );
                        }
                    }

                    // Clear the filter controls
                    phAttributeFilters.Controls.Clear();

                    if ( AvailableAttributes != null )
                    {
                        foreach ( var attribute in AvailableAttributes )
                        {
                            string controlId = "filter_" + attribute.Id.ToString();
                            var control = attribute.FieldType.Field.FilterControl( attribute.QualifierValues, controlId, 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 );
                                }

                                if ( setValues && searchSelections.ContainsKey(controlId))
                                {
                                    var values = searchSelections[controlId].FromJsonOrNull<List<string>>();
                                    attribute.FieldType.Field.SetFilterValues( control, attribute.QualifierValues, values );
                                }
                            }
                        }
                    }
                }
                else
                {
                    phAttributeFilters.Visible = false;
                }
            }
        }
        /// <summary>
        /// Adds the attribute columns.
        /// </summary>
        private void AddDynamicControls()
        {
            // Clear the filter controls
            phAttributeFilters.Controls.Clear();

            // Remove attribute columns
            foreach ( var column in gEventCalendarItems.Columns.OfType<AttributeField>().ToList() )
            {
                gEventCalendarItems.Columns.Remove( column );
            }

            // Remove status columns
            foreach ( var column in gEventCalendarItems.Columns.OfType<BoundField>()
                .Where( c =>
                    c.DataField == "Instances" ||
                    c.DataField == "Status" ||
                    c.DataField == "ApprovalStatus" )
                .ToList() )
            {
                gEventCalendarItems.Columns.Remove( column );
            }

            // Remove Delete column
            foreach ( var column in gEventCalendarItems.Columns.OfType<DeleteField>().ToList() )
            {
                gEventCalendarItems.Columns.Remove( column );
            }

            if ( AvailableAttributes != null )
            {
                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 = rFilter.GetUserPreference( MakeKeyUniqueToEventCalendar( attribute.Key ) );
                        if ( !string.IsNullOrWhiteSpace( savedValue ) )
                        {
                            try
                            {
                                var values = JsonConvert.DeserializeObject<List<string>>( savedValue );
                                attribute.FieldType.Field.SetFilterValues( control, attribute.QualifierValues, values );
                            }
                            catch { }
                        }
                    }

                    string dataFieldExpression = attribute.Key;
                    bool columnExists = gEventCalendarItems.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;
                        }

                        gEventCalendarItems.Columns.Add( boundField );
                    }
                }
            }

            // Add occurrences Count column
            var occurrencesField = new BadgeField();
            occurrencesField.ImportantMin = int.MaxValue;
            occurrencesField.WarningMin = 0;
            occurrencesField.WarningMax = 0;
            occurrencesField.InfoMin = 1;
            occurrencesField.InfoMax = int.MaxValue;
            occurrencesField.DataField = "Occurrences";
            occurrencesField.HeaderText = "Occurrences";
            occurrencesField.HtmlEncode = false;
            gEventCalendarItems.Columns.Add( occurrencesField );

            // Add Status column
            var statusField = new BoundField();
            statusField.DataField = "Status";
            statusField.SortExpression = "EventItem.IsActive";
            statusField.HeaderText = "Status";
            statusField.HtmlEncode = false;
            gEventCalendarItems.Columns.Add( statusField );

            // Add Approval Status column
            var approvalStatusField = new BoundField();
            approvalStatusField.DataField = "ApprovalStatus";
            approvalStatusField.SortExpression = "EventItem.IsApproved";
            approvalStatusField.HeaderText = "Approval Status";
            approvalStatusField.HtmlEncode = false;
            gEventCalendarItems.Columns.Add( approvalStatusField );

            // Add delete column
            if ( _canEdit )
            {
                var deleteField = new DeleteField();
                gEventCalendarItems.Columns.Add( deleteField );
                deleteField.Click += DeleteEventCalendarItem_Click;
            }
        }
        private void BuildRegistrantControls( RegistrantInfo registrant, bool setValues )
        {
            var anchor = new HtmlAnchor();
            anchor.Name = registrant.Id.ToString();
            phDynamicControls.Controls.Add( anchor );

            var divPanel = new HtmlGenericControl( "div" );
            divPanel.AddCssClass( "panel" );
            divPanel.AddCssClass( "panel-block" );
            phDynamicControls.Controls.Add( divPanel );

            var divHeading = new HtmlGenericControl( "div" );
            divHeading.AddCssClass( "panel-heading" );
            divHeading.AddCssClass( "clearfix" );
            divPanel.Controls.Add( divHeading );

            var h1Heading = new HtmlGenericControl( "h1" );
            h1Heading.AddCssClass( "panel-title" );
            h1Heading.AddCssClass( "pull-left" );
            h1Heading.InnerHtml = "<i class='fa fa-user'></i> " + registrant.PersonName;
            divHeading.Controls.Add( h1Heading );

            var divLabels = new HtmlGenericControl( "div" );
            divLabels.AddCssClass( "panel-labels" );
            divHeading.Controls.Add( divLabels );

            if ( registrant.OnWaitList )
            {
                var hlOnWaitList = new HighlightLabel();
                hlOnWaitList.ID = string.Format( "hlWaitList_{0}", registrant.Id );
                hlOnWaitList.LabelType = LabelType.Warning;
                hlOnWaitList.Text = "Wait List";
                hlOnWaitList.CssClass = "margin-r-sm";
                divLabels.Controls.Add( hlOnWaitList );
            }

            decimal discountedTotalCost = registrant.DiscountedTotalCost( Registration.DiscountPercentage, Registration.DiscountAmount );
            if ( discountedTotalCost != 0.0m )
            {
                var hlCost = new HighlightLabel();
                hlCost.ID = string.Format( "hlCost_{0}", registrant.Id );
                hlCost.LabelType = LabelType.Info;
                hlCost.ToolTip = "Cost";
                hlCost.Text = discountedTotalCost.FormatAsCurrency();
                divLabels.Controls.Add( hlCost );
            }

            if ( registrant.PersonId.HasValue )
            {
                var aProfileLink = new HtmlAnchor();
                aProfileLink.HRef = ResolveRockUrl( string.Format( "~/Person/{0}", registrant.PersonId.Value ) );
                divLabels.Controls.Add( aProfileLink );
                aProfileLink.AddCssClass( "btn btn-default btn-xs margin-l-sm" );
                var iProfileLink = new HtmlGenericControl( "i" );
                iProfileLink.AddCssClass( "fa fa-user" );
                aProfileLink.Controls.Add( iProfileLink );
            }

            var divBody = new HtmlGenericControl( "div" );
            divBody.AddCssClass( "panel-body" );
            divPanel.Controls.Add( divBody );

            SignatureDocumentTemplate documentTemplate = null;

            if ( Registration != null &&
                Registration.RegistrationInstance != null &&
                Registration.RegistrationInstance.RegistrationTemplate != null &&
                Registration.RegistrationInstance.RegistrationTemplate.RequiredSignatureDocumentTemplate != null )
            {
                documentTemplate = Registration.RegistrationInstance.RegistrationTemplate.RequiredSignatureDocumentTemplate;
            }

            if ( documentTemplate != null && !registrant.SignatureDocumentId.HasValue )
            {
                var template = Registration.RegistrationInstance.RegistrationTemplate;
                var divSigAlert = new HtmlGenericControl( "div" );
                divSigAlert.AddCssClass( "alert alert-warning" );
                divBody.Controls.Add( divSigAlert );

                StringBuilder sb = new StringBuilder();
                sb.Append( "<div class='row'><div class='col-md-9'>" );

                sb.AppendFormat(
                    "There is not a signed {0} for {1}",
                    template.RequiredSignatureDocumentTemplate.Name,
                    registrant.GetFirstName( template ) );

                if ( registrant.SignatureDocumentLastSent.HasValue )
                {
                    sb.AppendFormat(
                        " (a request was sent {0})",
                        registrant.SignatureDocumentLastSent.Value.ToElapsedString() );
                }
                sb.Append( ".</div>" );

                divSigAlert.Controls.Add( new LiteralControl( sb.ToString() ) );

                var divSigAction = new HtmlGenericControl( "div" );
                divSigAction.AddCssClass( "col-md-3 text-right" );
                divSigAlert.Controls.Add( divSigAction );

                var lbResendDocumentRequest = new LinkButton();
                lbResendDocumentRequest.CausesValidation = false;
                lbResendDocumentRequest.ID = string.Format( "lbResendDocumentRequest_{0}", registrant.Id );
                lbResendDocumentRequest.Text = registrant.SignatureDocumentLastSent.HasValue ? "Resend Signature Request" : "Send Signature Request";
                lbResendDocumentRequest.CssClass = "btn btn-warning btn-sm";
                lbResendDocumentRequest.Click += lbResendDocumentRequest_Click;
                divSigAction.Controls.Add( lbResendDocumentRequest );

                divSigAlert.Controls.Add( new LiteralControl( "</div>" ) );
            }

            var divRow = new HtmlGenericControl( "div" );
            divRow.AddCssClass( "row" );
            divBody.Controls.Add( divRow );

            var divLeftColumn = new HtmlGenericControl( "div" );
            divLeftColumn.AddCssClass( "col-md-6");
            divRow.Controls.Add( divLeftColumn );

            var divRightColumn = new HtmlGenericControl( "div" );
            divRightColumn.AddCssClass( "col-md-6");
            divRow.Controls.Add( divRightColumn );

            if ( RegistrationTemplateState != null &&
                RegistrationTemplateState.GroupTypeId.HasValue &&
                Registration != null &&
                Registration.Group != null &&
                Registration.Group.GroupTypeId == RegistrationTemplateState.GroupTypeId.Value )
            {
                if ( Registration != null && Registration.Group != null )
                {
                    var rcwGroupMember = new RockControlWrapper();
                    rcwGroupMember.ID = string.Format( "rcwGroupMember_{0}", registrant.Id );
                    divLeftColumn.Controls.Add( rcwGroupMember );
                    rcwGroupMember.Label = "Group";

                    var pGroupMember = new HtmlGenericControl( "p" );
                    pGroupMember.ID = string.Format( "pGroupMember_{0}", registrant.Id );
                    divRow.AddCssClass( "form-control-static" );
                    rcwGroupMember.Controls.Add( pGroupMember );

                    if ( registrant.GroupMemberId.HasValue )
                    {
                        var qryParams = new Dictionary<string, string>();
                        qryParams.Add( "GroupMemberId", registrant.GroupMemberId.Value.ToString() );

                        var aProfileLink = new HtmlAnchor();
                        aProfileLink.HRef = LinkedPageUrl( "GroupMemberPage", qryParams );
                        pGroupMember.Controls.Add( aProfileLink );
                        aProfileLink.Controls.Add( new LiteralControl( string.IsNullOrWhiteSpace( registrant.GroupName ) ? "Group" : registrant.GroupName ) );
                    }
                    else
                    {
                        pGroupMember.Controls.Add( new LiteralControl( "None (" ) );

                        var lbGroupMember = new LinkButton();
                        lbGroupMember.CausesValidation = false;
                        lbGroupMember.ID = string.Format( "lbGroupMember_{0}", registrant.Id );
                        lbGroupMember.Text = string.Format( "Add {0} to Target Group", registrant.GetFirstName( RegistrationTemplateState ) );
                        lbGroupMember.Click += lbGroupMember_Click;
                        pGroupMember.Controls.Add( lbGroupMember );

                        pGroupMember.Controls.Add( new LiteralControl( ")" ) );
                    }
                }
            }

            foreach( var form in RegistrationTemplateState.Forms.OrderBy( f => f.Order ) )
            {
                foreach( var field in form.Fields.OrderBy( f => f.Order ) )
                {
                    var fieldControl = BuildRegistrantFieldControl( field, registrant, setValues );
                    if ( fieldControl != null )
                    {
                        divLeftColumn.Controls.Add( fieldControl );
                    }
                }
            }

            if ( registrant.Cost > 0.0m)
            {
                var rlCost = new RockLiteral();
                rlCost.ID = string.Format( "rlCost_{0}", registrant.Id );
                rlCost.Label = "Cost";
                rlCost.Text = registrant.Cost.FormatAsCurrency();

                decimal discountedCost = registrant.DiscountedCost( Registration.DiscountPercentage, Registration.DiscountAmount );
                if ( registrant.Cost == discountedCost )
                {
                    var divCost = new HtmlGenericControl( "div" );
                    divCost.AddCssClass( "col-xs-12" );
                    divCost.Controls.Add( rlCost );
                    divRightColumn.Controls.Add( divCost );
                }
                else
                {
                    var rlDiscountedCost = new RockLiteral();
                    rlDiscountedCost.ID = string.Format( "rlDiscountedCost_{0}", registrant.Id );
                    rlDiscountedCost.Label = "Discounted Cost";
                    rlDiscountedCost.Text = discountedCost.FormatAsCurrency();

                    var divCost = new HtmlGenericControl( "div" );
                    divCost.AddCssClass( "col-xs-6" );
                    divCost.Controls.Add( rlCost );
                    divRightColumn.Controls.Add( divCost );

                    var divDiscountedCost = new HtmlGenericControl( "div" );
                    divDiscountedCost.AddCssClass( "col-xs-6" );
                    divDiscountedCost.Controls.Add( rlDiscountedCost );
                    divRightColumn.Controls.Add( divDiscountedCost );
                }
            }

            foreach ( var fee in registrant.FeeValues )
            {
                var templateFee = RegistrationTemplateState.Fees.Where( f => f.Id == fee.Key ).FirstOrDefault();
                if ( templateFee != null && fee.Value != null )
                {
                    foreach ( var feeInfo in fee.Value )
                    {
                        var discountedCost = registrant.DiscountApplies ? feeInfo.DiscountedCost( Registration.DiscountPercentage ) : feeInfo.TotalCost;
                        var feeControl = BuildRegistrantFeeControl( templateFee, feeInfo, registrant, setValues );
                        if ( feeControl != null )
                        {
                            if ( feeInfo.TotalCost == discountedCost )
                            {
                                var divFee = new HtmlGenericControl( "div" );
                                divFee.AddCssClass( "col-xs-12" );
                                divFee.Controls.Add( feeControl );
                                divRightColumn.Controls.Add( divFee );
                            }
                            else
                            {
                                var rlDiscountedFee = new RockLiteral();
                                rlDiscountedFee.ID = string.Format( "rlDiscountedFee_{0}_{1}_{2}", registrant.Id, templateFee.Id, feeInfo.Option );
                                rlDiscountedFee.Label = "Discounted Amount";
                                rlDiscountedFee.Text = discountedCost.FormatAsCurrency();

                                var divFee = new HtmlGenericControl( "div" );
                                divFee.AddCssClass( "col-xs-6" );
                                divFee.Controls.Add( feeControl );
                                divRightColumn.Controls.Add( divFee );

                                var divDiscountedFee = new HtmlGenericControl( "div" );
                                divDiscountedFee.AddCssClass( "col-xs-6" );
                                divDiscountedFee.Controls.Add( rlDiscountedFee );
                                divRightColumn.Controls.Add( divDiscountedFee );
                            }
                        }
                    }
                }
            }

            if ( documentTemplate != null && registrant.SignatureDocumentId.HasValue )
            {
                var rlDocumentLink = new RockLiteral();
                rlDocumentLink.ID = string.Format( "rlDocumentLink_{0}", registrant.Id );
                rlDocumentLink.Label = documentTemplate.Name;
                rlDocumentLink.Text = string.Format( "<a href='{0}?id={1}' target='_blank'>View Document</a>",
                    ResolveRockUrl( "~/GetFile.ashx" ), registrant.SignatureDocumentId.Value );
                divRightColumn.Controls.Add( rlDocumentLink );
            }

            var divActions = new HtmlGenericControl( "Div" );
            divActions.AddCssClass( "actions" );
            divBody.Controls.Add( divActions );

            var lbEditRegistrant = new LinkButton();
            lbEditRegistrant.Visible = EditAllowed;
            lbEditRegistrant.CausesValidation = false;
            lbEditRegistrant.ID = string.Format( "lbEditRegistrant_{0}", registrant.Id );
            lbEditRegistrant.Text = "Edit";
            lbEditRegistrant.CssClass = "btn btn-primary";
            lbEditRegistrant.Click += lbEditRegistrant_Click;
            divActions.Controls.Add( lbEditRegistrant );

            var lbDeleteRegistrant = new LinkButton();
            lbDeleteRegistrant.Visible = EditAllowed;
            lbDeleteRegistrant.CausesValidation = false;
            lbDeleteRegistrant.ID = string.Format( "lbDeleteRegistrant_{0}", registrant.Id );
            lbDeleteRegistrant.Text = "Delete";
            lbDeleteRegistrant.CssClass = "btn btn-link";
            lbDeleteRegistrant.Attributes["onclick"] = "javascript: return Rock.dialogs.confirmDelete(event, 'Registrant');";
            lbDeleteRegistrant.Click += lbDeleteRegistrant_Click;
            divActions.Controls.Add( lbDeleteRegistrant );
        }
        /// <summary>
        /// Updates the entity type controls.
        /// </summary>
        private void UpdateEntityTypeControls()
        {
            var metricService = new MetricService(new RockContext());
            var metric        = metricService.Get(this.MetricId ?? 0);

            _phEntityTypeEntityIdValue.Controls.Clear();

            string  fieldTypeName         = null;
            Control entityTypeEditControl = null;

            if (metric != null)
            {
                var entityType = EntityTypeCache.Read(metric.EntityTypeId ?? 0);
                if (entityType != null && entityType.SingleValueFieldType != null)
                {
                    fieldTypeName         = entityType.SingleValueFieldType.Name;
                    entityTypeEditControl = entityType.SingleValueFieldType.Field.EditControl(new Dictionary <string, Field.ConfigurationValue>(), string.Format("{0}_{1}_Picker", this.ID, fieldTypeName));
                }
            }

            // only set the _entityTypeEditControl is needs to be
            if (_entityTypeEditControl == null || !_entityTypeEditControl.GetType().Equals(entityTypeEditControl.GetType()) || _entityTypeEditControl.ID != entityTypeEditControl.ID)
            {
                _entityTypeEditControl = entityTypeEditControl;
            }

            if (_entityTypeEditControl != null)
            {
                var rockControlWrapper = new RockControlWrapper();
                rockControlWrapper.Label = string.Format("{0} filter", fieldTypeName);
                rockControlWrapper.Help  = string.Format(
                    "Either select a specific {0}, or select 'Get from page context' to determine the {0} based on the page context. Leave {0} blank to show values for all {1}",
                    fieldTypeName,
                    fieldTypeName.Pluralize());

                rockControlWrapper.ID = string.Format("{0}_{1}", this.ID, "rockControlWrapper");
                _phEntityTypeEntityIdValue.Controls.Add(rockControlWrapper);

                if (_rblSelectOrContext == null)
                {
                    _rblSelectOrContext    = new RockRadioButtonList();
                    _rblSelectOrContext.ID = string.Format("{0}_{1}", this.ID, "rblSelectOrContext");
                    _rblSelectOrContext.RepeatDirection = RepeatDirection.Horizontal;
                    _rblSelectOrContext.Items.Add(new ListItem("Select " + fieldTypeName, "0"));
                    _rblSelectOrContext.Items.Add(new ListItem("Get from page context", "1"));
                    _rblSelectOrContext.AutoPostBack          = true;
                    _rblSelectOrContext.SelectedIndexChanged += rblSelectOrContext_SelectedIndexChanged;
                }
                else
                {
                    _rblSelectOrContext.Items[0].Text = "Select " + fieldTypeName;
                }

                rockControlWrapper.Controls.Add(_rblSelectOrContext);
                if (string.IsNullOrEmpty(_rblSelectOrContext.SelectedValue))
                {
                    // might have to get the SelectedValue since we re-created the control after Load()
                    _rblSelectOrContext.SelectedValue = this.Page.Request.Params[_rblSelectOrContext.UniqueID];
                }

                if (string.IsNullOrEmpty(_rblSelectOrContext.SelectedValue))
                {
                    // if not set from either what it was, or from PageContext, default it to "Get from page context"
                    _rblSelectOrContext.SelectedValue = "1";
                }

                _entityTypeEditControl.Visible = _rblSelectOrContext.SelectedValue.AsIntegerOrNull() == 0;
                rockControlWrapper.Controls.Add(_entityTypeEditControl);
                if (_cbCombine == null)
                {
                    _cbCombine    = new RockCheckBox();
                    _cbCombine.ID = string.Format("{0}_{1}", this.ID, "cbCombine");
                }

                _cbCombine.Text = "Combine multiple values to one line when showing values for multiple " + fieldTypeName.Pluralize();

                rockControlWrapper.Controls.Add(_cbCombine);
            }
        }
Beispiel #10
0
        /// <summary>
        /// Sets the filters.
        /// </summary>
        private void SetFilters()
        {
            using ( var rockContext = new RockContext() )
            {
                var connectionType = new ConnectionTypeService( rockContext ).Get( GetAttributeValue( "ConnectionTypeId" ).AsInteger() );

                if ( !GetAttributeValue( "DisplayNameFilter" ).AsBoolean() )
                {
                    tbSearchName.Visible = false;
                }

                if ( GetAttributeValue( "DisplayCampusFilter" ).AsBoolean() )
                {
                    cblCampus.Visible = true;
                    cblCampus.DataSource = CampusCache.All();
                    cblCampus.DataBind();
                }
                else
                {
                    cblCampus.Visible = false;
                }

                if ( GetAttributeValue( "EnableCampusContext" ).AsBoolean() )
                {
                    var campusEntityType = EntityTypeCache.Read( "Rock.Model.Campus" );
                    var contextCampus = RockPage.GetCurrentContext( campusEntityType ) as Campus;

                    if ( contextCampus != null )
                    {
                        cblCampus.SetValue( contextCampus.Id.ToString() );
                    }
                }

                if ( GetAttributeValue( "DisplayAttributeFilters" ).AsBoolean() )
                {
                    // Parse the attribute filters
                    AvailableAttributes = new List<AttributeCache>();
                    if ( connectionType != null )
                    {
                        int entityTypeId = new ConnectionOpportunity().TypeId;
                        foreach ( var attributeModel in new AttributeService( new RockContext() ).Queryable()
                            .Where( a =>
                                a.EntityTypeId == entityTypeId &&
                                a.EntityTypeQualifierColumn.Equals( "ConnectionTypeId", StringComparison.OrdinalIgnoreCase ) &&
                                a.EntityTypeQualifierValue.Equals( connectionType.Id.ToString() ) )
                            .OrderBy( a => a.Order )
                            .ThenBy( a => a.Name ) )
                        {
                            AvailableAttributes.Add( AttributeCache.Read( attributeModel ) );
                        }
                    }

                    // Clear the filter controls
                    phAttributeFilters.Controls.Clear();

                    if ( AvailableAttributes != null )
                    {
                        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 );
                                }
                            }
                        }
                    }
                }
                else
                {
                    phAttributeFilters.Visible = false;
                }
            }
        }
        private void BuildRegistrantControls( RegistrantInfo registrant, bool setValues )
        {
            var anchor = new HtmlAnchor();
            anchor.Name = registrant.Id.ToString();
            phDynamicControls.Controls.Add( anchor );

            var divPanel = new HtmlGenericControl( "div" );
            divPanel.AddCssClass( "panel" );
            divPanel.AddCssClass( "panel-block" );
            phDynamicControls.Controls.Add( divPanel );

            var divHeading = new HtmlGenericControl( "div" );
            divHeading.AddCssClass( "panel-heading" );
            divHeading.AddCssClass( "clearfix" );
            divPanel.Controls.Add( divHeading );

            var h1Heading = new HtmlGenericControl( "h1" );
            h1Heading.AddCssClass( "panel-title" );
            h1Heading.AddCssClass( "pull-left" );
            h1Heading.InnerHtml = "<i class='fa fa-user'></i> " + registrant.PersonName;
            divHeading.Controls.Add( h1Heading );

            var divLabels = new HtmlGenericControl( "div" );
            divLabels.AddCssClass( "panel-labels" );
            divHeading.Controls.Add( divLabels );

            decimal registrantCost = registrant.TotalCost;
            if ( registrantCost != 0.0m )
            {
                var hlCost = new HighlightLabel();
                hlCost.ID = string.Format( "hlCost_{0}", registrant.Id );
                hlCost.LabelType = LabelType.Info;
                hlCost.ToolTip = "Cost";
                hlCost.Text = registrantCost.FormatAsCurrency();
                divLabels.Controls.Add( hlCost );
            }

            if ( registrant.PersonId.HasValue )
            {
                var aProfileLink = new HtmlAnchor();
                aProfileLink.HRef = ResolveRockUrl( string.Format( "~/Person/{0}", registrant.PersonId.Value ) );
                divLabels.Controls.Add( aProfileLink );
                aProfileLink.AddCssClass( "btn btn-default btn-xs margin-l-sm" );
                var iProfileLink = new HtmlGenericControl( "i" );
                iProfileLink.AddCssClass( "fa fa-user" );
                aProfileLink.Controls.Add( iProfileLink );
            }

            var divBody = new HtmlGenericControl( "div" );
            divBody.AddCssClass( "panel-body" );
            divPanel.Controls.Add( divBody );

            var divRow = new HtmlGenericControl( "div" );
            divRow.AddCssClass( "row" );
            divBody.Controls.Add( divRow );

            var divFields = new HtmlGenericControl( "div" );
            divFields.AddCssClass( "col-md-6");
            divRow.Controls.Add( divFields );

            var divFees = new HtmlGenericControl( "div" );
            divFees.AddCssClass( "col-md-6");
            divRow.Controls.Add( divFees );

            if ( RegistrationTemplateState != null &&
                RegistrationTemplateState.GroupTypeId.HasValue &&
                Registration != null &&
                Registration.Group != null &&
                Registration.Group.GroupTypeId == RegistrationTemplateState.GroupTypeId.Value )
            {
                if ( Registration != null && Registration.Group != null )
                {
                    var rcwGroupMember = new RockControlWrapper();
                    rcwGroupMember.ID = string.Format( "rcwGroupMember_{0}", registrant.Id );
                    divFields.Controls.Add( rcwGroupMember );
                    rcwGroupMember.Label = "Group";

                    var pGroupMember = new HtmlGenericControl( "p" );
                    pGroupMember.ID = string.Format( "pGroupMember_{0}", registrant.Id );
                    divRow.AddCssClass( "form-control-static" );
                    rcwGroupMember.Controls.Add( pGroupMember );

                    if ( registrant.GroupMemberId.HasValue )
                    {
                        var qryParams = new Dictionary<string, string>();
                        qryParams.Add( "GroupMemberId", registrant.GroupMemberId.Value.ToString() );

                        var aProfileLink = new HtmlAnchor();
                        aProfileLink.HRef = LinkedPageUrl( "GroupMemberPage", qryParams );
                        pGroupMember.Controls.Add( aProfileLink );
                        aProfileLink.Controls.Add( new LiteralControl( string.IsNullOrWhiteSpace( registrant.GroupName ) ? "Group" : registrant.GroupName ) );
                    }
                    else
                    {
                        pGroupMember.Controls.Add( new LiteralControl( "None (" ) );

                        var lbGroupMember = new LinkButton();
                        lbGroupMember.CausesValidation = false;
                        lbGroupMember.ID = string.Format( "lbGroupMember_{0}", registrant.Id );
                        lbGroupMember.Text = string.Format( "Add {0} to Target Group", registrant.GetFirstName( RegistrationTemplateState ) );
                        lbGroupMember.Click += lbGroupMember_Click;
                        pGroupMember.Controls.Add( lbGroupMember );

                        pGroupMember.Controls.Add( new LiteralControl( ")" ) );
                    }
                }
            }

            foreach( var form in RegistrationTemplateState.Forms.OrderBy( f => f.Order ) )
            {
                foreach( var field in form.Fields.OrderBy( f => f.Order ) )
                {
                    var fieldControl = BuildRegistrantFieldControl( field, registrant, setValues );
                    if ( fieldControl != null )
                    {
                        divFields.Controls.Add( fieldControl );
                    }
                }
            }

            if ( registrant.Cost > 0.0m)
            {
                var rlCost = new RockLiteral();
                rlCost.ID = string.Format( "rlCost_{0}", registrant.Id );
                rlCost.Label = "Cost";
                rlCost.Text = registrant.Cost.FormatAsCurrency();
                divFees.Controls.Add( rlCost );
            }

            foreach ( var fee in registrant.FeeValues )
            {
                var templateFee = RegistrationTemplateState.Fees.Where( f => f.Id == fee.Key ).FirstOrDefault();
                if ( templateFee != null && fee.Value != null )
                {
                    foreach ( var feeInfo in fee.Value )
                    {
                        var feeControl = BuildRegistrantFeeControl( templateFee, feeInfo, registrant, setValues );
                        if ( feeControl != null )
                        {
                            divFees.Controls.Add( feeControl );
                        }
                    }
                }
            }

            var divActions = new HtmlGenericControl( "Div" );
            divActions.AddCssClass( "actions" );
            divBody.Controls.Add( divActions );

            var lbEditRegistrant = new LinkButton();
            lbEditRegistrant.Visible = EditAllowed;
            lbEditRegistrant.CausesValidation = false;
            lbEditRegistrant.ID = string.Format( "lbEditRegistrant_{0}", registrant.Id );
            lbEditRegistrant.Text = "Edit";
            lbEditRegistrant.CssClass = "btn btn-primary";
            lbEditRegistrant.Click += lbEditRegistrant_Click;
            divActions.Controls.Add( lbEditRegistrant );

            var lbDeleteRegistrant = new LinkButton();
            lbDeleteRegistrant.Visible = EditAllowed;
            lbDeleteRegistrant.CausesValidation = false;
            lbDeleteRegistrant.ID = string.Format( "lbDeleteRegistrant_{0}", registrant.Id );
            lbDeleteRegistrant.Text = "Delete";
            lbDeleteRegistrant.CssClass = "btn btn-link";
            lbDeleteRegistrant.Attributes["onclick"] = "javascript: return Rock.dialogs.confirmDelete(event, 'Registrant');";
            lbDeleteRegistrant.Click += lbDeleteRegistrant_Click;
            divActions.Controls.Add( lbDeleteRegistrant );
        }
        private void AddDynamicControls()
        {
            if ( AvailableAttributes != null )
            {
                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 = rFilter.GetUserPreference( 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
                            }
                        }
                    }

                    bool columnExists = gList.Columns.OfType<AttributeField>().FirstOrDefault( a => a.AttributeId == attribute.Id ) != null;
                    if ( !columnExists )
                    {
                        AttributeField boundField = new AttributeField();
                        boundField.DataField = attribute.Key;
                        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;
                        }

                        gList.Columns.Add( boundField );
                    }
                }
            }

            // Add delete column
            var deleteField = new DeleteField();
            gList.Columns.Add( deleteField );
            deleteField.Click += gList_Delete;
        }
        /// <summary>
        /// Adds the filter controls and grid columns for all of the registration template's form fields
        /// that were configured to 'Show on Grid'
        /// </summary>
        private void AddDynamicControls()
        {
            phRegistrantFormFieldFilters.Controls.Clear();
            phWaitListFormFieldFilters.Controls.Clear();

            ClearGrid( gGroupPlacements );
            ClearGrid( gRegistrants );
            ClearGrid( gWaitList );

            if ( RegistrantFields != null )
            {
                foreach ( var field in RegistrantFields )
                {
                    if ( field.FieldSource == RegistrationFieldSource.PersonField && field.PersonFieldType.HasValue )
                    {
                        switch ( field.PersonFieldType.Value )
                        {
                            case RegistrationPersonFieldType.Campus:
                                {
                                    var ddlCampus = new RockDropDownList();
                                    ddlCampus.ID = "ddlCampus";
                                    ddlCampus.Label = "Home Campus";
                                    ddlCampus.DataValueField = "Id";
                                    ddlCampus.DataTextField = "Name";
                                    ddlCampus.DataSource = CampusCache.All();
                                    ddlCampus.DataBind();
                                    ddlCampus.Items.Insert( 0, new ListItem( "", "" ) );
                                    ddlCampus.SetValue( fRegistrants.GetUserPreference( "Home Campus" ) );
                                    phRegistrantFormFieldFilters.Controls.Add( ddlCampus );

                                    var ddlCampus2 = new RockDropDownList();
                                    ddlCampus2.ID = "ddlCampus";
                                    ddlCampus2.Label = "Home Campus";
                                    ddlCampus2.DataValueField = "Id";
                                    ddlCampus2.DataTextField = "Name";
                                    ddlCampus2.DataSource = CampusCache.All();
                                    ddlCampus2.DataBind();
                                    ddlCampus2.Items.Insert( 0, new ListItem( "", "" ) );
                                    ddlCampus2.SetValue( fRegistrants.GetUserPreference( "WL-Home Campus" ) );
                                    phWaitListFormFieldFilters.Controls.Add( ddlCampus2 );

                                    var templateField = new RockLiteralField();
                                    templateField.ID = "lCampus";
                                    templateField.HeaderText = "Campus";
                                    gRegistrants.Columns.Add( templateField );

                                    var templateField2 = new RockLiteralField();
                                    templateField2.ID = "lCampus";
                                    templateField2.HeaderText = "Campus";
                                    gGroupPlacements.Columns.Add( templateField2 );

                                    var templateField3 = new RockLiteralField();
                                    templateField3.ID = "lCampus";
                                    templateField3.HeaderText = "Campus";
                                    gWaitList.Columns.Add( templateField3 );

                                    break;
                                }

                            case RegistrationPersonFieldType.Email:
                                {
                                    var tbEmailFilter = new RockTextBox();
                                    tbEmailFilter.ID = "tbEmailFilter";
                                    tbEmailFilter.Label = "Email";
                                    tbEmailFilter.Text = fRegistrants.GetUserPreference( "Email" );
                                    phRegistrantFormFieldFilters.Controls.Add( tbEmailFilter );

                                    var tbEmailFilter2 = new RockTextBox();
                                    tbEmailFilter2.ID = "tbEmailFilter";
                                    tbEmailFilter2.Label = "Email";
                                    tbEmailFilter2.Text = fRegistrants.GetUserPreference( "WL-Email" );
                                    phWaitListFormFieldFilters.Controls.Add( tbEmailFilter2 );

                                    string dataFieldExpression = "PersonAlias.Person.Email";
                                    var emailField = new RockBoundField();
                                    emailField.DataField = dataFieldExpression;
                                    emailField.HeaderText = "Email";
                                    emailField.SortExpression = dataFieldExpression;
                                    gRegistrants.Columns.Add( emailField );

                                    var emailField2 = new RockBoundField();
                                    emailField2.DataField = dataFieldExpression;
                                    emailField2.HeaderText = "Email";
                                    emailField2.SortExpression = dataFieldExpression;
                                    gGroupPlacements.Columns.Add( emailField2 );

                                    var emailField3 = new RockBoundField();
                                    emailField3.DataField = dataFieldExpression;
                                    emailField3.HeaderText = "Email";
                                    emailField3.SortExpression = dataFieldExpression;
                                    gWaitList.Columns.Add( emailField3 );

                                    break;
                                }

                            case RegistrationPersonFieldType.Birthdate:
                                {
                                    var drpBirthdateFilter = new DateRangePicker();
                                    drpBirthdateFilter.ID = "drpBirthdateFilter";
                                    drpBirthdateFilter.Label = "Birthdate Range";
                                    drpBirthdateFilter.DelimitedValues = fRegistrants.GetUserPreference( "Birthdate Range" );
                                    phRegistrantFormFieldFilters.Controls.Add( drpBirthdateFilter );

                                    var drpBirthdateFilter2 = new DateRangePicker();
                                    drpBirthdateFilter2.ID = "drpBirthdateFilter";
                                    drpBirthdateFilter2.Label = "Birthdate Range";
                                    drpBirthdateFilter2.DelimitedValues = fRegistrants.GetUserPreference( "WL-Birthdate Range" );
                                    phWaitListFormFieldFilters.Controls.Add( drpBirthdateFilter2 );

                                    string dataFieldExpression = "PersonAlias.Person.BirthDate";
                                    var birthdateField = new DateField();
                                    birthdateField.DataField = dataFieldExpression;
                                    birthdateField.HeaderText = "Birthdate";
                                    birthdateField.SortExpression = dataFieldExpression;
                                    gRegistrants.Columns.Add( birthdateField );

                                    var birthdateField2 = new DateField();
                                    birthdateField2.DataField = dataFieldExpression;
                                    birthdateField2.HeaderText = "Birthdate";
                                    birthdateField2.SortExpression = dataFieldExpression;
                                    gGroupPlacements.Columns.Add( birthdateField2 );

                                    var birthdateField3 = new DateField();
                                    birthdateField3.DataField = dataFieldExpression;
                                    birthdateField3.HeaderText = "Birthdate";
                                    birthdateField3.SortExpression = dataFieldExpression;
                                    gWaitList.Columns.Add( birthdateField3 );

                                    break;
                                }

                            case RegistrationPersonFieldType.Grade:
                                {
                                    var gpGradeFilter = new GradePicker();
                                    gpGradeFilter.ID = "gpGradeFilter";
                                    gpGradeFilter.Label = "Grade";
                                    gpGradeFilter.UseAbbreviation = true;
                                    gpGradeFilter.UseGradeOffsetAsValue = true;
                                    gpGradeFilter.CssClass = "input-width-md";
                                    gpGradeFilter.SetValue( fRegistrants.GetUserPreference( "Grade" ).AsIntegerOrNull() );
                                    phRegistrantFormFieldFilters.Controls.Add( gpGradeFilter );

                                    var gpGradeFilter2 = new GradePicker();
                                    gpGradeFilter2.ID = "gpGradeFilter";
                                    gpGradeFilter2.Label = "Grade";
                                    gpGradeFilter2.UseAbbreviation = true;
                                    gpGradeFilter2.UseGradeOffsetAsValue = true;
                                    gpGradeFilter2.CssClass = "input-width-md";
                                    gpGradeFilter2.SetValue( fRegistrants.GetUserPreference( "WL-Grade" ).AsIntegerOrNull() );
                                    phWaitListFormFieldFilters.Controls.Add( gpGradeFilter2 );

                                    string dataFieldExpression = "PersonAlias.Person.GraduationYear";
                                    var gradeField = new RockBoundField();
                                    gradeField.DataField = dataFieldExpression;
                                    gradeField.HeaderText = "Graduation Year";
                                    gradeField.SortExpression = dataFieldExpression;
                                    gRegistrants.Columns.Add( gradeField );

                                    var gradeField2 = new RockBoundField();
                                    gradeField2.DataField = dataFieldExpression;
                                    gradeField2.HeaderText = "Graduation Year";
                                    gradeField2.SortExpression = dataFieldExpression;
                                    gGroupPlacements.Columns.Add( gradeField2 );

                                    var gradeField3 = new RockBoundField();
                                    gradeField3.DataField = dataFieldExpression;
                                    gradeField3.HeaderText = "Graduation Year";
                                    gradeField3.SortExpression = dataFieldExpression;
                                    gWaitList.Columns.Add( gradeField3 );

                                    break;
                                }

                            case RegistrationPersonFieldType.Gender:
                                {
                                    var ddlGenderFilter = new RockDropDownList();
                                    ddlGenderFilter.BindToEnum<Gender>( true );
                                    ddlGenderFilter.ID = "ddlGenderFilter";
                                    ddlGenderFilter.Label = "Gender";
                                    ddlGenderFilter.SetValue( fRegistrants.GetUserPreference( "Gender" ) );
                                    phRegistrantFormFieldFilters.Controls.Add( ddlGenderFilter );

                                    var ddlGenderFilter2 = new RockDropDownList();
                                    ddlGenderFilter2.BindToEnum<Gender>( true );
                                    ddlGenderFilter2.ID = "ddlGenderFilter";
                                    ddlGenderFilter2.Label = "Gender";
                                    ddlGenderFilter2.SetValue( fRegistrants.GetUserPreference( "WL-Gender" ) );
                                    phWaitListFormFieldFilters.Controls.Add( ddlGenderFilter2 );

                                    string dataFieldExpression = "PersonAlias.Person.Gender";
                                    var genderField = new EnumField();
                                    genderField.DataField = dataFieldExpression;
                                    genderField.HeaderText = "Gender";
                                    genderField.SortExpression = dataFieldExpression;
                                    gRegistrants.Columns.Add( genderField );

                                    var genderField2 = new EnumField();
                                    genderField2.DataField = dataFieldExpression;
                                    genderField2.HeaderText = "Gender";
                                    genderField2.SortExpression = dataFieldExpression;
                                    gGroupPlacements.Columns.Add( genderField2 );

                                    var genderField3 = new EnumField();
                                    genderField3.DataField = dataFieldExpression;
                                    genderField3.HeaderText = "Gender";
                                    genderField3.SortExpression = dataFieldExpression;
                                    gWaitList.Columns.Add( genderField3 );
                                    break;
                                }

                            case RegistrationPersonFieldType.MaritalStatus:
                                {
                                    var ddlMaritalStatusFilter = new RockDropDownList();
                                    ddlMaritalStatusFilter.BindToDefinedType( DefinedTypeCache.Read( Rock.SystemGuid.DefinedType.PERSON_MARITAL_STATUS.AsGuid() ), true );
                                    ddlMaritalStatusFilter.ID = "ddlMaritalStatusFilter";
                                    ddlMaritalStatusFilter.Label = "Marital Status";
                                    ddlMaritalStatusFilter.SetValue( fRegistrants.GetUserPreference( "Marital Status" ) );
                                    phRegistrantFormFieldFilters.Controls.Add( ddlMaritalStatusFilter );

                                    var ddlMaritalStatusFilter2 = new RockDropDownList();
                                    ddlMaritalStatusFilter2.BindToDefinedType( DefinedTypeCache.Read( Rock.SystemGuid.DefinedType.PERSON_MARITAL_STATUS.AsGuid() ), true );
                                    ddlMaritalStatusFilter2.ID = "ddlMaritalStatusFilter";
                                    ddlMaritalStatusFilter2.Label = "Marital Status";
                                    ddlMaritalStatusFilter2.SetValue( fRegistrants.GetUserPreference( "WL-Marital Status" ) );
                                    phWaitListFormFieldFilters.Controls.Add( ddlMaritalStatusFilter2 );

                                    string dataFieldExpression = "PersonAlias.Person.MaritalStatusValue.Value";
                                    var maritalStatusField = new RockBoundField();
                                    maritalStatusField.DataField = dataFieldExpression;
                                    maritalStatusField.HeaderText = "MaritalStatus";
                                    maritalStatusField.SortExpression = dataFieldExpression;
                                    gRegistrants.Columns.Add( maritalStatusField );

                                    var maritalStatusField2 = new RockBoundField();
                                    maritalStatusField2.DataField = dataFieldExpression;
                                    maritalStatusField2.HeaderText = "MaritalStatus";
                                    maritalStatusField2.SortExpression = dataFieldExpression;
                                    gGroupPlacements.Columns.Add( maritalStatusField2 );

                                    var maritalStatusField3 = new RockBoundField();
                                    maritalStatusField3.DataField = dataFieldExpression;
                                    maritalStatusField3.HeaderText = "MaritalStatus";
                                    maritalStatusField3.SortExpression = dataFieldExpression;
                                    gWaitList.Columns.Add( maritalStatusField3 );

                                    break;
                                }

                            case RegistrationPersonFieldType.MobilePhone:
                                {
                                    var tbPhoneFilter = new RockTextBox();
                                    tbPhoneFilter.ID = "tbPhoneFilter";
                                    tbPhoneFilter.Label = "Phone";
                                    tbPhoneFilter.Text = fRegistrants.GetUserPreference( "Phone" );
                                    phRegistrantFormFieldFilters.Controls.Add( tbPhoneFilter );

                                    var tbPhoneFilter2 = new RockTextBox();
                                    tbPhoneFilter2.ID = "tbPhoneFilter";
                                    tbPhoneFilter2.Label = "Phone";
                                    tbPhoneFilter2.Text = fRegistrants.GetUserPreference( "WL-Phone" );
                                    phWaitListFormFieldFilters.Controls.Add( tbPhoneFilter2 );

                                    var phoneNumbersField = new PhoneNumbersField();
                                    phoneNumbersField.DataField = "PersonAlias.Person.PhoneNumbers";
                                    phoneNumbersField.HeaderText = "Phone(s)";
                                    gRegistrants.Columns.Add( phoneNumbersField );

                                    var phoneNumbersField2 = new PhoneNumbersField();
                                    phoneNumbersField2.DataField = "PersonAlias.Person.PhoneNumbers";
                                    phoneNumbersField2.HeaderText = "Phone(s)";
                                    gGroupPlacements.Columns.Add( phoneNumbersField2 );

                                    var phoneNumbersField3 = new PhoneNumbersField();
                                    phoneNumbersField3.DataField = "PersonAlias.Person.PhoneNumbers";
                                    phoneNumbersField3.HeaderText = "Phone(s)";
                                    gWaitList.Columns.Add( phoneNumbersField3 );

                                    break;
                                }
                        }
                    }
                    else if ( field.Attribute != null )
                    {
                        var attribute = field.Attribute;

                        // add dynamic filter to registrant grid
                        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;
                                phRegistrantFormFieldFilters.Controls.Add( control );
                            }
                            else
                            {
                                var wrapper = new RockControlWrapper();
                                wrapper.ID = control.ID + "_wrapper";
                                wrapper.Label = attribute.Name;
                                wrapper.Controls.Add( control );
                                phRegistrantFormFieldFilters.Controls.Add( wrapper );
                            }

                            string savedValue = fRegistrants.GetUserPreference( attribute.Key );
                            if ( !string.IsNullOrWhiteSpace( savedValue ) )
                            {
                                try
                                {
                                    var values = JsonConvert.DeserializeObject<List<string>>( savedValue );
                                    attribute.FieldType.Field.SetFilterValues( control, attribute.QualifierValues, values );
                                }
                                catch { }
                            }
                        }

                        // add dynamic filter to wait list grid
                        var control2 = attribute.FieldType.Field.FilterControl( attribute.QualifierValues, "filter_" + attribute.Id.ToString(), false, Rock.Reporting.FilterMode.SimpleFilter );
                        if ( control2 != null )
                        {
                            if ( control2 is IRockControl )
                            {
                                var rockControl2 = (IRockControl)control2;
                                rockControl2.Label = attribute.Name;
                                rockControl2.Help = attribute.Description;
                                phWaitListFormFieldFilters.Controls.Add( control2 );
                            }
                            else
                            {
                                var wrapper2 = new RockControlWrapper();
                                wrapper2.ID = control.ID + "_wrapper";
                                wrapper2.Label = attribute.Name;
                                wrapper2.Controls.Add( control2 );
                                phWaitListFormFieldFilters.Controls.Add( wrapper2 );
                            }

                            string savedValue = fWaitList.GetUserPreference( "WL-" + attribute.Key );
                            if ( !string.IsNullOrWhiteSpace( savedValue ) )
                            {
                                try
                                {
                                    var values = JsonConvert.DeserializeObject<List<string>>( savedValue );
                                    attribute.FieldType.Field.SetFilterValues( control2, attribute.QualifierValues, values );
                                }
                                catch { }
                            }
                        }

                        string dataFieldExpression = attribute.Id.ToString() + attribute.Key;
                        bool columnExists = gRegistrants.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;

                            AttributeField boundField2 = new AttributeField();
                            boundField2.DataField = dataFieldExpression;
                            boundField2.AttributeId = attribute.Id;
                            boundField2.HeaderText = attribute.Name;

                            AttributeField boundField3 = new AttributeField();
                            boundField3.DataField = dataFieldExpression;
                            boundField3.AttributeId = attribute.Id;
                            boundField3.HeaderText = attribute.Name;

                            var attributeCache = Rock.Web.Cache.AttributeCache.Read( attribute.Id );
                            if ( attributeCache != null )
                            {
                                boundField.ItemStyle.HorizontalAlign = attributeCache.FieldType.Field.AlignValue;
                                boundField2.ItemStyle.HorizontalAlign = attributeCache.FieldType.Field.AlignValue;
                                boundField3.ItemStyle.HorizontalAlign = attributeCache.FieldType.Field.AlignValue;
                            }

                            gRegistrants.Columns.Add( boundField );
                            gGroupPlacements.Columns.Add( boundField2 );
                            gWaitList.Columns.Add( boundField3 );
                        }
                    }
                }
            }

            // Add fee column
            var feeField = new RockLiteralField();
            feeField.ID = "lFees";
            feeField.HeaderText = "Fees";
            gRegistrants.Columns.Add( feeField );

            var deleteField = new DeleteField();
            gRegistrants.Columns.Add( deleteField );
            deleteField.Click += gRegistrants_Delete;

            var groupPickerField = new GroupPickerField();
            groupPickerField.HeaderText = "Group";
            groupPickerField.RootGroupId = gpGroupPlacementParentGroup.SelectedValueAsInt();
            gGroupPlacements.Columns.Add( groupPickerField );
        }
Beispiel #14
0
 private void AddFilterControl( Control control, string name, string description )
 {
     if ( control is IRockControl )
     {
         var rockControl = ( IRockControl ) control;
         rockControl.Label = name;
         rockControl.Help = description;
         phFilterControls.Controls.Add( control );
     }
     else
     {
         var wrapper = new RockControlWrapper();
         wrapper.ID = control.ID + "_wrapper";
         wrapper.Label = name;
         wrapper.Controls.Add( control );
         phFilterControls.Controls.Add( wrapper );
     }
 }
        /// <summary>
        /// Updates the entity type controls.
        /// </summary>
        private void UpdateEntityTypeControls()
        {
            var metricService = new MetricService( new RockContext() );
            var metric = metricService.Get( this.MetricId ?? 0 );
            _phEntityTypeEntityIdValue.Controls.Clear();

            string fieldTypeName = null;
            Control entityTypeEditControl = null;
            if ( metric != null )
            {
                var entityType = EntityTypeCache.Read( metric.EntityTypeId ?? 0 );
                if ( entityType != null && entityType.SingleValueFieldType != null )
                {
                    fieldTypeName = entityType.SingleValueFieldType.Name;
                    entityTypeEditControl = entityType.SingleValueFieldType.Field.EditControl( new Dictionary<string, Field.ConfigurationValue>(), string.Format( "{0}_{1}_Picker", this.ID, fieldTypeName ) );
                }
            }

            // only set the _entityTypeEditControl is needs to be
            if ( _entityTypeEditControl == null || !_entityTypeEditControl.GetType().Equals( entityTypeEditControl.GetType() ) || _entityTypeEditControl.ID != entityTypeEditControl.ID )
            {
                _entityTypeEditControl = entityTypeEditControl;
            }

            if ( _entityTypeEditControl != null )
            {
                var rockControlWrapper = new RockControlWrapper();
                rockControlWrapper.Label = string.Format( "{0} filter", fieldTypeName );
                rockControlWrapper.Help = string.Format(
                    "Either select a specific {0}, or select 'Get from page context' to determine the {0} based on the page context. Leave {0} blank to show values for all {1}",
                    fieldTypeName,
                    fieldTypeName.Pluralize() );

                rockControlWrapper.ID = string.Format( "{0}_{1}", this.ID, "rockControlWrapper" );
                _phEntityTypeEntityIdValue.Controls.Add( rockControlWrapper );

                if ( _rblSelectOrContext == null )
                {
                    _rblSelectOrContext = new RockRadioButtonList();
                    _rblSelectOrContext.ID = string.Format( "{0}_{1}", this.ID, "rblSelectOrContext" );
                    _rblSelectOrContext.RepeatDirection = RepeatDirection.Horizontal;
                    _rblSelectOrContext.Items.Add( new ListItem( "Select " + fieldTypeName, "0" ) );
                    _rblSelectOrContext.Items.Add( new ListItem( "Get from page context", "1" ) );
                    _rblSelectOrContext.AutoPostBack = true;
                    _rblSelectOrContext.SelectedIndexChanged += rblSelectOrContext_SelectedIndexChanged;
                }
                else
                {
                    _rblSelectOrContext.Items[0].Text = "Select " + fieldTypeName;
                }

                rockControlWrapper.Controls.Add( _rblSelectOrContext );
                if ( string.IsNullOrEmpty( _rblSelectOrContext.SelectedValue ) )
                {
                    // might have to get the SelectedValue since we re-created the control after Load()
                    _rblSelectOrContext.SelectedValue = this.Page.Request.Params[_rblSelectOrContext.UniqueID];
                }

                if ( string.IsNullOrEmpty( _rblSelectOrContext.SelectedValue ) )
                {
                    // if not set from either what it was, or from PageContext, default it to "Get from page context"
                    _rblSelectOrContext.SelectedValue = "1";
                }

                _entityTypeEditControl.Visible = _rblSelectOrContext.SelectedValue.AsIntegerOrNull() == 0;
                rockControlWrapper.Controls.Add( _entityTypeEditControl );
                if ( _cbCombine == null )
                {
                    _cbCombine = new RockCheckBox();
                    _cbCombine.ID = string.Format( "{0}_{1}", this.ID, "cbCombine" );
                }

                _cbCombine.Text = "Combine multiple values to one line when showing values for multiple " + fieldTypeName.Pluralize();

                rockControlWrapper.Controls.Add( _cbCombine );
            }
        }
        /// <summary>
        /// Adds the attribute columns.
        /// </summary>
        private void AddDynamicControls()
        {
            // Clear the filter controls
            phAttributeFilters.Controls.Clear();

            // Remove attribute columns
            foreach ( var column in gWorkflows.Columns.OfType<AttributeField>().ToList() )
            {
                gWorkflows.Columns.Remove( column );
            }

            if ( AvailableAttributes != null )
            {
                foreach ( var attribute in AvailableAttributes )
                {
                    var control = attribute.FieldType.Field.FilterControl( attribute.QualifierValues, "filter_" + attribute.Id.ToString(), false, Rock.Reporting.FilterMode.SimpleFilter );
                    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 = gfWorkflows.GetUserPreference( MakeKeyUniqueToType( attribute.Key ) );
                    if ( !string.IsNullOrWhiteSpace( savedValue ) )
                    {
                        try
                        {
                            var values = JsonConvert.DeserializeObject<List<string>>( savedValue );
                            attribute.FieldType.Field.SetFilterValues( control, attribute.QualifierValues, values );
                        }
                        catch { }
                    }

                    string dataFieldExpression = attribute.Key;
                    bool columnExists = gWorkflows.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.Condensed = false;

                        var attributeCache = Rock.Web.Cache.AttributeCache.Read( attribute.Id );
                        if ( attributeCache != null )
                        {
                            boundField.ItemStyle.HorizontalAlign = attributeCache.FieldType.Field.AlignValue;
                        }

                        gWorkflows.Columns.Add( boundField );
                    }
                }
            }

            var dateField = new DateTimeField();
            gWorkflows.Columns.Add( dateField );
            dateField.DataField = "CreatedDateTime";
            dateField.SortExpression = "CreatedDateTime";
            dateField.HeaderText = "Created";
            dateField.FormatAsElapsedTime = true;

            var statusField = new BoundField();
            gWorkflows.Columns.Add( statusField );
            statusField.DataField = "Status";
            statusField.SortExpression = "Status";
            statusField.HeaderText = "Status";
            statusField.DataFormatString = "<span class='label label-info'>{0}</span>";
            statusField.HtmlEncode = false;

            var stateField = new CallbackField();
            gWorkflows.Columns.Add( stateField );
            stateField.DataField = "IsCompleted";
            stateField.SortExpression = "CompletedDateTime";
            stateField.HeaderText = "State";
            stateField.HtmlEncode = false;
            stateField.OnFormatDataValue += ( sender, e ) =>
            {
                if ( (bool)e.DataValue )
                {
                    e.FormattedValue = "<span class='label label-default'>Completed</span>";
                }
                else
                {
                    e.FormattedValue = "<span class='label label-success'>Active</span>";
                }
            };

            if ( _canView )
            {
                var manageField = new LinkButtonField();
                gWorkflows.Columns.Add( manageField );
                manageField.CssClass = "btn btn-default btn-sm fa fa-file-text-o";
                manageField.Click += gWorkflows_Manage;
            }

            if ( _canEdit )
            {
                var deleteField = new DeleteField();
                gWorkflows.Columns.Add( deleteField );
                deleteField.Click += gWorkflows_Delete;
            }
        }
        /// <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()
        {
            base.CreateChildControls();
            Controls.Clear();

            tbFrom = new RockTextBox();
            tbFrom.ID = string.Format("tbFrom_{0}", this.ID);
            tbFrom.MaxLength = 11;
            tbFrom.Label = "From";
            tbFrom.Help = "The name the recipient will see as the message originating from.";
            Controls.Add(tbFrom);

            lFrom = new RockLiteral();
            lFrom.ID = string.Format("lFrom_{0}", this.ID);
            lFrom.Label = "From";
            Controls.Add(lFrom);

            rcwMessage = new RockControlWrapper();
            rcwMessage.ID = string.Format("rcwMessage_{0}", this.ID);
            rcwMessage.Label = "Message";
            rcwMessage.Help = "<span class='tip tip-lava'></span>";
            Controls.Add(rcwMessage);

            mfpMessage = new MergeFieldPicker();
            mfpMessage.ID = string.Format("mfpMergeFields_{0}", this.ID);
            mfpMessage.MergeFields.Clear();
            mfpMessage.MergeFields.Add("GlobalAttribute");
            mfpMessage.MergeFields.Add("Rock.Model.Person");
            mfpMessage.CssClass += " pull-right margin-b-sm";
            mfpMessage.SelectItem += mfpMergeFields_SelectItem;
            rcwMessage.Controls.Add(mfpMessage);

            tbMessage = new RockTextBox();
            tbMessage.ID = string.Format("tbTextMessage_{0}", this.ID);
            tbMessage.TextMode = TextBoxMode.MultiLine;
            tbMessage.Rows = 3;
            rcwMessage.Controls.Add(tbMessage);

            cbAppendUserInfo = new RockCheckBox();
            cbAppendUserInfo.ID = string.Format("cbAppendUserInfo_{0}", this.ID);
            cbAppendUserInfo.Label = "Add organisation footer to message?";
            cbAppendUserInfo.Help = "Append your message with your organisation's custom mesage or just the name of your organisation?";
            cbAppendUserInfo.Checked = true;
            Controls.Add(cbAppendUserInfo);

            hfSenderGuid = new HiddenField();
            hfSenderGuid.ID = string.Format( "hfSenderGuid_{0}", this.ID );
            Controls.Add( hfSenderGuid );
        }