From 7db46abff98a697cdfaf3ed6018fcf6dc8af6cd0 Mon Sep 17 00:00:00 2001
From: tworrall
Date: Wed, 25 Apr 2012 14:40:24 +0000
Subject: [PATCH] last name field validation was not working correctly
---
.../edit/forms/js/orgHasPositionUtils.js | 72 +++++++++++++++++++
.../forms/organizationHasPositionHistory.ftl | 2 +-
2 files changed, 73 insertions(+), 1 deletion(-)
create mode 100644 productMods/templates/freemarker/edit/forms/js/orgHasPositionUtils.js
diff --git a/productMods/templates/freemarker/edit/forms/js/orgHasPositionUtils.js b/productMods/templates/freemarker/edit/forms/js/orgHasPositionUtils.js
new file mode 100644
index 00000000..42e3f48b
--- /dev/null
+++ b/productMods/templates/freemarker/edit/forms/js/orgHasPositionUtils.js
@@ -0,0 +1,72 @@
+/* $This file is distributed under the terms of the license in /doc/license.txt$ */
+
+var orgHasPositionUtils = {
+
+ onLoad: function(blankSentinel) {
+ this.sentinel = '';
+ if ( blankSentinel ) { this.sentinel = blankSentinel; }
+
+ this.initObjectReferences();
+ this.bindEventListeners();
+
+ $.extend(this, vitro.customFormUtils);
+
+ if ( this.findValidationErrors() ) {
+ this.resetLastNameLabel();
+ }
+ },
+
+ initObjectReferences: function() {
+
+ this.form = $('#organizationHasPositionHistory');
+ this.person = $('#person');
+ this.firstName = $('#firstName');
+ this.lastName = $('#lastName');
+ this.personUri = $('#personUri');
+
+ // may not need this
+ this.firstName.attr('disabled', '');
+
+ },
+
+ bindEventListeners: function() {
+ this.idCache = {};
+
+ this.form.submit(function() {
+ orgHasPositionUtils.resolvePersonNames();
+ });
+ },
+
+ resolvePersonNames: function() {
+ var firstName,
+ lastName,
+ name;
+
+ // If selecting an existing person, don't submit name fields
+ if (this.personUri.val() == '' || this.personUri.val() == this.sentinel ) {
+ firstName = this.firstName.val();
+ lastName = this.person.val();
+
+ name = lastName;
+ if (firstName) {
+ name += ', ' + firstName;
+ }
+ this.person.val(name);
+ this.lastName.val(lastName);
+ }
+ else {
+ this.firstName.attr('disabled', 'disabled');
+ this.lastName.attr('disabled', 'disabled');
+ }
+
+ },
+
+ resetLastNameLabel: function() {
+ var indx = this.person.val().indexOf(", ");
+ if ( indx != -1 ) {
+ var temp = this.person.val().substr(0,indx);
+ this.person.val(temp);
+ }
+ }
+
+}
diff --git a/productMods/templates/freemarker/edit/forms/organizationHasPositionHistory.ftl b/productMods/templates/freemarker/edit/forms/organizationHasPositionHistory.ftl
index 41d69e48..b526f42e 100644
--- a/productMods/templates/freemarker/edit/forms/organizationHasPositionHistory.ftl
+++ b/productMods/templates/freemarker/edit/forms/organizationHasPositionHistory.ftl
@@ -117,7 +117,7 @@ Set this flag on the input acUriReceiver where you would like this behavior to o
-