From 4e216e9360c63e10813645ce1cb26e4376ce70f5 Mon Sep 17 00:00:00 2001 From: tworrall Date: Mon, 9 Dec 2013 16:18:02 -0500 Subject: [PATCH 1/2] related to VIVO-628, there was no validation on the datetimeinterval form when no years are specified --- webapp/languages/es_GO/i18n/all_es_GO.properties | 2 ++ .../n3editing/VTwo/DateTimeIntervalValidationVTwo.java | 7 +++++-- webapp/web/i18n/all.properties | 4 +++- .../freemarker/edit/forms/dateTimeIntervalForm.ftl | 5 ++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/webapp/languages/es_GO/i18n/all_es_GO.properties b/webapp/languages/es_GO/i18n/all_es_GO.properties index 5544aafb0..6e9016109 100644 --- a/webapp/languages/es_GO/i18n/all_es_GO.properties +++ b/webapp/languages/es_GO/i18n/all_es_GO.properties @@ -862,3 +862,5 @@ view_labels_capitalized = Ver etiquetas view_labels_for = Ver Etiquetas de select_an_existing_document = Seleccione un documento existente + +datetime_year_required = Intervalos de fecha / hora deben empezar por un año. Ingrese una Fecha de inicio, un fin de año o los dos. \ No newline at end of file diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/DateTimeIntervalValidationVTwo.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/DateTimeIntervalValidationVTwo.java index aa3ca0ed6..65f5f420e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/DateTimeIntervalValidationVTwo.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/DateTimeIntervalValidationVTwo.java @@ -63,8 +63,11 @@ public class DateTimeIntervalValidationVTwo implements N3ValidatorVTwo { // errors.put(startFieldName, "If there is an end date, there should be a start date"); // return errors; // } - - + // We need to ensure that the user has entered a start year or end year -- tlw72 + if ( literalListIsNull(formStartYear) && literalListIsNull(formStartYear) ) { + errors.put(startFieldName, "Date/time intervals must begin with a year. Please enter a start year or an end year."); + return errors; + } //Assuming form start year and form end year are working in conjunction with multiple values int index; if (!literalListIsNull(formStartYear) && !literalListIsNull(formEndYear)) { diff --git a/webapp/web/i18n/all.properties b/webapp/web/i18n/all.properties index 818c27c4a..0fce78764 100644 --- a/webapp/web/i18n/all.properties +++ b/webapp/web/i18n/all.properties @@ -875,4 +875,6 @@ selection_in_process = Your selection is being processed. view_labels_capitalized = View Labels view_labels_for = View Labels for -select_an_existing_document = Select an existing document \ No newline at end of file +select_an_existing_document = Select an existing document + +datetime_year_required = Date/time intervals must begin with a year. Enter either a Start Year, an End Year or both. \ No newline at end of file diff --git a/webapp/web/templates/freemarker/edit/forms/dateTimeIntervalForm.ftl b/webapp/web/templates/freemarker/edit/forms/dateTimeIntervalForm.ftl index c7139c5c6..f61c42b61 100644 --- a/webapp/web/templates/freemarker/edit/forms/dateTimeIntervalForm.ftl +++ b/webapp/web/templates/freemarker/edit/forms/dateTimeIntervalForm.ftl @@ -58,7 +58,7 @@ <#if htmlForElements?keys?seq_contains("endField")> ${i18n().end_capitalized}  ${htmlForElements["endField"]} - + *${i18n().datetime_year_required}

@@ -69,8 +69,7 @@

-${stylesheets.add('', - '')} +${stylesheets.add('')} ${scripts.add('', '')} \ No newline at end of file From 772cde59e50c2e675b7783f51cf97e1b55272a48 Mon Sep 17 00:00:00 2001 From: tworrall Date: Mon, 9 Dec 2013 16:59:03 -0500 Subject: [PATCH 2/2] additional datetimeinterval validation tweaking --- .../VTwo/DateTimeIntervalValidationVTwo.java | 19 ++++++++++++++++--- .../DateTimeIntervalFormGenerator.java | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/DateTimeIntervalValidationVTwo.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/DateTimeIntervalValidationVTwo.java index 65f5f420e..ae87a397c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/DateTimeIntervalValidationVTwo.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/DateTimeIntervalValidationVTwo.java @@ -27,6 +27,7 @@ public class DateTimeIntervalValidationVTwo implements N3ValidatorVTwo { private String startFieldName; private String endFieldName; + private String templateName; private String startValueName; private String endValueName; @@ -43,6 +44,16 @@ public class DateTimeIntervalValidationVTwo implements N3ValidatorVTwo { endPrecisionName = endFieldName + "-precision"; } + public DateTimeIntervalValidationVTwo(String startFieldName, String endFieldName, String template){ + this.templateName = template; + this.startFieldName = startFieldName; + this.endFieldName = endFieldName; + startValueName = startFieldName + "-value"; + endValueName = endFieldName + "-value"; + startPrecisionName = startFieldName + "-precision"; + endPrecisionName = endFieldName + "-precision"; + } + public Map validate(EditConfigurationVTwo editConfig, MultiValueEditSubmission editSub) { Map> existingLiterals = editConfig.getLiteralsInScope(); @@ -64,9 +75,11 @@ public class DateTimeIntervalValidationVTwo implements N3ValidatorVTwo { // return errors; // } // We need to ensure that the user has entered a start year or end year -- tlw72 - if ( literalListIsNull(formStartYear) && literalListIsNull(formStartYear) ) { - errors.put(startFieldName, "Date/time intervals must begin with a year. Please enter a start year or an end year."); - return errors; + if ( templateName != null && templateName.equals("dateTimeIntervalForm.ftl")) { + if ( literalListIsNull(formStartYear) && literalListIsNull(formEndYear) ) { + errors.put(startFieldName, "Date/time intervals must begin with a year. Please enter a start year, an end year or both."); + return errors; + } } //Assuming form start year and form end year are working in conjunction with multiple values int index; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DateTimeIntervalFormGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DateTimeIntervalFormGenerator.java index 22c8fcb5c..7daa9743c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DateTimeIntervalFormGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DateTimeIntervalFormGenerator.java @@ -92,7 +92,7 @@ public class DateTimeIntervalFormGenerator extends conf.addField(startField); conf.addField(endField); //Need to add validators - conf.addValidator(new DateTimeIntervalValidationVTwo("startField","endField")); + conf.addValidator(new DateTimeIntervalValidationVTwo("startField","endField","dateTimeIntervalForm.ftl")); //Adding additional data, specifically edit mode addFormSpecificData(conf, vreq); }