/* $This file is distributed under the terms of the license in /doc/license.txt$ */ var addTerminologyForm = { /* *** Initial page setup *** */ onLoad: function() { if (this.disableFormInUnsupportedBrowsers()) { return; } this.mixIn(); this.initObjects(); this.initPage(); }, disableFormInUnsupportedBrowsers: function() { var disableWrapper = $('#ie67DisableWrapper'); // Check for unsupported browsers only if the element exists on the page if (disableWrapper.length) { if (vitro.browserUtils.isIELessThan8()) { disableWrapper.show(); $('.noIE67').hide(); return true; } } return false; }, mixIn: function() { // Mix in the custom form utility methods $.extend(this, vitro.customFormUtils); // Get the custom form data from the page $.extend(this, customFormData); //test alert(addTerminologyForm.UMLSCUIURL); alert(addTerminologyForm.dataServiceUri); }, // On page load, create references for easy access to form elements. initObjects: function() { this.form = $('#addTerminologyForm'); this.showFormButtonWrapper = $('#showAddForm'); this.submit = this.form.find(':submit'); this.cancel = this.form.find('.cancel'); //Add term this.addTermButton = $('#showAddFormButton'); //section where results should be displayed this.selectedTerm = $('#selectedTerm'); //input for search term form this.searchTerm = $('#searchTerm'); this.searchSubmit = $('#searchButton'); //Hidden inputs for eventual submission this.referencedTerm = $('#referencedTerm'); this.entryTerm = $('#entryTerm'); this.termLabel = $('#termLabel'); this.termType = $('#termType'); this.removeTermLinks = $('a.remove'); }, initPage: function() { this.initTermData(); this.bindEventListeners(); }, bindEventListeners: function() { this.searchSubmit.click(function() { addTerminologyForm.submitSearchTerm(); return false; }); this.form.submit(function() { return addTerminologyForm.prepareSubmit(); }); this.addTermButton.click(function() { addTerminologyForm.initForm(); }); this.removeTermLinks.click(function() { addTerminologyForm.removeExistingTerm(this); return false; }); }, initForm: function() { // Hide the button that shows the form this.showFormButtonWrapper.hide(); this.clearSearchResults(); this.cancel.unbind('click'); this.cancel.bind('click', function() { //show only list of existing terms and hide adding term form addTerminologyForm.showTermListOnlyView(); return false; }); // Show the form this.form.show(); }, // On page load, associate data with each existing term element. Then we don't // have to keep retrieving data from or modifying the DOM as we manipulate the // authorships. initTermData: function() { $('.existingTerm').each(function(index) { $(this).data(existingTermsData[index]); $(this).data('position', index+1); }); }, clearSearchResults:function() { $('#selectedTerm').empty(); }, showTermListOnlyView: function() { this.hideForm(); this.showFormButtonWrapper.show(); }, submitSearchTerm: function() { //Get value of search term var searchValue = this.searchTerm.val(); this.entryTerm.val(searchValue); var dataServiceUrl = addTerminologyForm.dataServiceUrl + "?searchTerm=" + encodeURIComponent(searchValue); $.getJSON(dataServiceUrl, function(results) { if ( results.All.length == 0 ) { } else { //update existing content type with correct class group name and hide class group select again var bestMatchResults = results["Best Match"]; var numberMatches = bestMatchResults.length; var i; //For each result, display var htmlAdd = ""; if(numberMatches > 0) { htmlAdd = "
No search results found.
"; } $('#selectedTerm').html(htmlAdd); } }); }, addResultsHeader:function() { var htmlAdd = "