Exemplo n.º 1
0
        public static MvcHtmlString DynamicRequiredSymbolForComponent <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, object viewData = null, bool readOnly = false, string symbol = "*", string message = "Esse campo é obrigatório!", string cssClass = "req editor-field-required")
        {
            DynamicComponentBaseFor <TModel, TProperty> dynamicComponentBase = new DynamicComponentBaseFor <TModel, TProperty>(helper, expression, viewData, readOnly);

            ModelMetadata modelMetadata = ModelMetadata.FromLambdaExpression(expression, helper.ViewData);

            return(helper.DynamicRequiredSymbol(viewData, modelMetadata.IsRequired, readOnly));
        }
		public static MvcHtmlString DynamicDropDownListFor<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>> expression, IEnumerable<SelectListItem> selectList, string optionLabel, object viewData = null, bool readOnly = false, bool disabled = false, bool visible = true)
		{
			DynamicComponentBaseFor<TModel, TProperty> dynamicComponentBase = new DynamicComponentBaseFor<TModel, TProperty>(helper, expression, viewData, readOnly, disabled, visible);

			TagBuilder_Select<TModel, TProperty> tagBuilder = new TagBuilder_Select<TModel, TProperty>(dynamicComponentBase);
			tagBuilder.AddOptionLabel(optionLabel);
			tagBuilder.AddOptions(selectList);

			return tagBuilder.GenerateElementMvcString(TagRenderMode.Normal);
		}
Exemplo n.º 3
0
        private static MvcHtmlString DynamicRange <TModel, TProperty>(DynamicComponentBaseFor <TModel, TProperty> dynamicComponentBase, bool showValue = false)
        {
            TagBuilder_Range <TModel, TProperty> range = new TagBuilder_Range <TModel, TProperty>(dynamicComponentBase);

            if (showValue)
            {
                TagBuilder_Label <TModel, TProperty> label = new TagBuilder_Label <TModel, TProperty>(dynamicComponentBase, null, dynamicComponentBase.FieldValue.ToString(), dynamicComponentBase.SanitizedId);
                label.TagElement.RemoveAttribute("class");
                label.TagElement.AddCssClass("slider_label");
                range.TagElement.InnerHtml = label.TagElement.ToMvcHtmlStringSanitized(TagRenderMode.Normal).ToString();
            }

            return(range.GenerateElementMvcString(TagRenderMode.Normal));
        }
        public static MvcHtmlString DynamicDisplayListFor <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, IEnumerable <SelectListItem> selectList, string optionLabel, DisplayListType displayType = DisplayListType.SelectedLabel, object viewData = null)
        {
            DynamicComponentBaseFor <TModel, TProperty> dynamicComponentBase = new DynamicComponentBaseFor <TModel, TProperty>(helper, expression, viewData, true, true);
            object selectedValue = dynamicComponentBase.FieldValue;
            string selectedText  = selectList.Where(w => w.Value == selectedValue?.ToString()).FirstOrDefault()?.Text;

            switch (displayType)
            {
            case DisplayListType.DropDownList:
                TagBuilder_Select <TModel, TProperty> tagBuilder = new TagBuilder_Select <TModel, TProperty>(dynamicComponentBase);
                tagBuilder.AddOptionLabel(optionLabel);
                tagBuilder.AddOptions(selectList);
                tagBuilder.TagElement.AddInputAttributeStaticValue("disabled", null);
                tagBuilder.TagElement.AddInputAttributeStaticValue("class", "");
                return(tagBuilder.GenerateElementMvcString(TagRenderMode.Normal));

            case DisplayListType.SelectedEdit:
                dynamicComponentBase.HtmlAttributes = (RouteValueDictionary)helper.MergeHtmlAttributes(dynamicComponentBase.HtmlAttributes, new RouteValueDictionary()
                {
                    { "class", "control-input" }
                });
                return(TagBuilderGenerators.GenerateTagEditor(dynamicComponentBase.SanitizedId, selectedText, dynamicComponentBase.HtmlAttributes, dynamicComponentBase.FieldModelMetadata.Description, false, true).ToMvcHtmlString(TagRenderMode.Normal));

            case DisplayListType.OptionsList:
                return(null);

            case DisplayListType.SelectedLabel:
                dynamicComponentBase.HtmlAttributes = (RouteValueDictionary)helper.MergeHtmlAttributes(dynamicComponentBase.HtmlAttributes, new RouteValueDictionary()
                {
                    { "class", "control-label" }
                });
                return(TagBuilderGenerators.GenerateTagLabel(dynamicComponentBase.SanitizedId, selectedText, dynamicComponentBase.SanitizedId, dynamicComponentBase.HtmlAttributes, dynamicComponentBase.FieldModelMetadata.Description).ToMvcHtmlString(TagRenderMode.Normal));

            case DisplayListType.SelectedSpan:
                dynamicComponentBase.HtmlAttributes = (RouteValueDictionary)helper.MergeHtmlAttributes(dynamicComponentBase.HtmlAttributes, new RouteValueDictionary()
                {
                    { "class", "control-span" }
                });
                return(TagBuilderGenerators.GenerateTagDisplay(dynamicComponentBase.SanitizedId, selectedText, dynamicComponentBase.HtmlAttributes, dynamicComponentBase.FieldModelMetadata.Description).ToMvcHtmlString(TagRenderMode.Normal));

            case DisplayListType.SelectedOnlyText:
            default:
                return(TagBuilderGenerators.GenerateOnlyText(selectedText, dynamicComponentBase.HtmlAttributes));
            }
        }
        public static MvcHtmlString DynamicDisplayFor <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, Rendering displayType = Rendering.Label, object viewData = null, bool blockShowRequiredSymbol = false, string requiredSymbol = null, string requiredMessage = null, string requiredClass = null)
        {
            DynamicComponentBaseFor <TModel, TProperty> dynamicComponentBase = new DynamicComponentBaseFor <TModel, TProperty>(helper, expression, viewData);

            switch (displayType)
            {
            case Rendering.Label:
                dynamicComponentBase.HtmlAttributes = (RouteValueDictionary)helper.MergeHtmlAttributes(dynamicComponentBase.HtmlAttributes, new RouteValueDictionary()
                {
                    { "class", "control-label" }
                });
                return(TagBuilderGenerators.GenerateTagLabel(dynamicComponentBase.SanitizedId, dynamicComponentBase.FieldValue.ToString(), null, dynamicComponentBase.HtmlAttributes, dynamicComponentBase.FieldModelMetadata.Description, false /*!blockShowRequiredSymbol && dynamicComponentBase.FieldModelMetadata.IsRequired*/, requiredSymbol, requiredMessage, requiredClass).ToMvcHtmlString(TagRenderMode.Normal));

            case Rendering.Span:
                dynamicComponentBase.HtmlAttributes = (RouteValueDictionary)helper.MergeHtmlAttributes(dynamicComponentBase.HtmlAttributes, new RouteValueDictionary()
                {
                    { "class", "control-span" }
                });
                return(TagBuilderGenerators.GenerateTagDisplay(dynamicComponentBase.SanitizedId, dynamicComponentBase.FieldValue.ToString(), dynamicComponentBase.HtmlAttributes, dynamicComponentBase.FieldModelMetadata.Description, false /*!blockShowRequiredSymbol && dynamicComponentBase.FieldModelMetadata.IsRequired*/, requiredSymbol, requiredMessage, requiredClass).ToMvcHtmlString(TagRenderMode.Normal));

            case Rendering.Edit:
                dynamicComponentBase.HtmlAttributes = (RouteValueDictionary)helper.MergeHtmlAttributes(dynamicComponentBase.HtmlAttributes, new RouteValueDictionary()
                {
                    { "class", "form-control control-input" }
                });
                return(TagBuilderGenerators.GenerateTagEditor(dynamicComponentBase.SanitizedId, dynamicComponentBase.FieldValue.ToString(), dynamicComponentBase.HtmlAttributes, dynamicComponentBase.FieldModelMetadata.Description, false, true).ToMvcHtmlString(TagRenderMode.Normal));

            case Rendering.Progress:
                dynamicComponentBase.HtmlAttributes = (RouteValueDictionary)helper.MergeHtmlAttributes(dynamicComponentBase.HtmlAttributes, new RouteValueDictionary()
                {
                    { "class", "form-control control-progress" }
                });
                double?value    = dynamicComponentBase.FieldValue == null ? (double?)null : double.Parse(dynamicComponentBase.FieldValue.ToString());
                double?maxValue = dynamicComponentBase.MetadataAttributes.GetValue <double?>("Progress", "MaxValue");
                return(TagBuilderGenerators.GenerateTagProgress(dynamicComponentBase.SanitizedId, dynamicComponentBase.FieldValue.ToString(), dynamicComponentBase.HtmlAttributes, value, maxValue, dynamicComponentBase.FieldModelMetadata.Description, false).ToMvcHtmlString(TagRenderMode.Normal));

            default:
                return(TagBuilderGenerators.GenerateOnlyText(dynamicComponentBase.FieldValue.ToString(), dynamicComponentBase.HtmlAttributes, false /*!blockShowRequiredSymbol && dynamicComponentBase.FieldModelMetadata.IsRequired*/, requiredSymbol, requiredMessage, requiredClass));
            }
        }
Exemplo n.º 6
0
        public static MvcHtmlString DynamicEditorFor <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, object viewData = null, bool readOnly = false, bool disabled = false, bool visible = true)
        {
            DynamicComponentBaseFor <TModel, TProperty> dynamicComponentBase = new DynamicComponentBaseFor <TModel, TProperty>(helper, expression, viewData, readOnly, disabled, visible);

            switch ((DataType)dynamicComponentBase.MetadataAttributes.GetValue <DataType>("DataType", "DataType"))
            {
            case DataType.MultilineText:
                return(DynamicTextArea(dynamicComponentBase));

            case DataType.Custom:
            case DataType.DateTime:
            case DataType.Date:
            case DataType.Time:
            case DataType.Duration:
            case DataType.PhoneNumber:
            case DataType.Currency:
            case DataType.Text:
            case DataType.Html:
            case DataType.EmailAddress:
            case DataType.Password:
            case DataType.Url:
            case DataType.ImageUrl:
            case DataType.CreditCard:
            case DataType.PostalCode:
            case DataType.Upload:
            default:
                if (expression.Body.Type.FullName == "System.Boolean")
                {
                    return(DynamicCheckbox(dynamicComponentBase));
                }
                else if (dynamicComponentBase.MetadataAttributes.HasAttribute <bool>("ProgressAttribute"))
                {
                    helper.AddScript("slider", "$(function() { $('.slider').on('input change', function() { $(this).next($('.slider_label')).html(this.value); }); $('.slider_label').each(function() { var value = $(this).prev().attr('value'); $(this).html(value); }); })");
                    return(DynamicRange(dynamicComponentBase, true));
                }

                return(DynamicInput(dynamicComponentBase));
            }
        }
        public static MvcHtmlString DynamicEditorListFor <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, IEnumerable <SelectListItem> selectList, string optionLabel, EditorListType editorType = EditorListType.DropDownList, object viewData = null)
        {
            DynamicComponentBaseFor <TModel, TProperty> dynamicComponentBase = new DynamicComponentBaseFor <TModel, TProperty>(helper, expression, viewData, true, true);
            object selectedValue = dynamicComponentBase.FieldValue;
            string selectedText  = selectList.Where(w => w.Value == selectedValue?.ToString()).FirstOrDefault()?.Text;

            switch (editorType)
            {
            case EditorListType.DropDownList:
                TagBuilder_Select <TModel, TProperty> tagSelBuilder = new TagBuilder_Select <TModel, TProperty>(dynamicComponentBase);
                tagSelBuilder.AddOptionLabel(optionLabel);
                tagSelBuilder.AddOptions(selectList);
                return(tagSelBuilder.GenerateElementMvcString(TagRenderMode.Normal));

            case EditorListType.OptionsList:
                //<input type="radio" name="group2" value="male" checked> Male
                TagBuilder_RadioGroup <TModel, TProperty> tagRadBuilder = new TagBuilder_RadioGroup <TModel, TProperty>(dynamicComponentBase);
                tagRadBuilder.AddOptions(selectList);
                return(tagRadBuilder.GenerateElementMvcString(TagRenderMode.Normal));

            default:
                return(null);
            }
        }
        public static MvcHtmlString DynamicDisplayNameFor <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, Rendering displayType = Rendering.OnlyText, object viewData = null, bool blockShowRequiredSymbol = false, string requiredSymbol = null, string requiredMessage = null, string requiredClass = null)
        {
            DynamicComponentBaseFor <TModel, TProperty> dynamicComponentBase = new DynamicComponentBaseFor <TModel, TProperty>(helper, expression, viewData);

            switch (displayType)
            {
            case Rendering.Label:
                dynamicComponentBase.HtmlAttributes = (RouteValueDictionary)helper.MergeHtmlAttributes(dynamicComponentBase.HtmlAttributes, new RouteValueDictionary()
                {
                    { "class", "control-label" }
                });
                return(TagBuilderGenerators.GenerateTagLabel($"display_{ dynamicComponentBase.SanitizedId }", dynamicComponentBase.FieldModelMetadata.DisplayName, dynamicComponentBase.SanitizedId, dynamicComponentBase.HtmlAttributes, dynamicComponentBase.FieldModelMetadata.Description, !blockShowRequiredSymbol && dynamicComponentBase.FieldModelMetadata.IsRequired, requiredSymbol, requiredMessage, requiredClass).ToMvcHtmlString(TagRenderMode.Normal));

            case Rendering.Span:
                dynamicComponentBase.HtmlAttributes = (RouteValueDictionary)helper.MergeHtmlAttributes(dynamicComponentBase.HtmlAttributes, new RouteValueDictionary()
                {
                    { "class", "control-span" }
                });
                return(TagBuilderGenerators.GenerateTagDisplay($"display_{ dynamicComponentBase.SanitizedId }", dynamicComponentBase.FieldModelMetadata.DisplayName, dynamicComponentBase.HtmlAttributes, dynamicComponentBase.FieldModelMetadata.Description, !blockShowRequiredSymbol && dynamicComponentBase.FieldModelMetadata.IsRequired, requiredSymbol, requiredMessage, requiredClass).ToMvcHtmlString(TagRenderMode.Normal));

            default:
                return(TagBuilderGenerators.GenerateOnlyText(dynamicComponentBase.FieldModelMetadata.DisplayName, dynamicComponentBase.HtmlAttributes, !blockShowRequiredSymbol && dynamicComponentBase.FieldModelMetadata.IsRequired, requiredSymbol, requiredMessage, requiredClass));
            }
        }
Exemplo n.º 9
0
 private static MvcHtmlString DynamicTextArea <TModel, TProperty>(DynamicComponentBaseFor <TModel, TProperty> dynamicComponentBase)
 {
     return(new TagBuilder_TextArea <TModel, TProperty>(dynamicComponentBase).GenerateElementMvcString(TagRenderMode.Normal));
 }
        public static MvcHtmlString DynamicProgressFor <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, object viewData = null, decimal maxValue = 100, bool readOnly = false, bool disabled = false, bool visible = true)
        {
            DynamicComponentBaseFor <TModel, TProperty> dynamicComponentBase = new DynamicComponentBaseFor <TModel, TProperty>(helper, expression, viewData, readOnly, disabled, visible);

            return(new TagBuilder_Progress <TModel, TProperty>(dynamicComponentBase).GenerateElementMvcString(TagRenderMode.Normal));
        }
Exemplo n.º 11
0
        public static MvcHtmlString DynamicListBoxFor <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, IEnumerable <SelectListItem> selectList, IDictionary <string, object> htmlAttributes)
        {
            DynamicComponentBaseFor <TModel, TProperty> dynamicComponentBase = new DynamicComponentBaseFor <TModel, TProperty>(helper, expression, htmlAttributes);

            return(null);
        }
Exemplo n.º 12
0
        public static MvcHtmlString DynamicListBoxFor <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, IEnumerable <SelectListItem> selectList)
        {
            DynamicComponentBaseFor <TModel, TProperty> dynamicComponentBase = new DynamicComponentBaseFor <TModel, TProperty>(helper, expression);

            return(null);
        }
        public static MvcHtmlString DynamicEnumDropDownListFor <TModel, TEnum>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TEnum> > expression, string optionLabel, IDictionary <string, object> htmlAttributes)
        {
            DynamicComponentBaseFor <TModel, TEnum> dynamicComponentBase = new DynamicComponentBaseFor <TModel, TEnum>(helper, expression, htmlAttributes);

            return(null);
        }
        public static MvcHtmlString DynamicEnumDropDownListFor <TModel, TEnum>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TEnum> > expression, string optionLabel)
        {
            DynamicComponentBaseFor <TModel, TEnum> dynamicComponentBase = new DynamicComponentBaseFor <TModel, TEnum>(helper, expression);

            return(null);
        }