VIVO-208: all fields now displayed when custom forms are rendered; customized 2-stage forms will still work as before

This commit is contained in:
tworrall 2013-08-05 15:12:24 -04:00
parent 578bc95b63
commit 37142c0231
2 changed files with 143 additions and 88 deletions

View file

@ -116,8 +116,20 @@ public class AutocompleteController extends VitroAjaxController {
} else {
name = (String) nameRaw;
}
SearchResult result = new SearchResult(name, uri);
Object mostSpecificType = doc.get(VitroSearchTermNames.MOST_SPECIFIC_TYPE_URIS);
String mst = null;
if (mostSpecificType instanceof List<?>) {
@SuppressWarnings("unchecked")
List<String> mstList = (List<String>) mostSpecificType;
mst = mstList.get(0);
} else {
mst = (String) mostSpecificType;
}
SearchResult result = new SearchResult(name, uri, mst);
results.add(result);
log.debug("results = " + results.toString());
} catch(Exception e){
log.error("problem getting usable individuals from search " +
"hits" + e.getMessage());
@ -153,9 +165,7 @@ public class AutocompleteController extends VitroAjaxController {
SolrQuery query = new SolrQuery();
query.setStart(0)
.setRows(DEFAULT_MAX_HIT_COUNT);
setNameQuery(query, queryStr, vreq);
// Filter by type
String typeParam = (String) vreq.getParameter(PARAM_RDFTYPE);
String multipleTypesParam = (String) vreq.getParameter(PARAM_MULTIPLE_RDFTYPE);
@ -163,7 +173,7 @@ public class AutocompleteController extends VitroAjaxController {
addFilterQuery(query, typeParam, multipleTypesParam);
}
query.setFields(VitroSearchTermNames.NAME_RAW, VitroSearchTermNames.URI); // fields to retrieve
query.setFields(VitroSearchTermNames.NAME_RAW, VitroSearchTermNames.URI, VitroSearchTermNames.MOST_SPECIFIC_TYPE_URIS); // fields to retrieve
// Can't sort on multivalued field, so we sort the results in Java when we get them.
// query.setSortField(VitroSearchTermNames.NAME_LOWERCASE, SolrQuery.ORDER.asc);
@ -188,8 +198,6 @@ public class AutocompleteController extends VitroAjaxController {
String filterQuery = StringUtils.join(filterQueries, " OR ");
query.addFilterQuery(filterQuery);
}
}
private void setNameQuery(SolrQuery query, String queryStr, HttpServletRequest request) {
@ -197,7 +205,6 @@ public class AutocompleteController extends VitroAjaxController {
if (StringUtils.isBlank(queryStr)) {
log.error("No query string");
}
String tokenizeParam = (String) request.getParameter("tokenize");
boolean tokenize = "true".equals(tokenizeParam);
@ -292,10 +299,12 @@ public class AutocompleteController extends VitroAjaxController {
public class SearchResult implements Comparable<Object> {
private String label;
private String uri;
private String msType;
SearchResult(String label, String uri) {
SearchResult(String label, String uri, String msType) {
this.label = label;
this.uri = uri;
this.msType = msType;
}
public String getLabel() {
@ -314,10 +323,18 @@ public class AutocompleteController extends VitroAjaxController {
return JSONObject.quote(uri);
}
public String getMsType() {
return msType;
}
public String getJsonMsType() {
return JSONObject.quote(msType);
}
Map<String, String> toMap() {
Map<String, String> map = new HashMap<String, String>();
map.put("label", label);
map.put("uri", uri);
map.put("msType", msType);
return map;
}

View file

@ -55,6 +55,11 @@ var customForm = {
// the verify popup window. Although there could be multiple verifyMatch objects
// selecting one and binding the event works for all of them
this.verifyMatch = this.form.find('.verifyMatch');
this.defaultAcType = ""; // will be set in setType() first time through
this.templateDefinedAcTypes = false;
if ( this.acTypes != undefined ) {
this.templateDefinedAcTypes = true;
}
// find all the acSelector input elements
this.acSelectors = [] ;
@ -126,6 +131,10 @@ var customForm = {
this.initFormView();
// Set the initial autocomplete help text in the acSelector fields.
$.each(this.acSelectors, function() {
customForm.addAcHelpText($(this));
});
},
initFormView: function() {
@ -314,6 +323,7 @@ var customForm = {
// Not sure why, but we need an explicit json parse here.
var results = $.parseJSON(xhr.responseText),
filteredResults = customForm.filterAcResults(results);
customForm.acCache[request.term] = filteredResults;
response(filteredResults);
}
@ -321,6 +331,9 @@ var customForm = {
},
select: function(event, ui) {
customForm.showAutocompleteSelection(ui.item.label, ui.item.uri, $(selectedObj));
if ( $(selectedObj).attr('acGroupName') == customForm.typeSelector.attr('acGroupName') ) {
customForm.typeSelector.val(ui.item.msType);
}
}
});
},
@ -420,9 +433,15 @@ var customForm = {
// provides a way to monitor selection in other js files, e.g. to hide fields upon selection
$acDiv.addClass("userSelected");
// If the form has a type selector, add type name to label in add mode. In edit mode, use typeSelectorSpan
// html. The second case is an "else if" and not an else because the template may not be passing the label
// to the acSelection macro or it may not be using the macro at all and the label is hard-coded in the html.
// If the form has a type selector, add type name to label in add mode. In edit mode,
// use typeSelectorSpan html. The second case is an "else if" and not an else because
// the template may not be passing the label to the acSelection macro or it may not be
// using the macro at all and the label is hard-coded in the html.
// ** With release 1.6 and display of all fields, more labels are hard-coded in html.
// ** So check if there's a label before doing anything else.
if ( $acDiv.find('label').html().length === 0 ) {
if ( this.typeSelector.length && ($acDiv.attr('acGroupName') == this.typeSelector.attr('acGroupName')) ) {
$acDiv.find('label').html('Selected ' + this.typeName + ':');
}
@ -432,6 +451,7 @@ var customForm = {
else if ( $acDiv.find('label').html() == '' ) {
$acDiv.find('label').html('Selected ' + this.multipleTypeNames[$(selectedObj).attr('acGroupName')] + ':');
}
}
$acDiv.show();
$acDiv.find("input").val(uri);
@ -447,7 +467,6 @@ var customForm = {
//On initialization in this mode, submit button is disabled
this.enableSubmit();
}
},
undoAutocompleteSelection: function(selectedObj) {
@ -487,6 +506,7 @@ var customForm = {
}
else {
$acSelectionObj = $(selectedObj);
customForm.typeSelector.val('');
}
$acSelector = this.getAcSelector($acSelectionObj);
@ -530,7 +550,6 @@ var customForm = {
// Note: we still need this in edit mode, to set the text values.
setType: function() {
var selectedType;
// If there's no type selector, these values have been specified in customFormData,
// and will not change over the life of the form.
if (!this.typeSelector.length) {
@ -543,6 +562,10 @@ var customForm = {
selectedType = this.typeSelector.find(':selected');
var acTypeKey = this.typeSelector.attr('acGroupName');
if ( this.templateDefinedAcTypes && !this.defaultAcType.length ) {
this.defaultAcType = this.acTypes[acTypeKey];
}
if (selectedType.val().length) {
this.acTypes[acTypeKey] = selectedType.val();
this.typeName = selectedType.html();
@ -551,15 +574,20 @@ var customForm = {
$acSelect.find('label').html( customForm.selectedString + ' ' + this.typeName + ':');
}
}
// reset to empty values; may not need
// reset to empty values;
else {
delete this.acTypes[acTypeKey];
this.typeName = '';
if ( this.templateDefinedAcTypes ) {
this.acTypes[acTypeKey] = this.defaultAcType;
}
else {
this.acTypes = new Object();
}
this.typeName = this.defaultTypeName;
}
},
// Set field labels based on type selection. Although these won't change in edit
// mode, it's easier to specify the text here than in the jsp.
// mode, it's easier to specify the text here than in the ftl.
setLabels: function() {
var typeName = this.getTypeNameForLabels();
@ -575,10 +603,20 @@ var customForm = {
// or in repair mode in a two-step form with no type selected. Use the default type
// name specified in the form data.
if ( !selectedObj || !this.hasMultipleTypeNames ) {
return this.acTypes ? this.typeName : this.capitalize(this.defaultTypeName);
if ( this.acTypes && this.typeName ) {
return this.typeName;
}
else {
return this.capitalize(this.defaultTypeName);
}
}
else if ( selectedObj && ( $(selectedObj).attr('acGroupName') == this.typeSelector.attr('acGroupName') ) ) {
return this.acTypes ? this.typeName : this.capitalize(this.defaultTypeName);
if ( this.acTypes && this.typeName ) {
return this.typeName;
}
else {
return this.capitalize(this.defaultTypeName);
}
}
else {
var name = customForm.multipleTypeNames[$(selectedObj).attr('id')];