示例#1
0
        /// <summary>
        /// Adds the control.
        /// </summary>
        /// <param name="controls">The controls.</param>
        /// <param name="value">The value.</param>
        /// <param name="validationGroup">The validation group.</param>
        /// <param name="setValue">if set to <c>true</c> [set value].</param>
        /// <param name="setId">if set to <c>true</c> [set identifier].</param>
        /// <param name="required">The required.</param>
        /// <param name="labelText">The label text.</param>
        /// <param name="helpText">The help text.</param>
        /// <param name="warningText">The warning text.</param>
        /// <param name="attributeControlId">The attribute control identifier.</param>
        /// <returns></returns>
        public Control AddControl(ControlCollection controls, string value, string validationGroup, bool setValue, bool setId, bool?required, string labelText, string helpText, string warningText, string attributeControlId)
        {
            AttributeControlOptions attributeControlOptions = new AttributeControlOptions
            {
                Value              = value,
                ValidationGroup    = validationGroup,
                SetValue           = setValue,
                SetId              = setId,
                Required           = required,
                LabelText          = labelText,
                HelpText           = helpText,
                WarningText        = warningText,
                AttributeControlId = attributeControlId
            };

            return(AddControl(controls, attributeControlOptions));
        }
示例#2
0
        /// <summary>
        /// Adds the control.
        /// </summary>
        /// <param name="controls">The controls.</param>
        /// <param name="options">The options.</param>
        /// <returns></returns>
        public Control AddControl(ControlCollection controls, AttributeControlOptions options)
        {
            options.LabelText          = options.LabelText ?? Name;
            options.HelpText           = options.HelpText ?? Description;
            options.AttributeControlId = options.AttributeControlId ?? $"attribute_field_{Id}";

            EntityTypeCache entityType = EntityTypeId.HasValue ? EntityTypeCache.Get(this.EntityTypeId.Value) : null;

            bool showPrePostHtml = (entityType?.AttributesSupportPrePostHtml ?? false) && (options?.ShowPrePostHtml ?? true);

            var attributeControl = FieldType.Field.EditControl(QualifierValues, options.SetId ? options.AttributeControlId : string.Empty);

            if (attributeControl == null)
            {
                return(null);
            }

            if (options.SetId)
            {
                attributeControl.ClientIDMode = ClientIDMode.AutoID;
            }

            // If the control is a RockControl
            var rockControl        = attributeControl as IRockControl;
            var controlHasRequired = attributeControl as IHasRequired;

            if (showPrePostHtml)
            {
                if (this.PreHtml.IsNotNullOrWhiteSpace())
                {
                    controls.Add(new Literal {
                        Text = this.PreHtml
                    });
                }
            }

            if (rockControl != null)
            {
                rockControl.Label           = options.LabelText;
                rockControl.Help            = options.HelpText;
                rockControl.Warning         = options.WarningText;
                rockControl.Required        = options.Required ?? IsRequired;
                rockControl.ValidationGroup = options.ValidationGroup;

                controls.Add(attributeControl);
            }
            else
            {
                if (controlHasRequired != null)
                {
                    controlHasRequired.Required        = options.Required ?? IsRequired;
                    controlHasRequired.ValidationGroup = options.ValidationGroup;
                }

                bool renderLabel   = !string.IsNullOrEmpty(options.LabelText);
                bool renderHelp    = !string.IsNullOrWhiteSpace(options.HelpText);
                bool renderWarning = !string.IsNullOrWhiteSpace(options.WarningText);

                if (renderLabel || renderHelp || renderWarning)
                {
                    var div = new DynamicControlsHtmlGenericControl("div")
                    {
                        ID = $"_formgroup_div_{Id}"
                    };
                    controls.Add(div);

                    div.Controls.Clear();
                    div.AddCssClass("form-group");
                    if (IsRequired)
                    {
                        div.AddCssClass("required");
                    }

                    div.ClientIDMode = ClientIDMode.AutoID;

                    if (renderLabel)
                    {
                        var label = new Label
                        {
                            ID                  = $"_label_{Id}",
                            ClientIDMode        = ClientIDMode.AutoID,
                            Text                = options.LabelText,
                            CssClass            = "control-label",
                            AssociatedControlID = attributeControl.ID
                        };
                        div.Controls.Add(label);
                    }

                    if (renderHelp)
                    {
                        var helpBlock = new HelpBlock
                        {
                            ID           = $"_helpBlock_{Id}",
                            ClientIDMode = ClientIDMode.AutoID,
                            Text         = options.HelpText
                        };
                        div.Controls.Add(helpBlock);
                    }

                    if (renderWarning)
                    {
                        var warningBlock = new WarningBlock
                        {
                            ID           = $"_warningBlock_{Id}",
                            ClientIDMode = ClientIDMode.AutoID,
                            Text         = options.WarningText
                        };
                        div.Controls.Add(warningBlock);
                    }

                    div.Controls.Add(attributeControl);
                }
                else
                {
                    controls.Add(attributeControl);
                }
            }

            if (options.ShowPrePostHtml)
            {
                if (this.PostHtml.IsNotNullOrWhiteSpace())
                {
                    controls.Add(new Literal {
                        Text = this.PostHtml
                    });
                }
            }

            if (options.SetValue)
            {
                FieldType.Field.SetEditValue(attributeControl, QualifierValues, options.Value);
            }

            return(attributeControl);
        }
示例#3
0
        /// <summary>
        /// Adds the control.
        /// </summary>
        /// <param name="controls">The controls.</param>
        /// <param name="options">The options.</param>
        /// <returns></returns>
        public Control AddControl(ControlCollection controls, AttributeControlOptions options)
        {
            var attributeControl = FieldType.Field.EditControl(QualifierValues, options.SetId ? options.AttributeControlId : string.Empty);

            if (attributeControl == null)
            {
                return(null);
            }

            if (options.SetId)
            {
                attributeControl.ClientIDMode = ClientIDMode.AutoID;
            }

            // If the control is a RockControl
            var rockControl        = attributeControl as IRockControl;
            var controlHasRequired = attributeControl as IHasRequired;

            if (rockControl != null)
            {
                rockControl.Label           = options.LabelText;
                rockControl.Help            = options.HelpText;
                rockControl.Warning         = options.WarningText;
                rockControl.Required        = options.Required ?? IsRequired;
                rockControl.ValidationGroup = options.ValidationGroup;

                controls.Add(attributeControl);
            }
            else
            {
                if (controlHasRequired != null)
                {
                    controlHasRequired.Required        = options.Required ?? IsRequired;
                    controlHasRequired.ValidationGroup = options.ValidationGroup;
                }

                bool renderLabel   = !string.IsNullOrEmpty(options.LabelText);
                bool renderHelp    = !string.IsNullOrWhiteSpace(options.HelpText);
                bool renderWarning = !string.IsNullOrWhiteSpace(options.WarningText);

                if (renderLabel || renderHelp || renderWarning)
                {
                    var div = new DynamicControlsHtmlGenericControl("div")
                    {
                        ID = $"_formgroup_div_{Id}"
                    };
                    controls.Add(div);

                    div.Controls.Clear();
                    div.AddCssClass("form-group");
                    if (IsRequired)
                    {
                        div.AddCssClass("required");
                    }

                    div.ClientIDMode = ClientIDMode.AutoID;

                    if (renderLabel)
                    {
                        var label = new Label
                        {
                            ID                  = $"_label_{Id}",
                            ClientIDMode        = ClientIDMode.AutoID,
                            Text                = options.LabelText,
                            CssClass            = "control-label",
                            AssociatedControlID = attributeControl.ID
                        };
                        div.Controls.Add(label);
                    }

                    if (renderHelp)
                    {
                        var helpBlock = new HelpBlock
                        {
                            ID           = $"_helpBlock_{Id}",
                            ClientIDMode = ClientIDMode.AutoID,
                            Text         = options.HelpText
                        };
                        div.Controls.Add(helpBlock);
                    }

                    if (renderWarning)
                    {
                        var warningBlock = new WarningBlock
                        {
                            ID           = $"_warningBlock_{Id}",
                            ClientIDMode = ClientIDMode.AutoID,
                            Text         = options.WarningText
                        };
                        div.Controls.Add(warningBlock);
                    }

                    div.Controls.Add(attributeControl);
                }
                else
                {
                    controls.Add(attributeControl);
                }
            }

            if (options.SetValue)
            {
                FieldType.Field.SetEditValue(attributeControl, QualifierValues, options.Value);
            }

            return(attributeControl);
        }