diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java index 16842d9db..294970953 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java @@ -84,6 +84,10 @@ public class AutocompleteController extends VitroAjaxController { hasMultipleTypes = true; } } + } else { + //if the type parameter is null, no range is specified and individuals of any class might be returned + //in this case, it would be useful to show the most specific type of the individual + hasMultipleTypes = true; } SearchQuery query = getQuery(qtxt, vreq); diff --git a/webapp/web/templates/freemarker/edit/forms/js/customFormWithAutocomplete.js b/webapp/web/templates/freemarker/edit/forms/js/customFormWithAutocomplete.js index 3eaeeeaca..63213e972 100644 --- a/webapp/web/templates/freemarker/edit/forms/js/customFormWithAutocomplete.js +++ b/webapp/web/templates/freemarker/edit/forms/js/customFormWithAutocomplete.js @@ -3,7 +3,9 @@ var customForm = { /* *** Initial page setup *** */ - + //Setting the default Concept class here + //This would need to change if we update the ontology, etc. + conceptClassURI: "http://www.w3.org/2004/02/skos/core#Concept", onLoad: function() { if (this.disableFormInUnsupportedBrowsers()) { @@ -323,9 +325,12 @@ var customForm = { // Not sure why, but we need an explicit json parse here. var results = $.parseJSON(xhr.responseText); var filteredResults = customForm.filterAcResults(results); - - if ( customForm.acTypes[$(selectedObj).attr('acGroupName')] == "http://www.w3.org/2004/02/skos/core#Concept" ) { + /* + if ( customForm.acTypes[$(selectedObj).attr('acGroupName')] == customForm.conceptClassURI ) { filteredResults = customForm.removeConceptSubclasses(filteredResults); + }*/ + if(customForm.doRemoveConceptSubclasses()) { + filteredResults = customForm.removeConceptSubclasses(filteredResults); } customForm.acCache[request.term] = filteredResults; @@ -342,6 +347,15 @@ var customForm = { }); }, + //Method to check whether we need to filter to individuals with a most specific type = Concept or other allowed subclasses + doRemoveConceptSubclasses:function() { + //if this array of allowable subclasses was declared annd there is at least one element in it + if(customForm.limitToConceptClasses && customForm.limitToConceptClasses.length) { + return true; + } + return false; + }, + // Store original or base text with elements that will have text substitutions. // Generally the substitution cannot be made on the current value, since that value // may have changed from the original. So we store the original text with the element to @@ -426,34 +440,52 @@ var customForm = { customForm.acFilter = customForm.acFilter.concat(this.acFilterForIndividuals); }, - + + //Updating this code to utilize an array to removeConceptSubclasses: function(array) { - $(array).each(function(i) { - var allMsTypes = this["allMsTypes"]; - var removeElement = false; - if(allMsTypes.length == 1 && this["msType"] != "http://www.w3.org/2004/02/skos/core#Concept") { - //Remove from array - removeElement = true; - } else if(allMsTypes.length > 1) { - //If there are multiple most specific types returned, check if none of them equals concept - removeElement = true; - var j; - for(j = 0; j < allMsTypes.length; j++) { - //this refers to the element itself - if(allMsTypes[j] == "http://www.w3.org/2004/02/skos/core#Concept") { - //don't remove this element if one of the most specific types is a concept - removeElement = false; - break; - } - } - } - - if(removeElement) { - array.splice(i, 1); - } - }); + //Using map because the resulting array might be different from the original + array = jQuery.map(array, function(arrayValue, i) { + var allMsTypes = arrayValue["allMsTypes"]; + var removeElement = false; + if(allMsTypes.length == 1 && !customForm.isAllowedConceptSubclass(arrayValue["msType"])) { + //Remove from array + removeElement = true; + } else if(allMsTypes.length > 1) { + //If there are multiple most specific types returned, check if none of them equals concept + removeElement = true; + var j; + + for(j = 0; j < allMsTypes.length; j++) { + //this refers to the element itself + if(customForm.isAllowedConceptSubclass(allMsTypes[j])) { + //don't remove this element if one of the most specific types is a concept + removeElement = false; + break; + } + } + } + + if(removeElement) + return null; + else + return arrayValue; + }); + + return array; }, + isAllowedConceptSubclass:function(classURI) { + if(customForm.limitToConceptClasses && customForm.limitToConceptClasses.length) { + var len = customForm.limitToConceptClasses.length; + var i; + for(i = 0; i < len; i++) { + if(classURI == customForm.limitToConceptClasses[i]) { + return true; + } + } + } + return false; + }, showAutocompleteSelection: function(label, uri, selectedObj) { // hide the acSelector field and set it's value to the selected ac item diff --git a/webapp/web/templates/freemarker/edit/forms/menuManagement.ftl b/webapp/web/templates/freemarker/edit/forms/menuManagement.ftl index b4c960ffa..6b5c79521 100644 --- a/webapp/web/templates/freemarker/edit/forms/menuManagement.ftl +++ b/webapp/web/templates/freemarker/edit/forms/menuManagement.ftl @@ -57,7 +57,7 @@