From 4e482a617e8763865e62fa1c0bfb67eca9e85afa Mon Sep 17 00:00:00 2001 From: josmas Date: Wed, 21 Mar 2018 10:01:56 +0000 Subject: [PATCH] Fix for #1523. Adds multiline text boxes for text entry. --- .../ear/default/web/partials/group.html | 8 ++++- .../ear/default/web/partials/input.html | 30 +++++++++++-------- .../paco/model/ExperimentProviderUtil.java | 6 ++++ Paco/src/com/pacoapp/paco/ui/InputLayout.java | 18 +++++++++-- .../pacoapp/paco/shared/model2/Input2.java | 27 +++++++++++++++-- 5 files changed, 71 insertions(+), 18 deletions(-) diff --git a/Paco-Server/ear/default/web/partials/group.html b/Paco-Server/ear/default/web/partials/group.html index dce566a2b..54d0beef7 100644 --- a/Paco-Server/ear/default/web/partials/group.html +++ b/Paco-Server/ear/default/web/partials/group.html @@ -34,7 +34,13 @@
-
+
+ + + +
+
diff --git a/Paco-Server/ear/default/web/partials/input.html b/Paco-Server/ear/default/web/partials/input.html index e845bb3ff..5449f1c6d 100644 --- a/Paco-Server/ear/default/web/partials/input.html +++ b/Paco-Server/ear/default/web/partials/input.html @@ -21,7 +21,7 @@ Response Type - {{option.name}} + {{option.name}} @@ -34,20 +34,19 @@
-
- - - - - -
+
+ + + + +
- + @@ -55,9 +54,16 @@ Help: Conditional Logic - - - +
+
+ + Multiple lines + +
+ + +
diff --git a/Paco/src/com/pacoapp/paco/model/ExperimentProviderUtil.java b/Paco/src/com/pacoapp/paco/model/ExperimentProviderUtil.java index 27b581300..37c3d3691 100644 --- a/Paco/src/com/pacoapp/paco/model/ExperimentProviderUtil.java +++ b/Paco/src/com/pacoapp/paco/model/ExperimentProviderUtil.java @@ -555,6 +555,12 @@ public static void copyAllPropertiesFromJsonToExperimentDAO(ExperimentDAO experi if (inputNode.has("multiselect")) { input.setMultiselect(inputNode.path("multiselect").getBooleanValue()); } + if (inputNode.has("multiline")) { + input.setMultiline(inputNode.path("multiline").getBooleanValue()); + } + if (inputNode.has("multilineNumber")) { + input.setMultilineNumber(inputNode.path("multilineNumber").getIntValue()); + } List listChoices = Lists.newArrayList(); ArrayNode listChoicesNode = (ArrayNode) inputNode.path("listChoices"); for (int l = 0; l < listChoicesNode.size(); l++) { diff --git a/Paco/src/com/pacoapp/paco/ui/InputLayout.java b/Paco/src/com/pacoapp/paco/ui/InputLayout.java index 9c8482979..d08ac3b97 100644 --- a/Paco/src/com/pacoapp/paco/ui/InputLayout.java +++ b/Paco/src/com/pacoapp/paco/ui/InputLayout.java @@ -27,6 +27,8 @@ import java.util.Date; import java.util.List; +import android.view.Gravity; +import android.view.inputmethod.EditorInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -482,7 +484,7 @@ private View getInputResponseTypeView(Input2 input2) { if (questionType.equals(Input2.LIKERT_SMILEYS)) { return renderGeistNowSmilerLikert(input2.getLikertSteps()); } else if (questionType.equals(Input2.OPEN_TEXT)) { - return renderOpenText(); + return renderOpenText(input2); } else if (questionType.equals(Input2.LIKERT)) { return renderLikert(input2); } else if (questionType.equals(Input2.LIST)) { @@ -907,8 +909,8 @@ private int getRadioGroupLayoutId(Integer steps) { } - private View renderOpenText() { - View likertView = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate( + private View renderOpenText(Input2 input2) { + ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate( R.layout.open_text, this, true); openTextView = (AutoCompleteTextView) findViewById(R.id.open_text_answer); openTextView.setThreshold(1); @@ -919,6 +921,16 @@ private View renderOpenText() { //ensureAutoCompleteDatabase(); //openTextView.setAdapter(new AutocompleteUsageFilteringArrayAdapter(getContext(), android.R.layout.simple_dropdown_item_1line, autocompleteDatabase)); //openTextView.setTokenizer(new AutoCompleteTextView(getContext())); + if (input2.getMultiline() != null && input2.getMultiline()) { + if (input2.getMultilineNumber() != null && input2.getMultilineNumber() > 1) { + openTextView.setSingleLine(false); + openTextView.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION); + openTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE + | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT | InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE); + openTextView.setLines(input2.getMultilineNumber()); + openTextView.setGravity(Gravity.LEFT | Gravity.TOP); + } + } openTextView.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { diff --git a/Shared/src/com/pacoapp/paco/shared/model2/Input2.java b/Shared/src/com/pacoapp/paco/shared/model2/Input2.java index 1a9e03b8b..1e0933e85 100755 --- a/Shared/src/com/pacoapp/paco/shared/model2/Input2.java +++ b/Shared/src/com/pacoapp/paco/shared/model2/Input2.java @@ -54,6 +54,9 @@ public class Input2 extends ModelBase implements Validatable, Serializable { private List listChoices; private Boolean multiselect = false; + private boolean multiline; + private int multilineNumber; + /** * */ @@ -72,10 +75,12 @@ public class Input2 extends ModelBase implements Validatable, Serializable { * @param rightSideLabel * @param listChoices * @param multiselect + * @param multiline + * @param multilineNumber */ public Input2(String name, String responseType, String text, Boolean required, Integer likertSteps, Boolean conditional, String conditionExpr, String leftSideLabel, - String rightSideLabel, List listChoices, Boolean multiselect) { + String rightSideLabel, List listChoices, Boolean multiselect, Boolean multiline, Integer multilineNumber) { this.text = text; this.required = required != null ? required : false; this.responseType = responseType; @@ -87,12 +92,14 @@ public Input2(String name, String responseType, String text, Boolean required, this.rightSideLabel = rightSideLabel; this.listChoices = listChoices; this.multiselect = multiselect != null ? multiselect : false; + this.multiline = multiline != null ? multiline : false; + this.multilineNumber = multilineNumber != null ? multilineNumber : 0; } // visible for testing public Input2(String name, String text) { this(name, LIKERT, text, false, null, false, null, null, null, null, - null); + null, null, null); } public Input2() { @@ -189,6 +196,22 @@ public void setMultiselect(Boolean multiselect) { this.multiselect = multiselect; } + public Boolean getMultiline() { + return multiline; + } + + public void setMultiline(Boolean multiline) { + this.multiline = multiline; + } + + public Integer getMultilineNumber() { + return multilineNumber; + } + + public void setMultilineNumber(Integer multilineNumber) { + this.multilineNumber = multilineNumber; + } + public void validateWith(Validator validator) { // System.out.println("VALIDATING Input"); validator.isNonEmptyString(name, "input name is not properly initialized");