diff --git a/productMods/templates/freemarker/edit/forms/js/customFormWithAutocomplete.js b/productMods/templates/freemarker/edit/forms/js/customFormWithAutocomplete.js index 937375da..51f6ff04 100644 --- a/productMods/templates/freemarker/edit/forms/js/customFormWithAutocomplete.js +++ b/productMods/templates/freemarker/edit/forms/js/customFormWithAutocomplete.js @@ -76,6 +76,8 @@ var customForm = { this.acTypes = new Object(); } + + // forms with multi ac fields will have this defined in customFormData // this is helpful when the type to display is not a single word, like "Subject Area" this.hasMultipleTypeNames = false; @@ -94,6 +96,12 @@ var customForm = { if (!this.editMode) { this.editMode = 'add'; // edit vs add: default to add } + + //Flag to clear label of selected object from autocomplete on submission + //This is used in the case where the label field is submitted only when a new object is being created + if(!this.flagClearLabelForExisting) { + this.flagClearLabelForExisting = null; + } if (!this.formSteps) { // Don't override formSteps specified in form data if ( !this.fullViewOnly.length || this.editMode === 'edit' || this.editMode === 'repair' ) { @@ -105,6 +113,10 @@ var customForm = { } } + if(!this.doNotRemoveOriginalObject) { + this.doNotRemoveOriginalObject = false; + } + this.bindEventListeners(); $.each(this.acSelectors, function() { @@ -245,6 +257,27 @@ var customForm = { }); this.form.submit(function() { + //TODO: update the following + //custom submission for edit mode in case where existing object should not remove original object + //if edit mode and custom flag and original uri not equivalent to new uri, then + //clear out label field entirely + //originally checked edit mode but want to add to work the same way in case an existing object + //is selected since the n3 now governs how labels + if(customForm.flagClearLabelForExisting != null) { + //Find the elements that have had autocomplete executed, tagged by class "userSelected" + customForm.form.find('.acSelection.userSelected').each(function() { + var groupName = $(this).attr("acGroupName"); + var inputs = $(this).find("input.acUriReceiver"); + //if user selected, then clear out the label since we only + //want to submit the label as value on form if it's a new label + if(inputs.length && $(inputs.eq(0)).attr(customForm.flagClearLabelForExisting)) { + //if(inputs.length) { + $("input.acSelector[acGroupName='" + groupName + "']").each(function() { + $(this).val(''); + }); + } + }); + } customForm.deleteAcHelpText(); }); }, @@ -262,7 +295,7 @@ var customForm = { //Reset the URI of the input to one that says new uri required //That will be overwritten if value selected from autocomplete //We do this everytime the user types anything in the autocomplete box - customForm.initDefaultNewURI(selectedObj); + customForm.initDefaultBlankURI(selectedObj); if (request.term in customForm.acCache) { // console.log('found term in cache'); response(customForm.acCache[request.term]); @@ -475,7 +508,7 @@ var customForm = { resetAcSelection: function(selectedObj) { this.hideFields($(selectedObj)); $(selectedObj).removeClass('userSelected'); - $(selectedObj).find("input.acUriReceiver").val(this.newUriSentinel); + $(selectedObj).find("input.acUriReceiver").val(this.blankSentinel); $(selectedObj).find("span").text(''); $(selectedObj).find("a.verifyMatch").attr('href', this.baseHref); }, @@ -592,12 +625,13 @@ var customForm = { this.button.removeAttr('disabled'); this.button.removeClass('disabledSubmit'); }, - initDefaultNewURI:function(selectedObj) { - //get uri input for selected object and set to value indicating - //this will require a new uri when submitted if the uri is not replaced - //with one selected from autocomplete selection + initDefaultBlankURI:function(selectedObj) { + //get uri input for selected object and set to value specified as "blank sentinel" + //If blank sentinel is neither null nor an empty string, this means if the user edits an + //existing relationship to an object and does not select anything from autocomplete + //from that object, the old relationship will be removed in n3 processing var $acDiv = this.acSelections[$(selectedObj).attr('acGroupName')]; - $acDiv.find("input").val(customForm.newUriSentinel); + $acDiv.find("input").val(customForm.blankSentinel); } }; diff --git a/productMods/templates/freemarker/edit/forms/personHasAdvisingRelationship.ftl b/productMods/templates/freemarker/edit/forms/personHasAdvisingRelationship.ftl index 76a5fcd9..da978611 100644 --- a/productMods/templates/freemarker/edit/forms/personHasAdvisingRelationship.ftl +++ b/productMods/templates/freemarker/edit/forms/personHasAdvisingRelationship.ftl @@ -1,11 +1,16 @@ <#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> -<#assign newUriSentinel = "" /> -<#if editConfigurationConstants?has_content> - <#assign newUriSentinel = editConfigurationConstants["NEW_URI_SENTINEL"] /> - -<#-- this is in request.subject.name --> +<#--The blank sentinel indicates what value should be put in a URI when no autocomplete result has been selected. +If the blank value is non-null or non-empty, n3 editing for an existing object will remove the original relationship +if nothing is selected for that object--> -<#-- leaving this edit/add mode code in for reference in case we decide we need it --> +<#assign blankSentinel = "" /> +<#if editConfigurationConstants?has_content && editConfigurationConstants?keys?seq_contains("BLANK_SENTINEL")> + <#assign blankSentinel = editConfigurationConstants["BLANK_SENTINEL"] /> + + +<#--This flag is for clearing the label field on submission for an existing object being selected from autocomplete. +Set this flag on the input acUriReceiver where you would like this behavior to occur. --> +<#assign flagClearLabelForExisting = "flagClearLabelForExisting" /> <#import "lib-vivo-form.ftl" as lvf> @@ -25,7 +30,7 @@ <#assign lastNameValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "lastName") /> <#assign advisingRelTypeValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "advisingRelType") /> <#assign advisingRelLabelValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "advisingRelLabel") /> -<#assign subjAreaValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "subjArea") /> +<#assign subjAreaValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "existingSubjArea") /> <#assign subjAreaLabelValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "subjAreaLabel") /> <#assign degreeValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "degree") /> <#assign acFilterForIndividuals = "['" + editConfiguration.subjectUri + "']" /> @@ -135,7 +140,9 @@ (Verify this match or change selection)

- + <#--When no autocomplete value is selected, the value of this field will be set to the 'blank sentinel'. + When an autocomplete value is selected, the 'flagClearLabelField' attribute will clear out the associated label input. --> +

@@ -178,8 +185,8 @@ - <#assign sparqlQueryUrl = "${urls.base}/ajax/sparqlQuery" > +<#assign doNotRemoveOriginalObject = "true" />