/// <summary>
        /// Creates the control(s) necessary for prompting user for a new value
        /// </summary>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="id"></param>
        /// <returns>
        /// The control
        /// </returns>
        public override Control EditControl( Dictionary<string, ConfigurationValue> configurationValues, string id )
        {
            var editControl = new RockDropDownList { ID = id };
            editControl.Items.Add( new ListItem() );

            var statuses = new ConnectionStatusService( new RockContext() )
                .Queryable().AsNoTracking()
                .OrderBy( s => s.ConnectionType.Name )
                .ThenBy( s => s.Name )
                .Select( s => new
                {
                    s.Guid,
                    s.Name,
                    ConnectionTypeName = s.ConnectionType.Name
                } )
                .ToList();

            if ( statuses.Any() )
            {
                foreach ( var status in statuses )
                {
                    var listItem = new ListItem( status.Name, status.Guid.ToString().ToUpper() );
                    listItem.Attributes.Add( "OptionGroup", status.ConnectionTypeName );
                    editControl.Items.Add( listItem );
                }

                return editControl;
            }

            return null;
        }
        /// <summary>
        /// Creates the control(s) necessary for prompting user for a new value
        /// </summary>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="id"></param>
        /// <returns>
        /// The control
        /// </returns>
        public override Control EditControl(Dictionary <string, ConfigurationValue> configurationValues, string id)
        {
            var editControl = new RockDropDownList {
                ID = id
            };

            editControl.Items.Add(new ListItem());

            var statuses = new ConnectionStatusService(new RockContext())
                           .Queryable().AsNoTracking()
                           .OrderBy(s => s.ConnectionType.Name)
                           .ThenBy(s => s.Name)
                           .Select(s => new
            {
                s.Guid,
                s.Name,
                ConnectionTypeName = s.ConnectionType.Name
            })
                           .ToList();

            if (statuses.Any())
            {
                foreach (var status in statuses)
                {
                    var listItem = new ListItem(status.Name, status.Guid.ToString().ToUpper());
                    listItem.Attributes.Add("OptionGroup", status.ConnectionTypeName);
                    editControl.Items.Add(listItem);
                }

                return(editControl);
            }

            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates the control(s) necessary for prompting user for a new value
        /// </summary>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="id"></param>
        /// <returns>
        /// The control
        /// </returns>
        public override Control EditControl(Dictionary <string, ConfigurationValue> configurationValues, string id)
        {
            var includeInactive        = false;
            int?connectionTypeFilterId = null;

            if (configurationValues != null)
            {
                includeInactive        = configurationValues.ContainsKey(INCLUDE_INACTIVE_KEY) && configurationValues[INCLUDE_INACTIVE_KEY].Value.AsBoolean();
                connectionTypeFilterId = configurationValues.ContainsKey(CONNECTION_TYPE_FILTER_KEY) ? configurationValues[CONNECTION_TYPE_FILTER_KEY].Value.AsIntegerOrNull() : null;
            }

            var statuses = new ConnectionStatusService(new RockContext())
                           .Queryable().AsNoTracking()
                           .Where(o => o.IsActive || includeInactive)
                           .OrderBy(o => o.ConnectionType.Name)
                           .ThenBy(o => o.Name)
                           .Select(o => new { o.Guid, o.Name, o.ConnectionType })
                           .ToList();

            var editControl = new RockDropDownList {
                ID = id
            };

            editControl.Items.Add(new ListItem());

            if (statuses.Any())
            {
                foreach (var status in statuses)
                {
                    if (connectionTypeFilterId != null && status.ConnectionType.Id != connectionTypeFilterId)
                    {
                        continue;
                    }

                    var listItem = new ListItem(status.Name, status.Guid.ToString().ToUpper());

                    // Don't add an option group if there is a filter since that would be only one group.
                    if (connectionTypeFilterId == null)
                    {
                        listItem.Attributes.Add("OptionGroup", status.ConnectionType.Name);
                    }

                    editControl.Items.Add(listItem);
                }

                return(editControl);
            }

            return(null);
        }