Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
*/
public class ObsSubmissionElement implements HtmlGeneratorElement, FormSubmissionControllerAction {

//To enable access of attributes via Java Script
private boolean enableParamJS = false;

private Locale locale = Context.getLocale();

private String id;
Expand Down Expand Up @@ -1028,6 +1031,10 @@ else if (parameters.containsKey("commentFieldCode")) {
} else {
context.addFieldToActiveSection(field);
}

//if enableParamJS is true
enableParamJS = "true".equals(parameters.get("enableParamJS"));

}

protected ObsField instatiateObsField() {
Expand Down Expand Up @@ -1117,13 +1124,36 @@ public String generateHtml(FormEntryContext context) {
ret.append(dateLabel);
}
ret.append(dateWidget.generateHtml(context));
}
if (enableParamJS && dateWidget == null) {
dateWidget = new DateWidget();
dateWidget.setHidden(true);
context.registerWidget(dateWidget);
context.registerErrorWidget(dateWidget, errorWidget);
context.registerPropertyAccessorInfo(id + ".date", context.getFieldNameIfRegistered(dateWidget),
"dateFieldGetterFunction", null, "dateSetterFunction");
ret.append(" ");
ret.append(dateWidget.generateHiddenHtml(context));
}
if (accessionNumberWidget != null) {
ret.append(" ");
if (accessionNumberLabel != null) {
ret.append("<br/>" + accessionNumberLabel);
}
ret.append(accessionNumberWidget.generateHtml(context));
}
if (enableParamJS && accessionNumberWidget == null) {
accessionNumberWidget = new TextFieldWidget();
context.registerWidget(accessionNumberWidget);
context.registerErrorWidget(accessionNumberWidget, errorWidget);
if (existingObs != null) {
accessionNumberWidget.setInitialValue(existingObs.getAccessionNumber());
}
context.registerPropertyAccessorInfo(id + ".accessionNumber",
context.getFieldNameIfRegistered(accessionNumberWidget), null, null, null);
ret.append(" ");
ret.append(accessionNumberWidget.generateHiddenHtml(context));

}
if (commentFieldWidget != null) {
ret.append(" ");
Expand All @@ -1134,6 +1164,18 @@ public String generateHtml(FormEntryContext context) {
}
ret.append(" ");
ret.append(commentFieldWidget.generateHtml(context));
}
if (enableParamJS && commentFieldWidget == null) {
commentFieldWidget = new TextFieldWidget();
context.registerWidget(commentFieldWidget);
context.registerErrorWidget(commentFieldWidget, errorWidget);
if (existingObs != null) {
commentFieldWidget.setInitialValue(existingObs.getComment());
}
context.registerPropertyAccessorInfo(id + ".value", context.getFieldNameIfRegistered(commentFieldWidget),
null, null, null);
ret.append(" ");
ret.append(commentFieldWidget.generateHiddenHtml(context));
}

if (context.getMode() != Mode.VIEW) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,26 @@ public DateWidget clone() {
clone.setDateFormat(this.getDateFormat());
return clone;
}

/**Generates hidden html so that it is accessible via javascript
* even if it is not displayed
*/
public String generateHiddenHtml(FormEntryContext context) {
StringBuilder sb = new StringBuilder();
String fieldName = context.getFieldName(this);

sb.append("<input style=\"display:none\" type=\"text\" size=\"10\" id=\"").append(fieldName).append("-display\"/>");

sb.append("<input type=\"hidden\" name=\"").append(fieldName).append("\" id=\"").append(fieldName).append("\"");
if (onChangeFunction != null) {
sb.append(" onChange=\"" + onChangeFunction + "\" ");
}
sb.append(" />");

sb.append("<script>setupDatePicker('" + jsDateFormat() + "', '" + getYearsRange() + "','" + getLocaleForJquery() + "', '#" + fieldName + "-display', '#" + fieldName + "'");

sb.append(")</script>");
return sb.toString();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,47 @@ public TextFieldWidget clone() {
clone.setTextAreaRows(this.getTextAreaRows());
return clone;
}

/**Generates hidden html so that it is accessible via javascript
* even if it is not displayed
*/
public String generateHiddenHtml(FormEntryContext context) {
StringBuilder sb = new StringBuilder();
if (textArea) {
sb.append("<textarea name=\"" + context.getFieldName(this) + "\" id=\"" + context.getFieldName(this) + "\"");
if (textAreaRows != null)
sb.append(" rows=\"" + textAreaRows + "\"");
if (textAreaColumns != null)
sb.append(" cols=\"" + textAreaColumns + "\"");
if (textFieldMaxLength != null && textFieldMaxLength.intValue() > 0){
sb.append(" maxlength=\"" + textFieldMaxLength.intValue() + "\"");
}
if (placeholder != null) {
// TODO escape
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do you plan to work on the above TODO?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These TODO's were present in generateHtml method at similar positions so I added them here as well. I couldn't understand their meaning that why they were added and what is to be done.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkayiwa Sorry for late reply. These TODO's were present in generateHtml method at similar condition so I added them here as well. I couldn't understand their meaning that why they were added and what is to be done.

sb.append(" placeholder=\"").append(placeholder).append("\"");
}
sb.append(" style=\"display: none\"");
sb.append(">");
if (initialValue != null)
sb.append(initialValue);
sb.append("</textarea>");
} else {
sb.append("<input type=\"text\" name=\"" + context.getFieldName(this) + "\" id=\"" + context.getFieldName(this) + "\"");
if (textFieldSize != null)
sb.append(" size=\"" + textFieldSize + "\"");
if (initialValue != null)
sb.append(" value=\"" + initialValue + "\"");
if (textFieldMaxLength != null && textFieldMaxLength.intValue() > 0){
sb.append(" maxlength=\"" + textFieldMaxLength.intValue() + "\"");
}
if (placeholder != null) {
// TODO escape
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do you plan to work on the above TODO?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same case as previous is here as well.

sb.append(" placeholder=\"").append(placeholder).append("\"");
}
sb.append(" style=\"display: none\"");
sb.append("/>");
}
return sb.toString();
}

}