Skip to content

Commit

Permalink
Merge pull request #8291 from mdmADA/8288-multi-line-textarea-in-gues…
Browse files Browse the repository at this point in the history
…tbook

8288 multi line textarea in guestbook
  • Loading branch information
kcondon authored Jan 20, 2022
2 parents 40c6f30 + 5823737 commit fbb5ed8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/java/edu/harvard/iq/dataverse/GuestbookPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public String save() {
boolean create = false;
if (!(guestbook.getCustomQuestions() == null)) {
for (CustomQuestion cq : guestbook.getCustomQuestions()) {
if (cq.getQuestionType().equals("text")) {
if (cq.getQuestionType().equals("text") || cq.getQuestionType().equals("textarea")) {
cq.setCustomQuestionValues(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import javax.persistence.Query;
import javax.persistence.StoredProcedureQuery;
import javax.persistence.TypedQuery;

import org.apache.commons.text.StringEscapeUtils;
/**
*
* @author skraffmiller
Expand Down Expand Up @@ -269,7 +269,7 @@ private String formatPersistentIdentifier(String protocol, String authority, Str
This method is used to produce an array of guestbook responses for displaying
on the guestbook-responses page.
*/
public List<Object[]> findArrayByGuestbookIdAndDataverseId (Long guestbookId, Long dataverseId, Long limit){
public List<Object[]> findArrayByGuestbookIdAndDataverseId(Long guestbookId, Long dataverseId, Long limit){

Guestbook gbIn = em.find(Guestbook.class, guestbookId);
boolean hasCustomQuestions = gbIn.getCustomQuestions() != null;
Expand Down Expand Up @@ -400,9 +400,9 @@ private Map<Integer, Object> selectCustomQuestionAnswers(Long dataverseId, Long

if (asString) {
// as combined strings of comma-separated question and answer values
//assuming the strings are only being created for writing out to csv which seems to be the case
String qa = SEPARATOR + StringEscapeUtils.escapeCsv((String)response[0]) + SEPARATOR + (response[1] == null ? "" : StringEscapeUtils.escapeCsv((String)response[1]));

String qa = SEPARATOR + ((String)response[0]).replace(',', ' ') + SEPARATOR + (response[1] == null ? "" : ((String)response[1]).replace(',', ' '));

if (ret.containsKey(responseId)) {
ret.put(responseId, ret.get(responseId) + qa);
} else {
Expand All @@ -414,6 +414,9 @@ private Map<Integer, Object> selectCustomQuestionAnswers(Long dataverseId, Long
if (!ret.containsKey(responseId)) {
ret.put(responseId, new ArrayList<>());
}
if(response[1] != null){
response[1]=((String)response[1]).replaceAll("(\r\n|\n)", "<br />");
}
((List) ret.get(responseId)).add(response);
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/propertyFiles/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,8 @@ dataset.manageGuestbooks.guestbook.customQuestions.description=Create your own q
dataset.manageGuestbooks.guestbook.customQuestions.questionType=Question Type
dataset.manageGuestbooks.guestbook.customQuestions.questionText=Question Text
dataset.manageGuestbooks.guestbook.customQuestions.responseOptions=Response Options
dataset.manageGuestbooks.guestbook.customQuestions.questionType.text=Text
dataset.manageGuestbooks.guestbook.customQuestions.questionType.text=Single Line
dataset.manageGuestbooks.guestbook.customQuestions.questionType.textarea=Multiple Line
dataset.manageGuestbooks.guestbook.customQuestions.questionType.multiple=Multiple Choice

# guestbookResponseFragment.xhtml
Expand Down
7 changes: 7 additions & 0 deletions src/main/webapp/file-download-popup-fragment.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@
requiredMessage="#{bundle['requiredField']}">
</p:inputText>
<p:message id="cqMessages" for="customQuestionResponse" display="text"/>
<p:inputTextarea id="customQuestionResponseTextArea" rows="8" autoResize="true"
styleClass="form-control"
value="#{customQuestionResponse.response}"
required="#{param['DO_GB_VALIDATION'] and customQuestionResponse.customQuestion.required}"
rendered="#{customQuestionResponse.customQuestion.questionType=='textarea'}"
requiredMessage="#{bundle['requiredField']}"/>
<p:message id="cqMessagesTA" for="customQuestionResponseTextArea" display="text"/>
<p:selectOneMenu id="customQuestionResponseSelect"
styleClass="form-control" value="#{customQuestionResponse.response}"
required="#{param[validateThisContext] and customQuestionResponse.customQuestion.required}"
Expand Down
8 changes: 6 additions & 2 deletions src/main/webapp/guestbook-responses.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@
<h:outputText value="#{response[4]}"/>
</p:column>
<p:column headerText="#{bundle['dataset.guestbooksResponses.customQuestions']}" >
<ui:repeat value="#{response[5]}" var="customQResponse"><b>#{customQResponse[0]}: </b>#{customQResponse[1]} <br></br></ui:repeat>
</p:column>
<ui:repeat value="#{response[5]}" var="customQResponse">
<b><h:outputText value="#{customQResponse[0]}"/>: </b>
<h:outputText escape="false" value="#{customQResponse[1]}"/>
<br />
</ui:repeat>
</p:column>
</p:dataTable>
</h:form>
</ui:define>
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/guestbook.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<h:selectOneMenu id="questionOptions" styleClass="form-control" value="#{cq.questionType}"
onchange="#{GuestbookPage.toggleQuestionType(cq)}">
<f:selectItem itemLabel="#{bundle['dataset.manageGuestbooks.guestbook.customQuestions.questionType.text']}" itemValue="text" />
<f:selectItem itemLabel="#{bundle['dataset.manageGuestbooks.guestbook.customQuestions.questionType.textarea']}" itemValue="textarea" />
<f:selectItem itemLabel="#{bundle['dataset.manageGuestbooks.guestbook.customQuestions.questionType.multiple']}" itemValue="options" />
<p:ajax update=":guestbookForm:customQuestions" />
<f:param name="SKIP_VALIDATION" value="true"/>
Expand Down

0 comments on commit fbb5ed8

Please sign in to comment.