use of org.openmrs.module.htmlformentry.Translator in project openmrs-module-coreapps by openmrs.
the class CodedOrFreeTextAnswerWidget method generateHtml.
@Override
public String generateHtml(FormEntryContext context) {
Translator translator = context.getTranslator();
String localeStr = locale.toString();
String title = translator.translate(localeStr, titleCode);
String placeholder = translator.translate(localeStr, placeholderCode);
StringBuilder ret = new StringBuilder();
if (context.getMode().equals(FormEntryContext.Mode.VIEW)) {
if (initialValue != null) {
ret.append("<span class=\"value\">" + initialValue.format(locale) + "</span>");
}
} else {
String hiddenInputName = context.getFieldName(this);
Map<String, Object> fragmentConfig = new HashMap<String, Object>();
fragmentConfig.put("formFieldName", hiddenInputName);
fragmentConfig.put("title", title);
fragmentConfig.put("placeholder", placeholder);
fragmentConfig.put("containerClasses", containerClasses);
fragmentConfig.put("initialValue", initialValueAsJson(initialValue));
try {
ret.append(uiUtils.includeFragment("coreapps", "htmlformentry/codedOrFreeTextAnswer", fragmentConfig));
} catch (PageAction pageAction) {
throw new IllegalStateException("fragment threw PageAction", pageAction);
} catch (NullPointerException ex) {
// (This is hacky, but I don't see a better way to do it.)
return "<input type=\"hidden\" name=\"" + context.getFieldName(this) + "\"/> (Submitting the form, so we don't generate HTML)";
}
}
return ret.toString();
}
use of org.openmrs.module.htmlformentry.Translator in project openmrs-module-coreapps by openmrs.
the class CodedOrFreeTextAnswerListWidgetTest method setUpEnter.
public void setUpEnter() throws Exception {
context = new FormEntryContext(FormEntryContext.Mode.ENTER) {
@Override
public Translator getTranslator() {
return new Translator() {
@Override
public String translate(String localeStr, String key) {
return key;
}
};
}
};
context.registerWidget(widget);
}
use of org.openmrs.module.htmlformentry.Translator in project openmrs-module-coreapps by openmrs.
the class CodedOrFreeTextAnswerListWidget method generateHtml.
@Override
public String generateHtml(FormEntryContext context) {
Translator translator = context.getTranslator();
String localeStr = locale.toString();
String title = translator.translate(localeStr, titleCode);
String betweenElements = translator.translate(localeStr, betweenElementsCode);
String placeholder = translator.translate(localeStr, placeholderCode);
StringBuilder ret = new StringBuilder();
ret.append("<div class=\"coded-or-free-text-list-widget\">");
if (context.getMode().equals(FormEntryContext.Mode.VIEW)) {
ret.append("<span class=\"coded-or-free-text-title\">" + title + "</span>\n");
if (initialValue != null) {
boolean first = true;
for (CodedOrFreeTextAnswer answer : initialValue) {
if (!first && StringUtils.isNotEmpty(betweenElements)) {
ret.append("<br/>");
ret.append("<span class=\"coded-or-free-text-between\">").append(betweenElements).append("</span>");
}
ret.append("<br/>");
ret.append("<span class=\"value\">").append(answer.format(locale)).append("</span>");
first = false;
}
}
} else {
String hiddenInputName = context.getFieldName(this);
Map<String, Object> fragmentConfig = new HashMap<String, Object>();
fragmentConfig.put("formFieldName", hiddenInputName);
fragmentConfig.put("title", title);
fragmentConfig.put("placeholder", placeholder);
fragmentConfig.put("betweenElements", betweenElements);
fragmentConfig.put("containerClasses", containerClasses);
fragmentConfig.put("initialValue", initialValueAsJson(initialValue));
try {
ret.append(uiUtils.includeFragment("coreapps", "htmlformentry/codedOrFreeTextAnswerList", fragmentConfig));
} catch (PageAction pageAction) {
throw new IllegalStateException("fragment threw PageAction", pageAction);
} catch (NullPointerException ex) {
// (This is hacky, but I don't see a better way to do it.)
return "<input type=\"hidden\" name=\"" + context.getFieldName(this) + "\"/> (Submitting the form, so we don't generate HTML)";
}
}
ret.append("</div>");
return ret.toString();
}
Aggregations