NIHVIVO-3530: Deleted old custom forms jsp files. This is what I have done for VIVO:
1-Deleted all the js, css, and js from VIVO/productMods/forms 2-Moved css and js to from VIVO/productMods/forms to VIVO/templates/freemarker/forms 3-Updated css and js path files for all the ftl files at VIVO/templates/freemarker/forms, which contains the new custom forms.
This commit is contained in:
parent
8d9a59c1bf
commit
59672b5156
52 changed files with 1523 additions and 5567 deletions
|
@ -1,661 +0,0 @@
|
|||
/* $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 "<firstname> <lastname>", 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();
|
||||
});
|
|
@ -1,326 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
var addConceptForm = {
|
||||
|
||||
/* *** 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.
|
||||
initObjects: function() {
|
||||
|
||||
this.form = $('#addConceptForm');
|
||||
this.showFormButtonWrapper = $('#showAddForm');
|
||||
this.submit = this.form.find(':submit');
|
||||
this.cancel = this.form.find('.cancel');
|
||||
//Add term
|
||||
this.addConceptButton = $('#showAddFormButton');
|
||||
//section where results should be displayed
|
||||
this.selectedConcept = $('#selectedConcept');
|
||||
//input for search term form
|
||||
this.searchTerm = $('#searchTerm');
|
||||
this.searchSubmit = $('#searchButton');
|
||||
//Hidden inputs for eventual submission
|
||||
this.externalConceptURI = $('#conceptNode');
|
||||
this.externalConceptLabel = $('#conceptLabel');
|
||||
this.externalConceptSource = $('#conceptSource');
|
||||
//remove links
|
||||
this.removeConceptLinks = $('a.remove');
|
||||
this.errors = $('#errors');
|
||||
this.createOwn1 = $('#createOwnOne');
|
||||
this.createOwn2 = $('#createOwnTwo');
|
||||
this.orSpan = $('span.or')
|
||||
},
|
||||
|
||||
initPage: function() {
|
||||
this.initConceptData();
|
||||
this.bindEventListeners();
|
||||
|
||||
},
|
||||
bindEventListeners: function() {
|
||||
this.searchSubmit.click(function() {
|
||||
addConceptForm.clearErrors();
|
||||
addConceptForm.submitSearchTerm();
|
||||
return false;
|
||||
});
|
||||
|
||||
this.form.submit(function() {
|
||||
return addConceptForm.prepareSubmit();
|
||||
});
|
||||
|
||||
this.addConceptButton.click(function() {
|
||||
addConceptForm.initForm();
|
||||
|
||||
});
|
||||
this.removeConceptLinks.click(function() {
|
||||
addConceptForm.removeExistingConcept(this);
|
||||
return false;
|
||||
});
|
||||
},
|
||||
initForm: function() {
|
||||
// Hide the button that shows the form
|
||||
this.showFormButtonWrapper.hide();
|
||||
this.clearSearchResults();
|
||||
// Hide the create own link, add selected button and "or"" span
|
||||
this.orSpan.hide();
|
||||
this.createOwn2.hide();
|
||||
this.submit.hide();
|
||||
//Also clear the search input
|
||||
this.searchTerm.val("");
|
||||
this.cancel.unbind('click');
|
||||
|
||||
// Show the form
|
||||
this.form.show();
|
||||
},
|
||||
// On page load, associate data with each existing term element. Then we don't
|
||||
// have to keep retrieving data from or modifying the DOM as we manipulate the
|
||||
// authorships.
|
||||
initConceptData: function() {
|
||||
$('.existingConcept').each(function(index) {
|
||||
$(this).data(existingConceptsData[index]);
|
||||
$(this).data('position', index+1);
|
||||
});
|
||||
},
|
||||
clearSearchResults:function() {
|
||||
$('#selectedConcept').empty();
|
||||
},
|
||||
clearErrors:function() {
|
||||
addConceptForm.errors.empty();
|
||||
},
|
||||
showHiddenElements:function(results) {
|
||||
this.createOwn1.hide();
|
||||
if ( results ) {
|
||||
this.orSpan.show();
|
||||
this.createOwn2.show();
|
||||
this.submit.show();
|
||||
}
|
||||
else {
|
||||
this.orSpan.show();
|
||||
this.createOwn2.show();
|
||||
}
|
||||
},
|
||||
showConceptListOnlyView: function() {
|
||||
this.hideForm();
|
||||
this.showFormButtonWrapper.show();
|
||||
},
|
||||
submitSearchTerm: function() {
|
||||
//Get value of search term
|
||||
var searchValue = this.searchTerm.val();
|
||||
var checkedVocabSource = $('input:radio[name="source"]:checked');
|
||||
var hasResults = false;
|
||||
if(!checkedVocabSource.length) {
|
||||
addConceptForm.showUncheckedSourceError();
|
||||
return;
|
||||
}
|
||||
var vocabSourceValue = checkedVocabSource.val();
|
||||
var dataServiceUrl = addConceptForm.dataServiceUrl + "?searchTerm=" + encodeURIComponent(searchValue) + "&source=" + encodeURIComponent(vocabSourceValue);
|
||||
//This should return an object including the concept list or any errors if there are any
|
||||
$.getJSON(dataServiceUrl, function(results) {
|
||||
var htmlAdd = "";
|
||||
var vocabUnavailable = "<p>The vocabulary service is unavailable. Please try again later.</p>";
|
||||
if ( results== null || results.semanticServicesError != null || results.conceptList == null) {
|
||||
htmlAdd = vocabUnavailable;
|
||||
}
|
||||
else {
|
||||
//array is an array of objects representing concept information
|
||||
//loop through and find all the best matches
|
||||
var bestMatchResults = addConceptForm.parseResults(results.conceptList);
|
||||
var numberMatches = bestMatchResults.length;
|
||||
var i;
|
||||
//For each result, display
|
||||
if(numberMatches > 0) {
|
||||
htmlAdd = "<ul class='dd' id='concepts' name='concepts'>";
|
||||
htmlAdd+= addConceptForm.addResultsHeader();
|
||||
for(i = 0; i < numberMatches; i++) {
|
||||
var conceptResult = bestMatchResults[i];
|
||||
var conceptId = conceptResult.conceptId;
|
||||
var label = conceptResult.label;
|
||||
var definition = conceptResult.definition;
|
||||
var definedBy = conceptResult.definedBy;
|
||||
var type = conceptResult.type;
|
||||
var uri = conceptResult.uri;
|
||||
htmlAdd+= addConceptForm.generateIndividualConceptDisplay(uri, label, definition, type, definedBy);
|
||||
}
|
||||
htmlAdd+= "</ul>";
|
||||
} else {
|
||||
htmlAdd+= "<p>No search results were found.</p>";
|
||||
}
|
||||
|
||||
}
|
||||
if(htmlAdd.length) {
|
||||
$('#selectedConcept').html(htmlAdd);
|
||||
if (htmlAdd.indexOf("No search results") >= 0) {
|
||||
addConceptForm.showHiddenElements(hasResults);
|
||||
}
|
||||
else {
|
||||
hasResults = true;
|
||||
addConceptForm.showHiddenElements(hasResults);
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
},
|
||||
parseResults:function(resultsArray) {
|
||||
//Loop through array and check if this is the best match
|
||||
var arrayLen = resultsArray.length;
|
||||
var bestMatchResults = new Array();
|
||||
var i;
|
||||
for(i = 0; i < arrayLen; i++) {
|
||||
var concept = resultsArray[i];
|
||||
if(concept.bestMatch != "false") {
|
||||
bestMatchResults.push(concept);
|
||||
}
|
||||
}
|
||||
return bestMatchResults;
|
||||
},
|
||||
addResultsHeader:function() {
|
||||
var htmlAdd = "<li class='concepts'><div class='row'><span class='column conceptLabel'>Label (Type) </span><span class='column conceptDefinition'>Definition</span></div></li>";
|
||||
return htmlAdd;
|
||||
},
|
||||
hideSearchResults:function() {
|
||||
this.selectedConcept.hide();
|
||||
},
|
||||
prepareSubmit:function() {
|
||||
var checkedElements = $("input[name='CUI']:checked");
|
||||
if(!addConceptForm.validateConceptSelection(checkedElements)) {
|
||||
return false;
|
||||
}
|
||||
var i;
|
||||
var len = checkedElements.length;
|
||||
var checkedConcept, checkedConceptElement, conceptLabel, conceptSource;
|
||||
var conceptNodes = [];
|
||||
var conceptLabels = [];
|
||||
var conceptSources = [];
|
||||
|
||||
checkedElements.each(function() {
|
||||
checkedConceptElement = $(this);
|
||||
checkedConcept = checkedConceptElement.val();
|
||||
conceptLabel = checkedConceptElement.attr("label");
|
||||
conceptSource = checkedConceptElement.attr("conceptDefinedBy");
|
||||
conceptNodes.push(checkedConcept);
|
||||
conceptLabels.push(conceptLabel);
|
||||
conceptSources.push(conceptSource);
|
||||
});
|
||||
this.externalConceptURI.val(conceptNodes);
|
||||
this.externalConceptLabel.val(conceptLabels);
|
||||
this.externalConceptSource.val(conceptSources);
|
||||
return true;
|
||||
},
|
||||
generateIndividualConceptDisplay: function(cuiURI, label, definition, type, definedBy) {
|
||||
var htmlAdd = "<li class='concepts'>" +
|
||||
"<div class='row'>" +
|
||||
"<span class='column conceptLabel'>" +
|
||||
addConceptForm.generateIndividualCUIInput(cuiURI, label, type, definedBy) +
|
||||
label + addConceptForm.generateIndividualTypeDisplay(type) + "</span>" +
|
||||
addConceptForm.generateIndividualDefinitionDisplay(definition) +
|
||||
"</div>" +
|
||||
"</li>";
|
||||
return htmlAdd;
|
||||
},
|
||||
generateIndividualCUIInput:function(cuiURI, label, type, definedBy) {
|
||||
return "<input type='checkbox' name='CUI' value='" + cuiURI + "' label='" + label + "' conceptType='" + type + "' conceptDefinedBy='" + definedBy + "'/>";
|
||||
},
|
||||
generateIndividualTypeDisplay:function(type) {
|
||||
if(type != null && type.length > 0) {
|
||||
return " (" + type + ")";
|
||||
}
|
||||
return "";
|
||||
},
|
||||
generateIndividualDefinitionDisplay:function(definition) {
|
||||
return "<span class='column conceptDefinition'>" + definition + "</span>";
|
||||
},
|
||||
validateConceptSelection:function(checkedElements) {
|
||||
var numberElements = checkedElements.length;
|
||||
if(numberElements < 1) {
|
||||
addConceptForm.errors.html("<p class='validationError'>Please select at least one term from the search search results.</p>");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
showUncheckedSourceError:function() {
|
||||
addConceptForm.errors.html("<p class='validationError'>Please select at least one external vocabulary source to search.</p>");
|
||||
},
|
||||
removeExistingConcept: function(link) {
|
||||
var removeLast = false,
|
||||
message = 'Are you sure you want to remove this term?';
|
||||
|
||||
if (!confirm(message)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($(link)[0] === $('.remove:last')[0]) {
|
||||
removeLast = true;
|
||||
}
|
||||
//Using primitive rdf edit which expects an n3 string for deletion
|
||||
$.ajax({
|
||||
url: $(link).attr('href'),
|
||||
type: 'POST',
|
||||
data: {
|
||||
additions: '',
|
||||
retractions: addConceptForm.generateDeletionN3($(link).parents('.existingConcept').data('conceptNodeUri'))
|
||||
},
|
||||
dataType: 'json',
|
||||
context: link, // context for callback
|
||||
complete: function(request, status) {
|
||||
var existingConcept,
|
||||
conceptNodeUri;
|
||||
|
||||
if (status === 'success') {
|
||||
|
||||
existingConcept = $(this).parents('.existingConcept');
|
||||
existingConcept.fadeOut(400, function() {
|
||||
var numConcepts;
|
||||
// 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:
|
||||
numConcepts = $('.existingConcept').length; // retrieve the length after removing authorship from the DOM
|
||||
});
|
||||
|
||||
} else {
|
||||
alert('Error processing request: term not removed');
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
generateDeletionN3: function(conceptNodeUri) {
|
||||
var n3String = "<" + addConceptForm.subjectUri + "> <" + addConceptForm.predicateUri + "> <" + conceptNodeUri + "> .";
|
||||
//add inverse string to also be removed
|
||||
if(addConceptForm.inversePredicateUri.length > 0) {
|
||||
n3String += "<" + conceptNodeUri + "> <" + addConceptForm.inversePredicateUri + "> <" + addConceptForm.subjectUri + "> .";
|
||||
}
|
||||
return n3String;
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
addConceptForm.onLoad();
|
||||
});
|
|
@ -1,250 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
var addTerminologyForm = {
|
||||
|
||||
/* *** 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.
|
||||
initObjects: function() {
|
||||
|
||||
this.form = $('#addTerminologyForm');
|
||||
this.showFormButtonWrapper = $('#showAddForm');
|
||||
this.submit = this.form.find(':submit');
|
||||
this.cancel = this.form.find('.cancel');
|
||||
//Add term
|
||||
this.addTermButton = $('#showAddFormButton');
|
||||
//section where results should be displayed
|
||||
this.selectedTerm = $('#selectedTerm');
|
||||
//input for search term form
|
||||
this.searchTerm = $('#searchTerm');
|
||||
this.searchSubmit = $('#searchButton');
|
||||
//Hidden inputs for eventual submission
|
||||
this.referencedTerm = $('#referencedTerm');
|
||||
this.entryTerm = $('#entryTerm');
|
||||
this.termLabel = $('#termLabel');
|
||||
this.termType = $('#termType');
|
||||
this.removeTermLinks = $('a.remove');
|
||||
this.errors = $('#errors');
|
||||
},
|
||||
|
||||
initPage: function() {
|
||||
this.initTermData();
|
||||
this.bindEventListeners();
|
||||
|
||||
},
|
||||
bindEventListeners: function() {
|
||||
this.searchSubmit.click(function() {
|
||||
addTerminologyForm.submitSearchTerm();
|
||||
addTerminologyForm.clearErrors();
|
||||
return false;
|
||||
});
|
||||
|
||||
this.form.submit(function() {
|
||||
return addTerminologyForm.prepareSubmit();
|
||||
});
|
||||
|
||||
this.addTermButton.click(function() {
|
||||
addTerminologyForm.initForm();
|
||||
|
||||
});
|
||||
this.removeTermLinks.click(function() {
|
||||
addTerminologyForm.removeExistingTerm(this);
|
||||
return false;
|
||||
});
|
||||
},
|
||||
initForm: function() {
|
||||
// Hide the button that shows the form
|
||||
this.showFormButtonWrapper.hide();
|
||||
this.clearSearchResults();
|
||||
|
||||
this.cancel.unbind('click');
|
||||
this.cancel.bind('click', function() {
|
||||
//show only list of existing terms and hide adding term form
|
||||
addTerminologyForm.showTermListOnlyView();
|
||||
return false;
|
||||
});
|
||||
|
||||
// Show the form
|
||||
this.form.show();
|
||||
},
|
||||
// On page load, associate data with each existing term element. Then we don't
|
||||
// have to keep retrieving data from or modifying the DOM as we manipulate the
|
||||
// authorships.
|
||||
initTermData: function() {
|
||||
$('.existingTerm').each(function(index) {
|
||||
$(this).data(existingTermsData[index]);
|
||||
$(this).data('position', index+1);
|
||||
});
|
||||
},
|
||||
clearSearchResults:function() {
|
||||
$('#selectedTerm').empty();
|
||||
},
|
||||
clearErrors:function() {
|
||||
addTerminologyForm.errors.empty();
|
||||
},
|
||||
showTermListOnlyView: function() {
|
||||
this.hideForm();
|
||||
this.showFormButtonWrapper.show();
|
||||
},
|
||||
submitSearchTerm: function() {
|
||||
//Get value of search term
|
||||
var searchValue = this.searchTerm.val();
|
||||
this.entryTerm.val(searchValue);
|
||||
var dataServiceUrl = addTerminologyForm.dataServiceUrl + "?searchTerm=" + encodeURIComponent(searchValue);
|
||||
$.getJSON(dataServiceUrl, function(results) {
|
||||
if ( results.All.length == 0 ) {
|
||||
} else {
|
||||
//update existing content type with correct class group name and hide class group select again
|
||||
var bestMatchResults = results["Best Match"];
|
||||
var numberMatches = bestMatchResults.length;
|
||||
var i;
|
||||
//For each result, display
|
||||
var htmlAdd = "";
|
||||
if(numberMatches > 0) {
|
||||
htmlAdd = "<ul class='dd' id='terms' name='terms'>";
|
||||
htmlAdd+= addTerminologyForm.addResultsHeader();
|
||||
for(i = 0; i < numberMatches; i++) {
|
||||
var termResult = bestMatchResults[i];
|
||||
var CUI = termResult.CUI;
|
||||
var label = termResult.label;
|
||||
var definition = termResult.definition;
|
||||
var type = termResult.type;
|
||||
var cuiURI = addTerminologyForm.UMLSCUIURL + CUI;
|
||||
htmlAdd+= addTerminologyForm.generateIndividualTermDisplay(cuiURI, label, definition, type);
|
||||
}
|
||||
htmlAdd+= "</ul>";
|
||||
} else {
|
||||
htmlAdd+= "<p>No search results found.</p>";
|
||||
}
|
||||
$('#selectedTerm').html(htmlAdd);
|
||||
}
|
||||
|
||||
});
|
||||
},
|
||||
addResultsHeader:function() {
|
||||
var htmlAdd = "<li class='terminology'><div class='row'><span class='column termLabel'>Label (Type) </span><span class='column termDefinition'>Definition</span></div></li>";
|
||||
return htmlAdd;
|
||||
},
|
||||
hideSearchResults:function() {
|
||||
this.selectedTerm.hide();
|
||||
},
|
||||
prepareSubmit:function() {
|
||||
var checkedElements = $("#CUI:checked");
|
||||
if(!addTerminologyForm.validateTermSelection(checkedElements)) {
|
||||
return false;
|
||||
}
|
||||
var i;
|
||||
var len = checkedElements.length;
|
||||
var checkedTerm, checkedTermElement, termLabel, termType;
|
||||
var referencedTerms = [];
|
||||
var termLabels = [];
|
||||
var termTypes = [];
|
||||
|
||||
checkedElements.each(function() {
|
||||
checkedTermElement = $(this);
|
||||
checkedTerm = checkedTermElement.val();
|
||||
termType = checkedTermElement.attr("termType");
|
||||
termLabel = checkedTermElement.attr("label");
|
||||
referencedTerms.push(checkedTerm);
|
||||
termLabels.push(termLabel);
|
||||
termTypes.push(termType);
|
||||
});
|
||||
this.referencedTerm.val(referencedTerms);
|
||||
this.termLabel.val(termLabels);
|
||||
this.termType.val(termTypes);
|
||||
return true;
|
||||
},
|
||||
generateIndividualTermDisplay: function(cuiURI, label, definition, type) {
|
||||
var htmlAdd = "<li class='terminology'>" +
|
||||
"<div class='row'>" +
|
||||
"<span class='column termLabel'>" +
|
||||
"<input type='checkbox' id='CUI' name='CUI' value='" + cuiURI + "' label='" + label + "' termType='" + type + "'/>" +
|
||||
label + " (" + type + ")</span>" +
|
||||
"<span class='column termDefinition'>" + definition + "</span>" +
|
||||
"</div>" +
|
||||
"</li>";
|
||||
return htmlAdd;
|
||||
}, validateTermSelection:function(checkedElements) {
|
||||
var numberElements = checkedElements.length;
|
||||
if(numberElements < 1) {
|
||||
addTerminologyForm.errors.html("<p class='validationError'>Please select at least one term from search results to add or click cancel.</p>");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}, removeExistingTerm: function(link) {
|
||||
var removeLast = false,
|
||||
message = 'Are you sure you want to remove this term?';
|
||||
|
||||
if (!confirm(message)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($(link)[0] === $('.remove:last')[0]) {
|
||||
removeLast = true;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: $(link).attr('href'),
|
||||
type: 'POST',
|
||||
data: {
|
||||
deletion: $(link).parents('.existingTerm').data('termNodeUri')
|
||||
},
|
||||
dataType: 'json',
|
||||
context: link, // context for callback
|
||||
complete: function(request, status) {
|
||||
var existingTerm,
|
||||
termNodeUri;
|
||||
|
||||
if (status === 'success') {
|
||||
|
||||
existingTerm = $(this).parents('.existingTerm');
|
||||
existingTerm.fadeOut(400, function() {
|
||||
var numTerms;
|
||||
// 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:
|
||||
numTerms = $('.existingTerm').length; // retrieve the length after removing authorship from the DOM
|
||||
});
|
||||
|
||||
} else {
|
||||
alert('Error processing request: term not removed');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
addTerminologyForm.onLoad();
|
||||
});
|
|
@ -1,140 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
var mailingAddressUtils = {
|
||||
|
||||
onLoad: function(mode,country) {
|
||||
this.initObjectReferences();
|
||||
this.bindEventListeners();
|
||||
this.sortCountrySelector(mode,country);
|
||||
|
||||
if ( mode == "add" ) {
|
||||
this.containerDiv.hide();
|
||||
this.submitButton.hide();
|
||||
}
|
||||
else {
|
||||
this.processCountryRelatedFields();
|
||||
}
|
||||
},
|
||||
|
||||
initObjectReferences: function() {
|
||||
this.form = $('#personHasMailingAddress');
|
||||
|
||||
// The external auth ID field and messages
|
||||
this.countrySelector = $('#country');
|
||||
this.countrySelectorOptions = $('#country option');
|
||||
this.address1Field = $('#addrLineOne');
|
||||
this.cityField = $('#city');
|
||||
this.stateField = $('#state');
|
||||
this.stateSelector= $('#stateSelect');
|
||||
this.stateLabel = $('#stateLabel');
|
||||
this.postalCodeField = $('#postalCode');
|
||||
this.postalCodeLabel = $('#postalCodeLabel');
|
||||
this.subjectField = $('#subjectName');
|
||||
this.rdfsLabel = $('#addrLabel');
|
||||
this.addrTypeField = $('#addressType');
|
||||
this.submitButton = $('#submit');
|
||||
this.containerDiv = $('#addressDetails');
|
||||
this.orSpan = $('span.or');
|
||||
|
||||
},
|
||||
|
||||
bindEventListeners: function() {
|
||||
this.idCache = {};
|
||||
|
||||
this.countrySelector.change(function() {
|
||||
mailingAddressUtils.processCountryRelatedFields();
|
||||
mailingAddressUtils.showHiddenElements();
|
||||
});
|
||||
|
||||
this.form.submit(function() {
|
||||
mailingAddressUtils.buildAddressLabel();
|
||||
});
|
||||
|
||||
this.stateSelector.change(function() {
|
||||
mailingAddressUtils.setStateValue();
|
||||
});
|
||||
},
|
||||
|
||||
addressClassIsNonUS: function() {
|
||||
var country = this.countrySelector.val();
|
||||
if ( country.search( 'United States' ) == -1 ) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
buildAddressLabel: function() {
|
||||
if ( mailingAddressUtils.addressClassIsNonUS() ) {
|
||||
this.rdfsLabel.val(this.address1Field.val() + " " + this.cityField.val() + " " + this.countrySelector.val());
|
||||
}
|
||||
else {
|
||||
this.rdfsLabel.val(this.address1Field.val() + " " + this.cityField.val() + " " + this.stateField.val());
|
||||
}
|
||||
},
|
||||
|
||||
processCountryRelatedFields: function() {
|
||||
if ( mailingAddressUtils.addressClassIsNonUS() ) {
|
||||
this.stateLabel.text("Province or Region");
|
||||
this.postalCodeField.attr('size', '40');
|
||||
this.stateSelector.hide();
|
||||
this.stateField.show();
|
||||
this.addrTypeField.val("http://vivoweb.org/ontology/core#Address");
|
||||
}
|
||||
else {
|
||||
this.stateLabel.text("State");
|
||||
this.postalCodeField.attr('size', '8');
|
||||
this.stateField.hide();
|
||||
this.stateSelector.show();
|
||||
this.addrTypeField.val("http://vivoweb.org/ontology/core#USPostalAddress");
|
||||
}
|
||||
},
|
||||
|
||||
showHiddenElements: function() {
|
||||
this.containerDiv.show();
|
||||
this.submitButton.show();
|
||||
this.orSpan.show();
|
||||
},
|
||||
|
||||
setStateValue: function() {
|
||||
this.stateField.val(this.stateSelector.val());
|
||||
},
|
||||
|
||||
// in the ftl we remove the "the" that precedes some countries, so we need to
|
||||
// re-sort them alphabetically
|
||||
sortCountrySelector: function(mode,country) {
|
||||
// Get options from select box
|
||||
var the_options = this.countrySelectorOptions;
|
||||
// sort alphabetically
|
||||
the_options.sort(function(a,b) {
|
||||
if (a.text > b.text) return 1;
|
||||
else if (a.text < b.text) return -1;
|
||||
else return 0
|
||||
})
|
||||
//replace with sorted the_options;
|
||||
this.countrySelector.append( the_options );
|
||||
|
||||
// if it's add mode, add the "select one" option have it be selected;
|
||||
// if it's edit mode, add the "Select one" option but have the correct country selected.
|
||||
// if it's repair mode, add the "Select one" option but only select it if there's no country
|
||||
if ( mode == "add" ) {
|
||||
this.countrySelector.prepend($("<option selected></option>")
|
||||
.attr("value","")
|
||||
.text("Select one"));
|
||||
}
|
||||
else if ( mode == "edit" || country.length > 1 ) {
|
||||
this.countrySelector.prepend($("<option></option>")
|
||||
.attr("value","")
|
||||
.text("Select one"));
|
||||
this.countrySelector.val(country);
|
||||
}
|
||||
else if ( country.length == 0 ) {
|
||||
this.countrySelector.prepend($("<option selected></option>")
|
||||
.attr("value","")
|
||||
.text("Select one"));
|
||||
this.countrySelector.val(country);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,226 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
var manageWebpages = {
|
||||
|
||||
/* *** Initial page setup *** */
|
||||
|
||||
onLoad: function() {
|
||||
|
||||
this.mixIn();
|
||||
this.initPage();
|
||||
},
|
||||
|
||||
mixIn: function() {
|
||||
|
||||
// Get the custom form data from the page
|
||||
$.extend(this, customFormData);
|
||||
},
|
||||
|
||||
// Initial page setup. Called only at page load.
|
||||
initPage: function() {
|
||||
|
||||
this.initWebpageData();
|
||||
|
||||
this.bindEventListeners();
|
||||
|
||||
this.initDragAndDrop();
|
||||
|
||||
if ($('.webpage').length) { // make sure we have at least one webpage
|
||||
// Reorder web pages on page load so that previously unranked items get a rank. Otherwise,
|
||||
// when we add a new web page, it will get put ahead of any previously unranked web pages, instead
|
||||
// of at the end of the list. (It is also helpful to normalize the data before we get started.)
|
||||
this.reorder();
|
||||
}
|
||||
},
|
||||
|
||||
// On page load, associate data with each list item. Then we don't
|
||||
// have to keep retrieving data from or modifying the DOM as we manipulate the
|
||||
// items.
|
||||
initWebpageData: function() {
|
||||
$('.webpage').each(function(index) {
|
||||
$(this).data(webpageData[index]);
|
||||
|
||||
// RY We might still need position to put back an element after reordering
|
||||
// failure. Rank might already have been reset? Check.
|
||||
$(this).data('position', index+1);
|
||||
});
|
||||
},
|
||||
|
||||
bindEventListeners: function() {
|
||||
|
||||
$('.remove').click(function() {
|
||||
manageWebpages.removeWebpage(this);
|
||||
return false;
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
/* *** Ajax initializations *** */
|
||||
|
||||
/* Drag-and-drop */
|
||||
initDragAndDrop: function() {
|
||||
|
||||
var webpages = $('#webpageList');
|
||||
|
||||
// No DD if < 2 items
|
||||
if (webpages.children('li') < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
$('.webpageName').each(function() {
|
||||
$(this).attr('title', 'Drag and drop to reorder web pages');
|
||||
});
|
||||
|
||||
webpages.sortable({
|
||||
cursor: 'move',
|
||||
update: function(event, ui) {
|
||||
manageWebpages.reorder(event, ui);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Reorder webpages. Called on page load and after drag-and-drop and remove.
|
||||
// Event and ui parameters are defined only in the case of drag-and-drop.
|
||||
reorder: function(event, ui) {
|
||||
var webpages = $('li.webpage').map(function(index, el) {
|
||||
return $(this).data('webpageUri');
|
||||
}).get();
|
||||
|
||||
$.ajax({
|
||||
url: manageWebpages.reorderUrl,
|
||||
data: {
|
||||
predicate: manageWebpages.rankPredicate,
|
||||
individuals: webpages
|
||||
},
|
||||
traditional: true, // serialize the array of individuals for the server
|
||||
dataType: 'json',
|
||||
type: 'POST',
|
||||
success: function(data, status, request) {
|
||||
var pos;
|
||||
$('.webpage').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.
|
||||
manageWebpages.setPosition(this, pos);
|
||||
});
|
||||
},
|
||||
error: function(request, status, error) {
|
||||
// ui is undefined on page load and after a webpage 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 = manageWebpages.getPosition(ui.item),
|
||||
nextpos = pos + 1,
|
||||
webpages = $('#webpageList'),
|
||||
next = manageWebpages.findWebpage('position', nextpos);
|
||||
|
||||
if (next.length) {
|
||||
ui.item.insertBefore(next);
|
||||
}
|
||||
else {
|
||||
ui.item.appendTo(webpages);
|
||||
}
|
||||
|
||||
alert('Reordering of web pages failed.');
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
getPosition: function(webpage) {
|
||||
return $(webpage).data('position');
|
||||
},
|
||||
|
||||
setPosition: function(webpage, pos) {
|
||||
$(webpage).data('position', pos);
|
||||
},
|
||||
|
||||
findWebpage: function(key, value) {
|
||||
var matchingWebpage = $(); // if we don't find one, return an empty jQuery set
|
||||
|
||||
$('.webpage').each(function() {
|
||||
var webpage = $(this);
|
||||
if ( webpage.data(key) === value ) {
|
||||
matchingWebpage = webpage;
|
||||
return false; // stop the loop
|
||||
}
|
||||
});
|
||||
|
||||
return matchingWebpage;
|
||||
},
|
||||
|
||||
removeWebpage: function(link) {
|
||||
// RY Upgrade this to a modal window
|
||||
var removeLast = false,
|
||||
message = 'Are you sure you want to remove this web page?';
|
||||
|
||||
if (!confirm(message)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($(link)[0] === $('.remove:last')[0]) {
|
||||
removeLast = true;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: $(link).attr('href'),
|
||||
type: 'POST',
|
||||
data: {
|
||||
deletion: $(link).parents('.webpage').data('webpageUri')
|
||||
},
|
||||
dataType: 'json',
|
||||
context: link, // context for callback
|
||||
complete: function(request, status) {
|
||||
var webpage;
|
||||
|
||||
if (status === 'success') {
|
||||
|
||||
webpage = $(this).parents('.webpage');
|
||||
|
||||
webpage.fadeOut(400, function() {
|
||||
var numWebpages;
|
||||
|
||||
// Remove from the DOM
|
||||
$(this).remove();
|
||||
|
||||
// Actions that depend on the webpage having been removed from the DOM:
|
||||
numWebpages = $('.webpage').length; // retrieve the new length after removing webpage from the DOM
|
||||
|
||||
// If removed item not last, reorder to remove any gaps
|
||||
if (numWebpages > 0 && ! removeLast) {
|
||||
manageWebpages.reorder();
|
||||
}
|
||||
|
||||
// If fewer than two webpages remaining, disable drag-drop
|
||||
if (numWebpages < 2) {
|
||||
manageWebpages.disableDD();
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
alert('Error processing request: web page not removed');
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Disable DD and associated cues if only one item remains
|
||||
disableDD: function() {
|
||||
var webpages = $('#webpageList');
|
||||
|
||||
$('#webpageList').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 webpage. 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 a webpage via Ajax request).
|
||||
*/
|
||||
.removeClass('dd');
|
||||
|
||||
$('.webpageName').removeAttr('title');
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
manageWebpages.onLoad();
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue