protected internal virtual void RenderInvalidMessageElement(IFormField formField,
                                                                    HtmlDocumentBuilder documentBuilder)
        {
            var divElement = new HtmlElementWriter(DivElement);

            var formFieldId  = formField.Id;
            var ifExpression = string.Format(InvalidExpression + " && " + DirtyExpression, formFieldId, formFieldId);

            divElement.Attribute(NgIfAttribute, ifExpression).Attribute(ClassAttribute, HasErrorClass);

            // <div ng-if="....$invalid && ....$dirty"...>
            documentBuilder.StartElement(divElement);

            if (!IsDate(formField))
            {
                RenderInvalidValueMessage(formField, documentBuilder);
                RenderInvalidTypeMessage(formField, documentBuilder);
            }
            else
            {
                RenderInvalidDateMessage(formField, documentBuilder);
            }

            documentBuilder.EndElement();
        }
        protected internal virtual void RenderInvalidDateMessage(IFormField formField,
                                                                 HtmlDocumentBuilder documentBuilder)
        {
            var formFieldId = formField.Id;

            var firstDivElement = new HtmlElementWriter(DivElement);

            var firstExpression = string.Format(RequiredErrorExpression + " && !" + DateErrorExpression,
                                                formFieldId, formFieldId);

            firstDivElement.Attribute(NgShowAttribute, firstExpression)
            .Attribute(ClassAttribute, HelpBlockClass)
            .TextContent(RequiredFieldMessage);

            documentBuilder.StartElement(firstDivElement).EndElement();

            var secondDivElement = new HtmlElementWriter(DivElement);

            var secondExpression = string.Format(DateErrorExpression, formFieldId);

            secondDivElement.Attribute(NgShowAttribute, secondExpression)
            .Attribute(ClassAttribute, HelpBlockClass)
            .TextContent(InvalidDateFieldMessage);

            documentBuilder.StartElement(secondDivElement).EndElement();
        }
        protected internal virtual string RenderFormData(IFormData formData)
        {
            if ((formData == null) ||
                (((formData.FormFields == null) || (formData.FormFields.Count == 0)) &&
                 ((formData.FormProperties == null) || (formData.FormProperties.Count == 0))))
            {
                return(null);
            }
            var formElement =
                new HtmlElementWriter(FormElement).Attribute(NameAttribute, GeneratedFormName)
                .Attribute(RoleAttribute, FormRole);

            var documentBuilder = new HtmlDocumentBuilder(formElement);

            // render fields
            foreach (var formField in formData.FormFields)
            {
                RenderFormField(formField, documentBuilder);
            }

            // render deprecated form properties
            foreach (var formProperty in formData.FormProperties)
            {
                RenderFormField(new FormPropertyAdapter(formProperty), documentBuilder);
            }

            // end document element
            documentBuilder.EndElement();

            return(documentBuilder.HtmlString);
        }
Пример #4
0
 public HtmlDocumentBuilder(HtmlElementWriter documentElement)
 {
     if (!_instanceFieldsInitialized)
     {
         InitializeInstanceFields();
         _instanceFieldsInitialized = true;
     }
     StartElement(documentElement);
 }
        protected internal virtual HtmlElementWriter CreateInputField(IFormField formField)
        {
            var inputField = new HtmlElementWriter(InputElement, true);

            AddCommonFormFieldAttributes(formField, inputField);

            inputField.Attribute(TypeAttribute, TextInputType);

            return(inputField);
        }
        protected internal virtual void RenderInvalidValueMessage(IFormField formField,
                                                                  HtmlDocumentBuilder documentBuilder)
        {
            var divElement = new HtmlElementWriter(DivElement);

            var formFieldId = formField.Id;

            var expression = string.Format(RequiredErrorExpression, formFieldId);

            divElement.Attribute(NgShowAttribute, expression)
            .Attribute(ClassAttribute, HelpBlockClass)
            .TextContent(RequiredFieldMessage);

            documentBuilder.StartElement(divElement).EndElement();
        }
        protected internal virtual void RenderSelectBox(IFormField formField, HtmlDocumentBuilder documentBuilder)
        {
            var selectBox = new HtmlElementWriter(SelectElement, false);

            AddCommonFormFieldAttributes(formField, selectBox);

            // <select ...>
            documentBuilder.StartElement(selectBox);

            // <option ...>
            RenderSelectOptions(formField, documentBuilder);

            // </select>
            documentBuilder.EndElement();
        }
Пример #8
0
        protected internal virtual void RenderSelectOptions(IFormField formField, HtmlDocumentBuilder documentBuilder)
        {
            //EnumFormType enumFormType = (EnumFormType) formField.Type;
            IDictionary <string, string> values = new Dictionary <string, string>(); //= enumFormType.Values;

            foreach (var value in values)
            {
                // <option>
                var option =
                    new HtmlElementWriter(OptionElement, false).Attribute(ValueAttribute, value.Key)
                    .TextContent(value.Value);

                documentBuilder.StartElement(option).EndElement();
            }
        }
        protected internal virtual void RenderInputField(IFormField formField, HtmlDocumentBuilder documentBuilder)
        {
            var inputField = new HtmlElementWriter(InputElement, true);

            AddCommonFormFieldAttributes(formField, inputField);

            var inputType = !IsBoolean(formField) ? TextInputType : CheckboxInputType;

            inputField.Attribute(TypeAttribute, inputType);

            // add default value
            var defaultValue = formField.DefaultValue;

            if (defaultValue != null)
            {
                inputField.Attribute(ValueAttribute, defaultValue.ToString());
            }

            // <input ... />
            documentBuilder.StartElement(inputField).EndElement();
        }
Пример #10
0
        protected internal virtual void RenderFormField(IFormField formField, HtmlDocumentBuilder documentBuilder)
        {
            // start group
            var divElement = new HtmlElementWriter(DivElement).Attribute(ClassAttribute, FormGroupClass);

            documentBuilder.StartElement(divElement);

            var formFieldId    = formField.Id;
            var formFieldLabel = formField.Label;

            // write label
            if (!ReferenceEquals(formFieldLabel, null) && (formFieldLabel.Length > 0))
            {
                var labelElement =
                    new HtmlElementWriter(LabelElement).Attribute(ForAttribute, formFieldId)
                    .TextContent(formFieldLabel);

                // <label for="...">...</label>
                documentBuilder.StartElement(labelElement).EndElement();
            }

            // render form control
            if (IsEnum(formField))
            {
                RenderSelectBox(formField, documentBuilder);
            }
            else if (IsDate(formField))
            {
                RenderDatePicker(formField, documentBuilder);
            }
            else
            {
                RenderInputField(formField, documentBuilder);
            }

            RenderInvalidMessageElement(formField, documentBuilder);

            // end group
            documentBuilder.EndElement();
        }
Пример #11
0
        protected internal virtual void RenderInvalidTypeMessage(IFormField formField,
                                                                 HtmlDocumentBuilder documentBuilder)
        {
            var divElement = new HtmlElementWriter(DivElement);

            var formFieldId = formField.Id;

            var expression = string.Format(TypeErrorExpression, formFieldId);

            var typeName = formField.TypeName;

            if (IsEnum(formField))
            {
                typeName = StringFormType.TypeName;
            }

            divElement.Attribute(NgShowAttribute, expression)
            .Attribute(ClassAttribute, HelpBlockClass)
            .TextContent(string.Format(TypeFieldMessage, typeName));

            documentBuilder.StartElement(divElement).EndElement();
        }
Пример #12
0
        protected internal virtual void AddCommonFormFieldAttributes(IFormField formField, HtmlElementWriter formControl)
        {
            var typeName = formField.TypeName;

            if (IsEnum(formField) || IsDate(formField))
            {
                typeName = StringFormType.TypeName;
            }

            typeName = typeName.Substring(0, 1).ToUpper() + typeName.Substring(1);

            var formFieldId = formField.Id;

            formControl.Attribute(ClassAttribute, FormControlClass)
            .Attribute(NameAttribute, formFieldId)
            .Attribute(CamVariableTypeAttribute, typeName)
            .Attribute(CamVariableNameAttribute, formFieldId);

            // add validation constraints
            foreach (var constraint in formField.ValidationConstraints)
            {
                var constraintName = constraint.Name;
                var configuration  = (string)constraint.Configuration;
                formControl.Attribute(constraintName, configuration);
            }
        }
Пример #13
0
        protected internal virtual void RenderDatePicker(IFormField formField, HtmlDocumentBuilder documentBuilder)
        {
            //bool isReadOnly = isReadOnly(formField);

            // start input-group
            var inputGroupDivElement = new HtmlElementWriter(DivElement).Attribute(ClassAttribute, InputGroupClass);

            var formFieldId = formField.Id;

            // <div>
            documentBuilder.StartElement(inputGroupDivElement);

            // input field
            var inputField = CreateInputField(formField);

            //if (!isReadOnly)
            {
                inputField.Attribute(DatepickerPopupAttribute, DateFormat)
                .Attribute(IsOpenAttribute, string.Format(DateFieldOpenedAttribute, formFieldId));
            }

            // <input ... />
            documentBuilder.StartElement(inputField).EndElement();


            // if form field is read only, do not render date picker open button
            //if (!isReadOnly)
            {
                // input addon
                var addonElement = new HtmlElementWriter(DivElement).Attribute(ClassAttribute, InputGroupBtnClass);

                // <div>
                documentBuilder.StartElement(addonElement);

                // button to open date picker
                var buttonElement =
                    new HtmlElementWriter(ButtonElement).Attribute(TypeAttribute, ButtonButtonType)
                    .Attribute(ClassAttribute, ButtonDefaultClass)
                    .Attribute(NgClickAttribute, string.Format(OpenDatepickerFunctionSnippet, formFieldId));

                // <button>
                documentBuilder.StartElement(buttonElement);

                var iconElement = new HtmlElementWriter(Element).Attribute(ClassAttribute, CalendarGlyphicon);

                // <i ...></i>
                documentBuilder.StartElement(iconElement).EndElement();

                // </button>
                documentBuilder.EndElement();

                // </div>
                documentBuilder.EndElement();


                var scriptElement =
                    new HtmlElementWriter(ScriptElement).Attribute(CamScriptAttribute, null)
                    .Attribute(TypeAttribute, TextFormScriptType)
                    .TextContent(string.Format(OpenDatepickerSnippet, formFieldId, formFieldId));

                // <script ...> </script>
                documentBuilder.StartElement(scriptElement).EndElement();
            }

            // </div>
            documentBuilder.EndElement();
        }
Пример #14
0
 public virtual HtmlDocumentBuilder StartElement(HtmlElementWriter renderer)
 {
     renderer.WriteStartTag(Context);
     Elements.Push(renderer);
     return(this);
 }