2010-03-29 15:41:45 +00:00
|
|
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
|
|
|
2010-04-02 23:21:42 +00:00
|
|
|
/* RY In a later iteration of the custom form Javascript, we'll create a customForm object
|
|
|
|
* with subclasses for one-step and two-step forms. The parent object will contain
|
|
|
|
* the utilities used by all form types.
|
|
|
|
*/
|
2010-04-01 19:45:23 +00:00
|
|
|
|
2010-04-02 23:21:42 +00:00
|
|
|
/* Two-step custom form workflow:
|
|
|
|
*
|
|
|
|
* ADD new property form
|
|
|
|
* Step 1: Initial step, with choice to select existing or add new secondary individual.
|
|
|
|
* Displays:
|
|
|
|
* - On page load, unless there are validation error messages in the form
|
|
|
|
* - if there are validation error messages in the form, we are returning from a failed
|
|
|
|
* submission, and will go directly to view 2 to display the error messages.
|
|
|
|
* - After cancelling out of step 2
|
|
|
|
*
|
|
|
|
* Step 2: Main data entry step
|
|
|
|
* Displays:
|
|
|
|
* - On page load after an attempted submission that fails validation
|
|
|
|
* - After clicking button or add new link in view 1
|
|
|
|
* Has three view variations:
|
|
|
|
* - Select an existing secondary individual view
|
|
|
|
* - Add new secondary individual view
|
|
|
|
* - Combined view, if we are returning from a failed validation and can't determine
|
|
|
|
* which variant of view 2 we had submitted the form from. Contains the select
|
|
|
|
* existing element plus the add new link.
|
|
|
|
*
|
|
|
|
* EDIT existing property form
|
2010-04-04 22:21:39 +00:00
|
|
|
* View variations are like one-step form, though button text is specific to edit version.
|
2010-04-02 23:21:42 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* We're jerry-rigging one-step forms into the two-step form process due to time constraints.
|
|
|
|
* In a later iteration of the custom form Javascript, we'll create a customForm object
|
|
|
|
* with subclasses for one-step and two-step forms. The parent object will contain
|
2010-04-05 02:34:27 +00:00
|
|
|
* the utilities used by all form types. The two-step edit form will be a type of one-step form.
|
2010-04-02 23:21:42 +00:00
|
|
|
*
|
|
|
|
* One-step custom form workflow:
|
|
|
|
*
|
2010-04-04 22:21:39 +00:00
|
|
|
* Has two view variations:
|
2010-04-04 19:37:20 +00:00
|
|
|
* - Combined view, as above for two step form. This is the default view for
|
|
|
|
* the one-step form, which shows unless we have clicked the add new link
|
|
|
|
* or are returning from a validation error where we had been in the add new view.
|
|
|
|
* - Add new secondary individual view. As above for two step form, but add new
|
|
|
|
* box contains a close link to return to combined view.
|
2010-04-02 23:21:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
var customForm = {
|
|
|
|
|
2010-04-04 20:20:45 +00:00
|
|
|
views: {
|
2010-04-13 23:05:28 +00:00
|
|
|
ADD_STEP_ONE: 1, // not 0, else can't test if (!view)
|
|
|
|
ADD_NEW: 2,
|
|
|
|
SELECT_EXISTING: 3,
|
|
|
|
COMBINED: 4
|
2010-04-04 20:20:45 +00:00
|
|
|
},
|
|
|
|
|
2010-04-12 23:49:23 +00:00
|
|
|
|
2010-04-02 23:21:42 +00:00
|
|
|
onLoad: function() {
|
|
|
|
|
|
|
|
this.initObjects();
|
|
|
|
this.adjustForJs();
|
|
|
|
this.initForm();
|
|
|
|
},
|
|
|
|
|
|
|
|
// On page load, create references within the customForm scope to DOM elements.
|
|
|
|
// NB These must be assigned after the elements have been loaded onto the page.
|
|
|
|
initObjects: function() {
|
|
|
|
|
|
|
|
this.form = $('#content form');
|
|
|
|
this.button = $('#submit');
|
2010-04-04 22:56:35 +00:00
|
|
|
this.or = $('span.or');
|
2010-04-02 23:21:42 +00:00
|
|
|
this.requiredLegend = $('#requiredLegend');
|
|
|
|
|
|
|
|
// These may need to be changed to classes rather than ids, if there are
|
|
|
|
// multiple sets of divs to show/hide during the workflow.
|
|
|
|
this.addNewLink = $('.addNewLink');
|
|
|
|
this.existing = $('.existing');
|
2010-04-04 22:56:35 +00:00
|
|
|
this.existingSelect = this.existing.children('select');
|
2010-04-02 23:21:42 +00:00
|
|
|
this.addNew = $('.new');
|
|
|
|
this.entry = $('.entry');
|
2010-04-12 23:49:23 +00:00
|
|
|
this.existingOrNew = $('.existingOrNew'); // just the word "or" between existing and add new
|
2010-04-14 20:33:42 +00:00
|
|
|
this.returnViewField = $("input[name='view']");
|
2010-04-02 23:21:42 +00:00
|
|
|
|
2010-04-14 20:33:42 +00:00
|
|
|
this.cancel = this.form.find('.cancel');
|
2010-04-02 23:21:42 +00:00
|
|
|
|
|
|
|
// Read values used to control display
|
|
|
|
this.editType = $("input[name='editType']").val();
|
|
|
|
this.entryType = $("input[name='entryType']").val().capitalizeWords();
|
|
|
|
this.secondaryType = $("input[name='secondaryType']").val().capitalizeWords();
|
2010-04-16 13:41:17 +00:00
|
|
|
// Enforce one step for edit forms, in case the form forgets to
|
|
|
|
this.formSteps = this.editType === 'edit' ? '1' : $("input[name='steps']").val();
|
2010-04-14 20:33:42 +00:00
|
|
|
this.returnView = parseInt(this.returnViewField.val()); // returns NaN for empty string
|
2010-04-02 23:21:42 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
// On page load, make changes to the non-Javascript version for the Javascript version.
|
2010-04-15 19:34:26 +00:00
|
|
|
// These are features that will NOT CHANGE throughout the workflow of the Javascript version.
|
2010-04-02 23:21:42 +00:00
|
|
|
adjustForJs: function() {
|
|
|
|
|
|
|
|
var selectExistingLabel = $('.existing label');
|
|
|
|
selectExistingLabel.html(selectExistingLabel.html().replace(/Select (Existing )?/, ''));
|
|
|
|
|
|
|
|
this.existingOrNew.hide();
|
2010-04-13 14:44:31 +00:00
|
|
|
|
2010-04-13 18:50:38 +00:00
|
|
|
this.toggleRequiredHints('show', this.addNew);
|
2010-04-15 19:34:26 +00:00
|
|
|
|
|
|
|
// The close link in the addNew div closes the addNew div and restores the
|
|
|
|
// combined view. It is needed for the one-step add form and the edit form
|
|
|
|
// (which is a one-step form), but not for the two-step add form, since we'd
|
|
|
|
// want it to restore step 1, but the Cancel link at the bottom of the form
|
|
|
|
// already performs that function.
|
|
|
|
if (this.formSteps == 1) {
|
|
|
|
this.addNew.prepend('<a class="close" href="#">cancel</a>');
|
|
|
|
}
|
|
|
|
this.close = this.form.find('.close');
|
|
|
|
|
2010-04-02 23:21:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
initForm: function() {
|
|
|
|
|
|
|
|
//Adding a new entry
|
2010-04-14 20:33:42 +00:00
|
|
|
if (this.editType === 'add') {
|
2010-04-02 23:21:42 +00:00
|
|
|
this.initAddForm();
|
|
|
|
// Editing an existing entry
|
|
|
|
} else {
|
|
|
|
this.initEditForm();
|
2010-04-04 19:37:20 +00:00
|
|
|
}
|
2010-04-02 23:21:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/***** ADD form *****/
|
|
|
|
|
|
|
|
// Set up add form on page load, or when returning to initial state from step 2
|
|
|
|
initAddForm: function() {
|
|
|
|
|
|
|
|
this.defaultButtonText = 'Create ' + this.entryType;
|
|
|
|
this.addNewButtonText = 'Create ' + this.secondaryType + ' & ' + this.entryType;
|
|
|
|
|
2010-04-14 21:28:11 +00:00
|
|
|
// If a returnView has been specified in the hidden input field, it means we are
|
|
|
|
// returning from a failed submission due to validation errors. We need to restore
|
|
|
|
// the view we were on when the form was submitted.
|
2010-04-14 20:33:42 +00:00
|
|
|
if (this.returnView) {
|
|
|
|
this.doAddFormStep2(this.returnView);
|
2010-04-13 23:05:28 +00:00
|
|
|
} else {
|
|
|
|
this.doAddFormStep1();
|
|
|
|
}
|
|
|
|
|
2010-04-02 23:21:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Reset add form to initial state (step 1) after cancelling out of step 2
|
|
|
|
resetAddFormToStep1: function() {
|
|
|
|
|
|
|
|
customForm.resetForm();
|
|
|
|
customForm.doAddFormStep1();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Set up the add form for step 1
|
|
|
|
doAddFormStep1: function() {
|
|
|
|
|
|
|
|
if (this.formSteps == 1) {
|
2010-04-04 22:21:39 +00:00
|
|
|
customForm.doAddFormStep2(customForm.views.COMBINED);
|
2010-04-04 04:48:41 +00:00
|
|
|
customForm.doClose();
|
2010-04-02 23:21:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
customForm.existing.show();
|
2010-04-13 18:50:38 +00:00
|
|
|
customForm.toggleRequiredHints('hide', customForm.existing);
|
2010-04-02 23:21:42 +00:00
|
|
|
customForm.addNewLink.show();
|
2010-04-14 20:33:42 +00:00
|
|
|
customForm.hideFields(customForm.addNew);
|
|
|
|
customForm.hideFields(customForm.entry);
|
2010-04-02 23:21:42 +00:00
|
|
|
customForm.requiredLegend.hide();
|
2010-04-09 16:42:14 +00:00
|
|
|
customForm.button.hide();
|
|
|
|
customForm.or.hide();
|
2010-04-14 20:33:42 +00:00
|
|
|
customForm.setReturnView(customForm.views.ADD_STEP_ONE);
|
2010-04-02 23:21:42 +00:00
|
|
|
|
|
|
|
// Assign event listeners
|
2010-04-04 22:56:35 +00:00
|
|
|
customForm.existingSelect.bind('change', function() {
|
|
|
|
if ($(this).val() != '') {
|
|
|
|
customForm.doAddFormStep2(customForm.views.SELECT_EXISTING);
|
|
|
|
return false;
|
|
|
|
}
|
2010-04-02 23:21:42 +00:00
|
|
|
});
|
2010-04-04 19:37:20 +00:00
|
|
|
// Note that addNewLink event listener is different
|
|
|
|
// in different views.
|
2010-04-02 23:21:42 +00:00
|
|
|
customForm.addNewLink.bind('click', function() {
|
2010-04-04 20:20:45 +00:00
|
|
|
customForm.doAddFormStep2(customForm.views.ADD_NEW);
|
2010-04-02 23:21:42 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2010-04-05 02:34:27 +00:00
|
|
|
// Set up add form for step 2. If no view is passed in, we're returning
|
|
|
|
// from a failed submission due to validation errors, and will attempt to
|
|
|
|
// determine the previous view from the form data that's been entered.
|
2010-04-04 20:20:45 +00:00
|
|
|
doAddFormStep2: function(view) {
|
2010-04-02 23:21:42 +00:00
|
|
|
|
|
|
|
switch (view) {
|
2010-04-13 23:05:28 +00:00
|
|
|
case customForm.views.SELECT_EXISTING: { fn = customForm.doAddFormStep2SelectExisting; break; }
|
|
|
|
case customForm.views.ADD_NEW: { fn = customForm.doAddFormStep2AddNew; break; }
|
|
|
|
default: { fn = customForm.doAddFormStep2Combined; break; }
|
2010-04-02 23:21:42 +00:00
|
|
|
}
|
|
|
|
|
2010-04-04 22:56:35 +00:00
|
|
|
fn.call(customForm);
|
|
|
|
|
|
|
|
customForm.button.show();
|
|
|
|
customForm.or.show();
|
2010-04-13 18:50:38 +00:00
|
|
|
customForm.toggleRequiredHints('show', customForm.existing, customForm.addNew);
|
2010-04-02 23:21:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Most methods below use 'customForm' rather than 'this', because 'this' doesn't reference
|
|
|
|
// customForm when the method is called from an event listener. Only if the method never
|
|
|
|
// gets called from an event listener can we use the 'this' reference.
|
|
|
|
|
|
|
|
// Step 2: selecting an existing individual
|
|
|
|
doAddFormStep2SelectExisting: function() {
|
|
|
|
|
2010-04-04 22:21:39 +00:00
|
|
|
if (customForm.formSteps == 1) {
|
|
|
|
customForm.doAddFormStep2Combined();
|
|
|
|
return;
|
|
|
|
}
|
2010-04-02 23:21:42 +00:00
|
|
|
customForm.showSelectExistingFields();
|
2010-04-13 18:50:38 +00:00
|
|
|
// This hint shows in step 2 but not in step 1
|
|
|
|
customForm.toggleRequiredHints('show', customForm.existing);
|
2010-04-02 23:21:42 +00:00
|
|
|
customForm.doButtonForStep2(customForm.defaultButtonText);
|
|
|
|
customForm.doCancelForStep2();
|
2010-04-14 20:33:42 +00:00
|
|
|
customForm.setReturnView(customForm.views.SELECT_EXISTING);
|
2010-04-02 23:21:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Step 2: adding a new individual
|
|
|
|
doAddFormStep2AddNew: function() {
|
|
|
|
|
|
|
|
customForm.showAddNewFields();
|
|
|
|
customForm.doButtonForStep2(customForm.addNewButtonText);
|
|
|
|
customForm.doCancelForStep2();
|
2010-04-04 19:37:20 +00:00
|
|
|
customForm.doClose();
|
2010-04-14 20:33:42 +00:00
|
|
|
customForm.setReturnView(customForm.views.ADD_NEW);
|
2010-04-02 23:21:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Step 2: combined view, when we are returning from validation errors and we
|
|
|
|
// can't determine which view of the form we had been on.
|
|
|
|
doAddFormStep2Combined: function() {
|
|
|
|
|
|
|
|
customForm.showCombinedFields();
|
2010-04-04 19:37:20 +00:00
|
|
|
customForm.doAddNewLinkForCombinedView();
|
2010-04-02 23:21:42 +00:00
|
|
|
customForm.doButtonForStep2(customForm.defaultButtonText);
|
|
|
|
customForm.doCancelForStep2();
|
2010-04-14 20:33:42 +00:00
|
|
|
customForm.setReturnView(customForm.views.COMBINED);
|
2010-04-02 23:21:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/***** Edit form *****/
|
|
|
|
|
|
|
|
initEditForm: function() {
|
|
|
|
|
|
|
|
this.defaultButtonText = 'Save Changes';
|
|
|
|
this.addNewButtonText = 'Create ' + this.secondaryType + ' & Save Changes';
|
2010-04-13 18:50:38 +00:00
|
|
|
this.toggleRequiredHints('show', this.existing);
|
2010-04-02 23:21:42 +00:00
|
|
|
|
2010-04-14 20:33:42 +00:00
|
|
|
switch (this.returnView) {
|
2010-04-13 23:05:28 +00:00
|
|
|
case this.views.ADD_NEW: { fn = this.doEditFormAddNew; break; }
|
2010-04-14 20:33:42 +00:00
|
|
|
default: { fn = this.doEditFormCombinedView; break; }
|
2010-04-13 23:05:28 +00:00
|
|
|
}
|
2010-04-15 19:53:18 +00:00
|
|
|
|
|
|
|
// Remember the original org. If we click the add new org link
|
|
|
|
// but then cancel out of it, we want to restore this value.
|
|
|
|
this.originalOrg = this.existingSelect.val();
|
|
|
|
// But we only want to restore the original value from when the
|
|
|
|
// form loaded. If we've already changed to a new value, we don't
|
|
|
|
// want to restore that.
|
|
|
|
this.existingSelect.bind('change', function() {
|
|
|
|
customForm.originalOrg = null;
|
|
|
|
});
|
2010-04-13 23:05:28 +00:00
|
|
|
|
2010-04-02 23:21:42 +00:00
|
|
|
fn.call(customForm);
|
|
|
|
},
|
|
|
|
|
|
|
|
doEditFormAddNew: function() {
|
|
|
|
this.showAddNewFields();
|
2010-04-13 23:05:28 +00:00
|
|
|
this.button.val(this.addNewButtonText);
|
2010-04-14 20:33:42 +00:00
|
|
|
this.setReturnView(this.views.ADD_NEW);
|
|
|
|
this.doClose();
|
2010-04-02 23:21:42 +00:00
|
|
|
},
|
|
|
|
|
2010-04-14 20:33:42 +00:00
|
|
|
doEditFormCombinedView: function() {
|
2010-04-02 23:21:42 +00:00
|
|
|
this.showCombinedFields();
|
|
|
|
this.button.val(this.defaultButtonText);
|
2010-04-04 19:37:20 +00:00
|
|
|
this.doAddNewLinkForCombinedView();
|
2010-04-14 20:33:42 +00:00
|
|
|
this.setReturnView(this.views.COMBINED);
|
2010-04-02 23:21:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/***** Utilities *****/
|
|
|
|
|
|
|
|
unbindEventListeners: function() {
|
|
|
|
customForm.cancel.unbind('click');
|
|
|
|
customForm.button.unbind('click');
|
2010-04-04 19:37:20 +00:00
|
|
|
customForm.addNewLink.unbind('click');
|
|
|
|
customForm.close.unbind('click');
|
2010-04-04 22:56:35 +00:00
|
|
|
customForm.existingSelect.unbind('change');
|
2010-04-02 23:21:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
clearFormData: function() {
|
|
|
|
customForm.clearFields(customForm.form);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Clear data from form elements in element el
|
|
|
|
clearFields: function(el) {
|
2010-04-14 20:33:42 +00:00
|
|
|
el.find(':input[type!="hidden"][type!="submit"][type!="button"]').val('');
|
|
|
|
|
2010-04-02 23:21:42 +00:00
|
|
|
// For now we can remove the error elements. Later we may include them in
|
|
|
|
// the markup, for customized positioning, in which case we will empty them
|
2010-04-04 22:21:39 +00:00
|
|
|
// but not remove them here. See findValidationErrors().
|
2010-04-14 20:33:42 +00:00
|
|
|
el.find('.validationError').remove();
|
2010-04-13 14:44:31 +00:00
|
|
|
},
|
2010-04-02 23:21:42 +00:00
|
|
|
|
2010-04-14 20:33:42 +00:00
|
|
|
// This method should always be called instead of calling hide() directly on any
|
|
|
|
// element containing form fields.
|
2010-04-02 23:21:42 +00:00
|
|
|
hideFields: function(el) {
|
2010-04-14 20:33:42 +00:00
|
|
|
// Clear any input and error message, so if we re-show the element it won't still be there.
|
2010-04-02 23:21:42 +00:00
|
|
|
customForm.clearFields(el);
|
|
|
|
el.hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Add event listener to the submit button in step 2
|
|
|
|
doButtonForStep2: function(text) {
|
|
|
|
customForm.button.unbind('click');
|
|
|
|
customForm.button.val(text);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Add event listener to the cancel link in step 2
|
|
|
|
doCancelForStep2: function() {
|
|
|
|
|
|
|
|
if (customForm.formSteps == 1) { return; }
|
|
|
|
|
|
|
|
customForm.cancel.unbind('click');
|
|
|
|
customForm.cancel.bind('click', function() {
|
|
|
|
customForm.resetAddFormToStep1();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2010-04-04 19:37:20 +00:00
|
|
|
doAddNewLinkForCombinedView: function() {
|
2010-04-02 23:21:42 +00:00
|
|
|
|
|
|
|
customForm.addNewLink.unbind('click');
|
|
|
|
customForm.addNewLink.bind('click', function() {
|
|
|
|
$(this).hide();
|
2010-04-04 04:48:41 +00:00
|
|
|
|
2010-04-02 23:21:42 +00:00
|
|
|
// Make sure to clear out what's in the existing select element,
|
|
|
|
// else it could be submitted even when hidden.
|
2010-04-04 04:48:41 +00:00
|
|
|
// RY When we have multiple existing and addNew divs, we won't
|
|
|
|
// show/hide them all, only the siblings of the addNewLink.
|
2010-04-04 18:11:45 +00:00
|
|
|
// And we'll need to figure out the button text based on which
|
|
|
|
// div we're opening.
|
2010-04-02 23:21:42 +00:00
|
|
|
customForm.hideFields(customForm.existing);
|
2010-04-13 14:44:31 +00:00
|
|
|
customForm.addNew.show();
|
2010-04-04 18:11:45 +00:00
|
|
|
customForm.button.val(customForm.addNewButtonText);
|
2010-04-04 19:37:20 +00:00
|
|
|
customForm.doClose();
|
2010-04-14 20:33:42 +00:00
|
|
|
customForm.setReturnView(customForm.views.ADD_NEW);
|
2010-04-04 04:48:41 +00:00
|
|
|
return false;
|
2010-04-02 23:21:42 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2010-04-04 04:48:41 +00:00
|
|
|
doClose: function() {
|
2010-04-04 19:37:20 +00:00
|
|
|
|
|
|
|
customForm.close.unbind('click');
|
|
|
|
customForm.close.bind('click', function() {
|
2010-04-04 04:48:41 +00:00
|
|
|
// RY When we have multiple existing and addNew divs, we won't
|
|
|
|
// show/hide them all, only the siblings of the addNewLink.
|
2010-04-13 14:44:31 +00:00
|
|
|
customForm.existing.show();
|
2010-04-04 04:48:41 +00:00
|
|
|
customForm.hideFields(customForm.addNew);
|
|
|
|
customForm.addNewLink.show();
|
2010-04-04 18:11:45 +00:00
|
|
|
customForm.button.val(customForm.defaultButtonText);
|
2010-04-04 19:37:20 +00:00
|
|
|
customForm.doAddNewLinkForCombinedView();
|
2010-04-15 19:34:26 +00:00
|
|
|
customForm.setReturnView(customForm.views.COMBINED);
|
2010-04-15 19:53:18 +00:00
|
|
|
|
|
|
|
if (customForm.originalOrg) {
|
|
|
|
customForm.existingSelect.val(customForm.originalOrg);
|
|
|
|
}
|
|
|
|
|
2010-04-04 04:48:41 +00:00
|
|
|
return false;
|
2010-04-15 19:34:26 +00:00
|
|
|
});
|
2010-04-04 04:48:41 +00:00
|
|
|
},
|
|
|
|
|
2010-04-02 23:21:42 +00:00
|
|
|
// Return true iff there are validation errors on the form
|
|
|
|
findValidationErrors: function() {
|
|
|
|
|
|
|
|
return customForm.form.find('.validationError').length > 0;
|
|
|
|
|
|
|
|
// RY For now, we just need to look for the presence of the error elements.
|
|
|
|
// Later, however, we may generate empty error messages in the markup, for
|
|
|
|
// customized positioning, in which case we need to look for whether they have
|
|
|
|
// content. See clearFormData().
|
|
|
|
// var foundErrors = false,
|
|
|
|
// errors = this.form.find('.validationError'),
|
|
|
|
// numErrors = errors.length,
|
|
|
|
// i,
|
|
|
|
// error;
|
|
|
|
//
|
|
|
|
// for (i = 0; foundErrors == false && i < numErrors; i++) {
|
|
|
|
// error = errors[i];
|
|
|
|
// if (error.html() != '') {
|
|
|
|
// foundErrors = true;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return foundErrors;
|
|
|
|
},
|
|
|
|
|
|
|
|
resetForm: function() {
|
|
|
|
|
|
|
|
// Clear all form data and error messages
|
|
|
|
customForm.clearFormData();
|
|
|
|
|
|
|
|
// Remove previously bound event handlers
|
2010-04-13 14:44:31 +00:00
|
|
|
customForm.unbindEventListeners();
|
2010-04-02 23:21:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
showSelectExistingFields: function() {
|
|
|
|
|
2010-04-13 18:50:38 +00:00
|
|
|
customForm.existing.show();
|
2010-04-02 23:21:42 +00:00
|
|
|
customForm.addNewLink.hide();
|
2010-04-14 20:33:42 +00:00
|
|
|
customForm.hideFields(customForm.addNew);
|
2010-04-02 23:21:42 +00:00
|
|
|
customForm.showFieldsForAllViews();
|
2010-04-14 21:28:11 +00:00
|
|
|
|
|
|
|
// Adjust the validation error that has been inserted by the server, which
|
|
|
|
// is phrased appropriately for the non-Javascript version of the form.
|
|
|
|
$('#organizationUri_validationError').html('Must select an organization.');
|
2010-04-02 23:21:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
showAddNewFields: function() {
|
|
|
|
|
2010-04-14 20:33:42 +00:00
|
|
|
customForm.hideFields(customForm.existing);
|
2010-04-02 23:21:42 +00:00
|
|
|
customForm.addNewLink.hide();
|
2010-04-13 14:44:31 +00:00
|
|
|
customForm.addNew.show();
|
2010-04-14 21:28:11 +00:00
|
|
|
customForm.showFieldsForAllViews();
|
|
|
|
|
|
|
|
// Adjust the validation error that has been inserted by the server, which
|
|
|
|
// is phrased appropriately for the non-Javascript version of the form.
|
|
|
|
$('#newOrgName_validationError').html('Must specify an organization.');
|
2010-04-02 23:21:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// This version of the form shows both the existing select and add new link.
|
|
|
|
// Used when loading edit form, and when returning from failed submission
|
|
|
|
// of add form when we can't determine which view was being used to make
|
|
|
|
// the submission.
|
|
|
|
showCombinedFields: function() {
|
|
|
|
|
2010-04-13 14:44:31 +00:00
|
|
|
customForm.existing.show();
|
2010-04-02 23:21:42 +00:00
|
|
|
customForm.addNewLink.show();
|
2010-04-04 22:21:39 +00:00
|
|
|
customForm.addNewLink.css('margin-bottom', '1em');
|
2010-04-14 20:33:42 +00:00
|
|
|
customForm.hideFields(customForm.addNew);
|
2010-04-02 23:21:42 +00:00
|
|
|
customForm.showFieldsForAllViews();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Show fields that appear in all views for add form step 2 and edit form
|
|
|
|
showFieldsForAllViews: function() {
|
|
|
|
customForm.entry.show();
|
|
|
|
customForm.requiredLegend.show();
|
|
|
|
},
|
|
|
|
|
2010-04-13 18:50:38 +00:00
|
|
|
toggleRequiredHints: function(action /* elements */) {
|
|
|
|
|
|
|
|
var hints,
|
|
|
|
selector = 'span.requiredHint',
|
|
|
|
numArgs = arguments.length;
|
|
|
|
|
|
|
|
if (numArgs < 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
hints = arguments[1].find(selector);
|
|
|
|
for (var i = 2; i < numArgs; i++) {
|
|
|
|
hints.add(arguments[i].find(selector));
|
|
|
|
}
|
|
|
|
|
|
|
|
action == 'show' ? hints.show() : hints.hide();
|
2010-04-13 23:05:28 +00:00
|
|
|
},
|
|
|
|
|
2010-04-14 21:28:11 +00:00
|
|
|
// Set the hidden input field indicating the view to return to if
|
|
|
|
// the submission fails due to validation errors.
|
2010-04-14 20:33:42 +00:00
|
|
|
setReturnView: function(value) {
|
|
|
|
customForm.returnViewField.val(value);
|
2010-04-13 18:50:38 +00:00
|
|
|
}
|
|
|
|
|
2010-04-02 23:21:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$(document).ready(function(){
|
|
|
|
customForm.onLoad();
|
|
|
|
});
|