use of org.apache.ofbiz.widget.model.ModelFormField in project ofbiz-framework by apache.
the class FoFormRenderer method renderLookupField.
public void renderLookupField(Appendable writer, Map<String, Object> context, LookupField lookupField) throws IOException {
ModelFormField modelFormField = lookupField.getModelFormField();
this.makeBlockString(writer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context, lookupField.getDefaultValue(context)));
appendWhitespace(writer);
}
use of org.apache.ofbiz.widget.model.ModelFormField in project ofbiz-framework by apache.
the class FoFormRenderer method renderFormatListWrapperOpen.
public void renderFormatListWrapperOpen(Appendable writer, Map<String, Object> context, ModelForm modelForm) throws IOException {
writer.append("<fo:table border=\"solid black\">");
List<ModelFormField> childFieldList = modelForm.getFieldList();
for (ModelFormField childField : childFieldList) {
int childFieldType = childField.getFieldInfo().getFieldType();
if (childFieldType == FieldInfo.HIDDEN || childFieldType == FieldInfo.IGNORED) {
continue;
}
writer.append("<fo:table-column");
String areaStyle = childField.getTitleAreaStyle();
if (UtilValidate.isNotEmpty(areaStyle)) {
writer.append(" ");
writer.append(MacroScreenRenderer.getFoStyle(areaStyle));
}
writer.append("/>");
appendWhitespace(writer);
}
appendWhitespace(writer);
}
use of org.apache.ofbiz.widget.model.ModelFormField in project ofbiz-framework by apache.
the class MacroFormRenderer method renderSubmitField.
public void renderSubmitField(Appendable writer, Map<String, Object> context, SubmitField submitField) throws IOException {
ModelFormField modelFormField = submitField.getModelFormField();
ModelForm modelForm = modelFormField.getModelForm();
String event = modelFormField.getEvent();
String action = modelFormField.getAction(context);
String title = modelFormField.getTitle(context);
String name = modelFormField.getParameterName(context);
String buttonType = submitField.getButtonType();
String formName = FormRenderer.getCurrentFormName(modelForm, context);
String imgSrc = submitField.getImageLocation(context);
String confirmation = submitField.getConfirmation(context);
String className = "";
String alert = "false";
if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle())) {
className = modelFormField.getWidgetStyle();
if (modelFormField.shouldBeRed(context)) {
alert = "true";
}
}
String formId = FormRenderer.getCurrentContainerId(modelForm, context);
List<ModelForm.UpdateArea> updateAreas = modelForm.getOnSubmitUpdateAreas();
// This is here for backwards compatibility. Use on-event-update-area
// elements instead.
String backgroundSubmitRefreshTarget = submitField.getBackgroundSubmitRefreshTarget(context);
if (UtilValidate.isNotEmpty(backgroundSubmitRefreshTarget)) {
if (updateAreas == null) {
updateAreas = new LinkedList<>();
}
updateAreas.add(new ModelForm.UpdateArea("submit", formId, backgroundSubmitRefreshTarget));
}
boolean ajaxEnabled = (UtilValidate.isNotEmpty(updateAreas) || UtilValidate.isNotEmpty(backgroundSubmitRefreshTarget)) && this.javaScriptEnabled;
String ajaxUrl = "";
if (ajaxEnabled) {
ajaxUrl = createAjaxParamsFromUpdateAreas(updateAreas, "", context);
}
String tabindex = modelFormField.getTabindex();
StringWriter sr = new StringWriter();
sr.append("<@renderSubmitField ");
sr.append("buttonType=\"");
sr.append(buttonType);
sr.append("\" className=\"");
sr.append(className);
sr.append("\" alert=\"");
sr.append(alert);
sr.append("\" formName=\"");
sr.append(formName);
sr.append("\" title=\"");
sr.append(encode(title, modelFormField, context));
sr.append("\" name=\"");
sr.append(name);
sr.append("\" event=\"");
if (event != null) {
sr.append(event);
}
sr.append("\" action=\"");
if (action != null) {
sr.append(action);
}
sr.append("\" imgSrc=\"");
sr.append(imgSrc);
sr.append("\" containerId=\"");
if (ajaxEnabled) {
sr.append(formId);
}
sr.append("\" confirmation =\"");
sr.append(confirmation);
sr.append("\" ajaxUrl=\"");
if (ajaxEnabled) {
sr.append(ajaxUrl);
}
sr.append("\" tabindex=\"");
sr.append(tabindex);
sr.append("\" />");
executeMacro(writer, sr.toString());
this.appendTooltip(writer, context, modelFormField);
}
use of org.apache.ofbiz.widget.model.ModelFormField in project ofbiz-framework by apache.
the class MacroFormRenderer method renderTextareaField.
public void renderTextareaField(Appendable writer, Map<String, Object> context, TextareaField textareaField) throws IOException {
ModelFormField modelFormField = textareaField.getModelFormField();
String name = modelFormField.getParameterName(context);
String cols = Integer.toString(textareaField.getCols());
String rows = Integer.toString(textareaField.getRows());
String id = modelFormField.getCurrentContainerId(context);
String className = "";
String alert = "false";
if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle())) {
className = modelFormField.getWidgetStyle();
if (modelFormField.shouldBeRed(context)) {
alert = "true";
}
}
// check for required field style on single forms
if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) {
String requiredStyle = modelFormField.getRequiredFieldStyle();
if (UtilValidate.isEmpty(requiredStyle)) {
requiredStyle = "required";
}
if (UtilValidate.isEmpty(className)) {
className = requiredStyle;
} else {
className = requiredStyle + " " + className;
}
}
String visualEditorEnable = "";
String buttons = "";
if (textareaField.getVisualEditorEnable()) {
visualEditorEnable = "true";
buttons = textareaField.getVisualEditorButtons(context);
if (UtilValidate.isEmpty(buttons)) {
buttons = "maxi";
}
}
String readonly = "";
if (textareaField.isReadOnly()) {
readonly = "readonly";
}
Map<String, Object> userLogin = UtilGenerics.checkMap(context.get("userLogin"));
String language = "en";
if (userLogin != null) {
language = UtilValidate.isEmpty((String) userLogin.get("lastLocale")) ? "en" : (String) userLogin.get("lastLocale");
}
String maxlength = "";
if (textareaField.getMaxlength() != null) {
maxlength = Integer.toString(textareaField.getMaxlength());
}
String tabindex = modelFormField.getTabindex();
String value = modelFormField.getEntry(context, textareaField.getDefaultValue(context));
StringWriter sr = new StringWriter();
sr.append("<@renderTextareaField ");
sr.append("name=\"");
sr.append(name);
sr.append("\" className=\"");
sr.append(className);
sr.append("\" alert=\"");
sr.append(alert);
sr.append("\" value=\"");
sr.append(value);
sr.append("\" cols=\"");
sr.append(cols);
sr.append("\" rows=\"");
sr.append(rows);
sr.append("\" maxlength=\"");
sr.append(maxlength);
sr.append("\" id=\"");
sr.append(id);
sr.append("\" readonly=\"");
sr.append(readonly);
sr.append("\" visualEditorEnable=\"");
sr.append(visualEditorEnable);
sr.append("\" language=\"");
sr.append(language);
sr.append("\" buttons=\"");
sr.append(buttons);
sr.append("\" tabindex=\"");
sr.append(tabindex);
sr.append("\" />");
executeMacro(writer, sr.toString());
this.addAsterisks(writer, context, modelFormField);
this.appendTooltip(writer, context, modelFormField);
}
use of org.apache.ofbiz.widget.model.ModelFormField in project ofbiz-framework by apache.
the class MacroFormRenderer method renderDisplayField.
public void renderDisplayField(Appendable writer, Map<String, Object> context, DisplayField displayField) throws IOException {
ModelFormField modelFormField = displayField.getModelFormField();
String idName = modelFormField.getCurrentContainerId(context);
String description = displayField.getDescription(context);
String type = displayField.getType();
String imageLocation = displayField.getImageLocation(context);
Integer size = Integer.valueOf("0");
String title = "";
if (UtilValidate.isNotEmpty(displayField.getSize())) {
try {
size = Integer.parseInt(displayField.getSize());
} catch (NumberFormatException nfe) {
Debug.logError(nfe, "Error reading size of a field fieldName=" + displayField.getModelFormField().getFieldName() + " FormName= " + displayField.getModelFormField().getModelForm().getName(), module);
}
}
ModelFormField.InPlaceEditor inPlaceEditor = displayField.getInPlaceEditor();
boolean ajaxEnabled = inPlaceEditor != null && this.javaScriptEnabled;
if (UtilValidate.isNotEmpty(description) && size > 0 && description.length() > size) {
title = description;
description = description.substring(0, size - 8) + "..." + description.substring(description.length() - 5);
}
StringWriter sr = new StringWriter();
sr.append("<@renderDisplayField ");
sr.append("type=\"");
sr.append(type);
sr.append("\" imageLocation=\"");
sr.append(imageLocation);
sr.append("\" idName=\"");
sr.append(idName);
sr.append("\" description=\"");
sr.append(encodeDoubleQuotes(description));
sr.append("\" title=\"");
sr.append(title);
sr.append("\" class=\"");
sr.append(modelFormField.getWidgetStyle());
sr.append("\" alert=\"");
sr.append(modelFormField.shouldBeRed(context) ? "true" : "false");
if (ajaxEnabled) {
String url = inPlaceEditor.getUrl(context);
StringBuffer extraParameterBuffer = new StringBuffer();
String extraParameter;
Map<String, Object> fieldMap = inPlaceEditor.getFieldMap(context);
Set<Entry<String, Object>> fieldSet = fieldMap.entrySet();
Iterator<Entry<String, Object>> fieldIterator = fieldSet.iterator();
int count = 0;
extraParameterBuffer.append("{");
while (fieldIterator.hasNext()) {
count++;
Entry<String, Object> field = fieldIterator.next();
extraParameterBuffer.append(field.getKey() + ":'" + (String) field.getValue() + "'");
if (count < fieldSet.size()) {
extraParameterBuffer.append(',');
}
}
extraParameterBuffer.append("}");
extraParameter = extraParameterBuffer.toString();
sr.append("\" inPlaceEditorUrl=\"");
sr.append(url);
sr.append("\" inPlaceEditorParams=\"");
StringWriter inPlaceEditorParams = new StringWriter();
inPlaceEditorParams.append("{name: '");
if (UtilValidate.isNotEmpty(inPlaceEditor.getParamName())) {
inPlaceEditorParams.append(inPlaceEditor.getParamName());
} else {
inPlaceEditorParams.append(modelFormField.getFieldName());
}
inPlaceEditorParams.append("'");
inPlaceEditorParams.append(", method: 'POST'");
inPlaceEditorParams.append(", submitdata: " + extraParameter);
inPlaceEditorParams.append(", type: 'textarea'");
inPlaceEditorParams.append(", select: 'true'");
inPlaceEditorParams.append(", onreset: function(){jQuery('#cc_" + idName + "').css('background-color', 'transparent');}");
if (UtilValidate.isNotEmpty(inPlaceEditor.getCancelText())) {
inPlaceEditorParams.append(", cancel: '" + inPlaceEditor.getCancelText() + "'");
} else {
inPlaceEditorParams.append(", cancel: 'Cancel'");
}
if (UtilValidate.isNotEmpty(inPlaceEditor.getClickToEditText())) {
inPlaceEditorParams.append(", tooltip: '" + inPlaceEditor.getClickToEditText() + "'");
}
if (UtilValidate.isNotEmpty(inPlaceEditor.getFormClassName())) {
inPlaceEditorParams.append(", cssclass: '" + inPlaceEditor.getFormClassName() + "'");
} else {
inPlaceEditorParams.append(", cssclass: 'inplaceeditor-form'");
}
if (UtilValidate.isNotEmpty(inPlaceEditor.getLoadingText())) {
inPlaceEditorParams.append(", indicator: '" + inPlaceEditor.getLoadingText() + "'");
}
if (UtilValidate.isNotEmpty(inPlaceEditor.getOkControl())) {
inPlaceEditorParams.append(", submit: ");
if (!"false".equals(inPlaceEditor.getOkControl())) {
inPlaceEditorParams.append("'");
}
inPlaceEditorParams.append(inPlaceEditor.getOkControl());
if (!"false".equals(inPlaceEditor.getOkControl())) {
inPlaceEditorParams.append("'");
}
} else {
inPlaceEditorParams.append(", submit: 'OK'");
}
if (UtilValidate.isNotEmpty(inPlaceEditor.getRows())) {
inPlaceEditorParams.append(", rows: '" + inPlaceEditor.getRows() + "'");
}
if (UtilValidate.isNotEmpty(inPlaceEditor.getCols())) {
inPlaceEditorParams.append(", cols: '" + inPlaceEditor.getCols() + "'");
}
inPlaceEditorParams.append("}");
sr.append(inPlaceEditorParams.toString());
}
sr.append("\" />");
executeMacro(writer, sr.toString());
if (displayField instanceof DisplayEntityField) {
makeHyperlinkString(writer, ((DisplayEntityField) displayField).getSubHyperlink(), context);
}
this.appendTooltip(writer, context, modelFormField);
}
Aggregations