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:
rjy7 2010-04-13 23:05:28 +00:00
parent b5db8baf0e
commit 83d1b564ef
3 changed files with 40 additions and 31 deletions

View file

@ -48,9 +48,10 @@
var customForm = {
views: {
ADD_NEW: 1, // not 0, else can't test if (!view)
SELECT_EXISTING: 2,
COMBINED: 3
ADD_STEP_ONE: 1, // not 0, else can't test if (!view)
ADD_NEW: 2,
SELECT_EXISTING: 3,
COMBINED: 4
},
@ -78,6 +79,7 @@ var customForm = {
this.addNew = $('.new');
this.entry = $('.entry');
this.existingOrNew = $('.existingOrNew'); // just the word "or" between existing and add new
this.viewField = $("input[name='view']");
this.cancel = this.form.find('.cancel');
@ -88,6 +90,7 @@ var customForm = {
this.entryType = $("input[name='entryType']").val().capitalizeWords();
this.secondaryType = $("input[name='secondaryType']").val().capitalizeWords();
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
// an attempted submission that failed validation, and we need to go
// directly to step 2.
if (this.findValidationErrors()) {
this.doAddFormStep2();
} else {
this.doAddFormStep1();
}
// if (this.findValidationErrors()) {
// this.doAddFormStep2();
// } else {
// 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
@ -156,6 +165,7 @@ var customForm = {
customForm.requiredLegend.hide();
customForm.button.hide();
customForm.or.hide();
customForm.setViewValue(customForm.views.ADD_STEP_ONE);
// Assign event listeners
customForm.existingSelect.bind('change', function() {
@ -176,14 +186,10 @@ var customForm = {
// determine the previous view from the form data that's been entered.
doAddFormStep2: function(view) {
if (!view) {
view = customForm.getPreviousViewFromFormData();
}
switch (view) {
case customForm.views.SELECT_EXISTING: { fn = this.doAddFormStep2SelectExisting; break; }
case customForm.views.ADD_NEW: { fn = this.doAddFormStep2AddNew; break; }
default: { fn = this.doAddFormStep2Combined; break; }
case customForm.views.SELECT_EXISTING: { fn = customForm.doAddFormStep2SelectExisting; break; }
case customForm.views.ADD_NEW: { fn = customForm.doAddFormStep2AddNew; break; }
default: { fn = customForm.doAddFormStep2Combined; break; }
}
fn.call(customForm);
@ -209,6 +215,7 @@ var customForm = {
customForm.toggleRequiredHints('show', customForm.existing);
customForm.doButtonForStep2(customForm.defaultButtonText);
customForm.doCancelForStep2();
customForm.setViewValue(customForm.views.SELECT_EXISTING);
},
// Step 2: adding a new individual
@ -218,6 +225,7 @@ var customForm = {
customForm.doButtonForStep2(customForm.addNewButtonText);
customForm.doCancelForStep2();
customForm.doClose();
customForm.setViewValue(customForm.views.ADD_NEW);
},
// Step 2: combined view, when we are returning from validation errors and we
@ -228,6 +236,7 @@ var customForm = {
customForm.doAddNewLinkForCombinedView();
customForm.doButtonForStep2(customForm.defaultButtonText);
customForm.doCancelForStep2();
customForm.setViewValue(customForm.views.COMBINED);
},
@ -235,37 +244,29 @@ var customForm = {
initEditForm: function() {
var view;
this.defaultButtonText = 'Save Changes';
this.addNewButtonText = 'Create ' + this.secondaryType + ' & Save Changes';
this.toggleRequiredHints('show', this.existing);
// If there are validation errors on the page, we're returning from
// an attempted submission that failed validation, and we need to go
// directly to step 2.
if (this.findValidationErrors()) {
view = this.getPreviousViewFromFormData();
switch (this.viewVal) {
case this.views.ADD_NEW: { fn = this.doEditFormAddNew; break; }
default: { fn = this.doEditFormDefaultView; break; }
}
switch (view) {
case this.views.ADD_NEW: { fn = this.doEditFormAddNew; break; }
default: { fn = this.doEditFormDefaultView; break; }
}
} else {
fn = this.doEditFormDefaultView;
}
fn.call(customForm);
},
doEditFormAddNew: function() {
this.showAddNewFields();
this.button.val(this.addNewButtonText);
this.setViewValue(this.views.ADD_NEW);
},
doEditFormDefaultView: function() {
this.showCombinedFields();
this.button.val(this.defaultButtonText);
this.doAddNewLinkForCombinedView();
this.setViewValue(this.views.COMBINED);
},
/***** Utilities *****/
@ -473,6 +474,10 @@ var customForm = {
}
action == 'show' ? hints.show() : hints.hide();
},
setViewValue: function(value) {
customForm.viewField.val(value);
}
};

View file

@ -357,6 +357,7 @@ the type still gets asserted. --%>
%>
<c:set var="requiredHint" value="<span class='requiredHint'> *</span>" />
<c:set var="view" value='<%= vreq.getAttribute("view") %>' />
<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="secondaryType" value="organization" />
<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>

View file

@ -311,6 +311,7 @@ the type still gets asserted. --%>
%>
<c:set var="requiredHint" value="<span class='requiredHint'> *</span>" />
<c:set var="view" value='<%= vreq.getAttribute("view") %>' />
<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
step 1 and edit cases in the Javascript. --%>
<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>