From 3d20ffa3129ba921fd30126cee6bf887b96f8e39 Mon Sep 17 00:00:00 2001 From: manolobevia Date: Fri, 13 Jan 2012 21:03:04 +0000 Subject: [PATCH] NIHVIVO-3530: I forgot to delete the css files from VIVO/productMods/forms. Also, fixed problem with adding authors to information resource. --- .../css/addAuthorsToInformationResource.css | 102 --- productMods/edit/forms/css/addConcept.css | 33 - productMods/edit/forms/css/autocomplete.css | 24 - productMods/edit/forms/css/customForm.css | 124 --- .../forms/css/customFormWithAutocomplete.css | 33 - .../forms/css/institutionalInternalClass.css | 20 - .../forms/css/manageWebpagesForIndividual.css | 49 -- .../css/addAuthorsToInformationResource.css | 755 +++--------------- .../js/addAuthorsToInformationResource.js | 661 +++++++++++++++ 9 files changed, 759 insertions(+), 1042 deletions(-) delete mode 100644 productMods/edit/forms/css/addAuthorsToInformationResource.css delete mode 100644 productMods/edit/forms/css/addConcept.css delete mode 100644 productMods/edit/forms/css/autocomplete.css delete mode 100644 productMods/edit/forms/css/customForm.css delete mode 100644 productMods/edit/forms/css/customFormWithAutocomplete.css delete mode 100644 productMods/edit/forms/css/institutionalInternalClass.css delete mode 100644 productMods/edit/forms/css/manageWebpagesForIndividual.css diff --git a/productMods/edit/forms/css/addAuthorsToInformationResource.css b/productMods/edit/forms/css/addAuthorsToInformationResource.css deleted file mode 100644 index a8106be2..00000000 --- a/productMods/edit/forms/css/addAuthorsToInformationResource.css +++ /dev/null @@ -1,102 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -#authorships { - margin-left: 0; -} -#authorships li { - list-style: none; - margin-bottom: .75em; -} -/* Use class dd rather than jQuery UI's class ui-sortable, so that we can remove -the class if there's fewer than one author. We don't want to remove the ui-sortable -class, in case we want to re-enable DD without a page reload. */ -#authorships.dd li { - padding-left: 1em; - background: url("../images/sortable_icon.png") no-repeat left center; - cursor: move; -} -#authorships .authorNameWrapper { - display: inline-block; - width: 15em; -} -#showAddForm span.or { - display: none; -} -#showAddForm a.cancel { - margin-left: 2em; -} -form h3 { - margin-bottom: 0; - padding-bottom: 0; -} -form a:link.cancel, -form a:visited.cancel, -#authorships a:link.remove, -#authorships a:visited.remove, -#authorships a:link.undo, -#authorships a:visited.undo, -#showAddForm a:link.cancel, -#showAddForm a:visited.cancel { - color: #f70; - border-color: #f70; -} -form a:hover.cancel, -#authorships a:hover.remove, -#authorships a:hover.undo, -#showAddForm a:hover.cancel { - color: #fff; - background: #f70; -} -#authorships a.undo { - margin-left: 1em; -} -#content form p.inline { - clear: left; - margin-bottom: 0; - padding-top: 1em; -} -#content form p.inline input, -#content form p.inline label { - float: left; - clear: none; -} -#content form p.inline label { - width: 13em; - margin-top: 0; -} -#content form p.inline input { - margin-bottom: 0; -} -#content form p.inline span.hint { - margin-left: .5em; -} -#selectedAuthor { - clear: left; -} -#content form #selectedAuthor p.inline label { - width: 10em; -} -#content form p.submit { - margin-top: 3em; -} -/* Disabling undo links for the present. Add back later. */ -/* -a.undo { - 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 { - display: none; -} -*/ - -/* These styles will need to be redone or removed to support a non-JS version of the form. */ -form#addAuthorForm { - display: none; -} \ No newline at end of file diff --git a/productMods/edit/forms/css/addConcept.css b/productMods/edit/forms/css/addConcept.css deleted file mode 100644 index 9dce6df8..00000000 --- a/productMods/edit/forms/css/addConcept.css +++ /dev/null @@ -1,33 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -.concepts .column { - float:left; - padding-right:3px; - -} - -.concepts .row { - clear:both; - float:left; - border-bottom: 1px solid #5F6464; -} - -.conceptLabel { - width:220px; -} - -.conceptType { - width: 40px; -} -.conceptDefinition{ - width:400px; -} - -form#addConceptForm { - display:none; -} - -form#addConceptForm span#createOwnOne{ - float:left; - margin-top:24px -} \ No newline at end of file diff --git a/productMods/edit/forms/css/autocomplete.css b/productMods/edit/forms/css/autocomplete.css deleted file mode 100644 index d87f9aa3..00000000 --- a/productMods/edit/forms/css/autocomplete.css +++ /dev/null @@ -1,24 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -/* Styles for autocomplete and autocomplete selections using jQuery UI. This is separated out so that forms -that don't load customFormWithAutocomplete.css still have access to these styles. */ - -.acSelection { - display: none; - margin-top: 2em; -} -.acSelectionInfo { - background-color: #d9d9d9; - padding: .2em .35em; -} -ul.ui-autocomplete { - font-size: .95em; -} -li.ui-menu-item a.ui-corner-all { - text-align: left; - padding-left: .25em; -} -.acSelectorWithHelpText{ - font-style: italic; - color: #555; -} \ No newline at end of file diff --git a/productMods/edit/forms/css/customForm.css b/productMods/edit/forms/css/customForm.css deleted file mode 100644 index 19a63659..00000000 --- a/productMods/edit/forms/css/customForm.css +++ /dev/null @@ -1,124 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -form.customForm div { - clear: left; -} -form.customForm h6 { - font-size: 110%; -} -form.customForm div.addNewLink { - float: left; - clear: none; - margin-left: 5em; - margin-top: .9em; - width: 200px; - padding: .8em; - border: 1px solid #9c9c9c; - display: none; /* Hide if Javascript disabled. Javascript will show. */ -} -form.customForm .existing span.requiredHint, -form.customForm .new span.requiredHint { - display: none; /* Hide if Javascript disabled. Javascript will show. */ -} -form.customForm .existing { - float: left; - clear: none; -} -.existingOrNew { - font-style: italic; - margin-left: 1em; -} -.new { - padding: .6em 0 .6em 1.5em; - border: 1px solid #9c9c9c; - width: 300px; -} -form.customForm p.inline input, -form.customForm p.inline label { - float: left; - clear: left; -} -form.customForm p.inline.year input { - margin-top: -1.75em; -} -input, -select, -form.customForm p { - margin-top: 0; - padding-top: 0; - margin-bottom: 0; - padding-bottom: 0; -} -option { - padding: 0 2px; -} -form.customForm .hint { - color: #9c9c9c; - font-weight: normal; -} -form.customForm .requiredHint { - color: #c00; - font-weight: normal; - font-size: small; -} -form.customForm #requiredLegend { - font-style: italic; - margin-top: .5em; -} -form.customForm p.validationError { - clear: both; - margin-bottom: 1.8em; - margin-top: 0; - padding-top: 0; - padding-left: .4em; - font-size: .8em; -} -form.customForm a.close { - float: right; - margin-right: 1em; - font-size: 90%; -} -form.customForm a.close:link, -form.customForm a.close:visited { - border-color: #ff7700; - color: #ff7700; -} -form.customForm textarea { - width: 30%; -} -div.acSelection { - margin-bottom: 15px; -} -#ie67DisableWrapper { - display: none; -} -form.customForm input.concept-search { - float: right; - margin-right: 1em; - margin-bottom: 1em; - background-color: #317e95; -} -form.customForm h4.services { - margin-bottom: -5px; - margin-top: -12px; -} -form.customForm p.inline-search { - float: left; - clear: left; -} -form.customForm p.inline-search #searchTerm{ - margin-top: 6px; -} -/* <------ DATE TIME*/ -form.customForm label.dateTime { - display: inline; -} -form.customForm fieldset { - display: inline; -} -fieldset.dateTime label { - display: inline; -} -fieldset.dateTime select { - margin-top: 0; -} \ No newline at end of file diff --git a/productMods/edit/forms/css/customFormWithAutocomplete.css b/productMods/edit/forms/css/customFormWithAutocomplete.css deleted file mode 100644 index 7c66f21b..00000000 --- a/productMods/edit/forms/css/customFormWithAutocomplete.css +++ /dev/null @@ -1,33 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -@import url("autocomplete.css"); - -/* Although Javascript hides these on page load, hide here as well to avoid the flash on page load. - This needs to be removed to support a non-JS version of the form. */ -.fullViewOnly, -#submit, -.or, -#requiredLegend { - display: none; -} -form.customForm p.inline label { - display: inline; - clear: none; - float: none; - margin-right: 1em; -} -.verifyMatch { - margin-left: .5em; -} -form.customForm h4 { - margin-top: 1em; - margin-bottom: .75em; -} -.acSelector[disabled="disabled"]{ - border-width: 0; - background: none; - color: #000; -} -.disabledSubmit { - cursor: default ! important; -} diff --git a/productMods/edit/forms/css/institutionalInternalClass.css b/productMods/edit/forms/css/institutionalInternalClass.css deleted file mode 100644 index 8b68760d..00000000 --- a/productMods/edit/forms/css/institutionalInternalClass.css +++ /dev/null @@ -1,20 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -#localClassName { - margin-bottom: 0; -} -#createNewLocalClass p.note { - margin-top: 3px; - margin-bottom: 15px; -} -#noLocalOntologyExists { - padding: 1em; - background: #f4f4f4; - display: inline-block; -} -#noLocalOntologyExists blockquote { - margin: .4em 0 .4em 1em; - padding: .5em; - background: #ffc; - display: inline-block; -} \ No newline at end of file diff --git a/productMods/edit/forms/css/manageWebpagesForIndividual.css b/productMods/edit/forms/css/manageWebpagesForIndividual.css deleted file mode 100644 index 1975a818..00000000 --- a/productMods/edit/forms/css/manageWebpagesForIndividual.css +++ /dev/null @@ -1,49 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -#webpageList { - margin-left: 0; -} - -#webpageList li { - list-style: none; - margin-bottom: .75em; -} - -/* Use class dd rather than jQuery UI's class ui-sortable, so that we can remove -the class if there's fewer than one author. We don't want to remove the ui-sortable -class, in case we want to re-enable DD without a page reload. */ -#webpageList.dd li { - padding-left: 1em; - background: url("../images/sortable_icon.png") no-repeat left center; - cursor: move; -} - -#webpageList .webpageName { - display: inline-block; - width: 15em; -} - -#addAndCancelLinks { - margin-top: 1.5em; -} - -#returnToIndividual { - margin-left: 2em; -} - -#showAddForm a:hover.cancel { - color: #fff; - background: #f70; -} - -#showAddForm a:hover.cancel { - color: #fff; - background: #f70; -} - -#webpageList a:link.remove, -#webpageList a:visited.remove, -#webpageList a:hover.remove { - color: #f70; - background: #fff; -} diff --git a/productMods/templates/freemarker/edit/forms/css/addAuthorsToInformationResource.css b/productMods/templates/freemarker/edit/forms/css/addAuthorsToInformationResource.css index 07137ebb..a8106be2 100644 --- a/productMods/templates/freemarker/edit/forms/css/addAuthorsToInformationResource.css +++ b/productMods/templates/freemarker/edit/forms/css/addAuthorsToInformationResource.css @@ -1,661 +1,102 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -var addAuthorForm = { +#authorships { + margin-left: 0; +} +#authorships li { + list-style: none; + margin-bottom: .75em; +} +/* Use class dd rather than jQuery UI's class ui-sortable, so that we can remove +the class if there's fewer than one author. We don't want to remove the ui-sortable +class, in case we want to re-enable DD without a page reload. */ +#authorships.dd li { + padding-left: 1em; + background: url("../images/sortable_icon.png") no-repeat left center; + cursor: move; +} +#authorships .authorNameWrapper { + display: inline-block; + width: 15em; +} +#showAddForm span.or { + display: none; +} +#showAddForm a.cancel { + margin-left: 2em; +} +form h3 { + margin-bottom: 0; + padding-bottom: 0; +} +form a:link.cancel, +form a:visited.cancel, +#authorships a:link.remove, +#authorships a:visited.remove, +#authorships a:link.undo, +#authorships a:visited.undo, +#showAddForm a:link.cancel, +#showAddForm a:visited.cancel { + color: #f70; + border-color: #f70; +} +form a:hover.cancel, +#authorships a:hover.remove, +#authorships a:hover.undo, +#showAddForm a:hover.cancel { + color: #fff; + background: #f70; +} +#authorships a.undo { + margin-left: 1em; +} +#content form p.inline { + clear: left; + margin-bottom: 0; + padding-top: 1em; +} +#content form p.inline input, +#content form p.inline label { + float: left; + clear: none; +} +#content form p.inline label { + width: 13em; + margin-top: 0; +} +#content form p.inline input { + margin-bottom: 0; +} +#content form p.inline span.hint { + margin-left: .5em; +} +#selectedAuthor { + clear: left; +} +#content form #selectedAuthor p.inline label { + width: 10em; +} +#content form p.submit { + margin-top: 3em; +} +/* Disabling undo links for the present. Add back later. */ +/* +a.undo { + display: none; +} +*/ - /* *** Initial page setup *** */ - - onLoad: function() { - - if (this.disableFormInUnsupportedBrowsers()) { - return; - } - this.mixIn(); - this.initObjects(); - this.initPage(); - }, +/* 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 { + display: none; +} +*/ - disableFormInUnsupportedBrowsers: function() { - var disableWrapper = $('#ie67DisableWrapper'); - - // Check for unsupported browsers only if the element exists on the page - if (disableWrapper.length) { - if (vitro.browserUtils.isIELessThan8()) { - disableWrapper.show(); - $('.noIE67').hide(); - return true; - } - } - return false; - }, - - mixIn: function() { - // Mix in the custom form utility methods - $.extend(this, vitro.customFormUtils); - - // Get the custom form data from the page - $.extend(this, customFormData); - }, - - // On page load, create references for easy access to form elements. - // NB These must be assigned after the elements have been loaded onto the page. - initObjects: function() { - - this.form = $('#addAuthorForm'); - this.showFormButtonWrapper = $('#showAddForm'); - this.showFormButton = $('#showAddFormButton'); - this.removeAuthorshipLinks = $('a.remove'); - //this.undoLinks = $('a.undo'); - this.submit = this.form.find(':submit'); - this.cancel = this.form.find('.cancel'); - this.acSelector = this.form.find('.acSelector'); - this.labelField = $('#label'); - this.firstNameField = $('#firstName'); - this.middleNameField = $('#middleName'); - this.lastNameField = $('#lastName'); - this.lastNameLabel = $('label[for=lastName]'); - this.personUriField = $('#personUri'); - this.firstNameWrapper = this.firstNameField.parent(); - this.middleNameWrapper = this.middleNameField.parent(); - this.lastNameWrapper = this.lastNameField.parent(); - this.selectedAuthor = $('#selectedAuthor'); - this.selectedAuthorName = $('#selectedAuthorName'); - this.acHelpTextClass = 'acSelectorWithHelpText'; - this.verifyMatch = this.form.find('.verifyMatch'); - - }, - - // Initial page setup. Called only at page load. - initPage: function() { - - this.initAuthorshipData(); - - // Show elements hidden by CSS for the non-JavaScript-enabled version. - // NB The non-JavaScript version of this form is currently not functional. - this.removeAuthorshipLinks.show(); - - //this.undoLinks.hide(); - - this.bindEventListeners(); - - this.initAutocomplete(); - - this.initElementData(); - - this.initAuthorDD(); - - if (this.findValidationErrors()) { - this.initFormAfterInvalidSubmission(); - } else { - this.initAuthorListOnlyView(); - } - }, - - - /* *** Set up the various page views *** */ - - // This initialization is done only on page load, not when returning to author list only view - // after hitting 'cancel.' - initAuthorListOnlyView: function() { - - if ($('.authorship').length) { // make sure we have at least one author - // Reorder authors on page load so that previously unranked authors get a rank. Otherwise, - // when we add a new author, it will get put ahead of any previously unranked authors, instead - // of at the end of the list. (It is also helpful to normalize the data before we get started.) - this.reorderAuthors(); - } - this.showAuthorListOnlyView(); - }, - - // This view shows the list of existing authors and hides the form. - // There is a button to show the form. We do this on page load, and after - // hitting 'cancel' from full view. - showAuthorListOnlyView: function() { - this.hideForm(); - this.showFormButtonWrapper.show(); - }, - - // View of form after returning from an invalid submission. On this form, - // validation errors entail that we were entering a new person, so we show - // all the fields straightaway. - initFormAfterInvalidSubmission: function() { - this.initForm(); - this.showFieldsForNewPerson(); - }, - - // Initial view of add author form. We get here by clicking the show form button, - // or by cancelling out of an autocomplete selection. - initFormView: function() { - - this.initForm(); - - // There's a conflict bewteen the last name fields .blur event and the cancel - // button's click. So display the middle and first names along with the last name tlw72 - //this.hideFieldsForNewPerson(); - - // This shouldn't be needed, because calling this.hideFormFields(this.lastNameWrapper) - // from showSelectedAuthor should do it. However, it doesn't work from there, - // or in the cancel action, or if referring to this.lastNameField. None of those work, - // however. - $('#lastName').val(''); - // Set the initial autocomplete help text in the acSelector field. - this.addAcHelpText(); - - return false; - - }, - - // Form initialization common to both a 'clean' form view and when - // returning from an invalid submission. - initForm: function() { - - // Hide the button that shows the form - this.showFormButtonWrapper.hide(); - - this.hideSelectedAuthor(); - - this.cancel.unbind('click'); - this.cancel.bind('click', function() { - addAuthorForm.showAuthorListOnlyView(); - return false; - }); - - // Reset the last name field. It had been hidden if we selected an author from - // the autocomplete field. - this.lastNameWrapper.show(); - this.showFieldsForNewPerson(); - - // Show the form - this.form.show(); - //this.lastNameField.focus(); - }, - - hideSelectedAuthor: function() { - this.selectedAuthor.hide(); - this.selectedAuthorName.html(''); - this.personUriField.val(''); - }, - - showFieldsForNewPerson: function() { - this.firstNameWrapper.show(); - this.middleNameWrapper.show(); - }, - - hideFieldsForNewPerson: function() { - this.hideFields(this.firstNameWrapper); - this.hideFields(this.middleNameWrapper); - }, - - /* *** Ajax initializations *** */ - - /* Autocomplete */ - initAutocomplete: function() { - - // Make cache a property of this so we can access it after removing - // an author. - this.acCache = {}; - this.setAcFilter(); - - this.lastNameField.autocomplete({ - minLength: 2, - source: function(request, response) { - if (request.term in addAuthorForm.acCache) { - // console.log('found term in cache'); - response(addAuthorForm.acCache[request.term]); - return; - } - // console.log('not getting term from cache'); - - // If the url query params are too long, we could do a post - // here instead of a get. Add the exclude uris to the data - // rather than to the url. - $.ajax({ - url: addAuthorForm.acUrl, - dataType: 'json', - data: { - term: request.term - }, - complete: function(xhr, status) { - // Not sure why, but we need an explicit json parse here. jQuery - // should parse the response text and return a json object. - var results = jQuery.parseJSON(xhr.responseText), - filteredResults = addAuthorForm.filterAcResults(results); - addAuthorForm.acCache[request.term] = filteredResults; - response(filteredResults); - } - - }); - }, - // Select event not triggered in IE6/7 when selecting with enter key rather - // than mouse. Thus form is disabled in these browsers. - // jQuery UI bug: when scrolling through the ac suggestions with up/down arrow - // keys, the input element gets filled with the highlighted text, even though no - // select event has been triggered. To trigger a select, the user must hit enter - // or click on the selection with the mouse. This appears to confuse some users. - select: function(event, ui) { - addAuthorForm.showSelectedAuthor(ui); - } - }); - - }, - - initElementData: function() { - this.verifyMatch.data('baseHref', this.verifyMatch.attr('href')); - }, - - setAcFilter: function() { - this.acFilter = []; - - $('.authorship').each(function() { - var uri = $(this).data('authorUri'); - addAuthorForm.acFilter.push(uri); - }); - }, - - removeAuthorFromAcFilter: function(author) { - var index = $.inArray(author, this.acFilter); - if (index > -1) { // this should always be true - this.acFilter.splice(index, 1); - } - }, - - filterAcResults: function(results) { - var filteredResults = []; - if (!this.acFilter.length) { - return results; - } - $.each(results, function() { - if ($.inArray(this.uri, addAuthorForm.acFilter) == -1) { - // console.log("adding " + this.label + " to filtered results"); - filteredResults.push(this); - } - else { - // console.log("filtering out " + this.label); - } - }); - return filteredResults; - }, - - // After removing an authorship, selectively clear matching autocomplete - // cache entries, else the associated author will not be included in - // subsequent autocomplete suggestions. - clearAcCacheEntries: function(name) { - name = name.toLowerCase(); - $.each(this.acCache, function(key, value) { - if (name.indexOf(key) == 0) { - delete addAuthorForm.acCache[key]; - } - }); - }, - - // Action taken after selecting an author from the autocomplete list - showSelectedAuthor: function(ui) { - - this.personUriField.val(ui.item.uri); - this.selectedAuthor.show(); - - // Transfer the name from the autocomplete to the selected author - // name display, and hide the last name field. - this.selectedAuthorName.html(ui.item.label); - // NB For some reason this doesn't delete the value from the last name - // field when the form is redisplayed. Thus it's done explicitly in initFormView. - this.hideFields(this.lastNameWrapper); - // These get displayed if the selection was made through an enter keystroke, - // since the keydown event on the last name field is also triggered (and - // executes first). So re-hide them here. - this.hideFieldsForNewPerson(); - this.verifyMatch.attr('href', this.verifyMatch.data('baseHref') + ui.item.uri); - - // Cancel restores initial form view - this.cancel.unbind('click'); - this.cancel.bind('click', function() { - addAuthorForm.initFormView(); - return false; - }); - }, - - /* Drag-and-drop */ - initAuthorDD: function() { - - var authorshipList = $('#authorships'), - authorships = authorshipList.children('li'); - - if (authorships.length < 2) { - return; - } - - $('.authorNameWrapper').each(function() { - $(this).attr('title', 'Drag and drop to reorder authors'); - }); - - authorshipList.sortable({ - cursor: 'move', - update: function(event, ui) { - addAuthorForm.reorderAuthors(event, ui); - } - }); - }, - - // Reorder authors. Called on page load and after author drag-and-drop and remove. - // Event and ui parameters are defined only in the case of drag-and-drop. - reorderAuthors: function(event, ui) { - var authorships = $('li.authorship').map(function(index, el) { - return $(this).data('authorshipUri'); - }).get(); - - $.ajax({ - url: addAuthorForm.reorderUrl, - data: { - predicate: addAuthorForm.rankPredicate, - individuals: authorships - }, - traditional: true, // serialize the array of individuals for the server - dataType: 'json', - type: 'POST', - success: function(data, status, request) { - var pos; - $('.authorship').each(function(index){ - pos = index + 1; - // Set the new position for this element. The only function of this value - // is so we can reset an element to its original position in case reordering fails. - addAuthorForm.setPosition(this, pos); - }); - // Set the form rank field value. - $('#rank').val(pos + 1); - }, - error: function(request, status, error) { - // ui is undefined on page load and after an authorship removal. - if (ui) { - // Put the moved item back to its original position. - // Seems we need to do this by hand. Can't see any way to do it with jQuery UI. ?? - var pos = addAuthorForm.getPosition(ui.item), - nextpos = pos + 1, - authorships = $('#authorships'), - next = addAuthorForm.findAuthorship('position', nextpos); - - if (next.length) { - ui.item.insertBefore(next); - } - else { - ui.item.appendTo(authorships); - } - - alert('Reordering of authors failed.'); - } - } - }); - }, - - // On page load, associate data with each authorship element. Then we don't - // have to keep retrieving data from or modifying the DOM as we manipulate the - // authorships. - initAuthorshipData: function() { - $('.authorship').each(function(index) { - $(this).data(authorshipData[index]); - - // RY We might still need position to put back an element after reordering - // failure. Rank might already have been reset? Check. - // We also may need position to implement undo links: we want the removed authorship - // to show up in the list, but it has no rank. - $(this).data('position', index+1); - }); - }, - - getPosition: function(authorship) { - return $(authorship).data('position'); - }, - - setPosition: function(authorship, pos) { - $(authorship).data('position', pos); - }, - - findAuthorship: function(key, value) { - var matchingAuthorship = $(); // if we don't find one, return an empty jQuery set - - $('.authorship').each(function() { - var authorship = $(this); - if ( authorship.data(key) === value ) { - matchingAuthorship = authorship; - return false; // stop the loop - } - }); - - return matchingAuthorship; - }, - - - /* *** Event listeners *** */ - - bindEventListeners: function() { - - this.showFormButton.click(function() { - addAuthorForm.initFormView(); - return false; - }); - - this.form.submit(function() { - // NB Important JavaScript scope issue: if we call it this way, this = addAuthorForm - // in prepareSubmit. If we do this.form.submit(this.prepareSubmit); then - // this != addAuthorForm in prepareSubmit. - addAuthorForm.deleteAcHelpText(); - addAuthorForm.prepareSubmit(); - }); - - this.lastNameField.blur(function() { - // Cases where this event should be ignored: - // 1. personUri field has a value: the autocomplete select event has already fired. - // 2. The last name field is empty (especially since the field has focus when the form is displayed). - // 3. Autocomplete suggestions are showing. - if ( addAuthorForm.personUriField.val() || !$(this).val() || $('ul.ui-autocomplete li.ui-menu-item').length ) { - return; - } - addAuthorForm.onLastNameChange(); - }); - - this.verifyMatch.click(function() { - window.open($(this).attr('href'), 'verifyMatchWindow', 'width=640,height=640,scrollbars=yes,resizable=yes,status=yes,toolbar=no,menubar=no,location=no'); - return false; - }); - - this.acSelector.focus(function() { - addAuthorForm.deleteAcHelpText(); - }); - - this.acSelector.blur(function() { - addAuthorForm.addAcHelpText(); - }); - - // When hitting enter in last name field, show first and middle name fields. - // NB This event fires when selecting an autocomplete suggestion with the enter - // key. Since it fires first, we undo its effects in the ac select event listener. - this.lastNameField.keydown(function(event) { - if (event.which === 13) { - addAuthorForm.onLastNameChange(); - return false; // don't submit form - } - }); - - this.removeAuthorshipLinks.click(function() { - addAuthorForm.removeAuthorship(this); - return false; - }); - -// this.undoLinks.click(function() { -// $.ajax({ -// url: $(this).attr('href') -// }); -// return false; -// }); - - }, - - prepareSubmit: function() { - var firstName, - middleName, - lastName, - name; - - // If selecting an existing person, don't submit name fields - if (this.personUriField.val() != '') { - this.firstNameField.attr('disabled', 'disabled'); - this.middleNameField.attr('disabled', 'disabled'); - this.lastNameField.attr('disabled', 'disabled'); - } - else { - firstName = this.firstNameField.val(); - middleName = this.middleNameField.val(); - lastName = this.lastNameField.val(); - - name = lastName; - if (firstName) { - name += ', ' + firstName; - } - if (middleName) { - name += ' ' + middleName; - } - - this.labelField.val(name); - } - - }, - - onLastNameChange: function() { - this.showFieldsForNewPerson(); - this.firstNameField.focus(); - // this.fixNames(); - }, - - // 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 - // or space into the first name field. - // RY Space is problematic because they may be entering " ", but - // comma is a clear case. -// fixNames: function() { -// var lastNameInput = this.lastNameField.val(), -// names = lastNameInput.split(/[, ]+/), -// lastName = names[0]; -// -// this.lastNameField.val(lastName); -// -// if (names.length > 1) { -// //firstName = names[1].replace(/^[, ]+/, ''); -// this.firstNameField.val(names[1]); -// } -// }, - - removeAuthorship: function(link) { - // RY Upgrade this to a modal window - - authorName = $(link).prev().children().text(); - - var removeLast = false, - message = 'Are you sure you want to remove this author:\n\n' + authorName + ' ?\n\n'; - - if (!confirm(message)) { - return false; - } - - if ($(link)[0] === $('.remove:last')[0]) { - removeLast = true; - } - - $.ajax({ - url: $(link).attr('href'), - type: 'POST', - data: { - deletion: $(link).parents('.authorship').data('authorshipUri') - }, - dataType: 'json', - context: link, // context for callback - complete: function(request, status) { - var authorship, - authorUri; - - if (status === 'success') { - - authorship = $(this).parents('.authorship'); - - // Clear autocomplete cache entries matching this author's name, else - // autocomplete will be retrieved from the cache, which excludes the removed author. - addAuthorForm.clearAcCacheEntries(authorship.data('authorName')); - - // Remove this author from the acFilter so it is included in autocomplete - // results again. - addAuthorForm.removeAuthorFromAcFilter(authorship.data('authorUri')); - - authorship.fadeOut(400, function() { - var numAuthors; - - // For undo link: add to a deletedAuthorships array - - // Remove from the DOM - $(this).remove(); - - // Actions that depend on the author having been removed from the DOM: - numAuthors = $('.authorship').length; // retrieve the length after removing authorship from the DOM - - // If removed item not last, reorder to remove any gaps - if (numAuthors > 0 && ! removeLast) { - addAuthorForm.reorderAuthors(); - } - - // If fewer than two authors remaining, disable drag-drop - if (numAuthors < 2) { - addAuthorForm.disableAuthorDD(); - } - }); - -// $(this).hide(); -// $(this).siblings('.undo').show(); -// author.html(authorName + ' has been removed'); -// author.css('width', 'auto'); -// author.effect('highlight', {}, 3000); - } else { - alert('Error processing request: author not removed'); - } - } - }); - }, - - // Disable DD and associated cues if only one author remains - disableAuthorDD: function() { - var authorships = $('#authorships'), - authorNameWrapper = $('.authorNameWrapper'); - - authorships.sortable({ disable: true } ); - - // Use class dd rather than jQuery UI's class ui-sortable, so that we can remove - // the class if there's fewer than one author. We don't want to remove the ui-sortable - // class, in case we want to re-enable DD without a page reload (e.g., if implementing - // adding an author via Ajax request). - authorships.removeClass('dd'); - - authorNameWrapper.removeAttr('title'); - }, - - // RY To be implemented later. - toggleRemoveLink: function() { - // when clicking remove: remove the author, and change link text to 'undo' - // when clicking undo: add the author back, and change link text to 'remove' - }, - - // Set the initial help text in the lastName field and change the class name. - addAcHelpText: function() { - var typeText; - - if (!this.acSelector.val()) { - this.acSelector.val("Select an existing Author or add a new one.") - .addClass(this.acHelpTextClass); - } - }, - - deleteAcHelpText: function() { - if (this.acSelector.hasClass(this.acHelpTextClass)) { - this.acSelector.val('') - .removeClass(this.acHelpTextClass); - } - } -}; - -$(document).ready(function() { - addAuthorForm.onLoad(); -}); +/* These styles will need to be redone or removed to support a non-JS version of the form. */ +form#addAuthorForm { + display: none; +} \ No newline at end of file diff --git a/productMods/templates/freemarker/edit/forms/js/addAuthorsToInformationResource.js b/productMods/templates/freemarker/edit/forms/js/addAuthorsToInformationResource.js index e69de29b..07137ebb 100644 --- a/productMods/templates/freemarker/edit/forms/js/addAuthorsToInformationResource.js +++ b/productMods/templates/freemarker/edit/forms/js/addAuthorsToInformationResource.js @@ -0,0 +1,661 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +var addAuthorForm = { + + /* *** Initial page setup *** */ + + onLoad: function() { + + if (this.disableFormInUnsupportedBrowsers()) { + return; + } + this.mixIn(); + this.initObjects(); + this.initPage(); + }, + + disableFormInUnsupportedBrowsers: function() { + var disableWrapper = $('#ie67DisableWrapper'); + + // Check for unsupported browsers only if the element exists on the page + if (disableWrapper.length) { + if (vitro.browserUtils.isIELessThan8()) { + disableWrapper.show(); + $('.noIE67').hide(); + return true; + } + } + return false; + }, + + mixIn: function() { + // Mix in the custom form utility methods + $.extend(this, vitro.customFormUtils); + + // Get the custom form data from the page + $.extend(this, customFormData); + }, + + // On page load, create references for easy access to form elements. + // NB These must be assigned after the elements have been loaded onto the page. + initObjects: function() { + + this.form = $('#addAuthorForm'); + this.showFormButtonWrapper = $('#showAddForm'); + this.showFormButton = $('#showAddFormButton'); + this.removeAuthorshipLinks = $('a.remove'); + //this.undoLinks = $('a.undo'); + this.submit = this.form.find(':submit'); + this.cancel = this.form.find('.cancel'); + this.acSelector = this.form.find('.acSelector'); + this.labelField = $('#label'); + this.firstNameField = $('#firstName'); + this.middleNameField = $('#middleName'); + this.lastNameField = $('#lastName'); + this.lastNameLabel = $('label[for=lastName]'); + this.personUriField = $('#personUri'); + this.firstNameWrapper = this.firstNameField.parent(); + this.middleNameWrapper = this.middleNameField.parent(); + this.lastNameWrapper = this.lastNameField.parent(); + this.selectedAuthor = $('#selectedAuthor'); + this.selectedAuthorName = $('#selectedAuthorName'); + this.acHelpTextClass = 'acSelectorWithHelpText'; + this.verifyMatch = this.form.find('.verifyMatch'); + + }, + + // Initial page setup. Called only at page load. + initPage: function() { + + this.initAuthorshipData(); + + // Show elements hidden by CSS for the non-JavaScript-enabled version. + // NB The non-JavaScript version of this form is currently not functional. + this.removeAuthorshipLinks.show(); + + //this.undoLinks.hide(); + + this.bindEventListeners(); + + this.initAutocomplete(); + + this.initElementData(); + + this.initAuthorDD(); + + if (this.findValidationErrors()) { + this.initFormAfterInvalidSubmission(); + } else { + this.initAuthorListOnlyView(); + } + }, + + + /* *** Set up the various page views *** */ + + // This initialization is done only on page load, not when returning to author list only view + // after hitting 'cancel.' + initAuthorListOnlyView: function() { + + if ($('.authorship').length) { // make sure we have at least one author + // Reorder authors on page load so that previously unranked authors get a rank. Otherwise, + // when we add a new author, it will get put ahead of any previously unranked authors, instead + // of at the end of the list. (It is also helpful to normalize the data before we get started.) + this.reorderAuthors(); + } + this.showAuthorListOnlyView(); + }, + + // This view shows the list of existing authors and hides the form. + // There is a button to show the form. We do this on page load, and after + // hitting 'cancel' from full view. + showAuthorListOnlyView: function() { + this.hideForm(); + this.showFormButtonWrapper.show(); + }, + + // View of form after returning from an invalid submission. On this form, + // validation errors entail that we were entering a new person, so we show + // all the fields straightaway. + initFormAfterInvalidSubmission: function() { + this.initForm(); + this.showFieldsForNewPerson(); + }, + + // Initial view of add author form. We get here by clicking the show form button, + // or by cancelling out of an autocomplete selection. + initFormView: function() { + + this.initForm(); + + // There's a conflict bewteen the last name fields .blur event and the cancel + // button's click. So display the middle and first names along with the last name tlw72 + //this.hideFieldsForNewPerson(); + + // This shouldn't be needed, because calling this.hideFormFields(this.lastNameWrapper) + // from showSelectedAuthor should do it. However, it doesn't work from there, + // or in the cancel action, or if referring to this.lastNameField. None of those work, + // however. + $('#lastName').val(''); + // Set the initial autocomplete help text in the acSelector field. + this.addAcHelpText(); + + return false; + + }, + + // Form initialization common to both a 'clean' form view and when + // returning from an invalid submission. + initForm: function() { + + // Hide the button that shows the form + this.showFormButtonWrapper.hide(); + + this.hideSelectedAuthor(); + + this.cancel.unbind('click'); + this.cancel.bind('click', function() { + addAuthorForm.showAuthorListOnlyView(); + return false; + }); + + // Reset the last name field. It had been hidden if we selected an author from + // the autocomplete field. + this.lastNameWrapper.show(); + this.showFieldsForNewPerson(); + + // Show the form + this.form.show(); + //this.lastNameField.focus(); + }, + + hideSelectedAuthor: function() { + this.selectedAuthor.hide(); + this.selectedAuthorName.html(''); + this.personUriField.val(''); + }, + + showFieldsForNewPerson: function() { + this.firstNameWrapper.show(); + this.middleNameWrapper.show(); + }, + + hideFieldsForNewPerson: function() { + this.hideFields(this.firstNameWrapper); + this.hideFields(this.middleNameWrapper); + }, + + /* *** Ajax initializations *** */ + + /* Autocomplete */ + initAutocomplete: function() { + + // Make cache a property of this so we can access it after removing + // an author. + this.acCache = {}; + this.setAcFilter(); + + this.lastNameField.autocomplete({ + minLength: 2, + source: function(request, response) { + if (request.term in addAuthorForm.acCache) { + // console.log('found term in cache'); + response(addAuthorForm.acCache[request.term]); + return; + } + // console.log('not getting term from cache'); + + // If the url query params are too long, we could do a post + // here instead of a get. Add the exclude uris to the data + // rather than to the url. + $.ajax({ + url: addAuthorForm.acUrl, + dataType: 'json', + data: { + term: request.term + }, + complete: function(xhr, status) { + // Not sure why, but we need an explicit json parse here. jQuery + // should parse the response text and return a json object. + var results = jQuery.parseJSON(xhr.responseText), + filteredResults = addAuthorForm.filterAcResults(results); + addAuthorForm.acCache[request.term] = filteredResults; + response(filteredResults); + } + + }); + }, + // Select event not triggered in IE6/7 when selecting with enter key rather + // than mouse. Thus form is disabled in these browsers. + // jQuery UI bug: when scrolling through the ac suggestions with up/down arrow + // keys, the input element gets filled with the highlighted text, even though no + // select event has been triggered. To trigger a select, the user must hit enter + // or click on the selection with the mouse. This appears to confuse some users. + select: function(event, ui) { + addAuthorForm.showSelectedAuthor(ui); + } + }); + + }, + + initElementData: function() { + this.verifyMatch.data('baseHref', this.verifyMatch.attr('href')); + }, + + setAcFilter: function() { + this.acFilter = []; + + $('.authorship').each(function() { + var uri = $(this).data('authorUri'); + addAuthorForm.acFilter.push(uri); + }); + }, + + removeAuthorFromAcFilter: function(author) { + var index = $.inArray(author, this.acFilter); + if (index > -1) { // this should always be true + this.acFilter.splice(index, 1); + } + }, + + filterAcResults: function(results) { + var filteredResults = []; + if (!this.acFilter.length) { + return results; + } + $.each(results, function() { + if ($.inArray(this.uri, addAuthorForm.acFilter) == -1) { + // console.log("adding " + this.label + " to filtered results"); + filteredResults.push(this); + } + else { + // console.log("filtering out " + this.label); + } + }); + return filteredResults; + }, + + // After removing an authorship, selectively clear matching autocomplete + // cache entries, else the associated author will not be included in + // subsequent autocomplete suggestions. + clearAcCacheEntries: function(name) { + name = name.toLowerCase(); + $.each(this.acCache, function(key, value) { + if (name.indexOf(key) == 0) { + delete addAuthorForm.acCache[key]; + } + }); + }, + + // Action taken after selecting an author from the autocomplete list + showSelectedAuthor: function(ui) { + + this.personUriField.val(ui.item.uri); + this.selectedAuthor.show(); + + // Transfer the name from the autocomplete to the selected author + // name display, and hide the last name field. + this.selectedAuthorName.html(ui.item.label); + // NB For some reason this doesn't delete the value from the last name + // field when the form is redisplayed. Thus it's done explicitly in initFormView. + this.hideFields(this.lastNameWrapper); + // These get displayed if the selection was made through an enter keystroke, + // since the keydown event on the last name field is also triggered (and + // executes first). So re-hide them here. + this.hideFieldsForNewPerson(); + this.verifyMatch.attr('href', this.verifyMatch.data('baseHref') + ui.item.uri); + + // Cancel restores initial form view + this.cancel.unbind('click'); + this.cancel.bind('click', function() { + addAuthorForm.initFormView(); + return false; + }); + }, + + /* Drag-and-drop */ + initAuthorDD: function() { + + var authorshipList = $('#authorships'), + authorships = authorshipList.children('li'); + + if (authorships.length < 2) { + return; + } + + $('.authorNameWrapper').each(function() { + $(this).attr('title', 'Drag and drop to reorder authors'); + }); + + authorshipList.sortable({ + cursor: 'move', + update: function(event, ui) { + addAuthorForm.reorderAuthors(event, ui); + } + }); + }, + + // Reorder authors. Called on page load and after author drag-and-drop and remove. + // Event and ui parameters are defined only in the case of drag-and-drop. + reorderAuthors: function(event, ui) { + var authorships = $('li.authorship').map(function(index, el) { + return $(this).data('authorshipUri'); + }).get(); + + $.ajax({ + url: addAuthorForm.reorderUrl, + data: { + predicate: addAuthorForm.rankPredicate, + individuals: authorships + }, + traditional: true, // serialize the array of individuals for the server + dataType: 'json', + type: 'POST', + success: function(data, status, request) { + var pos; + $('.authorship').each(function(index){ + pos = index + 1; + // Set the new position for this element. The only function of this value + // is so we can reset an element to its original position in case reordering fails. + addAuthorForm.setPosition(this, pos); + }); + // Set the form rank field value. + $('#rank').val(pos + 1); + }, + error: function(request, status, error) { + // ui is undefined on page load and after an authorship removal. + if (ui) { + // Put the moved item back to its original position. + // Seems we need to do this by hand. Can't see any way to do it with jQuery UI. ?? + var pos = addAuthorForm.getPosition(ui.item), + nextpos = pos + 1, + authorships = $('#authorships'), + next = addAuthorForm.findAuthorship('position', nextpos); + + if (next.length) { + ui.item.insertBefore(next); + } + else { + ui.item.appendTo(authorships); + } + + alert('Reordering of authors failed.'); + } + } + }); + }, + + // On page load, associate data with each authorship element. Then we don't + // have to keep retrieving data from or modifying the DOM as we manipulate the + // authorships. + initAuthorshipData: function() { + $('.authorship').each(function(index) { + $(this).data(authorshipData[index]); + + // RY We might still need position to put back an element after reordering + // failure. Rank might already have been reset? Check. + // We also may need position to implement undo links: we want the removed authorship + // to show up in the list, but it has no rank. + $(this).data('position', index+1); + }); + }, + + getPosition: function(authorship) { + return $(authorship).data('position'); + }, + + setPosition: function(authorship, pos) { + $(authorship).data('position', pos); + }, + + findAuthorship: function(key, value) { + var matchingAuthorship = $(); // if we don't find one, return an empty jQuery set + + $('.authorship').each(function() { + var authorship = $(this); + if ( authorship.data(key) === value ) { + matchingAuthorship = authorship; + return false; // stop the loop + } + }); + + return matchingAuthorship; + }, + + + /* *** Event listeners *** */ + + bindEventListeners: function() { + + this.showFormButton.click(function() { + addAuthorForm.initFormView(); + return false; + }); + + this.form.submit(function() { + // NB Important JavaScript scope issue: if we call it this way, this = addAuthorForm + // in prepareSubmit. If we do this.form.submit(this.prepareSubmit); then + // this != addAuthorForm in prepareSubmit. + addAuthorForm.deleteAcHelpText(); + addAuthorForm.prepareSubmit(); + }); + + this.lastNameField.blur(function() { + // Cases where this event should be ignored: + // 1. personUri field has a value: the autocomplete select event has already fired. + // 2. The last name field is empty (especially since the field has focus when the form is displayed). + // 3. Autocomplete suggestions are showing. + if ( addAuthorForm.personUriField.val() || !$(this).val() || $('ul.ui-autocomplete li.ui-menu-item').length ) { + return; + } + addAuthorForm.onLastNameChange(); + }); + + this.verifyMatch.click(function() { + window.open($(this).attr('href'), 'verifyMatchWindow', 'width=640,height=640,scrollbars=yes,resizable=yes,status=yes,toolbar=no,menubar=no,location=no'); + return false; + }); + + this.acSelector.focus(function() { + addAuthorForm.deleteAcHelpText(); + }); + + this.acSelector.blur(function() { + addAuthorForm.addAcHelpText(); + }); + + // When hitting enter in last name field, show first and middle name fields. + // NB This event fires when selecting an autocomplete suggestion with the enter + // key. Since it fires first, we undo its effects in the ac select event listener. + this.lastNameField.keydown(function(event) { + if (event.which === 13) { + addAuthorForm.onLastNameChange(); + return false; // don't submit form + } + }); + + this.removeAuthorshipLinks.click(function() { + addAuthorForm.removeAuthorship(this); + return false; + }); + +// this.undoLinks.click(function() { +// $.ajax({ +// url: $(this).attr('href') +// }); +// return false; +// }); + + }, + + prepareSubmit: function() { + var firstName, + middleName, + lastName, + name; + + // If selecting an existing person, don't submit name fields + if (this.personUriField.val() != '') { + this.firstNameField.attr('disabled', 'disabled'); + this.middleNameField.attr('disabled', 'disabled'); + this.lastNameField.attr('disabled', 'disabled'); + } + else { + firstName = this.firstNameField.val(); + middleName = this.middleNameField.val(); + lastName = this.lastNameField.val(); + + name = lastName; + if (firstName) { + name += ', ' + firstName; + } + if (middleName) { + name += ' ' + middleName; + } + + this.labelField.val(name); + } + + }, + + onLastNameChange: function() { + this.showFieldsForNewPerson(); + this.firstNameField.focus(); + // this.fixNames(); + }, + + // 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 + // or space into the first name field. + // RY Space is problematic because they may be entering " ", but + // comma is a clear case. +// fixNames: function() { +// var lastNameInput = this.lastNameField.val(), +// names = lastNameInput.split(/[, ]+/), +// lastName = names[0]; +// +// this.lastNameField.val(lastName); +// +// if (names.length > 1) { +// //firstName = names[1].replace(/^[, ]+/, ''); +// this.firstNameField.val(names[1]); +// } +// }, + + removeAuthorship: function(link) { + // RY Upgrade this to a modal window + + authorName = $(link).prev().children().text(); + + var removeLast = false, + message = 'Are you sure you want to remove this author:\n\n' + authorName + ' ?\n\n'; + + if (!confirm(message)) { + return false; + } + + if ($(link)[0] === $('.remove:last')[0]) { + removeLast = true; + } + + $.ajax({ + url: $(link).attr('href'), + type: 'POST', + data: { + deletion: $(link).parents('.authorship').data('authorshipUri') + }, + dataType: 'json', + context: link, // context for callback + complete: function(request, status) { + var authorship, + authorUri; + + if (status === 'success') { + + authorship = $(this).parents('.authorship'); + + // Clear autocomplete cache entries matching this author's name, else + // autocomplete will be retrieved from the cache, which excludes the removed author. + addAuthorForm.clearAcCacheEntries(authorship.data('authorName')); + + // Remove this author from the acFilter so it is included in autocomplete + // results again. + addAuthorForm.removeAuthorFromAcFilter(authorship.data('authorUri')); + + authorship.fadeOut(400, function() { + var numAuthors; + + // For undo link: add to a deletedAuthorships array + + // Remove from the DOM + $(this).remove(); + + // Actions that depend on the author having been removed from the DOM: + numAuthors = $('.authorship').length; // retrieve the length after removing authorship from the DOM + + // If removed item not last, reorder to remove any gaps + if (numAuthors > 0 && ! removeLast) { + addAuthorForm.reorderAuthors(); + } + + // If fewer than two authors remaining, disable drag-drop + if (numAuthors < 2) { + addAuthorForm.disableAuthorDD(); + } + }); + +// $(this).hide(); +// $(this).siblings('.undo').show(); +// author.html(authorName + ' has been removed'); +// author.css('width', 'auto'); +// author.effect('highlight', {}, 3000); + } else { + alert('Error processing request: author not removed'); + } + } + }); + }, + + // Disable DD and associated cues if only one author remains + disableAuthorDD: function() { + var authorships = $('#authorships'), + authorNameWrapper = $('.authorNameWrapper'); + + authorships.sortable({ disable: true } ); + + // Use class dd rather than jQuery UI's class ui-sortable, so that we can remove + // the class if there's fewer than one author. We don't want to remove the ui-sortable + // class, in case we want to re-enable DD without a page reload (e.g., if implementing + // adding an author via Ajax request). + authorships.removeClass('dd'); + + authorNameWrapper.removeAttr('title'); + }, + + // RY To be implemented later. + toggleRemoveLink: function() { + // when clicking remove: remove the author, and change link text to 'undo' + // when clicking undo: add the author back, and change link text to 'remove' + }, + + // Set the initial help text in the lastName field and change the class name. + addAcHelpText: function() { + var typeText; + + if (!this.acSelector.val()) { + this.acSelector.val("Select an existing Author or add a new one.") + .addClass(this.acHelpTextClass); + } + }, + + deleteAcHelpText: function() { + if (this.acSelector.hasClass(this.acHelpTextClass)) { + this.acSelector.val('') + .removeClass(this.acHelpTextClass); + } + } +}; + +$(document).ready(function() { + addAuthorForm.onLoad(); +});