diff --git a/productMods/templates/freemarker/edit/forms/js/advisingRelationshipUtils.js b/productMods/templates/freemarker/edit/forms/js/advisingRelationshipUtils.js index 1ac33f34..d0a8af91 100644 --- a/productMods/templates/freemarker/edit/forms/js/advisingRelationshipUtils.js +++ b/productMods/templates/freemarker/edit/forms/js/advisingRelationshipUtils.js @@ -2,8 +2,12 @@ var advisingRelUtils = { - onLoad: function(subject) { - if ( subject ) { subjName = subject; } + onLoad: function(subject,blankSentinel) { + this.subjName = ''; + if ( subject ) { this.subjName = subject; } + + this.sentinel = ''; + if ( blankSentinel ) { this.sentinel = blankSentinel; } this.initObjectReferences(); this.bindEventListeners(); @@ -12,35 +16,54 @@ var advisingRelUtils = { initObjectReferences: function() { this.form = $('#personHasAdvisingRelationship'); - this.label = $('#advisingRelLabel'); + this.adRelshiplabel = $('#advisingRelLabel'); this.advisee = $('#advisee'); this.subjArea = $('#SubjectArea'); this.firstName = $('#firstName'); this.lastName = $('#lastName'); this.adviseeUri = $('#adviseeUri'); + this.subjAreaUri = $('#subjAreaUri'); + this.saveAdviseeLabel = $('#saveAdviseeLabel'); + this.adviseeAcSelection = $('div#adviseeAcSelection'); + + + // may not need this + this.firstName.attr('disabled', ''); }, bindEventListeners: function() { this.idCache = {}; + //we want to use the advisee label in the relationship label. + // since the former gets cleared on submit in some cases, store + //the value in a hidden field and map to relationship label + this.advisee.change( function(objEvent) { + window.setTimeout('advisingRelUtils.mapAdviseeValue()', 180); + }); + this.advisee.blur( function(objEvent) { + window.setTimeout('advisingRelUtils.mapAdviseeValue()', 180); + }); + + this.form.submit(function() { advisingRelUtils.resolveAdviseeNames(); advisingRelUtils.buildAdvisingRelLabel(); }); }, + mapAdviseeValue: function() { + if ( this.adviseeAcSelection.attr('class').indexOf('userSelected') != -1 ) { + this.saveAdviseeLabel.val(this.advisee.val()); + } + }, resolveAdviseeNames: function() { var firstName, lastName, name; // If selecting an existing person, don't submit name fields - if (this.adviseeUri.val() != '') { - this.firstName.attr('disabled', 'disabled'); - this.lastName.attr('disabled', 'disabled'); - } - else { + if (this.adviseeUri.val() == '' || this.adviseeUri.val() == this.sentinel ) { firstName = this.firstName.val(); lastName = this.advisee.val(); @@ -50,19 +73,22 @@ var advisingRelUtils = { } this.advisee.val(name); this.lastName.val(lastName); - + } + else { + this.firstName.attr('disabled', 'disabled'); + this.lastName.attr('disabled', 'disabled'); } }, buildAdvisingRelLabel: function() { - if ( this.advisee.val().substring(0, 18) != "Select an existing") { - this.label.val(subjName + " advising " + this.advisee.val()); + if ( this.advisee.val() != "" ) { + this.adRelshiplabel.val(this.subjName + " advising " + this.advisee.val()); } - else if ( this.subjArea.val().substring(0, 18) != "Select an existing" ) { - this.label.val(subjName + " advising in " + this.subjArea.val()); + else if ( this.saveAdviseeLabel.val() != "" ){ + this.adRelshiplabel.val(this.subjName + " advising " + this.saveAdviseeLabel.val()); } else { - this.label.val(subjName + " advising relationship"); + this.adRelshiplabel.val(this.subjName + " advising relationship"); } } diff --git a/productMods/templates/freemarker/edit/forms/js/awardReceiptUtils.js b/productMods/templates/freemarker/edit/forms/js/awardReceiptUtils.js index b804fa40..6c8bbe53 100644 --- a/productMods/templates/freemarker/edit/forms/js/awardReceiptUtils.js +++ b/productMods/templates/freemarker/edit/forms/js/awardReceiptUtils.js @@ -3,14 +3,22 @@ var awardReceiptUtils = { - onLoad: function(mode, subjectName) { + onLoad: function(mode, subjectName, href) { this.initObjectReferences(); this.bindEventListeners(); - // in edit mode, copy the year awarded to the displayed input element - if ( mode == "edit" ) { + this.baseHref = href; + this.editMode = mode; + // in edit mode copy the year awarded to the displayed input element + if ( this.editMode == "edit" ) { + this.hiddenOrgDiv = $('div#hiddenOrgLabel'); this.displayedYear.val(this.yearAwarded.val()); + if ( this.org.val() != '' ) { + window.setTimeout('awardReceiptUtils.hiddenOrgDiv.removeClass("hidden")', 100); + window.setTimeout('awardReceiptUtils.orgAcSelection.hide()', 100); + } } this.subjectName = subjectName; + $.extend(this, vitro.customFormUtils); }, initObjectReferences: function() { @@ -18,21 +26,66 @@ var awardReceiptUtils = { this.form = $('#personHasAwardOrHonor'); this.recLabel = $('#awardReceiptLabel'); this.award = $('#award'); + this.org = $('#org'); this.yearAwarded = $('#yearAwarded-year'); this.displayedYear = $('#yearAwardedDisplay'); - + this.awardAcSelection = $('div#awardAcSelection'); + this.orgAcSelection = $('div#orgAcSelection'); + this.orgUriReceiver = $('input#orgUri'); + this.changeLink = this.awardAcSelection.children('p').children('#changeSelection'); + }, bindEventListeners: function() { this.idCache = {}; + // the delay ensures that the function is called after the ac selection is completed + this.award.change( function(objEvent) { + window.setTimeout('awardReceiptUtils.hideConferredBy()', 180); + }); + + this.award.blur( function(objEvent) { + window.setTimeout('awardReceiptUtils.hideConferredBy()', 180); + }); + this.form.submit(function() { - awardReceiptUtils.setYearAwardedLabel(); + awardReceiptUtils.setYearAwardedValue(); awardReceiptUtils.buildAwardReceiptLabel(); }); + this.changeLink.click( function() { + awardReceiptUtils.showConferredBy(); + }); }, + hideConferredBy: function() { + if ( this.awardAcSelection.attr('class').indexOf('userSelected') != -1 ) { + this.org.parent('p').hide(); + this.org.val(''); + this.resetAcSelection(); } + }, + + showConferredBy: function() { + this.org.val('Select an existing Organization or create a new one.'); + this.org.addClass('acSelectorWithHelpText'); + this.org.parent('p').show(); + if ( this.editMode == "edit" ) { + this.hiddenOrgDiv.hide(); + } + this.resetAcSelection(); + }, + + resetAcSelection: function() { + var $acSelection = $("div.acSelection[acGroupName='org']"); + + if ( this.orgUriReceiver.val() != '' ) { + this.hideFields($acSelection); + $acSelection.removeClass('userSelected'); + $acSelection.find("span.acSelectionInfo").text(''); + $acSelection.find("a.verifyMatch").attr('href', this.baseHref); + } + }, + buildAwardReceiptLabel: function() { var rdfsLabel = this.award.val(); if ( this.yearAwarded.val().length ) { @@ -41,7 +94,7 @@ var awardReceiptUtils = { this.recLabel.val(rdfsLabel); }, - setYearAwardedLabel: function() { + setYearAwardedValue: function() { this.yearAwarded.val(this.displayedYear.val()); } diff --git a/productMods/templates/freemarker/edit/forms/js/customFormWithAutocomplete.js b/productMods/templates/freemarker/edit/forms/js/customFormWithAutocomplete.js index 51f6ff04..55f2df5d 100644 --- a/productMods/templates/freemarker/edit/forms/js/customFormWithAutocomplete.js +++ b/productMods/templates/freemarker/edit/forms/js/customFormWithAutocomplete.js @@ -271,10 +271,10 @@ var customForm = { //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(''); - }); + var $selectorInput = $("input.acSelector[acGroupName='" + groupName + "']"); + var $displayInput = $("input.display[acGroupName='" + groupName + "']"); + $displayInput.val($selectorInput.val()); + $selectorInput.val(''); } }); } @@ -480,7 +480,7 @@ var customForm = { if ( $checkSelection.is(':hidden') && $checkSelection.attr('acGroupName') != $acSelectionObj.attr('acGroupName') ) { customForm.resetAcSelection($checkSelection); $acSelector = customForm.getAcSelector($checkSelection); - $acSelector.parent("p").show(); + $acSelector.parent('p').show(); } }); } @@ -490,7 +490,7 @@ var customForm = { } $acSelector = this.getAcSelector($acSelectionObj); - $acSelector.parent("p").show(); + $acSelector.parent('p').show(); this.resetAcSelection($acSelectionObj); if ( clearAcSelectorVal == true ) { $acSelector.val(''); diff --git a/productMods/templates/freemarker/edit/forms/personHasAdvisingRelationship.ftl b/productMods/templates/freemarker/edit/forms/personHasAdvisingRelationship.ftl index da978611..e6a97403 100644 --- a/productMods/templates/freemarker/edit/forms/personHasAdvisingRelationship.ftl +++ b/productMods/templates/freemarker/edit/forms/personHasAdvisingRelationship.ftl @@ -24,14 +24,16 @@ Set this flag on the input acUriReceiver where you would like this behavior to o <#assign htmlForElements = editConfiguration.pageData.htmlForElements /> <#--Retrieve variables needed--> -<#assign adviseeValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "advisee") /> +<#assign adviseeValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "existingAdvisee") /> <#assign adviseeLabelValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "adviseeLabel") /> +<#assign adviseeLabelDisplayValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "adviseeLabelDisplay") /> <#assign firstNameValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "firstName") /> <#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, "existingSubjArea") /> <#assign subjAreaLabelValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "subjAreaLabel") /> +<#assign subjAreaLabelDisplayValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "subjAreaLabelDisplay") /> <#assign degreeValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "degree") /> <#assign acFilterForIndividuals = "['" + editConfiguration.subjectUri + "']" /> <#assign sparqlForAcFilter = editConfiguration.pageData.sparqlForAcFilter /> @@ -58,6 +60,8 @@ Set this flag on the input acUriReceiver where you would like this behavior to o <#--Display error messages if any--> <#if submissionErrors?has_content> + <#assign adviseeLabelValue = adviseeLabelDisplayValue /> + <#assign subjAreaLabelValue = subjAreaLabelDisplayValue />