Ejemplo n.º 1
0
        /// <summary>
        /// Creates the child controls.
        /// </summary>
        /// <param name="parentControl"></param>
        /// <returns></returns>
        public override System.Web.UI.Control[] CreateChildControls( System.Web.UI.Control parentControl )
        {
            RockDropDownList locationTypeList = new RockDropDownList();
            locationTypeList.Items.Clear();
            foreach ( var value in DefinedTypeCache.Read( Rock.SystemGuid.DefinedType.GROUP_LOCATION_TYPE.AsGuid() ).DefinedValues.OrderBy( a => a.Order ).ThenBy( a => a.Value ) )
            {
                locationTypeList.Items.Add( new ListItem( value.Value, value.Guid.ToString() ) );
            }

            locationTypeList.Items.Insert( 0, Rock.Constants.None.ListItem );

            locationTypeList.ID = parentControl.ID + "_grouplocationType";
            locationTypeList.Label = "Address Type";
            parentControl.Controls.Add( locationTypeList );

            RockRadioButtonList addressPartRadioButtonList = new RockRadioButtonList();
            addressPartRadioButtonList.Items.Clear();
            addressPartRadioButtonList.BindToEnum<AddressNamePart>( false );

            // default to first one
            addressPartRadioButtonList.SelectedIndex = 0;
            addressPartRadioButtonList.ID = parentControl.ID + "_addressPartRadioButtonList";
            addressPartRadioButtonList.Label = "Address Part";
            addressPartRadioButtonList.Help = "Select the part of the address to show in the grid, or select Full to show the full address";
            parentControl.Controls.Add( addressPartRadioButtonList );

            return new System.Web.UI.Control[] { locationTypeList, addressPartRadioButtonList };
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the child controls.
        /// </summary>
        /// <param name="parentControl"></param>
        /// <returns></returns>
        public override System.Web.UI.Control[] CreateChildControls( System.Web.UI.Control parentControl )
        {
            RockDropDownList locationTypeList = new RockDropDownList();
            locationTypeList.Items.Clear();
            foreach ( var value in DefinedTypeCache.Read( Rock.SystemGuid.DefinedType.GROUP_LOCATION_TYPE.AsGuid() ).DefinedValues.OrderBy( a => a.Order ).ThenBy( a => a.Value ) )
            {
                locationTypeList.Items.Add( new ListItem( value.Value, value.Guid.ToString() ) );
            }

            locationTypeList.ID = parentControl.ID + "_grouplocationType";
            locationTypeList.Label = "Address Type";
            locationTypeList.SelectedIndex = 0;
            parentControl.Controls.Add( locationTypeList );

            RockRadioButtonList addressPartRadioButtonList = new RockRadioButtonList();
            addressPartRadioButtonList.Items.Clear();
            addressPartRadioButtonList.BindToEnum<RockUdfHelper.AddressNamePart>( false );

            // Localises the radio button list by modifying the text Value of radio buttons
            Dictionary<string, string> newLabels = new Dictionary<string, string>();
            var globalAttributesCache = GlobalAttributesCache.Read();
            var defaultCountry = ( !string.IsNullOrWhiteSpace( globalAttributesCache.OrganizationCountry ) ) ? globalAttributesCache.OrganizationCountry : "US";
            var countryValue = DefinedTypeCache.Read( new Guid( SystemGuid.DefinedType.LOCATION_COUNTRIES ) )
                    .DefinedValues
                    .Where( v => v.Value.Equals( defaultCountry, StringComparison.OrdinalIgnoreCase ) )
                    .FirstOrDefault();

            if ( countryValue != null )
            {
                if ( !newLabels.ContainsKey( "City" ) )
                {
                    newLabels.Add( "City", countryValue.GetAttributeValue( "CityLabel" ) );
                }

                if ( !newLabels.ContainsKey( "Region" ) )
                {
                    newLabels.Add( "Region", countryValue.GetAttributeValue( "StateLabel" ) );
                }

                if ( !newLabels.ContainsKey( "PostalCode" ) )
                {
                    newLabels.Add( "PostalCode", countryValue.GetAttributeValue( "PostalCodeLabel" ) );
                }
            }

            foreach ( KeyValuePair<string, string> pair in newLabels )
            {
                string oldValue = pair.Key.SplitCase();
                string newValue = pair.Value.SplitCase();
                var listItem = addressPartRadioButtonList.Items.FindByText( oldValue );
                if ( listItem != null )
                {
                    listItem.Text = newValue;
                }
            }

            // default to first one
            addressPartRadioButtonList.SelectedIndex = 0;
            addressPartRadioButtonList.ID = parentControl.ID + "_addressPartRadioButtonList";
            addressPartRadioButtonList.Label = "Address Part";
            addressPartRadioButtonList.Help = "Select the part of the address to show in the grid, or select Full to show the full address";
            parentControl.Controls.Add( addressPartRadioButtonList );

            return new System.Web.UI.Control[] { locationTypeList, addressPartRadioButtonList };
        }