updates for concept addition javascript, and inclusion of error div in form where error messages can be displayed,

This commit is contained in:
hjkhjk54 2011-12-01 14:54:00 +00:00
parent a3dfd5f179
commit 88e9f45445
2 changed files with 26 additions and 15 deletions

View file

@ -64,8 +64,8 @@ var addConceptForm = {
}, },
bindEventListeners: function() { bindEventListeners: function() {
this.searchSubmit.click(function() { this.searchSubmit.click(function() {
addConceptForm.clearErrors();
addConceptForm.submitSearchTerm(); addConceptForm.submitSearchTerm();
addConceptForm.clearErrors();
return false; return false;
}); });
@ -86,7 +86,8 @@ var addConceptForm = {
// Hide the button that shows the form // Hide the button that shows the form
this.showFormButtonWrapper.hide(); this.showFormButtonWrapper.hide();
this.clearSearchResults(); this.clearSearchResults();
//Also clear the search input
this.searchTerm.val("");
this.cancel.unbind('click'); this.cancel.unbind('click');
this.cancel.bind('click', function() { this.cancel.bind('click', function() {
//show only list of existing terms and hide adding term form //show only list of existing terms and hide adding term form
@ -119,13 +120,18 @@ var addConceptForm = {
submitSearchTerm: function() { submitSearchTerm: function() {
//Get value of search term //Get value of search term
var searchValue = this.searchTerm.val(); var searchValue = this.searchTerm.val();
var vocabSourceValue = $('input:radio[name="source"]:checked').val(); var checkedVocabSource = $('input:radio[name="source"]:checked');
if(!checkedVocabSource.length) {
addConceptForm.showUncheckedSourceError();
return;
}
var vocabSourceValue = checkedVocabSource.val();
var dataServiceUrl = addConceptForm.dataServiceUrl + "?searchTerm=" + encodeURIComponent(searchValue) + "&source=" + encodeURIComponent(vocabSourceValue); var dataServiceUrl = addConceptForm.dataServiceUrl + "?searchTerm=" + encodeURIComponent(searchValue) + "&source=" + encodeURIComponent(vocabSourceValue);
$.getJSON(dataServiceUrl, function(results) { $.getJSON(dataServiceUrl, function(results) {
var htmlAdd = ""; var htmlAdd = "";
if ( results== null || results.array == null || results.array.length == 0 ) { if ( results== null || results.array == null || results.array.length == 0 ) {
htmlAdd = "<p>No search results</p>"; htmlAdd = "<p>No search results found.</p>";
} else { } else {
//array is an array of objects representing concept information //array is an array of objects representing concept information
//loop through and find all the best matches //loop through and find all the best matches
@ -151,10 +157,13 @@ var addConceptForm = {
} else { } else {
htmlAdd+= "<p>No search results found.</p>"; htmlAdd+= "<p>No search results found.</p>";
} }
}
if(htmlAdd.length) {
$('#selectedConcept').html(htmlAdd); $('#selectedConcept').html(htmlAdd);
} }
}); });
return true;
}, },
parseResults:function(resultsArray) { parseResults:function(resultsArray) {
//Loop through array and check if this is the best match //Loop through array and check if this is the best match
@ -177,7 +186,7 @@ var addConceptForm = {
this.selectedConcept.hide(); this.selectedConcept.hide();
}, },
prepareSubmit:function() { prepareSubmit:function() {
var checkedElements = $("#CUI:checked"); var checkedElements = $("input[name='CUI']:checked");
if(!addConceptForm.validateConceptSelection(checkedElements)) { if(!addConceptForm.validateConceptSelection(checkedElements)) {
return false; return false;
} }
@ -214,7 +223,7 @@ var addConceptForm = {
return htmlAdd; return htmlAdd;
}, },
generateIndividualCUIInput:function(cuiURI, label, type, definedBy) { generateIndividualCUIInput:function(cuiURI, label, type, definedBy) {
return "<input type='checkbox' id='CUI' name='CUI' value='" + cuiURI + "' label='" + label + "' conceptType='" + type + "' conceptDefinedBy='" + definedBy + "'/>"; return "<input type='checkbox' name='CUI' value='" + cuiURI + "' label='" + label + "' conceptType='" + type + "' conceptDefinedBy='" + definedBy + "'/>";
}, },
generateIndividualTypeDisplay:function(type) { generateIndividualTypeDisplay:function(type) {
if(type != null && type.length > 0) { if(type != null && type.length > 0) {
@ -232,7 +241,11 @@ var addConceptForm = {
return false; return false;
} }
return true; return true;
}, removeExistingConcept: function(link) { },
showUncheckedSourceError:function() {
addConceptForm.errors.html("<p class='validationError'>Please select at least one external vocabulary source to search.</p>");
},
removeExistingConcept: function(link) {
var removeLast = false, var removeLast = false,
message = 'Are you sure you want to remove this term?'; message = 'Are you sure you want to remove this term?';

View file

@ -77,9 +77,9 @@
<a class="cancel" href="${cancelUrl}&url=/individual">Return</a> <a class="cancel" href="${cancelUrl}&url=/individual">Return</a>
</div> </div>
<form id="addConceptForm" class="customForm" action="${submitUrl}"> <form id="addConceptForm" class="customForm" action="${submitUrl}">
<#assign checkedSource = false />
<#list sources?keys as sourceUri> <#list sources?keys as sourceUri>
<input type="radio" id="source" name="source" value="${sourceUri}" role="radio" /> <input type="radio" name="source" value="${sourceUri}" role="radio" <#if checkedSource = false><#assign checkedSource = true/>checked="checked"</#if>>
<label class="inline" for="${sources[sourceUri]}"> ${sources[sourceUri]}</label> <label class="inline" for="${sources[sourceUri]}"> ${sources[sourceUri]}</label>
<br /> <br />
</#list> </#list>
@ -90,14 +90,13 @@
</p> </p>
<input type="hidden" id="conceptNode" name="conceptNode" value=""/> <!-- Field value populated by JavaScript --> <input type="hidden" id="conceptNode" name="conceptNode" value=""/> <!-- Field value populated by JavaScript -->
<input type="hidden" id="conceptLabel" name="conceptLabel" value="" /> <!-- Field value populated by JavaScript --> <input type="hidden" id="conceptLabel" name="conceptLabel" value="" /> <!-- Field value populated by JavaScript -->
<!--TODO: Change this so this is populated by the javascript-->
<input type="hidden" id="conceptSource" name="conceptSource" value="" /> <!-- Field value populated by JavaScript --> <input type="hidden" id="conceptSource" name="conceptSource" value="" /> <!-- Field value populated by JavaScript -->
<div id="selectedConcept" name="selectedConcept" class="acSelection"> <div id="selectedConcept" name="selectedConcept" class="acSelection">
<%-- RY maybe make this a label and input field. See what looks best. --%>
<p class="inline"> <p class="inline">
</p> </p>
<!-- Field value populated by JavaScript --> <!-- Search results populated by JavaScript -->
</div> </div>
<div id="errors" name="errors"></div>
<div><a href="${userDefinedConceptUrl}" > Can't find the concept you want? Create your own.</a> <div><a href="${userDefinedConceptUrl}" > Can't find the concept you want? Create your own.</a>
</div> </div>
@ -114,8 +113,7 @@
<script type="text/javascript"> <script type="text/javascript">
var customFormData = { var customFormData = {
dataServiceUrl: '${urls.base}/conceptSearchService', dataServiceUrl: '${urls.base}/conceptSearchService'
UMLSCUIURL: 'http://link.informatics.stonybrook.edu/umls/CUI/'
}; };
</script> </script>