NIHVIVO-1049 and 2284: generator, template and js for mailingAddress
This commit is contained in:
parent
47b47d0b69
commit
9d520d14b5
3 changed files with 588 additions and 0 deletions
140
productMods/edit/forms/js/mailingAddressUtils.js
Normal file
140
productMods/edit/forms/js/mailingAddressUtils.js
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
var mailingAddressUtils = {
|
||||||
|
|
||||||
|
onLoad: function(mode,country) {
|
||||||
|
this.initObjectReferences();
|
||||||
|
this.bindEventListeners();
|
||||||
|
this.sortCountrySelector(mode,country);
|
||||||
|
|
||||||
|
if ( mode == "add" ) {
|
||||||
|
this.containerDiv.hide();
|
||||||
|
this.submitButton.hide();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.processCountryRelatedFields();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
initObjectReferences: function() {
|
||||||
|
this.form = $('#personHasMailingAddress');
|
||||||
|
|
||||||
|
// The external auth ID field and messages
|
||||||
|
this.countrySelector = $('#country');
|
||||||
|
this.countrySelectorOptions = $('#country option');
|
||||||
|
this.address1Field = $('#addrLineOne');
|
||||||
|
this.cityField = $('#city');
|
||||||
|
this.stateField = $('#state');
|
||||||
|
this.stateSelector= $('#stateSelect');
|
||||||
|
this.stateLabel = $('#stateLabel');
|
||||||
|
this.postalCodeField = $('#postalCode');
|
||||||
|
this.postalCodeLabel = $('#postalCodeLabel');
|
||||||
|
this.subjectField = $('#subjectName');
|
||||||
|
this.rdfsLabel = $('#addrLabel');
|
||||||
|
this.addrTypeField = $('#addressType');
|
||||||
|
this.submitButton = $('#submit');
|
||||||
|
this.containerDiv = $('#addressDetails');
|
||||||
|
this.orSpan = $('span.or');
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
bindEventListeners: function() {
|
||||||
|
this.idCache = {};
|
||||||
|
|
||||||
|
this.countrySelector.change(function() {
|
||||||
|
mailingAddressUtils.processCountryRelatedFields();
|
||||||
|
mailingAddressUtils.showHiddenElements();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.form.submit(function() {
|
||||||
|
mailingAddressUtils.buildAddressLabel();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.stateSelector.change(function() {
|
||||||
|
mailingAddressUtils.setStateValue();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
addressClassIsNonUS: function() {
|
||||||
|
var country = this.countrySelector.val();
|
||||||
|
if ( country.search( 'United States' ) == -1 ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
buildAddressLabel: function() {
|
||||||
|
if ( mailingAddressUtils.addressClassIsNonUS() ) {
|
||||||
|
this.rdfsLabel.val(this.address1Field.val() + " " + this.cityField.val() + " " + this.countrySelector.val());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.rdfsLabel.val(this.address1Field.val() + " " + this.cityField.val() + " " + this.stateField.val());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
processCountryRelatedFields: function() {
|
||||||
|
if ( mailingAddressUtils.addressClassIsNonUS() ) {
|
||||||
|
this.stateLabel.text("Province or Region");
|
||||||
|
this.postalCodeField.attr('size', '40');
|
||||||
|
this.stateSelector.hide();
|
||||||
|
this.stateField.show();
|
||||||
|
this.addrTypeField.val("http://vivoweb.org/ontology/core#Address");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.stateLabel.text("State");
|
||||||
|
this.postalCodeField.attr('size', '8');
|
||||||
|
this.stateField.hide();
|
||||||
|
this.stateSelector.show();
|
||||||
|
this.addrTypeField.val("http://vivoweb.org/ontology/core#USPostalAddress");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
showHiddenElements: function() {
|
||||||
|
this.containerDiv.show();
|
||||||
|
this.submitButton.show();
|
||||||
|
this.orSpan.show();
|
||||||
|
},
|
||||||
|
|
||||||
|
setStateValue: function() {
|
||||||
|
this.stateField.val(this.stateSelector.val());
|
||||||
|
},
|
||||||
|
|
||||||
|
// in the ftl we remove the "the" that precedes some countries, so we need to
|
||||||
|
// re-sort them alphabetically
|
||||||
|
sortCountrySelector: function(mode,country) {
|
||||||
|
// Get options from select box
|
||||||
|
var the_options = this.countrySelectorOptions;
|
||||||
|
// sort alphabetically
|
||||||
|
the_options.sort(function(a,b) {
|
||||||
|
if (a.text > b.text) return 1;
|
||||||
|
else if (a.text < b.text) return -1;
|
||||||
|
else return 0
|
||||||
|
})
|
||||||
|
//replace with sorted the_options;
|
||||||
|
this.countrySelector.append( the_options );
|
||||||
|
|
||||||
|
// if it's add mode, add the "select one" option have it be selected;
|
||||||
|
// if it's edit mode, add the "Select one" option but have the correct country selected.
|
||||||
|
// if it's repair mode, add the "Select one" option but only select it if there's no country
|
||||||
|
if ( mode == "add" ) {
|
||||||
|
this.countrySelector.prepend($("<option selected></option>")
|
||||||
|
.attr("value","")
|
||||||
|
.text("Select one"));
|
||||||
|
}
|
||||||
|
else if ( mode == "edit" || country.length > 1 ) {
|
||||||
|
this.countrySelector.prepend($("<option></option>")
|
||||||
|
.attr("value","")
|
||||||
|
.text("Select one"));
|
||||||
|
this.countrySelector.val(country);
|
||||||
|
}
|
||||||
|
else if ( country.length == 0 ) {
|
||||||
|
this.countrySelector.prepend($("<option selected></option>")
|
||||||
|
.attr("value","")
|
||||||
|
.text("Select one"));
|
||||||
|
this.countrySelector.val(country);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,211 @@
|
||||||
|
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||||
|
|
||||||
|
<#-- this is in request.subject.name -->
|
||||||
|
|
||||||
|
<#-- leaving this edit/add mode code in for reference in case we decide we need it -->
|
||||||
|
|
||||||
|
<#import "lib-vivo-form.ftl" as lvf>
|
||||||
|
|
||||||
|
<#--Retrieve certain edit configuration information-->
|
||||||
|
<#if editConfiguration.objectUri?has_content>
|
||||||
|
<#assign editMode = "edit">
|
||||||
|
<#else>
|
||||||
|
<#assign editMode = "add">
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#assign htmlForElements = editConfiguration.pageData.htmlForElements />
|
||||||
|
|
||||||
|
<#--Retrieve variables needed-->
|
||||||
|
<#assign addrLabelValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "addrLabel") />
|
||||||
|
<#assign addressTypeValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "addressType") />
|
||||||
|
<#assign addrLineOneValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "addrLineOne") />
|
||||||
|
<#assign addrLineTwoValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "addrLineTwo") />
|
||||||
|
<#assign addrLineThreeValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "addrLineThree") />
|
||||||
|
<#assign cityValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "city") />
|
||||||
|
<#assign stateValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "state") />
|
||||||
|
<#assign postalCodeValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "postalCode") />
|
||||||
|
<#assign countryValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "country") />
|
||||||
|
|
||||||
|
<#--If edit submission exists, then retrieve validation errors if they exist-->
|
||||||
|
<#if editSubmission?has_content && editSubmission.submissionExists = true && editSubmission.validationErrors?has_content>
|
||||||
|
<#assign submissionErrors = editSubmission.validationErrors/>
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#if editMode == "edit">
|
||||||
|
<#assign titleVerb="Edit">
|
||||||
|
<#assign submitButtonText="Edit Mailing Address">
|
||||||
|
<#assign disabledVal="disabled">
|
||||||
|
<#else>
|
||||||
|
<#assign titleVerb="Create">
|
||||||
|
<#assign submitButtonText="Create Mailing Address">
|
||||||
|
<#assign disabledVal=""/>
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#assign requiredHint = "<span class='requiredHint'> *</span>" />
|
||||||
|
|
||||||
|
<h2>${titleVerb} mailing address for ${editConfiguration.subjectName}</h2>
|
||||||
|
|
||||||
|
<#--Display error messages if any-->
|
||||||
|
<#if submissionErrors?has_content>
|
||||||
|
<section id="error-alert" role="alert">
|
||||||
|
<img src="${urls.images}/iconAlert.png" width="24" height="24" alert="Error alert icon" />
|
||||||
|
<p>
|
||||||
|
<#--Checking if any required fields are empty-->
|
||||||
|
<#if lvf.submissionErrorExists(editSubmission, "country")>
|
||||||
|
Please select a country.<br />
|
||||||
|
</#if>
|
||||||
|
<#if lvf.submissionErrorExists(editSubmission, "addrLineOne")>
|
||||||
|
Please enter a value in the Address Line 1 field.<br />
|
||||||
|
</#if>
|
||||||
|
<#if lvf.submissionErrorExists(editSubmission, "city")>
|
||||||
|
Please enter a value in the City field.<br />
|
||||||
|
</#if>
|
||||||
|
<#if lvf.submissionErrorExists(editSubmission, "postalCode")>
|
||||||
|
Please enter a value in the Postal Code field.
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<@lvf.unsupportedBrowser urls.base />
|
||||||
|
|
||||||
|
<section id="personHasMailingAddress" role="region">
|
||||||
|
|
||||||
|
<form id="personHasMailingAddress" class="customForm noIE67" action="${submitUrl}" role="add/edit educational training">
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<label for="country" style="margin-bottom:-4px">Country ${requiredHint}</label>
|
||||||
|
<#assign countryOpts = editConfiguration.pageData.country />
|
||||||
|
<select id="country" name="country" >
|
||||||
|
<#list countryOpts?keys as key>
|
||||||
|
<option value="${countryOpts[key]?uncap_first?replace("the ", "")?cap_first}" >
|
||||||
|
${countryOpts[key]?uncap_first?replace("the ", "")?cap_first}
|
||||||
|
</option>
|
||||||
|
</#list>
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<input type="hidden" id="countryEditMode" name="countryEditMode" value="${countryValue}" />
|
||||||
|
|
||||||
|
<div id="addressDetails" >
|
||||||
|
<p>
|
||||||
|
<label for="addrLineOne">Street Address 1 ${requiredHint}</label>
|
||||||
|
<input size="50" type="text" id="addrLineOne" name="addrLineOne" value="${addrLineOneValue}" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<label for="addrLineTwo">Street Address 2</label>
|
||||||
|
<input size="50" type="text" id="addrLineTwo" name="addrLineTwo" value="${addrLineTwoValue}" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<label for="addrLineThree">Street Address 3</label>
|
||||||
|
<input size="50" type="text" id="addrLineThree" name="addrLineThree" value="${addrLineThreeValue}" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<label for="city">City ${requiredHint}</label>
|
||||||
|
<input size="40" type="text" id="city" name="city" value="${cityValue}" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<label for="state" id="stateLabel">State</label>
|
||||||
|
<input size="40" type="text" id="state" name="state" value="${stateValue}" />
|
||||||
|
<select id="stateSelect" name="stateSelect">
|
||||||
|
<option value="" <#if editMode == "add">selected</#if> >Select one</option>
|
||||||
|
<option value="Alabama" <#if stateValue == "Alabama" || stateValue == "AL" >selected</#if> >Alabama</option>
|
||||||
|
<option value="Alaska" <#if stateValue == "Alaska" || stateValue == "AK" >selected</#if> >Alaska</option>
|
||||||
|
<option value="Arizona" <#if stateValue == "Arizona " || stateValue == "AZ" >selected</#if>>Arizona</option>
|
||||||
|
<option value="Arkansas" <#if stateValue == "Arkansas " || stateValue == "AR" >selected</#if>>Arkansas</option>
|
||||||
|
<option value="California" <#if stateValue == "California " || stateValue == "CA" >selected</#if>>California</option>
|
||||||
|
<option value="Colorado" <#if stateValue == "Colorado " || stateValue == "CO" >selected</#if>>Colorado</option>
|
||||||
|
<option value="Connecticut" <#if stateValue == "Connecticut " || stateValue == "CT" >selected</#if>>Connecticut</option>
|
||||||
|
<option value="Delaware" <#if stateValue == "Delaware " || stateValue == "DE" >selected</#if>>Delaware</option>
|
||||||
|
<option value="Florida" <#if stateValue == "Florida " || stateValue == "FA" >selected</#if>>Florida</option>
|
||||||
|
<option value="Georgia" <#if stateValue == "Georgia " || stateValue == "GA" >selected</#if>>Georgia</option>
|
||||||
|
<option value="Hawaii" <#if stateValue == "Hawaii" || stateValue == "HI" >selected</#if>>Hawaii</option>
|
||||||
|
<option value="Idaho" <#if stateValue == "Idaho " || stateValue == "ID" >selected</#if>>Idaho</option>
|
||||||
|
<option value="Illinois" <#if stateValue == "Illinois " || stateValue == "IL" >selected</#if>>Illinois</option>
|
||||||
|
<option value="Indiana" <#if stateValue == "Indiana " || stateValue == "IN" >selected</#if>>Indiana</option>
|
||||||
|
<option value="Iowa" <#if stateValue == "Iowa " || stateValue == "IA" >selected</#if>>Iowa</option>
|
||||||
|
<option value="Kansas" <#if stateValue == "Kansas" || stateValue == "KS" >selected</#if>> Kansas</option>
|
||||||
|
<option value="Kentucky" <#if stateValue == "Kentucky" || stateValue == "KY" >selected</#if>>Kentucky</option>
|
||||||
|
<option value="Louisiana" <#if stateValue == "Louisiana" || stateValue == "LA" >selected</#if>>Louisiana</option>
|
||||||
|
<option value="Maine" <#if stateValue == "Maine" || stateValue == "ME" >selected</#if>>Maine</option>
|
||||||
|
<option value="Maryland" <#if stateValue == "Maryland" || stateValue == "MD" >selected</#if>>Maryland</option>
|
||||||
|
<option value="Massachusetts" <#if stateValue == "Massachusetts" || stateValue == "MA" >selected</#if>>Massachusetts</option>
|
||||||
|
<option value="Michigan" <#if stateValue == "Michigan" || stateValue == "MI" >selected</#if>>Michigan</option>
|
||||||
|
<option value="Minnesota" <#if stateValue == "Minnesota" || stateValue == "MN" >selected</#if>>Minnesota</option>
|
||||||
|
<option value="Mississippi" <#if stateValue == "Mississippi" || stateValue == "MS" >selected</#if>>Mississippi</option>
|
||||||
|
<option value="Missouri" <#if stateValue == "Missouri" || stateValue == "MO" >selected</#if>>Missouri</option>
|
||||||
|
<option value="Montana" <#if stateValue == "Montana" || stateValue == "MT" >selected</#if>>Montana</option>
|
||||||
|
<option value="Nebraska" <#if stateValue == "Nebraska" || stateValue == "NE" >selected</#if>>Nebraska</option>
|
||||||
|
<option value="Nevada" <#if stateValue == "Nevada" || stateValue == "NV" >selected</#if>>Nevada</option>
|
||||||
|
<option value="New Hampshire" <#if stateValue == "New Hampshire" || stateValue == "NH" >selected</#if>>New Hampshire</option>
|
||||||
|
<option value="New Jersey" <#if stateValue == "New Jersey" || stateValue == "NJ" >selected</#if>>New Jersey</option>
|
||||||
|
<option value="New Mexico" <#if stateValue == "New Mexico" || stateValue == "NM" >selected</#if>>New Mexico</option>
|
||||||
|
<option value="New York" <#if stateValue == "New York" || stateValue == "NY" >selected</#if>>New York</option>
|
||||||
|
<option value="North Carolina<" <#if stateValue == "North Carolina" || stateValue == "NC" >selected</#if>>North Carolina</option>
|
||||||
|
<option value="North Dakota" <#if stateValue == "North Dakota" || stateValue == "ND" >selected</#if>>North Dakota</option>
|
||||||
|
<option value="Ohio" <#if stateValue == "Ohio" || stateValue == "OH" >selected</#if>>Ohio</option>
|
||||||
|
<option value="Oklahoma" <#if stateValue == "Oklahoma" || stateValue == "OK" >selected</#if>>Oklahoma</option>
|
||||||
|
<option value="Oregon" <#if stateValue == "Oregon" || stateValue == "OR" >selected</#if>>Oregon</option>
|
||||||
|
<option value="Pennsylvania" <#if stateValue == "Pennsylvania" || stateValue == "PA" >selected</#if>>Pennsylvania</option>
|
||||||
|
<option value="Rhode Island" <#if stateValue == "Rhode Island" || stateValue == "RI" >selected</#if>>Rhode Island</option>
|
||||||
|
<option value="South Carolina" <#if stateValue == "South Carolina" || stateValue == "SC" >selected</#if>>South Carolina</option>
|
||||||
|
<option value="South Dakota" <#if stateValue == "South Dakota" || stateValue == "SD" >selected</#if>>South Dakota</option>
|
||||||
|
<option value="Tennessee" <#if stateValue == "Tennessee" || stateValue == "TN" >selected</#if>>Tennessee</option>
|
||||||
|
<option value="Texas" <#if stateValue == "Texas" || stateValue == "TX" >selected</#if>>Texas</option>
|
||||||
|
<option value="Utah" <#if stateValue == "Utah" || stateValue == "UT" >selected</#if>>Utah</option>
|
||||||
|
<option value="Vermont" <#if stateValue == "Vermont" || stateValue == "VT" >selected</#if>>Vermont</option>
|
||||||
|
<option value="Virginia" <#if stateValue == "Virginia" || stateValue == "VA" >selected</#if>>Virginia</option>
|
||||||
|
<option value="Washington" <#if stateValue == "Washington" || stateValue == "WA" >selected</#if>>Washington</option>
|
||||||
|
<option value="West Virginia" <#if stateValue == "West Virginia" || stateValue == "WV" >selected</#if>>West Virginia</option>
|
||||||
|
<option value="Wisconsin" <#if stateValue == "Wisconsin" || stateValue == "WI" >selected</#if>>Wisconsin</option>
|
||||||
|
<option value="Wyoming" <#if stateValue == "Wyoming" || stateValue == "WY" >selected</#if>>Wyoming</option>
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<label for="postalCode" id="postalCodeLabel">Postal Code ${requiredHint}</label>
|
||||||
|
<input size="8" type="text" id="postalCode" name="postalCode" value="${postalCodeValue}" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="hidden" id="addrLabel" name="addrLabel" value="${addrLabelValue}" />
|
||||||
|
<input type="hidden" id="addressType" name="addressType" value="${addressTypeValue}" />
|
||||||
|
<input type="hidden" id="editKey" name="editKey" value="${editKey}"/>
|
||||||
|
|
||||||
|
<p class="submit">
|
||||||
|
<input type="submit" id="submit" value="${submitButtonText}"/><span class="or"> or </span>
|
||||||
|
<a class="cancel" href="${cancelUrl}" title="Cancel">Cancel</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p id="requiredLegend" class="requiredHint">* required fields</p>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(document).ready(function(){
|
||||||
|
mailingAddressUtils.onLoad("${editMode}","${countryValue}");
|
||||||
|
});
|
||||||
|
</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/extensions/String.js"></script>',
|
||||||
|
'<script type="text/javascript" src="${urls.base}/js/browserUtils.js"></script>',
|
||||||
|
'<script type="text/javascript" src="${urls.base}/edit/forms/js/mailingAddressUtils.js"></script>',
|
||||||
|
'<script type="text/javascript" src="${urls.base}/js/jquery_plugins/jquery.bgiframe.pack.js"></script>')}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,237 @@
|
||||||
|
/* $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.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||||
|
import com.hp.hpl.jena.vocabulary.XSD;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeIntervalValidationVTwo;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeWithPrecisionVTwo;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.generators.EditModeUtils;
|
||||||
|
|
||||||
|
public class PersonHasMailingAddressGenerator extends VivoBaseGenerator implements
|
||||||
|
EditConfigurationGenerator {
|
||||||
|
|
||||||
|
final static String addressClass = vivoCore + "Address";
|
||||||
|
final static String countryPred = vivoCore + "addressCountry";
|
||||||
|
final static String countryClass = vivoCore + "Country";
|
||||||
|
final static String addrLine1Pred =vivoCore+"address1" ;
|
||||||
|
final static String addrLine2Pred =vivoCore+"address2" ;
|
||||||
|
final static String addrLine3Pred =vivoCore+"address3" ;
|
||||||
|
final static String cityPred =vivoCore+"addressCity" ;
|
||||||
|
final static String statePred =vivoCore+"addressState" ;
|
||||||
|
final static String postalCodePred =vivoCore+"addressPostalCode" ;
|
||||||
|
final static String mailingAddressPred =vivoCore+"mailingAddress" ;
|
||||||
|
|
||||||
|
public PersonHasMailingAddressGenerator() {}
|
||||||
|
|
||||||
|
// There are 4 modes that this form can be in:
|
||||||
|
// 1. Add. There is a subject and a predicate but no position and
|
||||||
|
// nothing else.
|
||||||
|
//
|
||||||
|
// 2. Normal edit where everything should already be filled out.
|
||||||
|
// There is a subject, a object and an individual on
|
||||||
|
// the other end of the object's core:personInOrganization stmt.
|
||||||
|
//
|
||||||
|
// 3. Repair a bad role node. There is a subject, predicate and object
|
||||||
|
// but there is no individual on the other end of the object's
|
||||||
|
// core:personInOrganization stmt. This should be similar to an add
|
||||||
|
// but the form should be expanded.
|
||||||
|
//
|
||||||
|
// 4. Really bad node. multiple core:personInOrganization statements.
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq,
|
||||||
|
HttpSession session) {
|
||||||
|
|
||||||
|
EditConfigurationVTwo conf = new EditConfigurationVTwo();
|
||||||
|
|
||||||
|
initBasics(conf, vreq);
|
||||||
|
initPropertyParameters(vreq, session, conf);
|
||||||
|
initObjectPropForm(conf, vreq);
|
||||||
|
|
||||||
|
conf.setTemplate("personHasMailingAddress.ftl");
|
||||||
|
|
||||||
|
conf.setVarNameForSubject("person");
|
||||||
|
conf.setVarNameForPredicate("predicate");
|
||||||
|
conf.setVarNameForObject("address");
|
||||||
|
|
||||||
|
conf.setN3Required( Arrays.asList( n3ForNewAddress,
|
||||||
|
addrLabelAssertion,
|
||||||
|
addressTypeAssertion ) );
|
||||||
|
conf.setN3Optional( Arrays.asList( addrLineOneAssertion, addrLineTwoAssertion, addrLineThreeAssertion, cityAssertion, stateAssertion, countryAssertion, postalCodeAssertion ) );
|
||||||
|
|
||||||
|
conf.addNewResource("address", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||||
|
|
||||||
|
//uris in scope: none
|
||||||
|
//literals in scope: none
|
||||||
|
|
||||||
|
conf.setUrisOnform(Arrays.asList("addressType"));
|
||||||
|
conf.setLiteralsOnForm(Arrays.asList("addrLineOne", "addrLineTwo", "addrLineThree", "city", "postalCode", "addrLabel","country", "state" ));
|
||||||
|
|
||||||
|
conf.addSparqlForExistingLiteral("addrLabel", addrLabelQuery);
|
||||||
|
conf.addSparqlForExistingLiteral("addrLineOne", addrLineOneQuery);
|
||||||
|
conf.addSparqlForExistingLiteral("addrLineTwo", addrLineTwoQuery);
|
||||||
|
conf.addSparqlForExistingLiteral("addrLineThree", addrLineThreeQuery);
|
||||||
|
conf.addSparqlForExistingLiteral("city", cityQuery);
|
||||||
|
conf.addSparqlForExistingLiteral("postalCode", postalCodeQuery);
|
||||||
|
conf.addSparqlForExistingLiteral("state", stateQuery);
|
||||||
|
conf.addSparqlForExistingLiteral("country", countryQuery);
|
||||||
|
|
||||||
|
conf.addSparqlForExistingUris("addressType", addressTypeQuery);
|
||||||
|
|
||||||
|
conf.addField( new FieldVTwo().
|
||||||
|
setName("country").
|
||||||
|
setOptionsType( FieldVTwo.OptionsType.INDIVIDUALS_VIA_VCLASS ).
|
||||||
|
setObjectClassUri( countryClass ) .
|
||||||
|
setValidators( list("nonempty") )
|
||||||
|
);
|
||||||
|
|
||||||
|
conf.addField( new FieldVTwo().
|
||||||
|
setName("addrLineOne")
|
||||||
|
.setRangeDatatypeUri( XSD.xstring.toString() ).
|
||||||
|
setValidators( list("nonempty") )
|
||||||
|
);
|
||||||
|
|
||||||
|
conf.addField( new FieldVTwo().
|
||||||
|
setName("addrLineTwo")
|
||||||
|
.setRangeDatatypeUri( XSD.xstring.toString() ).
|
||||||
|
setValidators( list("datatype:" + XSD.xstring.toString()) )
|
||||||
|
);
|
||||||
|
|
||||||
|
conf.addField( new FieldVTwo().
|
||||||
|
setName("addrLineThree")
|
||||||
|
.setRangeDatatypeUri( XSD.xstring.toString() ).
|
||||||
|
setValidators( list("datatype:" + XSD.xstring.toString()) )
|
||||||
|
);
|
||||||
|
|
||||||
|
conf.addField( new FieldVTwo().
|
||||||
|
setName("postalCode")
|
||||||
|
.setRangeDatatypeUri( XSD.xstring.toString() ).
|
||||||
|
setValidators( list("nonempty") )
|
||||||
|
);
|
||||||
|
|
||||||
|
conf.addField( new FieldVTwo().
|
||||||
|
setName("city")
|
||||||
|
.setRangeDatatypeUri( XSD.xstring.toString() ).
|
||||||
|
setValidators( list("nonempty") )
|
||||||
|
);
|
||||||
|
|
||||||
|
conf.addField( new FieldVTwo().
|
||||||
|
setName("state")
|
||||||
|
.setRangeDatatypeUri( XSD.xstring.toString() ).
|
||||||
|
setValidators( list("datatype:" + XSD.xstring.toString()) )
|
||||||
|
);
|
||||||
|
|
||||||
|
conf.addField( new FieldVTwo().
|
||||||
|
setName("addrLabel")
|
||||||
|
.setRangeDatatypeUri( XSD.xstring.toString() ).
|
||||||
|
setValidators( list("datatype:" + XSD.xstring.toString()) )
|
||||||
|
);
|
||||||
|
|
||||||
|
conf.addField( new FieldVTwo().
|
||||||
|
setName("addressType").
|
||||||
|
setOptionsType(FieldVTwo.OptionsType.CHILD_VCLASSES).
|
||||||
|
setObjectClassUri(addressClass)
|
||||||
|
);
|
||||||
|
|
||||||
|
conf.addValidator(new AntiXssValidation());
|
||||||
|
|
||||||
|
prepare(vreq, conf);
|
||||||
|
return conf;
|
||||||
|
}
|
||||||
|
|
||||||
|
final static String n3ForNewAddress =
|
||||||
|
"@prefix vivo: <" + vivoCore + "> . \n\n" +
|
||||||
|
"?person vivo:mailingAddress ?address . \n" +
|
||||||
|
"?address a vivo:Address . \n" +
|
||||||
|
// "?address a ?addressType . \n" +
|
||||||
|
"?address vivo:mailingAddressFor ?person . \n" ;
|
||||||
|
|
||||||
|
final static String addrLineOneAssertion =
|
||||||
|
"?address <"+ addrLine1Pred +"> ?addrLineOne .";
|
||||||
|
|
||||||
|
final static String addrLineTwoAssertion =
|
||||||
|
"?address <"+ addrLine2Pred +"> ?addrLineTwo .";
|
||||||
|
|
||||||
|
final static String addrLineThreeAssertion =
|
||||||
|
"?address <"+ addrLine3Pred +"> ?addrLineThree .";
|
||||||
|
|
||||||
|
final static String cityAssertion =
|
||||||
|
"?address <"+ cityPred +"> ?city .";
|
||||||
|
|
||||||
|
final static String postalCodeAssertion =
|
||||||
|
"?address <"+ postalCodePred +"> ?postalCode .";
|
||||||
|
|
||||||
|
final static String stateAssertion =
|
||||||
|
"?address <"+ statePred +"> ?state .";
|
||||||
|
|
||||||
|
final static String countryAssertion =
|
||||||
|
"?address <" + countryPred + "> ?country .";
|
||||||
|
|
||||||
|
final static String addrLabelAssertion =
|
||||||
|
"?address <" + label + "> ?addrLabel .";
|
||||||
|
|
||||||
|
final static String addressTypeAssertion =
|
||||||
|
"?address a ?addressType .";
|
||||||
|
|
||||||
|
final static String addrLabelQuery =
|
||||||
|
"SELECT ?existingAddrLabel WHERE { \n" +
|
||||||
|
// " ?person <"+ mailingAddressPred +"> ?address . \n" +
|
||||||
|
" ?address <" + label + "> ?existingAddrLabel . \n" +
|
||||||
|
"}";
|
||||||
|
|
||||||
|
final static String addrLineOneQuery =
|
||||||
|
"SELECT ?existingaddrLineOne WHERE {\n"+
|
||||||
|
// "?person <"+ mailingAddressPred +"> ?address . \n" +
|
||||||
|
"?address <"+ addrLine1Pred +"> ?existingaddrLineOne . }";
|
||||||
|
|
||||||
|
final static String addrLineTwoQuery =
|
||||||
|
"SELECT ?existingaddrLineTwo WHERE {\n"+
|
||||||
|
// "?person <"+ mailingAddressPred +"> ?address . \n" +
|
||||||
|
"?address <"+ addrLine2Pred +"> ?existingaddrLineTwo . }";
|
||||||
|
|
||||||
|
final static String addrLineThreeQuery =
|
||||||
|
"SELECT ?existingaddrLineThree WHERE {\n"+
|
||||||
|
// "?person <"+ mailingAddressPred +"> ?address . \n" +
|
||||||
|
"?address <"+ addrLine3Pred +"> ?existingaddrLineThree . }";
|
||||||
|
|
||||||
|
final static String cityQuery =
|
||||||
|
"SELECT ?existingCity WHERE {\n"+
|
||||||
|
// "?person <"+ mailingAddressPred +"> ?address . \n" +
|
||||||
|
"?address <"+ cityPred +"> ?existingCity . }";
|
||||||
|
|
||||||
|
final static String stateQuery =
|
||||||
|
"SELECT ?existingState WHERE {\n"+
|
||||||
|
// "?person <"+ mailingAddressPred +"> ?address . \n" +
|
||||||
|
"?address <"+ statePred +"> ?existingState . }";
|
||||||
|
|
||||||
|
final static String postalCodeQuery =
|
||||||
|
"SELECT ?existingPostalCode WHERE {\n"+
|
||||||
|
// "?person <"+ mailingAddressPred +"> ?address . \n" +
|
||||||
|
"?address <"+ postalCodePred +"> ?existingPostalCode . }";
|
||||||
|
|
||||||
|
final static String countryQuery =
|
||||||
|
"SELECT ?existingCountry WHERE {\n"+
|
||||||
|
// "?person <"+ mailingAddressPred +"> ?address . \n" +
|
||||||
|
"?address <"+ countryPred +"> ?existingCountry . }";
|
||||||
|
|
||||||
|
final static String addressTypeQuery =
|
||||||
|
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
|
||||||
|
"SELECT ?existingAddressType WHERE { \n" +
|
||||||
|
"?address vitro:mostSpecificType ?existingAddressType . }";
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue