refactoring brapi
[sgn.git] / js / solGS / searchTraits.js
blob9fbaa9ec897ea3fc429dab35b0b252646dfef64c
1 /** 
2 * search traits
4 * @author Isaak Y Tecle <iyt2@cornell.edu>
6 */
9 jQuery(document).ready( function () {
10     
11      jQuery('#search_trait_entry').keyup(function(e) {          
12          if(e.keycode == 13) {      
13              jQuery('#search_trait').click();
14          }
15      });
17     jQuery('#search_trait').on('click', function () {
18         var entry = jQuery('#search_trait_entry').val();
20         if (entry) {
21             searchTraits(entry);
22         }
23     });
24           
25 });
28 function searchTraits (name) {
29    
30         jQuery.ajax({
31             type: 'POST',
32             dataType: 'json',
33             data: {'name': name},
34             url: '/solgs/search/traits/' + name,
35             success: function (res) {   
36                 
37                 if (res.status) {               
38                     window.location = '/solgs/search/result/traits/' + name;
39                 } else {                    
40                     jQuery("#search_trait_message")
41                         .html('There are no entries for trait: ' + name)
42                         .show()
43                         .fadeOut(5000);
44                 }
45             },      
46             error: function () {
47                 jQuery("#search_trait_message")
48                     .html('Error occured searching for trait ' + name)
49                     .show()
50                     .fadeOut(5000);
51                 
52             },
53         });
54