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(); }
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); } }
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(); } }
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(); }
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(); }
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(); }
public HtmlWriteContext(HtmlDocumentBuilder outerInstance) { this.outerInstance = outerInstance; }
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(); }
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(); }
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(); }
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(); }