diff --git a/productMods/edit/forms/js/customFormWithAutocomplete.js b/productMods/edit/forms/js/customFormWithAutocomplete.js index e7f46230..8ee7ef2c 100644 --- a/productMods/edit/forms/js/customFormWithAutocomplete.js +++ b/productMods/edit/forms/js/customFormWithAutocomplete.js @@ -77,6 +77,14 @@ var customForm = { this.formSteps = 2; } } + + //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(); @@ -94,11 +102,13 @@ var customForm = { // Put this case first, because in edit mode with // validation errors we just want initFormFullView. - if (this.editMode == 'edit' || this.editMode == 'repair') { + if ((!this.supportEdit) && (this.editMode == 'edit' || this.editMode == 'repair')) { this.initFormFullView(); } else if (this.findValidationErrors()) { this.initFormWithValidationErrors(); + } else if(this.supportEdit && this.editMode == 'edit') { + this.initFormWithSupportEdit(); } // 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 @@ -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 // that depend on the view should be initialized in the view setup method. @@ -209,7 +224,7 @@ var customForm = { initAutocomplete: function() { - if (this.editMode === 'edit') { + if (this.editMode === 'edit' && !this.supportEdit) { return; } @@ -350,7 +365,10 @@ var customForm = { this.acSelector.val(label); this.acSelectionInfo.html(label); 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.cancel.unbind('click'); @@ -431,6 +449,11 @@ var customForm = { if (this.editMode === 'edit') { return; } + + //if support select editing, keep button label same + if(this.supportEdit) { + return; + } typeText = this.getTypeNameForLabels(); diff --git a/productMods/templates/freemarker/edit/forms/autoCompleteObjectPropForm.ftl b/productMods/templates/freemarker/edit/forms/autoCompleteObjectPropForm.ftl new file mode 100644 index 00000000..4ee228ec --- /dev/null +++ b/productMods/templates/freemarker/edit/forms/autoCompleteObjectPropForm.ftl @@ -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/> + +<#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 = ""/> + + + +

${editConfiguration.formTitle}

+ +<#if editConfiguration.propertySelectFromExisting = true> + <#if rangeOptionsExist = true > +
+ + <#if editConfiguration.propertyPublicDescription?has_content> +

${editConfiguration.propertyPublicDescription}

+ + + + + <#---This section should become autocomplete instead--> +

+ + +

+ +
+

+ + + (Verify this match) + (Change selection) +

+
+ + + <#--The above section should be autocomplete--> + + +

+ + or + Cancel +

+
+ <#else> +

There are no entries in the system from which to select.

+ + + +<#if editConfiguration.propertyOfferCreateNewOption = true> +<#include "defaultOfferCreateNewOptionForm.ftl"> + + + +<#if editConfiguration.propertySelectFromExisting = false && editConfiguration.propertyOfferCreateNewOption = false> +

This property is currently configured to prohibit editing.

+ + + +<#if editConfiguration.includeDeletionForm = true> +<#include "defaultDeletePropertyForm.ftl"> + + + +<#assign sparqlQueryUrl = "${urls.base}/ajax/sparqlQuery" > + + + + + +${stylesheets.add('')} + ${stylesheets.add('')} + ${stylesheets.add('')} + + + ${scripts.add('', + '', + '', + '')} diff --git a/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AutocompleteObjectPropertyFormGenerator.java b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AutocompleteObjectPropertyFormGenerator.java new file mode 100644 index 00000000..11ce332d --- /dev/null +++ b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AutocompleteObjectPropertyFormGenerator.java @@ -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 formSpecificData = new HashMap(); + //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 getTypes(VitroRequest vreq) { + Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq); + String predicateUri = EditConfigurationUtils.getPredicateUri(vreq); + WebappDaoFactory wDaoFact = vreq.getWebappDaoFactory(); + List types = new ArrayList(); + List vclasses = new ArrayList(); + 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; + } + +}