NIHVIVO-194. Sorted out issues with event listeners in one-step custom form.

This commit is contained in:
rjy7 2010-04-04 19:37:20 +00:00
parent 99d737a399
commit 59d8ccef74

View file

@ -39,14 +39,13 @@
* One-step custom form workflow: * One-step custom form workflow:
* *
* Has three view variations: * Has three view variations:
* - Select an existing secondary individual view * - Combined view, as above for two step form. This is the default view for
* - Add new secondary individual view * the one-step form, which shows unless we have clicked the add new link
* - Combined view, if we are returning from a failed validation and can't determine * or are returning from a validation error where we had been in the add new view.
* which variant of the view we had submitted the form from. Contains the select * - Add new secondary individual view. As above for two step form, but add new
* existing element plus the add new link. * box contains a close link to return to combined view.
*/ */
var customForm = { var customForm = {
onLoad: function() { onLoad: function() {
@ -153,7 +152,8 @@ var customForm = {
customForm.doAddFormStep2SelectExisting(); customForm.doAddFormStep2SelectExisting();
return false; return false;
}); });
// Note that addNewLink event listener is different
// in different views.
customForm.addNewLink.bind('click', function() { customForm.addNewLink.bind('click', function() {
customForm.doAddFormStep2AddNew(); customForm.doAddFormStep2AddNew();
}); });
@ -192,6 +192,7 @@ var customForm = {
customForm.showAddNewFields(); customForm.showAddNewFields();
customForm.doButtonForStep2(customForm.addNewButtonText); customForm.doButtonForStep2(customForm.addNewButtonText);
customForm.doCancelForStep2(); customForm.doCancelForStep2();
customForm.doClose();
}, },
// 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
@ -199,7 +200,7 @@ var customForm = {
doAddFormStep2Combined: function() { doAddFormStep2Combined: function() {
customForm.showCombinedFields(); customForm.showCombinedFields();
customForm.doAddNewLink(); customForm.doAddNewLinkForCombinedView();
customForm.doButtonForStep2(customForm.defaultButtonText); customForm.doButtonForStep2(customForm.defaultButtonText);
customForm.doCancelForStep2(); customForm.doCancelForStep2();
}, },
@ -244,7 +245,7 @@ var customForm = {
doEditFormDefaultView: function() { doEditFormDefaultView: function() {
this.showCombinedFields(); this.showCombinedFields();
this.button.val(this.defaultButtonText); this.button.val(this.defaultButtonText);
this.doAddNewLink(); this.doAddNewLinkForCombinedView();
}, },
/***** Utilities *****/ /***** Utilities *****/
@ -253,6 +254,7 @@ var customForm = {
customForm.cancel.unbind('click'); customForm.cancel.unbind('click');
customForm.button.unbind('click'); customForm.button.unbind('click');
customForm.addNewLink.unbind('click'); customForm.addNewLink.unbind('click');
customForm.close.unbind('click');
}, },
clearFormData: function() { clearFormData: function() {
@ -323,7 +325,7 @@ var customForm = {
}); });
}, },
doAddNewLink: function() { doAddNewLinkForCombinedView: function() {
customForm.addNewLink.unbind('click'); customForm.addNewLink.unbind('click');
customForm.addNewLink.bind('click', function() { customForm.addNewLink.bind('click', function() {
@ -338,21 +340,24 @@ var customForm = {
customForm.hideFields(customForm.existing); customForm.hideFields(customForm.existing);
customForm.showFields(customForm.addNew); customForm.showFields(customForm.addNew);
customForm.button.val(customForm.addNewButtonText); customForm.button.val(customForm.addNewButtonText);
customForm.doClose();
return false; return false;
}); });
}, },
doClose: function() { doClose: function() {
// This can be bound once on page load, doesn't need to be unbound
// or rebound. if (customForm.formSteps > 1) { return; }
customForm.close.click(function() {
customForm.close.unbind('click');
customForm.close.bind('click', function() {
// RY When we have multiple existing and addNew divs, we won't // RY When we have multiple existing and addNew divs, we won't
// show/hide them all, only the siblings of the addNewLink. // show/hide them all, only the siblings of the addNewLink.
customForm.showFields(customForm.existing); customForm.showFields(customForm.existing);
customForm.hideFields(customForm.addNew); customForm.hideFields(customForm.addNew);
customForm.addNewLink.show(); customForm.addNewLink.show();
customForm.button.val(customForm.defaultButtonText); customForm.button.val(customForm.defaultButtonText);
customForm.doAddNewLinkForCombinedView();
return false; return false;
}); });
}, },
@ -463,7 +468,6 @@ var customForm = {
} }
return view; return view;
} }
}; };
$(document).ready(function(){ $(document).ready(function(){