NIHVIVO-193 Additions to support non-Javascript version of position history form.

This commit is contained in:
rjy7 2010-03-31 14:39:12 +00:00
parent 0c273a67a2
commit 490d9db068
3 changed files with 54 additions and 28 deletions

View file

@ -32,12 +32,18 @@
display: inline-block;
}
#existingOrNew {
font-style:italic;
margin-left: 1em;
}
#new {
padding: .6em 0 .6em 1.5em;
border: 1px solid #9c9c9c;
width: 70%;
}
/* #content form p.inline span,*/
#content form p.inline input {
float: right;

View file

@ -5,16 +5,21 @@ var customForm = {
onLoad: function() {
// Create references to form elements.
// NB must be done after document has loaded, else the elements aren't present
// in the DOM yet.
// NB must be done after the elements have been loaded.
this.form = $('#content form'),
this.button = $('#submit'),
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'),
this.addNew = $('#new'),
this.entry = $('#entry'),
this.existingOrNew = $('#existingOrNew'),
this.cancel = this.form.find('.cancel'),
this.requiredLegend = $('#requiredLegend'),
this.requiredHints = this.form.find('.requiredHint'),
// Read values used to control display
@ -22,6 +27,8 @@ var customForm = {
this.entryType = $("input[name='entryType']").val().capitalize(),
this.newType = $("input[name='newType']").val().capitalize();
this.adjustForJs();
if (this.editType == 'add') { //adding a new entry
this.initAddForm();
@ -30,10 +37,21 @@ var customForm = {
}
},
// On page load, make changes to the non-Javascript version for the Javascript version.
// These are features that will not change in the Javascript version.
adjustForJs: function() {
this.existingOrNew.hide();
var selectExistingLabel = $('#existing label');
selectExistingLabel.html(selectExistingLabel.html().replace('Select Existing ', ''));
},
// Reset add form to initial state (step 1)
// Should only be needed after returning to step 1 from step 2,
// but sometimes seems to be needed on page load as well, so call it from initAddForm()
resetAddForm: function() {
// Clear all form data and error messages
$('input:text').val('');
$('.error').text('');
@ -47,9 +65,6 @@ var customForm = {
},
// Set up add form on page load, or when returning to initial state
// (The latter is not yet implemented, but we are preparing for it. Note
// that initializations to occur ONLY on page load are done in the onLoad() method.)
// RY *** SOME of this will be shared with the edit form - figure out which
initAddForm: function() {
this.resetAddForm();
@ -63,19 +78,6 @@ var customForm = {
this.button.val('Continue');
// Assign event listeners
// add new link => step 2b
this.addNewLink.bind('click', function() {
$(this).hide();
customForm.existing.hide();
customForm.showFields(customForm.addNew);
customForm.entry.show();
customForm.requiredLegend.show();
customForm.button.val('Create ' + customForm.entryType + ' & ' + customForm.newType);
customForm.button.unbind('click');
customForm.doCancel();
});
// button => step 2a
this.button.bind('click', function() {
@ -91,6 +93,20 @@ var customForm = {
return false;
});
// add new link => step 2b
this.addNewLink.bind('click', function() {
$(this).hide();
customForm.existing.hide();
customForm.showFields(customForm.addNew);
customForm.entry.show();
customForm.requiredLegend.show();
customForm.button.val('Create ' + customForm.entryType + ' & ' + customForm.newType);
customForm.button.unbind('click');
customForm.doCancel();
});
},
initEditForm: function() {
@ -112,12 +128,14 @@ var customForm = {
},
// Add required hints to required fields in element array elArray.
// Add required hints to required fields in a list of elements.
// Use when the non-Javascript version should not show the required hint,
// because the field is not required in that version.
// because the field is not required in that version (e.g., it's one of two
// fields, where one of the two must be filled in but neither one is required).
// Arguments: action = 'add' or 'remove'
// Varargs: element(s)
toggleRequiredHints: function(action /* elements */) {
var labelText,
newLabelText,
requiredHintText = '<span class="requiredHint"> *</span>';

View file

@ -314,9 +314,11 @@
</div>
<div id="existing">
<v:input type="select" label="Organization" labelClass="required" id="organizationUri" />
<v:input type="select" label="Select Existing Organization" labelClass="required" id="organizationUri" /><span id="existingOrNew">or</span>
</div>
<div id="new">
<h6>Add a New Organization</h6>
<v:input type="text" label="Organization Name" labelClass="required" id="newOrgName" />