NIHVIVO-646 JS changes

This commit is contained in:
rjy7 2010-06-29 22:08:28 +00:00
parent 37a85a5e97
commit 5ae7580002
3 changed files with 67 additions and 14 deletions

View file

@ -280,8 +280,22 @@ SPARQL queries for existing values. --%>
<h2>${title}</h2> <h2>${title}</h2>
<%
// Try this in order to get the new author hightlighted after page reload.
// If we do an ajax submit, we won't need it.
//String processedForm = (String) vreq.getAttribute("processedForm");
//String ulClass = "";
//if (processedForm != null && processedForm.equals("true")) {
// ulClass = "class='processedSubmission'";
//}
//System.out.println(vreq.getAttribute("entToReturnTo"));
%>
<ul id="authors"> <ul id="authors">
<% <%
int rank = 0; int rank = 0;
for ( Individual authorship : authorships ) { for ( Individual authorship : authorships ) {
rank = Integer.valueOf(authorship.getDataValue(rankUri)); rank = Integer.valueOf(authorship.getDataValue(rankUri));
@ -292,6 +306,8 @@ SPARQL queries for existing values. --%>
//request.setAttribute("authorUri", URLEncoder.encode(author.getURI(), "UTF-8")); //request.setAttribute("authorUri", URLEncoder.encode(author.getURI(), "UTF-8"));
request.setAttribute("authorUri", author.getURI()); request.setAttribute("authorUri", author.getURI());
request.setAttribute("authorshipUri", authorship.getURI()); request.setAttribute("authorshipUri", authorship.getURI());
%> %>
<c:url var="authorHref" value="/individual"> <c:url var="authorHref" value="/individual">
<c:param name="uri" value="${authorUri}"/> <c:param name="uri" value="${authorUri}"/>
@ -329,7 +345,7 @@ SPARQL queries for existing values. --%>
<h3>Add an Author</h3> <h3>Add an Author</h3>
<p class="inline"><v:input type="text" id="lastName" label="Last name ${requiredHint}" size="30" /></p> <p class="inline"><v:input type="text" id="lastName" label="Name ${requiredHint}" size="30" /></p>
<p class="inline"><v:input type="text" id="firstName" label="First name ${requiredHint} ${initialHint}" size="20" /></p> <p class="inline"><v:input type="text" id="firstName" label="First name ${requiredHint} ${initialHint}" size="20" /></p>
<p class="inline"><v:input type="text" id="middleName" label="Middle name ${initialHint}" size="20" /></p> <p class="inline"><v:input type="text" id="middleName" label="Middle name ${initialHint}" size="20" /></p>
<input type="hidden" id="label" name="label" value="" /> <!-- Field value populated by JavaScript --> <input type="hidden" id="label" name="label" value="" /> <!-- Field value populated by JavaScript -->

View file

@ -9,7 +9,6 @@
margin-bottom: .75em; margin-bottom: .75em;
} }
#authors a.existingAuthor { #authors a.existingAuthor {
display: inline-block; display: inline-block;
width: 15em; width: 15em;
@ -20,14 +19,6 @@
display: none; display: none;
} }
/* Hide elements not used in non-JS version of form */
#showAddForm,
a.remove,
a.undo,
#selectedAuthor {
display: none;
}
#showAddForm span.or { #showAddForm span.or {
display: none; display: none;
} }
@ -93,3 +84,24 @@ form a:hover.cancel,
#content form p.submit { #content form p.submit {
margin-top: 3em; margin-top: 3em;
} }
a.undo,
#selectedAuthor {
display: none;
}
/* Hide elements not used in non-JS version of form */
/* rjy7 Currently not supporting non-JS version of this form. */
/*
#showAddForm,
a.remove,
a.undo,
#selectedAuthor {
display: none;
}
*/
/* These styles will need to be redone or removed to support a non-JS version of the form. */
form#addAuthorForm {
display: none;
}

View file

@ -29,6 +29,7 @@ var addAuthorForm = {
this.firstNameField = $('#firstName'); this.firstNameField = $('#firstName');
this.middleNameField = $('#middleName'); this.middleNameField = $('#middleName');
this.lastNameField = $('#lastName'); this.lastNameField = $('#lastName');
this.lastNameLabel = $('label[for=lastName]');
this.personUriField = $('#personUri'); this.personUriField = $('#personUri');
this.firstNameWrapper = this.firstNameField.parent(); this.firstNameWrapper = this.firstNameField.parent();
this.middleNameWrapper = this.middleNameField.parent(); this.middleNameWrapper = this.middleNameField.parent();
@ -134,18 +135,42 @@ var addAuthorForm = {
onLastNameChange: function() { onLastNameChange: function() {
this.showFieldsForNewPerson(); this.showFieldsForNewPerson();
this.firstNameField.focus(); this.firstNameField.focus();
this.fixNames();
}, },
showFieldsForNewPerson: function() { showFieldsForNewPerson: function() {
this.firstNameWrapper.show(); this.firstNameWrapper.show();
this.middleNameWrapper.show(); this.middleNameWrapper.show();
this.toggleLastNameLabel('Name', 'Last name');
},
// User may have typed first name as well as last name into last name field.
// If so, when showing first and middle name fields, move anything after a comma
// into the first name field.
fixNames: function() {
var lastNameInput = this.lastNameField.val(),
names = lastNameInput.split(','),
lastName = names[0].replace(/[, ]+$/, ''),
firstName;
this.lastNameField.val(lastName);
if (names.length > 1) {
firstName = names[1].replace(/^[, ]+/, '');
this.firstNameField.val(firstName);
}
}, },
hideFieldsForNewPerson: function() { hideFieldsForNewPerson: function() {
// Hide form fields that shouldn't display on first view.
// Includes clearing their contents.
this.hideFields(this.firstNameWrapper); this.hideFields(this.firstNameWrapper);
this.hideFields(this.middleNameWrapper); this.hideFields(this.middleNameWrapper);
this.toggleLastNameLabel('Last name', 'Name');
},
toggleLastNameLabel: function(currentText, newText) {
var lastNameLabelText = this.lastNameLabel.html(),
newLastNameLabelText = lastNameLabelText.replace(currentText, newText);
this.lastNameLabel.html(newLastNameLabelText);
}, },
// This view shows the list of existing authors and hides the form. // This view shows the list of existing authors and hides the form.