Exemplo n.º 1
0
        /// <summary>
        /// Returns metadata associated with the TModel type.
        /// </summary>
        public IModelMetadata For(Type modelType)
        {
            IModelMetadata metadata = null;

            if (!typeMetadata.TryGetValue(modelType, out metadata))
            {
                metadata = new ModelMetadata(modelType);
                typeMetadata.Add(modelType, metadata);
            }
            return(metadata);
        }
        protected internal virtual IFormComponent <IFormComponentInput> CreateTextInputComponent(string text, IModelMetadata modelMetadata)
        {
            if (modelMetadata == null)
            {
                throw new ArgumentNullException(nameof(modelMetadata));
            }

            IFormComponent <IFormComponentInput> textInputComponent;

            var id = this.HtmlIdFactory.Create(modelMetadata.ContainerType.Name + modelMetadata.PropertyName + "Input");

            var dataType = modelMetadata.GetDataType();

            if (dataType != null && dataType.Value == DataType.MultilineText)
            {
                textInputComponent = new TextAreaComponent(modelMetadata.GetDisplayName(), this.HttpEncoder, id, modelMetadata.PropertyName, modelMetadata.IsRequired, text);
            }
            else
            {
                textInputComponent = new InputComponent(modelMetadata.GetDisplayName(), this.HttpEncoder, id, modelMetadata.PropertyName, modelMetadata.IsRequired, InputType.Text, text);
            }

            if (!string.IsNullOrWhiteSpace(modelMetadata.Watermark))
            {
                textInputComponent.Input.SetAttribute(HtmlAttributeKey.Placeholder, modelMetadata.Watermark);
            }

            if (!string.IsNullOrEmpty(this.Settings.ComponentClass))
            {
                textInputComponent.AddClass(this.Settings.ComponentClass);
            }

            if (!string.IsNullOrEmpty(this.Settings.TextInputClass))
            {
                textInputComponent.Input.AddClass(this.Settings.TextInputClass);
            }

            foreach (var additionalValue in modelMetadata.AdditionalValues)
            {
                textInputComponent.Input.SetAttribute(additionalValue.Key, additionalValue.Value);
            }

            this.AddValidationClassIfNecessary(textInputComponent, modelMetadata.PropertyName);

            return(textInputComponent);
        }
Exemplo n.º 3
0
 public DummyPatientIdentifierProcessor()
 {
     _modelMetaData = new Lpp.Dns.DataMart.Client.DomainManger.ProxyModelMetadata.EmptyModelMetaData();
 }
        protected internal virtual IHtmlContainer CreateCheckBoxesComponent(Choices choices, IModelMetadata modelMetadata)
        {
            if (modelMetadata == null)
            {
                throw new ArgumentNullException(nameof(modelMetadata));
            }

            var id = this.HtmlIdFactory.Create(modelMetadata.ContainerType.Name + modelMetadata.PropertyName + "Input");

            var container = new HtmlTag(this.HttpEncoder, HtmlTextWriterTag.Div);

            container.SetId(id);

            if (!string.IsNullOrEmpty(this.Settings.CheckBoxClass))
            {
                container.AddClass(this.Settings.CheckBoxClass);
            }

            foreach (var property in modelMetadata.Properties)
            {
                var isChecked = false;

                if (choices != null)
                {
                    switch (property.PropertyName)
                    {
                    case "Blue":
                        isChecked = choices.Blue;
                        break;

                    case "Green":
                        isChecked = choices.Green;
                        break;

                    case "Red":
                        isChecked = choices.Red;
                        break;

                    default:
                        break;
                    }
                }

                id = this.HtmlIdFactory.Create(modelMetadata.ContainerType.Name + modelMetadata.PropertyName + "Checkbox" + property.PropertyName);

                var checkBox = new Input(this.HttpEncoder, InputType.CheckBox);
                checkBox.SetId(id);
                checkBox.SetName(modelMetadata.PropertyName + "." + property.PropertyName);
                checkBox.SetAttribute(HtmlAttributeKey.Value, true.ToString());

                if (isChecked)
                {
                    checkBox.SetAttribute(HtmlAttributeKey.Checked, HtmlAttributeKey.Checked);
                }

                container.Children.Add(checkBox);

                var label = new HtmlTag(this.HttpEncoder, HtmlTextWriterTag.Label);
                label.SetAttribute(HtmlAttributeKey.For, id);

                var displayText = property.GetDisplayName();

                if (!string.IsNullOrEmpty(displayText))
                {
                    label.Children.Add(new HtmlText(this.HttpEncoder)
                    {
                        Value = displayText
                    });
                }

                container.Children.Add(label);
            }

            return(container);
        }
Exemplo n.º 5
0
 public VueInstanceBoundValue(IElement <IVueInstance> instance, IModelMetadata metadata) : base(metadata?.NestedPropertyName)
 {
     Instance = instance ?? throw new ArgumentNullException(nameof(instance));
     Metadata = metadata ?? throw new ArgumentNullException(nameof(metadata));
 }