moving auto complete forms to VIVO b/c rely on autocomplete javascript that exists in VIVO - updating customFormWithAutocomplete.js to support these forms

This commit is contained in:
hjkhjk54 2011-12-06 18:47:33 +00:00
parent 71dd74f5c3
commit e06d58ca90
3 changed files with 221 additions and 3 deletions

View file

@ -78,6 +78,14 @@ var customForm = {
} }
} }
//Handles special case such as autocomplete which allows for editing with autocomplete
//By default set to false
if(!this.supportEdit) {
this.supportEdit = false;
} else {
this.supportEdit = true;
}
this.bindEventListeners(); this.bindEventListeners();
this.initAutocomplete(); this.initAutocomplete();
@ -94,11 +102,13 @@ var customForm = {
// Put this case first, because in edit mode with // Put this case first, because in edit mode with
// validation errors we just want initFormFullView. // validation errors we just want initFormFullView.
if (this.editMode == 'edit' || this.editMode == 'repair') { if ((!this.supportEdit) && (this.editMode == 'edit' || this.editMode == 'repair')) {
this.initFormFullView(); this.initFormFullView();
} }
else if (this.findValidationErrors()) { else if (this.findValidationErrors()) {
this.initFormWithValidationErrors(); this.initFormWithValidationErrors();
} else if(this.supportEdit && this.editMode == 'edit') {
this.initFormWithSupportEdit();
} }
// If type is already selected when the page loads (Firefox retains value // If type is already selected when the page loads (Firefox retains value
// on a refresh), go directly to full view. Otherwise user has to reselect // on a refresh), go directly to full view. Otherwise user has to reselect
@ -165,6 +175,11 @@ var customForm = {
} }
}, },
initFormWithSupportEdit: function() {
this.initFormWithValidationErrors();
//Hide verify match when edit mode
this.verifyMatch.hide();
},
// Bind event listeners that persist over the life of the page. Event listeners // Bind event listeners that persist over the life of the page. Event listeners
// that depend on the view should be initialized in the view setup method. // that depend on the view should be initialized in the view setup method.
@ -209,7 +224,7 @@ var customForm = {
initAutocomplete: function() { initAutocomplete: function() {
if (this.editMode === 'edit') { if (this.editMode === 'edit' && !this.supportEdit) {
return; return;
} }
@ -350,7 +365,10 @@ var customForm = {
this.acSelector.val(label); this.acSelector.val(label);
this.acSelectionInfo.html(label); this.acSelectionInfo.html(label);
this.verifyMatch.attr('href', this.verifyMatch.data('baseHref') + uri); this.verifyMatch.attr('href', this.verifyMatch.data('baseHref') + uri);
//Verify match is hidden in edit mode and support edit so unhide it
if(this.editMode == 'edit' && this.supportEdit) {
this.verifyMatch.show();
}
this.setButtonText('existing'); this.setButtonText('existing');
this.cancel.unbind('click'); this.cancel.unbind('click');
@ -432,6 +450,11 @@ var customForm = {
return; return;
} }
//if support select editing, keep button label same
if(this.supportEdit) {
return;
}
typeText = this.getTypeNameForLabels(); typeText = this.getTypeNameForLabels();
// Creating new related individual // Creating new related individual

View file

@ -0,0 +1,109 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#--Assign variables from editConfig-->
<#assign rangeOptions = editConfiguration.pageData.objectVar />
<#assign rangeOptionsExist = false />
<#if (rangeOptions?keys?size > 0)>
<#assign rangeOptionsExist = true/>
</#if>
<#assign objectTypes = editConfiguration.pageData.objectTypes />
<#assign sparqlForAcFilter = editConfiguration.pageData.sparqlForAcFilter />
<#assign editMode = editConfiguration.pageData.editMode />
<#if editMode = "edit" >
<#assign titleVerb = "Edit" />
<#assign objectLabel = editConfiguration.pageData.objectLabel />
<#assign selectedObjectUri = editConfiguration.objectUri />
<#else>
<#assign titleVerb = "Add" >
<#assign objectLabel = "" />
<#assign selectedObjectUri = ""/>
</#if>
<h2>${editConfiguration.formTitle}</h2>
<#if editConfiguration.propertySelectFromExisting = true>
<#if rangeOptionsExist = true >
<form class="customForm" action = "${submitUrl}">
<input type="hidden" name="editKey" id="editKey" value="${editKey}" role="input" />
<#if editConfiguration.propertyPublicDescription?has_content>
<p>${editConfiguration.propertyPublicDescription}</p>
</#if>
<#---This section should become autocomplete instead-->
<p>
<label for="relatedIndLabel"> ${titleVerb} <span class='requiredHint'> *</span></label>
<input class="acSelector" size="50" type="text" id="relatedIndLabel" name="objectLabel" value="${objectLabel}" />
</p>
<div class="acSelection">
<p class="inline">
<label>Selected:</label>
<span class="acSelectionInfo"></span>
<a href="/vivo/individual?uri="
class="verifyMatch">(Verify this match)</a>
<a href="#"
class="cancel">(Change selection)</a>
</p> <input class="acUriReceiver" type="hidden" id="objectVar" name="objectVar" value="${selectedObjectUri}" />
</div>
<#--The above section should be autocomplete-->
<p>
<input type="submit" id="submit" value="${editConfiguration.submitLabel}" role="button "/>
<span class="or"> or </span>
<a title="Cancel" class="cancel" href="${cancelUrl}">Cancel</a>
</p>
</form>
<#else>
<p> There are no entries in the system from which to select. </p>
</#if>
</#if>
<#if editConfiguration.propertyOfferCreateNewOption = true>
<#include "defaultOfferCreateNewOptionForm.ftl">
</#if>
<#if editConfiguration.propertySelectFromExisting = false && editConfiguration.propertyOfferCreateNewOption = false>
<p>This property is currently configured to prohibit editing. </p>
</#if>
<#if editConfiguration.includeDeletionForm = true>
<#include "defaultDeletePropertyForm.ftl">
</#if>
<#assign sparqlQueryUrl = "${urls.base}/ajax/sparqlQuery" >
<script type="text/javascript">
var customFormData = {
acUrl: '${urls.base}/autocomplete?tokenize=true',
acType: '${objectTypes}',
acMultipleTypes: 'true',
submitButtonTextType: 'simple',
editMode: '${editMode}',
typeName:'object',
supportEdit: 'true',
sparqlForAcFilter: '${sparqlForAcFilter}',
sparqlQueryUrl: '${sparqlQueryUrl}',
defaultTypeName: 'thing' // used in repair mode to generate button text
};
</script>
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/js/jquery-ui/css/smoothness/jquery-ui-1.8.9.custom.css" />')}
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/edit/forms/css/customForm.css" />')}
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/edit/forms/css/customFormWithAutocomplete.css" />')}
${scripts.add('<script type="text/javascript" src="${urls.base}/js/jquery-ui/js/jquery-ui-1.8.9.custom.min.js"></script>',
'<script type="text/javascript" src="${urls.base}/js/customFormUtils.js"></script>',
'<script type="text/javascript" src="${urls.base}/js/browserUtils.js"></script>',
'<script type="text/javascript" src="${urls.base}/edit/forms/js/customFormWithAutocomplete.js"></script>')}

View file

@ -0,0 +1,86 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils;
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode;
/**
* Generates the edit configuration for a default property form.
*
*/
public class AutocompleteObjectPropertyFormGenerator extends DefaultObjectPropertyFormGenerator {
//The only thing that changes here are the templates
private Log log = LogFactory.getLog(AutocompleteObjectPropertyFormGenerator.class);
private String objectPropertyTemplate = "autoCompleteObjectPropForm.ftl";
private String dataPropertyTemplate = "autoCompleteDataPropForm.ftl";
@Override
public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
HashMap<String, Object> formSpecificData = new HashMap<String, Object>();
//Get the edit mode
formSpecificData.put("editMode", getEditMode(vreq).toString().toLowerCase());
//We also need the type of the object itself
formSpecificData.put("objectTypes", StringUtils.join(getTypes(vreq), ","));
//Get label for individual if it exists
if(EditConfigurationUtils.getObjectIndividual(vreq) != null) {
String objectLabel = EditConfigurationUtils.getObjectIndividual(vreq).getName();
formSpecificData.put("objectLabel", objectLabel);
}
formSpecificData.put("sparqlForAcFilter", getSparqlForAcFilter(vreq));
editConfiguration.setTemplate(objectPropertyTemplate);
editConfiguration.setFormSpecificData(formSpecificData);
}
private List<String> getTypes(VitroRequest vreq) {
Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq);
String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
WebappDaoFactory wDaoFact = vreq.getWebappDaoFactory();
List<String> types = new ArrayList<String>();
List <VClass> vclasses = new ArrayList<VClass>();
vclasses = wDaoFact.getVClassDao().getVClassesForProperty(subject.getVClassURI(),predicateUri);
for(VClass v: vclasses) {
types.add(v.getURI());
}
return types;
}
public EditMode getEditMode(VitroRequest vreq) {
//In this case, the original jsp didn't rely on FrontEndEditingUtils
//but instead relied on whether or not the object Uri existed
String objectUri = EditConfigurationUtils.getObjectUri(vreq);
EditMode editMode = FrontEndEditingUtils.EditMode.ADD;
if(objectUri != null && !objectUri.isEmpty()) {
editMode = FrontEndEditingUtils.EditMode.EDIT;
}
return editMode;
}
public String getSparqlForAcFilter(VitroRequest vreq) {
String subject = EditConfigurationUtils.getSubjectUri(vreq);
String predicate = EditConfigurationUtils.getPredicateUri(vreq);
//Get all objects for existing predicate, filters out results from addition and edit
String query = "SELECT ?objectVar WHERE { " +
"<" + subject + "> <" + predicate + "> ?objectVar .} ";
return query;
}
}