updates for enabling autocomplete editing and n3editing to work.
This commit is contained in:
parent
95ae1cfdd9
commit
6963c32e6b
3 changed files with 82 additions and 27 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -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"] />
|
||||
</#if>
|
||||
<#-- 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"] />
|
||||
</#if>
|
||||
|
||||
<#--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 @@
|
|||
<a href="" class="verifyMatch" title="verify match">(Verify this match</a> or
|
||||
<a href="#" class="changeSelection" id="changeSelection">change selection)</a>
|
||||
</p>
|
||||
<input class="acUriReceiver" type="hidden" id="subjAreaUri" name="subjArea" value="${subjAreaValue}" />
|
||||
<#--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. -->
|
||||
<input class="acUriReceiver" type="hidden" id="subjAreaUri" name="existingSubjArea" value="${subjAreaValue}" ${flagClearLabelForExisting}="true"/>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
|
@ -178,8 +185,8 @@
|
|||
</form>
|
||||
|
||||
</section>
|
||||
|
||||
<#assign sparqlQueryUrl = "${urls.base}/ajax/sparqlQuery" >
|
||||
<#assign doNotRemoveOriginalObject = "true" />
|
||||
<script type="text/javascript">
|
||||
var customFormData = {
|
||||
acUrl: '${urls.base}/autocomplete?tokenize=true&stem=true',
|
||||
|
@ -191,8 +198,11 @@ var customFormData = {
|
|||
sparqlQueryUrl: '${sparqlQueryUrl}',
|
||||
acFilterForIndividuals: ${acFilterForIndividuals},
|
||||
baseHref: '${urls.base}/individual?uri=',
|
||||
newUriSentinel : '${newUriSentinel}'
|
||||
blankSentinel: '${blankSentinel}',
|
||||
flagClearLabelForExisting: '${flagClearLabelForExisting}'
|
||||
};
|
||||
<#--Removing this line for now from above : newUriSentinel : '${newUriSentinel}',-->
|
||||
<#--Also removed this: ,doNotRemoveOriginalObject: '${doNotRemoveOriginalObject}'-->
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
|
|
@ -72,13 +72,14 @@ public class PersonHasAdvisingRelationshipGenerator extends VivoBaseGenerator im
|
|||
degreeAssertion,
|
||||
firstNameAssertion,
|
||||
lastNameAssertion,
|
||||
n3ForSubjAreaAssertion + "\n" + subjAreaLabelAssertion, //putting these statements together to prevent an empty label from generating a new URI
|
||||
n3ForExistingSubjAreaAssertion, //relationship to existing subject area
|
||||
n3ForNewSubjAreaAssertion, //this will include all the new information that needs to be captured
|
||||
n3ForStart,
|
||||
n3ForEnd ) );
|
||||
|
||||
conf.addNewResource("advisingRelationship", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
conf.addNewResource("advisee", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
conf.addNewResource("subjArea", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
conf.addNewResource("newSubjArea", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
conf.addNewResource("intervalNode", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
conf.addNewResource("startNode", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
conf.addNewResource("endNode", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
|
@ -86,7 +87,7 @@ public class PersonHasAdvisingRelationshipGenerator extends VivoBaseGenerator im
|
|||
//uris in scope: none
|
||||
//literals in scope: none
|
||||
|
||||
conf.setUrisOnform(Arrays.asList("advisingRelType", "subjArea", "degree", "advisee"));
|
||||
conf.setUrisOnform(Arrays.asList("advisingRelType", "existingSubjArea", "degree", "advisee"));
|
||||
conf.setLiteralsOnForm(Arrays.asList("advisingRelLabel", "subjAreaLabel", "adviseeLabel", "firstName", "lastName" ));
|
||||
|
||||
conf.addSparqlForExistingLiteral("advisingRelLabel", advisingRelLabelQuery);
|
||||
|
@ -99,7 +100,7 @@ public class PersonHasAdvisingRelationshipGenerator extends VivoBaseGenerator im
|
|||
conf.addSparqlForExistingLiteral("endField-value", existingEndDateQuery);
|
||||
|
||||
conf.addSparqlForExistingUris("advisingRelType", advisingRelTypeQuery);
|
||||
conf.addSparqlForExistingUris("subjArea", subjAreaQuery);
|
||||
conf.addSparqlForExistingUris("existingSubjArea", subjAreaQuery);
|
||||
conf.addSparqlForExistingUris("advisee", adviseeQuery);
|
||||
conf.addSparqlForExistingUris("degree", degreeQuery);
|
||||
conf.addSparqlForExistingUris("intervalNode",existingIntervalNodeQuery);
|
||||
|
@ -134,7 +135,7 @@ public class PersonHasAdvisingRelationshipGenerator extends VivoBaseGenerator im
|
|||
);
|
||||
|
||||
conf.addField( new FieldVTwo().
|
||||
setName("subjArea").
|
||||
setName("existingSubjArea").
|
||||
setOptionsType(FieldVTwo.OptionsType.INDIVIDUALS_VIA_VCLASS).
|
||||
setObjectClassUri( subjAreaClass )
|
||||
);
|
||||
|
@ -220,12 +221,22 @@ public class PersonHasAdvisingRelationshipGenerator extends VivoBaseGenerator im
|
|||
final static String degreeAssertion =
|
||||
"?advisingRelationship <"+ degreePred +"> ?degree .";
|
||||
|
||||
final static String n3ForSubjAreaAssertion =
|
||||
"?advisingRelationship <"+ subjAreaPred +"> ?subjArea .\n" +
|
||||
"?subjArea a <" + subjAreaClass + "> . ";
|
||||
final static String n3ForSubjAreaType =
|
||||
"?subjArea a <" + subjAreaClass + "> . ";
|
||||
|
||||
final static String subjAreaLabelAssertion =
|
||||
"?subjArea <"+ label + "> ?subjAreaLabel . ";
|
||||
//This is for an existing subject area
|
||||
//Where we only need the existing subject area label
|
||||
final static String n3ForExistingSubjAreaAssertion =
|
||||
"?advisingRelationship <"+ subjAreaPred +"> ?existingSubjArea .";
|
||||
//For new subject area, we include all new information
|
||||
//new subject area should always be a new resource
|
||||
//and the following should only get evaluated
|
||||
//when there is something in the label
|
||||
|
||||
final static String n3ForNewSubjAreaAssertion =
|
||||
"?advisingRelationship <"+ subjAreaPred +"> ?newSubjArea . \n" +
|
||||
"?newSubjArea <"+ label + "> ?subjAreaLabel . \n" +
|
||||
"?newSubjArea a <" + subjAreaClass + "> . ";
|
||||
|
||||
final static String n3ForStart =
|
||||
"?advisingRelationship <" + advisingRelToInterval + "> ?intervalNode . \n" +
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue