NIHVIVO-377 Initial work on getting custom form to retrieve its past state after a failed form submission. Not all cases working yet.
This commit is contained in:
parent
b5db8baf0e
commit
83d1b564ef
3 changed files with 40 additions and 31 deletions
|
@ -48,9 +48,10 @@
|
||||||
var customForm = {
|
var customForm = {
|
||||||
|
|
||||||
views: {
|
views: {
|
||||||
ADD_NEW: 1, // not 0, else can't test if (!view)
|
ADD_STEP_ONE: 1, // not 0, else can't test if (!view)
|
||||||
SELECT_EXISTING: 2,
|
ADD_NEW: 2,
|
||||||
COMBINED: 3
|
SELECT_EXISTING: 3,
|
||||||
|
COMBINED: 4
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,6 +79,7 @@ var customForm = {
|
||||||
this.addNew = $('.new');
|
this.addNew = $('.new');
|
||||||
this.entry = $('.entry');
|
this.entry = $('.entry');
|
||||||
this.existingOrNew = $('.existingOrNew'); // just the word "or" between existing and add new
|
this.existingOrNew = $('.existingOrNew'); // just the word "or" between existing and add new
|
||||||
|
this.viewField = $("input[name='view']");
|
||||||
|
|
||||||
this.cancel = this.form.find('.cancel');
|
this.cancel = this.form.find('.cancel');
|
||||||
|
|
||||||
|
@ -88,6 +90,7 @@ var customForm = {
|
||||||
this.entryType = $("input[name='entryType']").val().capitalizeWords();
|
this.entryType = $("input[name='entryType']").val().capitalizeWords();
|
||||||
this.secondaryType = $("input[name='secondaryType']").val().capitalizeWords();
|
this.secondaryType = $("input[name='secondaryType']").val().capitalizeWords();
|
||||||
this.formSteps = $("input[name='steps']").val();
|
this.formSteps = $("input[name='steps']").val();
|
||||||
|
this.viewVal = parseInt(this.viewField.val());
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -125,11 +128,17 @@ var customForm = {
|
||||||
// If there are validation errors on the page, we're returning from
|
// If there are validation errors on the page, we're returning from
|
||||||
// an attempted submission that failed validation, and we need to go
|
// an attempted submission that failed validation, and we need to go
|
||||||
// directly to step 2.
|
// directly to step 2.
|
||||||
if (this.findValidationErrors()) {
|
// if (this.findValidationErrors()) {
|
||||||
this.doAddFormStep2();
|
// this.doAddFormStep2();
|
||||||
} else {
|
// } else {
|
||||||
this.doAddFormStep1();
|
// this.doAddFormStep1();
|
||||||
}
|
// }
|
||||||
|
if (this.viewVal) {
|
||||||
|
this.doAddFormStep2(this.viewVal);
|
||||||
|
} else {
|
||||||
|
this.doAddFormStep1();
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Reset add form to initial state (step 1) after cancelling out of step 2
|
// Reset add form to initial state (step 1) after cancelling out of step 2
|
||||||
|
@ -156,6 +165,7 @@ var customForm = {
|
||||||
customForm.requiredLegend.hide();
|
customForm.requiredLegend.hide();
|
||||||
customForm.button.hide();
|
customForm.button.hide();
|
||||||
customForm.or.hide();
|
customForm.or.hide();
|
||||||
|
customForm.setViewValue(customForm.views.ADD_STEP_ONE);
|
||||||
|
|
||||||
// Assign event listeners
|
// Assign event listeners
|
||||||
customForm.existingSelect.bind('change', function() {
|
customForm.existingSelect.bind('change', function() {
|
||||||
|
@ -176,14 +186,10 @@ var customForm = {
|
||||||
// determine the previous view from the form data that's been entered.
|
// determine the previous view from the form data that's been entered.
|
||||||
doAddFormStep2: function(view) {
|
doAddFormStep2: function(view) {
|
||||||
|
|
||||||
if (!view) {
|
|
||||||
view = customForm.getPreviousViewFromFormData();
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (view) {
|
switch (view) {
|
||||||
case customForm.views.SELECT_EXISTING: { fn = this.doAddFormStep2SelectExisting; break; }
|
case customForm.views.SELECT_EXISTING: { fn = customForm.doAddFormStep2SelectExisting; break; }
|
||||||
case customForm.views.ADD_NEW: { fn = this.doAddFormStep2AddNew; break; }
|
case customForm.views.ADD_NEW: { fn = customForm.doAddFormStep2AddNew; break; }
|
||||||
default: { fn = this.doAddFormStep2Combined; break; }
|
default: { fn = customForm.doAddFormStep2Combined; break; }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn.call(customForm);
|
fn.call(customForm);
|
||||||
|
@ -209,6 +215,7 @@ var customForm = {
|
||||||
customForm.toggleRequiredHints('show', customForm.existing);
|
customForm.toggleRequiredHints('show', customForm.existing);
|
||||||
customForm.doButtonForStep2(customForm.defaultButtonText);
|
customForm.doButtonForStep2(customForm.defaultButtonText);
|
||||||
customForm.doCancelForStep2();
|
customForm.doCancelForStep2();
|
||||||
|
customForm.setViewValue(customForm.views.SELECT_EXISTING);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Step 2: adding a new individual
|
// Step 2: adding a new individual
|
||||||
|
@ -218,6 +225,7 @@ var customForm = {
|
||||||
customForm.doButtonForStep2(customForm.addNewButtonText);
|
customForm.doButtonForStep2(customForm.addNewButtonText);
|
||||||
customForm.doCancelForStep2();
|
customForm.doCancelForStep2();
|
||||||
customForm.doClose();
|
customForm.doClose();
|
||||||
|
customForm.setViewValue(customForm.views.ADD_NEW);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Step 2: combined view, when we are returning from validation errors and we
|
// Step 2: combined view, when we are returning from validation errors and we
|
||||||
|
@ -228,6 +236,7 @@ var customForm = {
|
||||||
customForm.doAddNewLinkForCombinedView();
|
customForm.doAddNewLinkForCombinedView();
|
||||||
customForm.doButtonForStep2(customForm.defaultButtonText);
|
customForm.doButtonForStep2(customForm.defaultButtonText);
|
||||||
customForm.doCancelForStep2();
|
customForm.doCancelForStep2();
|
||||||
|
customForm.setViewValue(customForm.views.COMBINED);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
@ -235,37 +244,29 @@ var customForm = {
|
||||||
|
|
||||||
initEditForm: function() {
|
initEditForm: function() {
|
||||||
|
|
||||||
var view;
|
|
||||||
|
|
||||||
this.defaultButtonText = 'Save Changes';
|
this.defaultButtonText = 'Save Changes';
|
||||||
this.addNewButtonText = 'Create ' + this.secondaryType + ' & Save Changes';
|
this.addNewButtonText = 'Create ' + this.secondaryType + ' & Save Changes';
|
||||||
this.toggleRequiredHints('show', this.existing);
|
this.toggleRequiredHints('show', this.existing);
|
||||||
|
|
||||||
// If there are validation errors on the page, we're returning from
|
switch (this.viewVal) {
|
||||||
// an attempted submission that failed validation, and we need to go
|
case this.views.ADD_NEW: { fn = this.doEditFormAddNew; break; }
|
||||||
// directly to step 2.
|
default: { fn = this.doEditFormDefaultView; break; }
|
||||||
if (this.findValidationErrors()) {
|
}
|
||||||
view = this.getPreviousViewFromFormData();
|
|
||||||
|
|
||||||
switch (view) {
|
|
||||||
case this.views.ADD_NEW: { fn = this.doEditFormAddNew; break; }
|
|
||||||
default: { fn = this.doEditFormDefaultView; break; }
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fn = this.doEditFormDefaultView;
|
|
||||||
}
|
|
||||||
fn.call(customForm);
|
fn.call(customForm);
|
||||||
},
|
},
|
||||||
|
|
||||||
doEditFormAddNew: function() {
|
doEditFormAddNew: function() {
|
||||||
this.showAddNewFields();
|
this.showAddNewFields();
|
||||||
this.button.val(this.addNewButtonText);
|
this.button.val(this.addNewButtonText);
|
||||||
|
this.setViewValue(this.views.ADD_NEW);
|
||||||
},
|
},
|
||||||
|
|
||||||
doEditFormDefaultView: function() {
|
doEditFormDefaultView: function() {
|
||||||
this.showCombinedFields();
|
this.showCombinedFields();
|
||||||
this.button.val(this.defaultButtonText);
|
this.button.val(this.defaultButtonText);
|
||||||
this.doAddNewLinkForCombinedView();
|
this.doAddNewLinkForCombinedView();
|
||||||
|
this.setViewValue(this.views.COMBINED);
|
||||||
},
|
},
|
||||||
|
|
||||||
/***** Utilities *****/
|
/***** Utilities *****/
|
||||||
|
@ -473,6 +474,10 @@ var customForm = {
|
||||||
}
|
}
|
||||||
|
|
||||||
action == 'show' ? hints.show() : hints.hide();
|
action == 'show' ? hints.show() : hints.hide();
|
||||||
|
},
|
||||||
|
|
||||||
|
setViewValue: function(value) {
|
||||||
|
customForm.viewField.val(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -357,6 +357,7 @@ the type still gets asserted. --%>
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<c:set var="requiredHint" value="<span class='requiredHint'> *</span>" />
|
<c:set var="requiredHint" value="<span class='requiredHint'> *</span>" />
|
||||||
|
<c:set var="view" value='<%= vreq.getAttribute("view") %>' />
|
||||||
|
|
||||||
<jsp:include page="${preForm}" />
|
<jsp:include page="${preForm}" />
|
||||||
|
|
||||||
|
@ -399,6 +400,7 @@ the type still gets asserted. --%>
|
||||||
<input type="hidden" name="entryType" value="educational background" />
|
<input type="hidden" name="entryType" value="educational background" />
|
||||||
<input type="hidden" name="secondaryType" value="organization" />
|
<input type="hidden" name="secondaryType" value="organization" />
|
||||||
<input type="hidden" name="steps" value="1" />
|
<input type="hidden" name="steps" value="1" />
|
||||||
|
<input type="hidden" name="view" value="${view}" />
|
||||||
|
|
||||||
<p class="submit"><v:input type="submit" id="submit" value="${submitLabel}" cancel="${param.subjectUri}"/></p>
|
<p class="submit"><v:input type="submit" id="submit" value="${submitLabel}" cancel="${param.subjectUri}"/></p>
|
||||||
|
|
||||||
|
|
|
@ -311,6 +311,7 @@ the type still gets asserted. --%>
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<c:set var="requiredHint" value="<span class='requiredHint'> *</span>" />
|
<c:set var="requiredHint" value="<span class='requiredHint'> *</span>" />
|
||||||
|
<c:set var="view" value='<%= vreq.getAttribute("view") %>' />
|
||||||
|
|
||||||
<jsp:include page="${preForm}" />
|
<jsp:include page="${preForm}" />
|
||||||
|
|
||||||
|
@ -349,6 +350,7 @@ the type still gets asserted. --%>
|
||||||
<%-- RY If set steps to 1 when editType == 'edit', may be able to combine the
|
<%-- RY If set steps to 1 when editType == 'edit', may be able to combine the
|
||||||
step 1 and edit cases in the Javascript. --%>
|
step 1 and edit cases in the Javascript. --%>
|
||||||
<input type="hidden" name="steps" value="2" />
|
<input type="hidden" name="steps" value="2" />
|
||||||
|
<input type="hidden" name="view" value="${view}" />
|
||||||
|
|
||||||
<p class="submit"><v:input type="submit" id="submit" value="${submitLabel}" cancel="${param.subjectUri}"/></p>
|
<p class="submit"><v:input type="submit" id="submit" value="${submitLabel}" cancel="${param.subjectUri}"/></p>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue