NIHVIVO-3162 and 3245 date time interval form gernerator and template

This commit is contained in:
tworrall 2011-11-21 18:35:09 +00:00
parent e1ae645bd8
commit 3bf1f4b789
3 changed files with 97 additions and 119 deletions

View file

@ -2,15 +2,23 @@
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.rdf.model.Model;
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.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.utils.FrontEndEditingUtils.EditMode;
import edu.cornell.mannlib.vitro.webapp.utils.generators.EditModeUtils;
public class DateTimeIntervalFormGenerator extends
BaseEditConfigurationGenerator implements EditConfigurationGenerator {
@ -58,21 +66,28 @@ public class DateTimeIntervalFormGenerator extends
conf.addSparqlForExistingUris(
"endField-precision", existingEndPrecisionQuery);
conf.addField(new FieldVTwo().setName("startField").
setEditElement(new DateTimeWithPrecisionVTwo(null,
FieldVTwo startField = new FieldVTwo().setName("startField");
startField.setEditElement(new DateTimeWithPrecisionVTwo(startField,
VitroVocabulary.Precision.SECOND.uri(),
VitroVocabulary.Precision.NONE.uri())));
conf.addField(new FieldVTwo().setName("endField").
setEditElement(new DateTimeWithPrecisionVTwo(null,
VitroVocabulary.Precision.SECOND.uri(),
VitroVocabulary.Precision.NONE.uri())));
VitroVocabulary.Precision.NONE.uri()));
FieldVTwo endField = new FieldVTwo().setName("endField");
endField.setEditElement(new DateTimeWithPrecisionVTwo(endField,
VitroVocabulary.Precision.SECOND.uri(),
VitroVocabulary.Precision.NONE.uri()));
conf.addField(startField);
conf.addField(endField);
//Adding additional data, specifically edit mode
addFormSpecificData(conf, vreq);
return conf;
}
final static String n3ForStart =
"?subject <" + toDateTimeInterval + " ?intervalNode . \n" +
"?subject <" + toDateTimeInterval + "> ?intervalNode . \n" +
"?intervalNode a <" + intervalType + "> . \n" +
"?intervalNode <" + intervalToStart + "> ?startNode . \n" +
"?startNode a <" + dateTimeValueType + "> . \n" +
@ -134,8 +149,20 @@ public class DateTimeIntervalFormGenerator extends
"SELECT ?existingEndPrecision WHERE { \n" +
"?subject <" + toDateTimeInterval + "> ?existingIntervalNode . \n" +
"?intervalNode a <" + intervalType + "> . \n" +
"intervalNode <" + intervalToEnd + "> ?endNode . \n" +
"?intervalNode <" + intervalToEnd + "> ?endNode . \n" +
"?endNode a <" + dateTimeValueType + "> . \n" +
"?endNode <" + dateTimePrecision + "> ?existingEndPrecision . }";
//Adding form specific data such as edit mode
public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
HashMap<String, Object> formSpecificData = new HashMap<String, Object>();
formSpecificData.put("editMode", getEditMode(vreq).name().toLowerCase());
editConfiguration.setFormSpecificData(formSpecificData);
}
public EditMode getEditMode(VitroRequest vreq) {
List<String> predicates = new ArrayList<String>();
predicates.add(toDateTimeInterval);
return EditModeUtils.getEditMode(vreq, predicates);
}
}

View file

@ -101,7 +101,7 @@ public class DateTimeValueFormGenerator extends BaseEditConfigurationGenerator
public EditMode getEditMode(VitroRequest vreq) {
List<String> predicates = new ArrayList<String>();
predicates.add(dateTimeValue);
predicates.add(toDateTimeValue);
return EditModeUtils.getEditMode(vreq, predicates);
}
}

View file

@ -1,126 +1,77 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#-- Custom form for adding date time intervals -->
<#-- Template for adding/editing time values -->
<#if editConfig.object?has_content>
<#assign editMode = "edit">
<#else>
<#assign editMode = "add">
</#if>
<#--Retrieve certain edit configuration information-->
<#assign editMode = editConfiguration.pageData.editMode />
<#assign htmlForElements = editConfiguration.pageData.htmlForElements />
<#if editMode == "edit">
<#assign titleVerb="Edit">
<#assign submitButtonText="Edit Date/Time Interval">
<#assign submitButtonText="Edit Date/Time Value">
<#assign disabledVal="disabled">
<#else>
<#assign titleVerb="Create">
<#assign submitButtonText="Create Date/Time Interval">
<#assign submitButtonText="Create Date/Time Value">
<#assign disabledVal=""/>
</#if>startField-
</#if>
<#--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>
<h2>${titleVerb} date time interval for ${subjectName}</h2>
<h2>${titleVerb} date time value 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>
<#--below shows examples of both printing out all error messages and checking the error message for a specific field-->
<#list submissionErrors?keys as errorFieldName>
<#if errorFieldName == "startField">
<#if submissionErrors[errorFieldName]?contains("before")>
The Start interval must be earlier than the End interval.
<#else>
${submissionErrors[errorFieldName]}
</#if>
<br />
<#elseif errorFieldName == "endField">
<#if submissionErrors[errorFieldName]?contains("after")>
The End interval must be later than the Start interval.
<#else>
${submissionErrors[errorFieldName]}
</#if>
</#if>
</#list>
</p>
</section>
</#if>
<form class="customForm" action ="${submitUrl}" class="customForm">
<fieldset class="dateTime" role="group">
<h3>Start</h3>
<label for="startField-year">Year</label>
<input class="text-field" name="startField-year" id="startField-year" type="text" value="" size="4" maxlength="4" role="input"/>
<p></p>
<#--Need to draw edit elements for dates here-->
<#if htmlForElements?keys?seq_contains("startField")>
Start&nbsp; ${htmlForElements["startField"]}
</#if>
<br /><br />
<#if htmlForElements?keys?seq_contains("endField")>
End&nbsp; ${htmlForElements["endField"]}
</#if>
<label for="startField-month">Month</label>
<select name="startField-month" id="startField-month" role="select">
<option value="" role="option" <#if startField-month="">selected</#if>month</option>
<#list startField-months as startFieldMonth>
<option value="startField-month" <#if startFieldMonth = startField-month.uri>selected</#if> >${startFieldMonth.label}</option>
</#list>
</select>
<label for="startField-day">Day</label>
<select name="startField-day" id="startField-day" role="select">
<option value="" role="option"><#if startField-day="">selected</#if>day</option>
<#list startField-day as startField-day>
<option value="startField-day" role="option" <#if startField-day=startField-day.uri>selected</#if> >${startField-day.label}</option>
</#list>
</select>
</fieldset>
<fieldset class="dateTime" role="group">
<label for="startField-hour">Hour</label>
<select name="startField-hour" id="startField-hour" role="select">
<option value="" role="option"><#if startField-hour="">selected</#if>hour</option>
<#list startField-hours as startField-hour>
<option value="startField-hour" role="option" <#if startField-hour=startField-hour.uri>selected</#if> >${startField-hour.label}</option>
</#list>
</select>
<label for="startField-minute">Minutes</label>
<select name="startField-hour" id="startField-hour" role="select">
<option value="" role="option"><#if startField-minute="">selected</#if>minutes</option>
<#list startField-minutes as startField-minute>
<option value="startField-minute" role="option" <#if startField-minute=startField-minute.uri>selected</#if> >${startField-minute.label}</option>
</#list>
</select>
<label for="startField-second">Seconds</label>
<select name="startField-second" id="startField-second" role="select">
<option value="" role="option"><#if startField-second="">selected</#if>seconds</option>
<#list startField-seconds as startField-second>
<option value="startField-second" role="option" <#if startField-second=startField-second.uri>selected</#if> >${startField-second.label}</option>
</#list>
</select>
</fieldset>
<fieldset class="dateTime" role="group">
<h3>End</h3>
<label for="endField-year">Year</label>
<input class="text-field" name="endField-year" id="endField-year" type="text" value="" size="4" maxlength="4" role="input"/>
<label for="endField-month">Month</label>
<select name="endField-month" id="endField-month" role="select">
<option value="" role="option" <#if endField-month="">selected</#if>month</option>
<#list endField-months as endField-month>
<option value="endField-month" <#if endField-month = endField-month.uri>selected</#if> >${endField-month.label}</option>
</#list>
</select>
<label for="endField-day">Day</label>
<select name="endField-day" id="endField-day" role="select">
<option value="" role="option"><#if endField-day="">selected</#if>day</option>
<#list endField-day as endField-day>
<option value="endField-day" role="option" <#if endField-day=endField-day.uri>selected</#if> >${endField-day.label}</option>
</#list>
</select>
</fieldset>
<fieldset class="dateTime" role="group">
<label for="endField-hour">Hour</label>
<select name="endField-hour" id="endField-hour" role="select">
<option value="" role="option"><#if endField-hour="">selected</#if>hour</option>
<#list endField-hours as endField-hour>
<option value="endField-hour" role="option" <#if endField-hour=endField-hour.uri>selected</#if> >${endField-hour.label}</option>
</#list>
</select>
<label for="endField-minute">Minutes</label>
<select name="endField-hour" id="endField-hour" role="select">
<option value="" role="option"><#if endField-minute="">selected</#if>minutes</option>
<#list endField-minutes as endField-minute>
<option value="endField-minute" role="option" <#if endField-minute=endField-minute.uri>selected</#if> >${endField-minute.label}</option>
</#list>
</select>
<label for="endField-second">Seconds</label>
<select name="endField-second" id="endField-second" role="select">
<option value="" role="option"><#if endField-second="">selected</#if>seconds</option>
<#list endField-seconds as endField-second>
<option value="endField-second" role="option" <#if endField-second=endField-second.uri>selected</#if> >${endField-second.label}</option>
</#list>
</select>
</fieldset>
<p class="submit">
<input type="submit" id="submit" value="${submitButtonText}" role="button" />
<input type="hidden" name="editKey" value="${editKey}" />
<input type="submit" id="submit" value="${submitButtonText}" role="button" />
<span class="or"> or </span>
<a class="cancel" href="${editConfiguration.cancelUrl}" title="Cancel">Cancel</a>
</p>
</form>
<span class="or"> or </span>
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/edit/forms/css/customForm.css" />',
'<link rel="stylesheet" href="${urls.base}/edit/forms/css/personHasEducationalTraining.css" />')}
<a class="Cancel" href="${editConfiguration.cancelUrl}" title="Cancel">Cancel</a>
</p>
</form>
${scripts.add('<script type="text/javascript" src="${urls.base}/js/utils.js"></script>',
'<script type="text/javascript" src="${urls.base}/js/customFormUtils.js"></script>',
'<script type="text/javascript" src="${urls.base}/edit/forms/js/customFormWithAutocomplete.js"></script>')}