Skip to content

Commit

Permalink
Merge 965dabb into 5011d67
Browse files Browse the repository at this point in the history
  • Loading branch information
bennsimon committed Mar 16, 2020
2 parents 5011d67 + 965dabb commit 09181bf
Show file tree
Hide file tree
Showing 12 changed files with 413 additions and 227 deletions.
202 changes: 132 additions & 70 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,20 @@ public JSONObject getmJSONObject() {

@Override
public void setmJSONObject(JSONObject mJSONObject) {
this.mJSONObject = mJSONObject;
super.setmJSONObject(mJSONObject);
}

@Override
protected void initiateFormUpdate(JSONObject json) {
if (getForm() != null && ((getForm().getHiddenFields() != null && !getForm().getHiddenFields().isEmpty()) || (getForm().getDisabledFields() != null && !getForm().getDisabledFields().isEmpty()))) {
JSONArray fieldsJsonObject = FormUtils.getMultiStepFormFields(json);
for (int k = 0; k < fieldsJsonObject.length(); k++) {
Utils.handleFieldBehaviour(fieldsJsonObject.optJSONObject(k), getForm());
}
}
}


@Override
public void updateGenericPopupSecondaryValues(JSONArray jsonArray) {
setExtraFieldsWithValues(jsonArray);
Expand Down Expand Up @@ -623,6 +634,11 @@ public boolean skipBlankSteps() {
}
}

@Override
public Form form() {
return getForm();
}

private String getViewKey(View view) {
String key = (String) view.getTag(R.id.key);
if (view.getTag(R.id.childKey) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ protected void onCreate(Bundle savedInstanceState) {
lifeCycleListeners = new ArrayList<>();
isFormFragmentInitialized = false;
if (savedInstanceState == null) {
this.form = extractForm(getIntent().getSerializableExtra(JsonFormConstants.JSON_FORM_KEY.FORM));
init(getForm());
initializeFormFragment();
onFormStart();
this.form = extractForm(getIntent().getSerializableExtra(JsonFormConstants.JSON_FORM_KEY.FORM));
} else {
init(savedInstanceState.getString(JSON_STATE));
this.form = extractForm(savedInstanceState.getSerializable(FORM_STATE));
init(savedInstanceState.getString(JSON_STATE));
}
for (LifeCycleListener lifeCycleListener : lifeCycleListeners) {
lifeCycleListener.onCreate(savedInstanceState);
Expand All @@ -95,7 +95,7 @@ private String getForm() {
public void init(String json) {
try {
setmJSONObject(new JSONObject(json));
if (!mJSONObject.has("encounter_type")) {
if (!mJSONObject.has(JsonFormConstants.ENCOUNTER_TYPE)) {
mJSONObject = new JSONObject();
throw new JSONException("Form encounter_type not set");
}
Expand All @@ -121,6 +121,8 @@ public void init(String json) {
}
}

protected abstract void initiateFormUpdate(JSONObject json);

public synchronized void initializeFormFragment() {
isFormFragmentInitialized = true;
getSupportFragmentManager().beginTransaction()
Expand All @@ -147,6 +149,7 @@ private Form extractForm(Serializable serializable) {
}

public void setmJSONObject(JSONObject mJSONObject) {
initiateFormUpdate(mJSONObject);
this.mJSONObject = mJSONObject;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ public class JsonFormConstants {
public static final String REFERENCE_EDIT_TEXT = "reference_edit_text";
public static final String DISPLAY_LABEL = "display_label";
public static final String PERFORM_FORM_TRANSLATION = "perform_form_translation";

public static final String APP_PROPERTIES_FILE = "app.properties";
public static final String DISABLED = "disabled";
public static final String ENCOUNTER_TYPE = "encounter_type";
public interface MultiSelectUtils {
String IS_HEADER = "isHeader";
String TEXT = "text";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public String getStepName() {
return stepName;
}

public void setStepName(String stepName) {
this.stepName = stepName;
}

protected void loadPartialSecondaryValues() throws JSONException {
if (getMainFormFields() != null && getMainFormFields().length() > 0) {
for (int i = 0; i < getMainFormFields().length(); i++) {
Expand Down Expand Up @@ -186,19 +190,33 @@ public JSONArray getMainFormFields() {
return mainFormFields;
}

public void setMainFormFields(JSONArray mainFormFields) {
this.mainFormFields = mainFormFields;
}

public JSONArray getSecondaryValues() {
return secondaryValues;
}

public void setSecondaryValues(JSONArray secondaryValues) {
this.secondaryValues = secondaryValues;
}

public Map<String, SecondaryValueModel> getSecondaryValuesMap() {
return secondaryValuesMap;
}

public void setSecondaryValuesMap(Map<String, SecondaryValueModel> secondaryValuesMap) {
this.secondaryValuesMap = secondaryValuesMap;
}

@Nullable
protected JSONObject getSubForm() {
JSONObject subForm = new JSONObject();
try {
subForm = FormUtils.getSubFormJson(getFormIdentity(), getFormLocation(), context);
Utils.updateSubFormFields(subForm, getJsonApi().form());

} catch (Exception e) {
Timber.e(e, "GenericPopupDialog --> getSubForm");
}
Expand Down Expand Up @@ -244,6 +262,10 @@ public JSONArray getSpecifyContent() {
return specifyContent;
}

public void setSpecifyContent(JSONArray specifyContent) {
this.specifyContent = specifyContent;
}

public String getFormLocation() {
return formLocation;
}
Expand All @@ -262,26 +284,6 @@ public void setWidgetType(String widgetType) {
this.widgetType = widgetType;
}

public void setSpecifyContent(JSONArray specifyContent) {
this.specifyContent = specifyContent;
}

public void setSecondaryValuesMap(Map<String, SecondaryValueModel> secondaryValuesMap) {
this.secondaryValuesMap = secondaryValuesMap;
}

public void setSecondaryValues(JSONArray secondaryValues) {
this.secondaryValues = secondaryValues;
}

public void setMainFormFields(JSONArray mainFormFields) {
this.mainFormFields = mainFormFields;
}

public void setStepName(String stepName) {
this.stepName = stepName;
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Expand Down Expand Up @@ -364,6 +366,10 @@ public CommonListener getCommonListener() {
return commonListener;
}

public void setCommonListener(CommonListener commonListener) {
this.commonListener = commonListener;
}

public void setContext(Context context) throws IllegalStateException {
this.context = context;
}
Expand Down Expand Up @@ -411,6 +417,10 @@ public String getChildKey() {
return childKey;
}

public void setChildKey(String childKey) {
this.childKey = childKey;
}

/**
* Adding the secondary values on to the specific json widget
*
Expand Down Expand Up @@ -471,6 +481,10 @@ public JSONArray getNewSelectedValues() {
return newSelectedValues;
}

public void setNewSelectedValues(JSONArray newSelectedValues) {
this.newSelectedValues = newSelectedValues;
}

protected JSONArray createValues() throws JSONException {
JSONArray selectedValues = new JSONArray();
JSONArray formFields = getSubFormsFields();
Expand Down Expand Up @@ -522,18 +536,6 @@ public void setSubFormsFields(JSONArray subFormsFields) {
this.subFormsFields = subFormsFields;
}

public void setNewSelectedValues(JSONArray newSelectedValues) {
this.newSelectedValues = newSelectedValues;
}

public void setChildKey(String childKey) {
this.childKey = childKey;
}

public void setCommonListener(CommonListener commonListener) {
this.commonListener = commonListener;
}

@Override
public void onResume() {
super.onResume();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.vijay.jsonwizard.domain;

import java.io.Serializable;
import java.util.Set;

public class Form implements Serializable {

Expand All @@ -23,6 +24,10 @@ public class Form implements Serializable {
private boolean hideNextButton = false;
private boolean hidePreviousButton = false;

private Set<String> hiddenFields;

private Set<String> disabledFields;

public String getName() {
return name;
}
Expand Down Expand Up @@ -118,4 +123,20 @@ public boolean isHideNextButton(){
public boolean isHidePreviousButton() {
return hidePreviousButton;
}

public Set<String> getHiddenFields() {
return hiddenFields;
}

public void setHiddenFields(Set<String> hiddenFields) {
this.hiddenFields = hiddenFields;
}

public Set<String> getDisabledFields() {
return disabledFields;
}

public void setDisabledFields(Set<String> disabledFields) {
this.disabledFields = disabledFields;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.view.View;

import com.vijay.jsonwizard.customviews.GenericPopupDialog;
import com.vijay.jsonwizard.domain.Form;
import com.vijay.jsonwizard.utils.ValidationStatus;

import org.json.JSONArray;
Expand Down Expand Up @@ -119,4 +120,6 @@ void addOnActivityRequestPermissionResultListener(Integer requestCode,
boolean isPreviousPressed();

void setPreviousPressed(boolean previousPressed);

Form form();
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected void onPostExecute(List<View> result) {

try {
((JsonApi) widgetArgs.getContext()).invokeRefreshLogic(null, false, null, null);
} catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
}
hideProgressDialog();
Expand Down Expand Up @@ -195,8 +195,10 @@ protected void addUniqueIdentifiers(JSONObject element, String uniqueId) throws
currKey += ("_" + uniqueId);
element.put(KEY, currKey);
// modify relevance to reflect changes in unique key name
Utils.buildRulesWithUniqueId(element, uniqueId, RELEVANCE, widgetArgs, rulesFileMap);
Utils.buildRulesWithUniqueId(element, uniqueId, CALCULATION, widgetArgs, rulesFileMap);
if (widgetArgs != null && widgetArgs.getContext() != null) {
Utils.buildRulesWithUniqueId(element, uniqueId, RELEVANCE, widgetArgs.getContext(), rulesFileMap);
Utils.buildRulesWithUniqueId(element, uniqueId, CALCULATION, widgetArgs.getContext(), rulesFileMap);
}
// modify relative max validator to reflect changes in unique key name
JSONObject relativeMaxValidator = element.optJSONObject(V_RELATIVE_MAX);
if (relativeMaxValidator != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ public static JSONArray getMultiStepFormFields(JSONObject jsonForm) {
if (jsonForm.has(JsonFormConstants.COUNT)) {
int stepCount = Integer.parseInt(jsonForm.getString(JsonFormConstants.COUNT));
for (int i = 0; i < stepCount; i++) {
String stepName = "step" + (i + 1);
String stepName = JsonFormConstants.STEP + (i + 1);
JSONObject step = jsonForm.has(stepName) ? jsonForm.getJSONObject(stepName) : null;
if (step != null && step.has(JsonFormConstants.FIELDS)) {
JSONArray stepFields = step.getJSONArray(JsonFormConstants.FIELDS);
Expand Down

0 comments on commit 09181bf

Please sign in to comment.