From c885ae010f20b9852afabf44b3173c4bcdb444c7 Mon Sep 17 00:00:00 2001 From: rjy7 Date: Tue, 22 Jun 2010 22:12:33 +0000 Subject: [PATCH] NIHVIVO-646 more work on javascript for add authors to publication form --- .../forms/addAuthorsToInformationResource.jsp | 6 +-- .../css/addAuthorsToInformationResource.css | 6 ++- .../js/addAuthorsToInformationResource.js | 41 ++++++++++++++++--- productMods/edit/forms/js/customForm.js | 25 ----------- 4 files changed, 43 insertions(+), 35 deletions(-) diff --git a/productMods/edit/forms/addAuthorsToInformationResource.jsp b/productMods/edit/forms/addAuthorsToInformationResource.jsp index b633a7b4..149269f2 100644 --- a/productMods/edit/forms/addAuthorsToInformationResource.jsp +++ b/productMods/edit/forms/addAuthorsToInformationResource.jsp @@ -273,7 +273,7 @@ SPARQL queries for existing values. --%> - + @@ -323,8 +323,8 @@ SPARQL queries for existing values. --%>

Add an Author

-

${initialHint}

-

${initialHint}

+

+

diff --git a/productMods/edit/forms/css/addAuthorsToInformationResource.css b/productMods/edit/forms/css/addAuthorsToInformationResource.css index 1c5d20ac..5adcb2b5 100644 --- a/productMods/edit/forms/css/addAuthorsToInformationResource.css +++ b/productMods/edit/forms/css/addAuthorsToInformationResource.css @@ -65,7 +65,7 @@ form a:hover.cancel, } #content form p.inline label { - width: 10em; + width: 13em; margin-top: 0; } @@ -81,3 +81,7 @@ form a:hover.cancel, #selectedAuthor { clear: left; } + +#content form p.submit { + margin-top: 3em; +} diff --git a/productMods/edit/forms/js/addAuthorsToInformationResource.js b/productMods/edit/forms/js/addAuthorsToInformationResource.js index 521aa201..4c0795fa 100644 --- a/productMods/edit/forms/js/addAuthorsToInformationResource.js +++ b/productMods/edit/forms/js/addAuthorsToInformationResource.js @@ -48,7 +48,13 @@ var addAuthorForm = { this.setUpAutocomplete(); - this.initAuthorListOnlyView(); + // On this form, validation errors entail that a new person was being entered. + if (this.findValidationErrors()) { + this.initFormView(); + this.showFieldsForNewPerson(); + } else { + this.initAuthorListOnlyView(); + } }, bindEventListeners: function() { @@ -59,13 +65,35 @@ var addAuthorForm = { }); this.submit.click(function() { + // NB Important JavaScript scope issue: if we call it this way, this = addAuthorForm + // in prepareFieldValuesForSubmit. If we do + // this.submit.click(this.prepareFieldValuesForSubmit); then + // this != addAuthorForm in prepareFieldValuesForSubmit. addAuthorForm.prepareFieldValuesForSubmit(); }); - + this.lastNameField.blur(function() { - addAuthorForm.firstNameWrapper.show(); - addAuthorForm.middleNameWrapper.show(); + console.log("in blur") + addAuthorForm.onLastNameChange(); }); + // Prevent form submission when hitting enter in last name field + this.lastNameField.keydown(function(event) { + if (event.keyCode === 13) { + console.log('in keydown') + addAuthorForm.onLastNameChange(); + return false; + } + }); + }, + + onLastNameChange: function() { + this.showFieldsForNewPerson(); + this.firstNameField.focus(); + }, + + showFieldsForNewPerson: function() { + this.firstNameWrapper.show(); + this.middleNameWrapper.show(); }, // This view shows the list of existing authors and hides the form. @@ -139,11 +167,12 @@ var addAuthorForm = { var cache = {}; var url = $('#acUrl').val(); - var existingAuthorUris = addAuthorForm.getExistingAuthorUris(); - console.log(existingAuthorUris); + var existingAuthorUris = addAuthorForm.getExistingAuthorUris(); + jQuery.each(existingAuthorUris, function(index, element) { url += '&filter=' + element; }); + $('#lastName').autocomplete({ minLength: 2, source: url, diff --git a/productMods/edit/forms/js/customForm.js b/productMods/edit/forms/js/customForm.js index da833d67..ff910f5c 100644 --- a/productMods/edit/forms/js/customForm.js +++ b/productMods/edit/forms/js/customForm.js @@ -359,31 +359,6 @@ var customForm = { }); }, - // 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