Esempio n. 1
0
        public override IHtmlString GetHtmlString(BaseFormBuilderRequestContext context, FormField field, IDictionary <string, string> htmlAttributes)
        {
            var sb              = new StringBuilder();
            var renderer        = context.FormRenderer;
            var placeholderText = field.PlaceholderText;

            if (String.IsNullOrEmpty(placeholderText) && renderer.HideLabels)
            {
                placeholderText = field.Label;
            }

            sb.AppendFormat(Markup,
                            "password",
                            HttpUtility.HtmlAttributeEncode(field.Name),
                            HttpUtility.HtmlAttributeEncode(field.Id),
                            HttpUtility.HtmlAttributeEncode(field.Label),
                            HttpUtility.HtmlAttributeEncode(placeholderText));

            AddHtmlAttribute("class", renderer.FormControlClass, htmlAttributes);

            AddReadOnlyAttribute(field, htmlAttributes);
            AddMaxLengthAttribute(field, htmlAttributes);
            RenderExtraHtmlTags(sb, field, htmlAttributes);

            sb.Append(" />");

            return(new HtmlString(sb.ToString()));
        }
Esempio n. 2
0
        public override string Render(BaseFormBuilderRequestContext context)
        {
            var sb       = new StringBuilder();
            var renderer = context.FormRenderer;

            renderer.WriteRowStart(InputFieldName, "captcha", renderer.WriteErrorClass(InputFieldName, context), true, null, sb);

            renderer.WriteLabelStart(false, InputFieldName, sb);
            renderer.WriteLabelContent(true, Localization.T("Captcha.GoogleReCAPTCHA.Label"), sb);
            renderer.WriteLabelEnd(sb);

            using (new ControlsGroup(sb, renderer))
            {
                if (!String.IsNullOrEmpty(Localization.T("Captcha.GoogleReCAPTCHA.Help")))
                {
                    renderer.WriteFieldHelpStart(sb);
                }

                sb.AppendFormat("<div class=\"g-recaptcha captcha-img\" data-sitekey=\"{0}\"></div>", _siteKey);
                sb.AppendFormat("<script type=\"text/javascript\" src=\"https://www.google.com/recaptcha/api.js?hl={0}\"></script>", Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName);

                if (!String.IsNullOrEmpty(Localization.T("Captcha.CompositeC1.Help")))
                {
                    renderer.WriteFieldHelpEnd(Localization.T("Captcha.GoogleReCAPTCHA.Help"), sb);
                }
            }

            renderer.WriteRowEnd(sb);

            return(sb.ToString());
        }
        public override IHtmlString GetHtmlString(BaseFormBuilderRequestContext context, FormField field, IDictionary <string, string> htmlAttributes)
        {
            var sb = new StringBuilder();
            var htmlAttributesDictionary = MapHtmlTagAttributes(field, htmlAttributes);

            sb.AppendFormat("<input type=\"{0}\" name=\"{1}\" id=\"{2}\"",
                            ElementName,
                            HttpUtility.HtmlAttributeEncode(field.Name),
                            HttpUtility.HtmlAttributeEncode(field.Id));

            if (field.ValueType == typeof(IEnumerable <FormFile>))
            {
                htmlAttributesDictionary.Add("multiple", new List <string>()
                {
                    "multiple"
                });
            }

            var fileMimeTypeValidatorAttr = field.Attributes.OfType <FileMimeTypeValidatorAttribute>().SingleOrDefault();

            if (fileMimeTypeValidatorAttr != null)
            {
                htmlAttributesDictionary.Add("accept", fileMimeTypeValidatorAttr.MimeTypes);
            }

            AddReadOnlyAttribute(field, htmlAttributes);
            AddMaxLengthAttribute(field, htmlAttributes);
            RenderExtraHtmlTags(sb, htmlAttributesDictionary);

            sb.Append(" />");

            return(new HtmlString(sb.ToString()));
        }
        public override IHtmlString GetHtmlString(BaseFormBuilderRequestContext context, FormField field, IDictionary <string, string> htmlAttributes)
        {
            var sb       = new StringBuilder();
            var renderer = context.FormRenderer;

            if (field.DataSource != null && field.DataSource.Any())
            {
                var ix    = 0;
                var value = field.Value;
                var htmlAttributesDictionary = MapHtmlTagAttributes(field, htmlAttributes);

                foreach (var item in field.DataSource)
                {
                    sb.AppendFormat("<label class=\"{0}\">", renderer.FormControlLabelClass(this));

                    sb.AppendFormat("<input type=\"{0}\" name=\"{2}\" id=\"{3}\" value=\"{4}\" title=\"{1}\" {5}",
                                    ElementName,
                                    HttpUtility.HtmlAttributeEncode(item.Value),
                                    HttpUtility.HtmlAttributeEncode(field.Name),
                                    HttpUtility.HtmlAttributeEncode(field.Id + "_" + ix++),
                                    HttpUtility.HtmlAttributeEncode(item.Key),
                                    (value == null ? String.Empty : renderer.WriteChecked(item.Key.IsEqualTo(value), "checked")));

                    AddReadOnlyAttribute(field, htmlAttributes);
                    RenderExtraHtmlTags(sb, htmlAttributesDictionary);

                    sb.AppendFormat(" /> {0}</label>", HttpUtility.HtmlEncode(item.Value));
                }
            }

            return(new HtmlString(sb.ToString()));
        }
        public IHtmlString InputFor(BaseFormBuilderRequestContext context, FormField field, Dictionary <string, string> htmlAttributes)
        {
            var sb = new StringBuilder();

            WriteField(context, field, sb, htmlAttributes);

            return(new HtmlString(sb.ToString()));
        }
        private IHtmlString WriteRow(BaseFormBuilderRequestContext context, FormField field, IDictionary <string, string> htmlAttributes)
        {
            var sb = new StringBuilder();

            WriteRowStart(field.Name, field.InputElementType.ElementName,
                          WriteErrorClass(field.Name, context), field.IsRequired,
                          builder => DependencyAttributeFor(field, builder), sb);

            if (!HideLabels)
            {
                if (!(field.InputElementType is CheckboxInputElementAttribute && field.ValueType == typeof(bool)))
                {
                    var showLabel = ShowLabel(field);
                    if (showLabel)
                    {
                        WriteLabel(field, sb);
                    }
                    else
                    {
                        WritePropertyHeading(field, sb);
                    }
                }
            }

            using (new ControlsGroup(sb, this))
            {
                if (!HideLabels)
                {
                    if (field.InputElementType is CheckboxInputElementAttribute && field.ValueType == typeof(bool))
                    {
                        sb.AppendFormat("<div class=\"{0}\">", field.InputElementType.ElementName);
                        sb.Append("   <label>");
                    }
                }

                WriteField(context, field, sb, htmlAttributes);

                if (!HideLabels)
                {
                    if (field.InputElementType is CheckboxInputElementAttribute && field.ValueType == typeof(bool))
                    {
                        WriteLabelContent(field, sb);

                        sb.Append("  </label>");
                        sb.Append("</div>");
                    }
                }
            }

            WriteRowEnd(sb);

            return(new HtmlString(sb.ToString()));
        }
        public static IHtmlString Captcha <T>(BaseFormBuilderRequestContext <T> context) where T : class, IModelInstance
        {
            if (!context.ModelInstance.RequiresCaptcha)
            {
                return(null);
            }

            var requiresCaptchaAttr = new RequiresCaptchaAttribute();
            var s = requiresCaptchaAttr.Render(context);

            return(new HtmlString(s));
        }
        private void WriteField(BaseFormBuilderRequestContext context, FormField field, StringBuilder sb, IDictionary <string, string> htmlAttributes)
        {
            var str = field.InputElementType.GetHtmlString(context, field, htmlAttributes);

            if (!String.IsNullOrWhiteSpace(field.Help))
            {
                WriteFieldHelpStart(sb);
            }

            sb.Append(str);

            if (!String.IsNullOrWhiteSpace(field.Help))
            {
                WriteFieldHelpEnd(field.Help, sb);
            }
        }
        public override string Render(BaseFormBuilderRequestContext context)
        {
            var sb             = new StringBuilder();
            var encryptedValue = Captcha.CreateEncryptedValue();
            var renderer       = context.FormRenderer;

            sb.AppendFormat("<input type=\"hidden\" name=\"{0}\" id=\"{1}\" value=\"{2}\" />",
                            HttpUtility.HtmlAttributeEncode(HiddenFieldName),
                            HttpUtility.HtmlAttributeEncode(HiddenFieldName),
                            HttpUtility.HtmlAttributeEncode(encryptedValue));

            renderer.WriteRowStart(InputFieldName, "captcha", renderer.WriteErrorClass(InputFieldName, context), true, null, sb);

            renderer.WriteLabelStart(false, InputFieldName, sb);
            renderer.WriteLabelContent(true, Localization.T("Captcha.CompositeC1.Label"), sb);
            renderer.WriteLabelEnd(sb);

            using (new ControlsGroup(sb, context.FormRenderer))
            {
                if (!String.IsNullOrEmpty(Localization.T("Captcha.CompositeC1.Help")))
                {
                    renderer.WriteFieldHelpStart(sb);
                }

                sb.AppendFormat("<div class=\"captcha-input\">");
                sb.AppendFormat("<input name=\"{0}\" id=\"{0}\" type=\"text\"  />", InputFieldName);
                sb.AppendFormat("</div>");

                sb.AppendFormat("<div class=\"captcha-img\">");
                sb.AppendFormat("<img src=\"{0}\" />", Captcha.GetImageUrl(encryptedValue));
                sb.AppendFormat("</div>");

                if (!String.IsNullOrEmpty(Localization.T("Captcha.CompositeC1.Help")))
                {
                    renderer.WriteFieldHelpEnd(Localization.T("Captcha.CompositeC1.Help"), sb);
                }
            }

            renderer.WriteRowEnd(sb);

            return(sb.ToString());
        }
Esempio n. 10
0
        public static IHtmlString RenderModelFields(IModelInstance instance, BaseFormBuilderRequestContext context)
        {
            var renderingMarkup = RenderingLayoutFacade.GetRenderingLayout(instance.Name);

            foreach (var field in instance.Fields.Where(f => f.Label != null))
            {
                var fieldElement = renderingMarkup.Body.Descendants().SingleOrDefault(el => el.Name == Namespaces.Xhtml + "p" && el.Value.Trim() == "%" + field.Name + "%");
                if (fieldElement == null)
                {
                    continue;
                }

                var html     = context.FormRenderer.FieldFor(context, field).ToString();
                var newValue = XElement.Parse(html);

                fieldElement.ReplaceWith(newValue);
            }

            return(new HtmlString(renderingMarkup.Body.ToString()));
        }
        public IHtmlString ValidationSummary <T>(BaseFormBuilderRequestContext <T> context) where T : IModelInstance
        {
            var sb = new StringBuilder();

            sb.Append("<div class=\"" + ValidationSummaryClass + "\">");

            if (context.IsOwnSubmit && context.ValidationResult.Any())
            {
                var s = ValidationSummary(context.ValidationResult.Select(r => new ValidationError
                {
                    AffectedFields = r.AffectedFormIds,
                    Message        = r.ValidationMessage
                }));

                sb.Append(s);
            }

            sb.Append("</div>");

            return(new HtmlString(sb.ToString()));
        }
        public override IHtmlString GetHtmlString(BaseFormBuilderRequestContext context, FormField field, IDictionary <string, string> htmlAttributes)
        {
            var function = FunctionFacade.GetFunction(_c1FunctionName);

            if (function == null)
            {
                throw new InvalidOperationException("C1 function " + _c1FunctionName + " not recognized");
            }

            var parameters = new Dictionary <string, object>
            {
                { "Name", field.Name },
                { "HtmlAttributes", htmlAttributes },
                { "IsRequired", field.IsRequired },
                { "Label", field.Label },
                { "Placeholder", field.PlaceholderText }
            };

            var result = FunctionFacade.Execute <XhtmlDocument>(function, parameters);

            return(new HtmlString(result.ToString()));
        }
Esempio n. 13
0
 public string Render(BaseFormBuilderRequestContext context)
 {
     return(Provider.Render(context));
 }
        public override IHtmlString GetHtmlString(BaseFormBuilderRequestContext context, FormField field, IDictionary <string, string> htmlAttributes)
        {
            var sb       = new StringBuilder();
            var renderer = context.FormRenderer;
            var value    = field.Value;

            if (field.ValueType == typeof(bool))
            {
                var bValue = false;
                try
                {
                    bValue = Convert.ToBoolean(value);
                }
                catch { }

                sb.AppendFormat("<input type=\"{0}\" name=\"{1}\" id=\"{2}\" value=\"on\" title=\"{3}\" {4}",
                                ElementName,
                                HttpUtility.HtmlAttributeEncode(field.Name),
                                HttpUtility.HtmlAttributeEncode(field.Id),
                                HttpUtility.HtmlAttributeEncode(field.Label),
                                renderer.WriteChecked(bValue, "checked"));

                AddReadOnlyAttribute(field, htmlAttributes);
                RenderExtraHtmlTags(sb, field, htmlAttributes);

                sb.Append(" />");
            }
            else if (field.ValueType == typeof(IEnumerable <string>))
            {
                var checkboxListOptions = field.DataSource;
                if (checkboxListOptions != null)
                {
                    var            ix = 0;
                    IList <string> list;

                    if (value == null)
                    {
                        list = Enumerable.Empty <string>().ToList();
                    }
                    else
                    {
                        if (value is string str)
                        {
                            list = new[] { str };
                        }
                        else
                        {
                            list = ((IEnumerable <string>)value).ToList();
                        }
                    }

                    foreach (var item in checkboxListOptions)
                    {
                        sb.AppendFormat("<label class=\"{0}\">", renderer.FormControlLabelClass(this));

                        sb.AppendFormat("<input type=\"checkbox\" name=\"{1}\" id=\"{2}\" value=\"{3}\" title=\"{0}\" {4}",
                                        HttpUtility.HtmlAttributeEncode(item.Value),
                                        HttpUtility.HtmlAttributeEncode(field.Name),
                                        HttpUtility.HtmlAttributeEncode(field.Id + "_" + ix++),
                                        HttpUtility.HtmlAttributeEncode(item.Key),
                                        renderer.WriteChecked(list.Contains(item.Key), "checked"));

                        AddReadOnlyAttribute(field, htmlAttributes);
                        AddMaxLengthAttribute(field, htmlAttributes);
                        RenderExtraHtmlTags(sb, field, htmlAttributes);

                        sb.AppendFormat("/> {0}</label>", HttpUtility.HtmlEncode(item.Value));
                    }
                }
            }

            return(new HtmlString(sb.ToString()));
        }
 public string WriteErrorClass(string name, BaseFormBuilderRequestContext context)
 {
     return(context.ValidationResult.Any(el => el.AffectedFormIds.Contains(name)) ? ErrorClass : String.Empty);
 }
Esempio n. 16
0
 public abstract IHtmlString GetHtmlString(BaseFormBuilderRequestContext context, FormField field, IDictionary <string, string> htmlAttributes);
Esempio n. 17
0
 protected string WriteErrorClass(string name, BaseFormBuilderRequestContext context)
 {
     return(FormRenderer.WriteErrorClass(name, context));
 }
 public IHtmlString FieldFor(BaseFormBuilderRequestContext context, FormField field, Dictionary <string, string> htmlAttributes)
 {
     return(WriteRow(context, field, htmlAttributes));
 }
 public IHtmlString FieldFor(BaseFormBuilderRequestContext context, FormField field)
 {
     return(FieldFor(context, field, new Dictionary <string, string>()));
 }
        public override IHtmlString GetHtmlString(BaseFormBuilderRequestContext context, FormField field, IDictionary <string, string> htmlAttributes)
        {
            var sb       = new StringBuilder();
            var renderer = context.FormRenderer;
            var htmlAttributesDictionary = MapHtmlTagAttributes(field, htmlAttributes);

            if (!String.IsNullOrEmpty(renderer.FormControlClass))
            {
                if (!htmlAttributesDictionary.TryGetValue("class", out var list))
                {
                    list = new List <string>();

                    htmlAttributesDictionary.Add("class", list);
                }

                list.Add(renderer.FormControlClass);
            }

            sb.AppendFormat("<select name=\"{0}\" id=\"{1}\"",
                            HttpUtility.HtmlAttributeEncode(field.Name),
                            HttpUtility.HtmlAttributeEncode(field.Id));

            if (field.ValueType == typeof(IEnumerable <string>))
            {
                htmlAttributesDictionary.Add("multiple", new List <string>()
                {
                    "multiple"
                });
            }

            RenderExtraHtmlTags(sb, htmlAttributesDictionary);

            sb.Append(">");

            if (field.DataSource != null && field.DataSource.Any())
            {
                var value       = field.Value;
                var selectLabel = renderer.HideLabels ? field.Label : Localization.T("Widgets.Dropdown.SelectLabel");

                sb.AppendFormat("<option value=\"\" selected=\"selected\" disabled=\"disabled\">{0}</option>", HttpUtility.HtmlEncode(selectLabel));

                foreach (var item in field.DataSource)
                {
                    bool checkedValue;
                    if (field.ValueType == typeof(IEnumerable <string>))
                    {
                        checkedValue = ((IEnumerable <string>)field.Value ?? new String[] { }).Contains(item.Key);
                    }
                    else
                    {
                        checkedValue = item.Key == (value ?? String.Empty).ToString();
                    }

                    sb.AppendFormat("<option value=\"{0}\" {1}>{2}</option>",
                                    HttpUtility.HtmlAttributeEncode(item.Key),
                                    renderer.WriteChecked(checkedValue, "selected"),
                                    HttpUtility.HtmlEncode(item.Value));
                }
            }

            sb.Append("</select>");

            return(new HtmlString(sb.ToString()));
        }