Esempio n. 1
0
        /// <summary>
        /// Creates the HTML controls required to configure this type of field
        /// </summary>
        /// <returns></returns>
        public override List <Control> ConfigurationControls()
        {
            var controls = base.ConfigurationControls();

            // build a drop down list of enity types (the one that gets selected is
            // used to build a list of attributes)
            var etp = new EntityTypePicker();

            controls.Add(etp);
            etp.AutoPostBack          = true;
            etp.SelectedIndexChanged += OnQualifierUpdated;
            etp.Label = "Entity Type";
            etp.Help  = "The Entity Type to select attributes for.";

            var entityTypeList = new Model.EntityTypeService(new RockContext()).GetEntities().ToList();

            etp.EntityTypes = entityTypeList;

            // Add checkbox for deciding if the defined values list is renedered as a drop
            // down list or a checkbox list.
            var cb = new RockCheckBox();

            controls.Add(cb);
            cb.AutoPostBack    = true;
            cb.CheckedChanged += OnQualifierUpdated;
            cb.Label           = "Allow Multiple Values";
            cb.Text            = "Yes";
            cb.Help            = "When set, allows multiple attributes to be selected.";
            return(controls);
        }
Esempio n. 2
0
        /// <summary>
        /// Reads new values entered by the user for the field ( as Guid)
        /// </summary>
        /// <param name="control">Parent control that controls were added to in the CreateEditControl() method</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <returns></returns>
        public override string GetEditValue(Control control, Dictionary <string, ConfigurationValue> configurationValues)
        {
            EntityTypePicker entityTypePicker = control as EntityTypePicker;

            if (entityTypePicker != null && entityTypePicker.SelectedEntityTypeId.HasValue)
            {
                var entityType = EntityTypeCache.Read(entityTypePicker.SelectedEntityTypeId.Value);
                if (entityType != null)
                {
                    return(entityType.Guid.ToString());
                }
            }

            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Sets the value ( as Guid )
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="value">The value.</param>
        public override void SetEditValue(Control control, Dictionary <string, ConfigurationValue> configurationValues, string value)
        {
            EntityTypePicker entityTypePicker = control as EntityTypePicker;

            if (entityTypePicker != null)
            {
                EntityTypeCache entityType = null;
                Guid?           guid       = value.AsGuidOrNull();
                if (guid.HasValue)
                {
                    entityType = EntityTypeCache.Get(guid.Value);
                }

                entityTypePicker.SelectedEntityTypeId = entityType?.Id;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Creates the HTML controls required to configure this type of field
        /// </summary>
        /// <returns></returns>
        public override List <Control> ConfigurationControls()
        {
            List <Control> controls = new List <Control>();

            var etp = new EntityTypePicker();

            controls.Add(etp);
            etp.EntityTypes = new EntityTypeService(new RockContext())
                              .GetEntities()
                              .OrderBy(t => t.FriendlyName)
                              .ToList();
            etp.AutoPostBack          = true;
            etp.SelectedIndexChanged += OnQualifierUpdated;
            etp.Label = "Entity Type";
            etp.Help  = "The type of entity to display dataviews for.";

            return(controls);
        }
Esempio n. 5
0
        /// <summary>
        /// Sets the value ( as Guid )
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="value">The value.</param>
        public override void SetEditValue(Control control, Dictionary <string, ConfigurationValue> configurationValues, string value)
        {
            Guid guid = Guid.Empty;

            if (Guid.TryParse(value, out guid))
            {
                EntityTypePicker entityTypePicker = control as EntityTypePicker;
                if (entityTypePicker != null)
                {
                    int selectedValue = 0;
                    var entityType    = EntityTypeCache.Read(guid);
                    if (entityType != null)
                    {
                        selectedValue = entityType.Id;
                    }
                    entityTypePicker.SelectedEntityTypeId = selectedValue;
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Creates the control(s) neccessary 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 entityTypePicker = new EntityTypePicker {
                ID = id
            };

            entityTypePicker.IncludeGlobalOption = true;

            if (configurationValues != null)
            {
                bool includeGlobal = false;
                if (configurationValues.ContainsKey("includeglobal") &&
                    bool.TryParse(configurationValues["includeglobal"].Value, out includeGlobal) &&
                    !includeGlobal)
                {
                    entityTypePicker.IncludeGlobalOption = false;
                }
            }
            entityTypePicker.EntityTypes = new EntityTypeService().GetEntities().ToList();
            return(entityTypePicker);
        }
Esempio n. 7
0
        /// <summary>
        /// Reads new values entered by the user for the field ( as Guid)
        /// </summary>
        /// <param name="control">Parent control that controls were added to in the CreateEditControl() method</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <returns></returns>
        public override string GetEditValue(Control control, Dictionary <string, ConfigurationValue> configurationValues)
        {
            EntityTypePicker entityTypePicker = control as EntityTypePicker;

            if (entityTypePicker != null && entityTypePicker.SelectedEntityTypeId.HasValue)
            {
                if (entityTypePicker.SelectedEntityTypeId == 0 && entityTypePicker.IncludeGlobalOption)
                {
                    return(Guid.Empty.ToString());
                }
                else
                {
                    var entityType = EntityTypeCache.Get(entityTypePicker.SelectedEntityTypeId.Value);
                    if (entityType != null)
                    {
                        return(entityType.Guid.ToString());
                    }
                }
            }

            return(null);
        }
        /// <summary>
        /// Sets the value ( as Guid )
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="value">The value.</param>
        public override void SetEditValue(Control control, Dictionary <string, ConfigurationValue> configurationValues, string value)
        {
            EntityTypePicker entityTypePicker = control as EntityTypePicker;

            if (entityTypePicker != null)
            {
                EntityTypeCache entityType = null;
                Guid?           guid       = value.AsGuidOrNull();
                if (guid.HasValue)
                {
                    entityType = EntityTypeCache.Get(guid.Value);

                    // If the guid had a value, but the EntityType is null, it's probably the "None (Global Attributes)" entity.
                    if (entityType == null && entityTypePicker.IncludeGlobalOption)
                    {
                        entityTypePicker.SelectedEntityTypeId = 0;
                    }
                    else
                    {
                        entityTypePicker.SelectedEntityTypeId = entityType?.Id;
                    }
                }
            }
        }