Ejemplo n.º 1
0
        protected internal virtual void renderDatePicker(FormField formField, HtmlDocumentBuilder documentBuilder)
        {
            bool isReadOnly = isReadOnly(formField);

            // start input-group
            HtmlElementWriter inputGroupDivElement = (new HtmlElementWriter(DIV_ELEMENT)).attribute(CLASS_ATTRIBUTE, INPUT_GROUP_CLASS);

            string formFieldId = formField.Id;

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

            // input field
            HtmlElementWriter inputField = createInputField(formField);

            if (!isReadOnly)
            {
                inputField.attribute(DATEPICKER_POPUP_ATTRIBUTE, DATE_FORMAT).attribute(IS_OPEN_ATTRIBUTE, string.format(DATE_FIELD_OPENED_ATTRIBUTE, formFieldId));
            }

            // <input ... />
            documentBuilder.startElement(inputField).endElement();


            // if form field is read only, do not render date picker open button
            if (!isReadOnly)
            {
                // input addon
                HtmlElementWriter addonElement = (new HtmlElementWriter(DIV_ELEMENT)).attribute(CLASS_ATTRIBUTE, INPUT_GROUP_BTN_CLASS);

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

                // button to open date picker
                HtmlElementWriter buttonElement = (new HtmlElementWriter(BUTTON_ELEMENT)).attribute(TYPE_ATTRIBUTE, BUTTON_BUTTON_TYPE).attribute(CLASS_ATTRIBUTE, BUTTON_DEFAULT_CLASS).attribute(NG_CLICK_ATTRIBUTE, string.format(OPEN_DATEPICKER_FUNCTION_SNIPPET, formFieldId));

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

                HtmlElementWriter iconElement = (new HtmlElementWriter(I_ELEMENT)).attribute(CLASS_ATTRIBUTE, CALENDAR_GLYPHICON);

                // <i ...></i>
                documentBuilder.startElement(iconElement).endElement();

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

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


                HtmlElementWriter scriptElement = (new HtmlElementWriter(SCRIPT_ELEMENT)).attribute(CAM_SCRIPT_ATTRIBUTE, null).attribute(TYPE_ATTRIBUTE, TEXT_FORM_SCRIPT_TYPE).textContent(string.format(OPEN_DATEPICKER_SNIPPET, formFieldId, formFieldId));

                // <script ...> </script>
                documentBuilder.startElement(scriptElement).endElement();
            }

            // </div>
            documentBuilder.endElement();
        }
Ejemplo n.º 2
0
        protected internal virtual string renderFormData(FormData formData)
        {
            if (formData == null || (formData.FormFields == null || formData.FormFields.Count == 0) && (formData.FormProperties == null || formData.FormProperties.Count == 0))
            {
                return(null);
            }
            else
            {
                HtmlElementWriter formElement = (new HtmlElementWriter(FORM_ELEMENT)).attribute(NAME_ATTRIBUTE, GENERATED_FORM_NAME).attribute(ROLE_ATTRIBUTE, FORM_ROLE);

                HtmlDocumentBuilder documentBuilder = new HtmlDocumentBuilder(formElement);

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

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

                // end document element
                documentBuilder.endElement();

                return(documentBuilder.HtmlString);
            }
        }
Ejemplo n.º 3
0
        public virtual HtmlDocumentBuilder endElement()
        {
            HtmlElementWriter renderer = elements.Pop();

            renderer.writeContent(context);
            renderer.writeEndTag(context);
            return(this);
        }
Ejemplo n.º 4
0
 public HtmlDocumentBuilder(HtmlElementWriter documentElement)
 {
     if (!InstanceFieldsInitialized)
     {
         InitializeInstanceFields();
         InstanceFieldsInitialized = true;
     }
     startElement(documentElement);
 }
Ejemplo n.º 5
0
        protected internal virtual HtmlElementWriter createInputField(FormField formField)
        {
            HtmlElementWriter inputField = new HtmlElementWriter(INPUT_ELEMENT, true);

            addCommonFormFieldAttributes(formField, inputField);

            inputField.attribute(TYPE_ATTRIBUTE, TEXT_INPUT_TYPE);

            return(inputField);
        }
Ejemplo n.º 6
0
        protected internal virtual void renderInvalidValueMessage(FormField formField, HtmlDocumentBuilder documentBuilder)
        {
            HtmlElementWriter divElement = new HtmlElementWriter(DIV_ELEMENT);

            string formFieldId = formField.Id;

            string expression = string.format(REQUIRED_ERROR_EXPRESSION, formFieldId);

            divElement.attribute(NG_SHOW_ATTRIBUTE, expression).attribute(CLASS_ATTRIBUTE, HELP_BLOCK_CLASS).textContent(REQUIRED_FIELD_MESSAGE);

            documentBuilder.startElement(divElement).endElement();
        }
Ejemplo n.º 7
0
        protected internal virtual void renderSelectOptions(FormField formField, HtmlDocumentBuilder documentBuilder)
        {
            EnumFormType enumFormType           = (EnumFormType)formField.Type;
            IDictionary <string, string> values = enumFormType.Values;

            foreach (KeyValuePair <string, string> value in values.SetOfKeyValuePairs())
            {
                // <option>
                HtmlElementWriter option = (new HtmlElementWriter(OPTION_ELEMENT, false)).attribute(VALUE_ATTRIBUTE, value.Key).textContent(value.Value);

                documentBuilder.startElement(option).endElement();
            }
        }
Ejemplo n.º 8
0
        protected internal virtual void renderSelectBox(FormField formField, HtmlDocumentBuilder documentBuilder)
        {
            HtmlElementWriter selectBox = new HtmlElementWriter(SELECT_ELEMENT, false);

            addCommonFormFieldAttributes(formField, selectBox);

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

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

            // </select>
            documentBuilder.endElement();
        }
Ejemplo n.º 9
0
        protected internal virtual void renderInvalidTypeMessage(FormField formField, HtmlDocumentBuilder documentBuilder)
        {
            HtmlElementWriter divElement = new HtmlElementWriter(DIV_ELEMENT);

            string formFieldId = formField.Id;

            string expression = string.format(TYPE_ERROR_EXPRESSION, formFieldId);

            string typeName = formField.TypeName;

            if (isEnum(formField))
            {
                typeName = StringFormType.TYPE_NAME;
            }

            divElement.attribute(NG_SHOW_ATTRIBUTE, expression).attribute(CLASS_ATTRIBUTE, HELP_BLOCK_CLASS).textContent(string.format(TYPE_FIELD_MESSAGE, typeName));

            documentBuilder.startElement(divElement).endElement();
        }
Ejemplo n.º 10
0
        protected internal virtual void renderInvalidDateMessage(FormField formField, HtmlDocumentBuilder documentBuilder)
        {
            string formFieldId = formField.Id;

            HtmlElementWriter firstDivElement = new HtmlElementWriter(DIV_ELEMENT);

            string firstExpression = string.format(REQUIRED_ERROR_EXPRESSION + " && !" + DATE_ERROR_EXPRESSION, formFieldId, formFieldId);

            firstDivElement.attribute(NG_SHOW_ATTRIBUTE, firstExpression).attribute(CLASS_ATTRIBUTE, HELP_BLOCK_CLASS).textContent(REQUIRED_FIELD_MESSAGE);

            documentBuilder.startElement(firstDivElement).endElement();

            HtmlElementWriter secondDivElement = new HtmlElementWriter(DIV_ELEMENT);

            string secondExpression = string.format(DATE_ERROR_EXPRESSION, formFieldId);

            secondDivElement.attribute(NG_SHOW_ATTRIBUTE, secondExpression).attribute(CLASS_ATTRIBUTE, HELP_BLOCK_CLASS).textContent(INVALID_DATE_FIELD_MESSAGE);

            documentBuilder.startElement(secondDivElement).endElement();
        }
Ejemplo n.º 11
0
        protected internal virtual void renderInputField(FormField formField, HtmlDocumentBuilder documentBuilder)
        {
            HtmlElementWriter inputField = new HtmlElementWriter(INPUT_ELEMENT, true);

            addCommonFormFieldAttributes(formField, inputField);

            string inputType = !isBoolean(formField) ? TEXT_INPUT_TYPE : CHECKBOX_INPUT_TYPE;

            inputField.attribute(TYPE_ATTRIBUTE, inputType);

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

            if (defaultValue != null)
            {
                inputField.attribute(VALUE_ATTRIBUTE, defaultValue.ToString());
            }

            // <input ... />
            documentBuilder.startElement(inputField).endElement();
        }
Ejemplo n.º 12
0
        protected internal virtual void renderFormField(FormField formField, HtmlDocumentBuilder documentBuilder)
        {
            // start group
            HtmlElementWriter divElement = (new HtmlElementWriter(DIV_ELEMENT)).attribute(CLASS_ATTRIBUTE, FORM_GROUP_CLASS);

            documentBuilder.startElement(divElement);

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

            // write label
            if (!string.ReferenceEquals(formFieldLabel, null) && formFieldLabel.Length > 0)
            {
                HtmlElementWriter labelElement = (new HtmlElementWriter(LABEL_ELEMENT)).attribute(FOR_ATTRIBUTE, formFieldId).textContent(formFieldLabel);

                // <label for="...">...</label>
                documentBuilder.startElement(labelElement).endElement();
            }

            // render form control
            if (isEnum(formField))
            {
                // <select ...>
                renderSelectBox(formField, documentBuilder);
            }
            else if (isDate(formField))
            {
                renderDatePicker(formField, documentBuilder);
            }
            else
            {
                // <input ...>
                renderInputField(formField, documentBuilder);
            }

            renderInvalidMessageElement(formField, documentBuilder);

            // end group
            documentBuilder.endElement();
        }
Ejemplo n.º 13
0
        protected internal virtual void renderInvalidMessageElement(FormField formField, HtmlDocumentBuilder documentBuilder)
        {
            HtmlElementWriter divElement = new HtmlElementWriter(DIV_ELEMENT);

            string formFieldId  = formField.Id;
            string ifExpression = string.format(INVALID_EXPRESSION + " && " + DIRTY_EXPRESSION, formFieldId, formFieldId);

            divElement.attribute(NG_IF_ATTRIBUTE, ifExpression).attribute(CLASS_ATTRIBUTE, HAS_ERROR_CLASS);

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

            if (!isDate(formField))
            {
                renderInvalidValueMessage(formField, documentBuilder);
                renderInvalidTypeMessage(formField, documentBuilder);
            }
            else
            {
                renderInvalidDateMessage(formField, documentBuilder);
            }

            documentBuilder.endElement();
        }
Ejemplo n.º 14
0
 public virtual HtmlDocumentBuilder startElement(HtmlElementWriter renderer)
 {
     renderer.writeStartTag(context);
     elements.Push(renderer);
     return(this);
 }
Ejemplo n.º 15
0
        protected internal virtual void addCommonFormFieldAttributes(FormField formField, HtmlElementWriter formControl)
        {
            string typeName = formField.TypeName;

            if (isEnum(formField) || isDate(formField))
            {
                typeName = StringFormType.TYPE_NAME;
            }

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

            string formFieldId = formField.Id;

            formControl.attribute(CLASS_ATTRIBUTE, FORM_CONTROL_CLASS).attribute(NAME_ATTRIBUTE, formFieldId).attribute(CAM_VARIABLE_TYPE_ATTRIBUTE, typeName).attribute(CAM_VARIABLE_NAME_ATTRIBUTE, formFieldId);

            // add validation constraints
            foreach (FormFieldValidationConstraint constraint in formField.ValidationConstraints)
            {
                string constraintName = constraint.Name;
                string configuration  = (string)constraint.Configuration;
                formControl.attribute(constraintName, configuration);
            }
        }