diff --git a/productMods/edit/forms/css/addTerminology.css b/productMods/edit/forms/css/addConcept.css similarity index 66% rename from productMods/edit/forms/css/addTerminology.css rename to productMods/edit/forms/css/addConcept.css index fffd9038..54762e40 100644 --- a/productMods/edit/forms/css/addTerminology.css +++ b/productMods/edit/forms/css/addConcept.css @@ -1,29 +1,29 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -.terminology .column { +.concepts .column { float:left; padding-right:3px; } -.terminology .row { +.concepts .row { clear:both; float:left; border-bottom: 1px solid #5F6464; } -.termLabel { +.conceptLabel { width:220px; font-weight:bold; } -.termType { +.conceptType { width: 40px; } -.termDefinition{ +.conceptDefinition{ width:400px; } -form#addTerminologyForm { +form#addConceptForm { display:none; } \ No newline at end of file diff --git a/productMods/edit/forms/js/addConcept.js b/productMods/edit/forms/js/addConcept.js new file mode 100644 index 00000000..f7facc6e --- /dev/null +++ b/productMods/edit/forms/js/addConcept.js @@ -0,0 +1,268 @@ +/* $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'); + this.vocabSource = $('#source'); + //Hidden inputs for eventual submission + this.externalConceptURI = $('#conceptNode'); + this.externalConceptLabel = $('#conceptLabel'); + this.externalConceptSource = $('#conceptSource'); + //remove links + this.removeTermLinks = $('a.remove'); + this.errors = $('#errors'); + }, + + initPage: function() { + this.initConceptData(); + this.bindEventListeners(); + + }, + bindEventListeners: function() { + this.searchSubmit.click(function() { + addConceptForm.submitSearchTerm(); + addConceptForm.clearErrors(); + return false; + }); + + this.form.submit(function() { + return addConceptForm.prepareSubmit(); + }); + + this.addTermButton.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(); + + this.cancel.unbind('click'); + this.cancel.bind('click', function() { + //show only list of existing terms and hide adding term form + addConceptForm.showConceptListOnlyView(); + 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. + initConceptData: function() { + $('.existingConcept').each(function(index) { + $(this).data(existingConceptsData[index]); + $(this).data('position', index+1); + }); + }, + clearSearchResults:function() { + $('#selectedConcept').empty(); + }, + clearErrors:function() { + addConceptForm.errors.empty(); + }, + showConceptListOnlyView: function() { + this.hideForm(); + this.showFormButtonWrapper.show(); + }, + submitSearchTerm: function() { + //Get value of search term + var searchValue = this.searchTerm.val(); + this.entryTerm.val(searchValue); + var dataServiceUrl = addConceptForm.dataServiceUrl + "?searchTerm=" + encodeURIComponent(searchValue); + $.getJSON(dataServiceUrl, function(results) { + if ( results.array.length == 0 ) { + alert("results not correct length"); + } else { + //array is an array of objects representing concept information + //loop through and find all the best matches + + var bestMatchResults = addConceptForm.parseResults(results.array); + var numberMatches = bestMatchResults.length; + var i; + //For each result, display + var htmlAdd = ""; + if(numberMatches > 0) { + htmlAdd = ""; + } else { + htmlAdd+= "

No search results found.

"; + } + $('#selectedConcept').html(htmlAdd); + } + + }); + }, + 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 == "true") { + bestMatchResults.push(concept); + } + } + return bestMatchResults; + }, + addResultsHeader:function() { + var htmlAdd = "
  • Label (Type) Definition
  • "; + return htmlAdd; + }, + hideSearchResults:function() { + this.selectedConcept.hide(); + }, + prepareSubmit:function() { + var checkedElements = $("#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 = checkedTermElement.val(); + conceptLabel = checkedConceptElement.attr("label"); + conceptSource = checkedConceptElement.attr("conceptDefinedBy"); + conceptNodes.push(checkedConcept); + conceptLabels.push(termLabel); + conceptSources.push(conceptSource); + }); + this.externalConceptURI.val(conceptNodes); + this.externalConceptLabel.val(conceptLabels); + this.externalConceptSource.val(conceptSources); + return true; + }, + generateIndividualTermDisplay: function(cuiURI, label, definition, type, definedBy) { + var htmlAdd = "
  • " + + "
    " + + "" + + "" + + label + " (" + type + ")" + + "" + definition + "" + + "
    " + + "
  • "; + return htmlAdd; + }, validateConceptSelection:function(checkedElements) { + var numberElements = checkedElements.length; + if(numberElements < 1) { + addConceptForm.errors.html("

    Please select at least one term from search results to add or click cancel.

    "); + return false; + } + return true; + }, 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; + } + + $.ajax({ + url: $(link).attr('href'), + type: 'POST', + data: { + deletion: $(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'); + } + } + }); + } +}; + +$(document).ready(function() { + addConceptForm.onLoad(); +}); diff --git a/productMods/edit/forms/terminologyAnnotation.jsp b/productMods/edit/forms/terminologyAnnotation.jsp index 8458898d..b4104115 100644 --- a/productMods/edit/forms/terminologyAnnotation.jsp +++ b/productMods/edit/forms/terminologyAnnotation.jsp @@ -10,6 +10,7 @@ <%@ page import="com.hp.hpl.jena.rdf.model.Model" %> <%@ page import="com.hp.hpl.jena.vocabulary.XSD" %> +<%@ page import="com.hp.hpl.jena.vocabulary.RDFS" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyComparator" %> @@ -219,12 +220,12 @@ SPARQL queries for existing values. --%> for ( Individual termNode : terminologyAnnotationNodes ) { request.setAttribute("termNodeUri", termNode.getURI()); //Get label and type only as mirroring authorship where labels but no links for individuals incoldued - DataPropertyStatement termLabelStatement = termNode.getDataPropertyStatement(termLabelUri); + DataPropertyStatement termLabelStatement = termNode.getDataPropertyStatement(RDFS.label.getURI()); String termLabel = termLabelStatement.getData(); - request.setAttribute("termLabel", termLabel); - DataPropertyStatement termTypeStatement = termNode.getDataPropertyStatement(termTypeUri); - String termType = termTypeStatement.getData(); - request.setAttribute("termType", termType); + //request.setAttribute("termLabel", termLabel); + //DataPropertyStatement termTypeStatement = termNode.getDataPropertyStatement(termTypeUri); + //String termType = termTypeStatement.getData(); + request.setAttribute("termType", "fake"); %>
  • <%-- span.author will be used in the next phase, when we display a message that the author has been diff --git a/productMods/templates/freemarker/edit/forms/addAssociatedConcept.ftl b/productMods/templates/freemarker/edit/forms/addAssociatedConcept.ftl index a5f67d92..53a6c599 100644 --- a/productMods/templates/freemarker/edit/forms/addAssociatedConcept.ftl +++ b/productMods/templates/freemarker/edit/forms/addAssociatedConcept.ftl @@ -37,20 +37,22 @@ -