Merge pull request #4272 from solgenomics/topic/fix-vcf-download
[sgn.git] / mason / stock / add_phenotype.mas
blobb134a4812dc8c2c95ebc5bc1ce88ba15b429a2d1
1 <%doc>
3 =head1 NAME
5 add_phenotype.mas
7 =head1 DESCRIPTION
9 print form for adding a single phenotype to a stock
11 =head1 AUTHOR
13 Naama Menda <nm249@cornell.edu>
15 =head1 ARGUMENTS
17 =over 2
19 =item stock_id
21 the id of the stock
23 =item trait_ontology_db_name
24 the default db name for the server  trait ontology
26 =back
28 =cut
30 </%doc>
32 <%args>
34 $stock_id
35 $trait_ontology_db_name
36 $uri => "/ajax/cvterm/autocomplete"
38 </%args>
41 <& /util/import_javascript.mas, classes => [ 'jqueryui' ] &>
43 <script language="javascript">
44   
45   //test("test_alert");
47   
48   //function test(message) {
49   //       alert(message);
50   //}
52   jQuery(function() {
53      jQuery("#trait_ontology_name").autocomplete({
54       source: '<% $uri %>' + '?db_name=' + '<% $trait_ontology_db_name %>'
55      });
56   });
58    function associate_phenotype() {
59       var trait = jQuery("#trait_ontology_name").val();
60       if (!trait) { alert("Must choose a trait name!"); return; }
61       var stock_id = '<% $stock_id %>';
62       var phenotype_value = jQuery("#phenotye_value").val();
63       jQuery.ajax({
64         url: '/ajax/stock/add_phenotype',
65         dataType: "json",
66         method: "POST",
67         async: false,
68         data: { 'stock_id' : stock_id, 'trait': trait, 'phenotype_value': phenotype_value },
69         //error: function(response) { alert("An error occurred. Please try again later!"+response); },
70         //parseerror: function(response) { alert("A parse error occurred. Please try again."+response); },
71         success: function(response) {
72           if (response.error) { alert(response.error); }
73           else {
74             alert("The phenotype has been added. ["+response.error+"]");
75            //jQuery("#add_phenotype_form").dialog("close");
76             document.location.reload(); // reload the entire page, might be faster then rendering phenotype section with AJAX
77           }
78         }
79       });
82 </script>
84 <div id="add_phenotype_form">
85      <div id="phenotype_add">
86           <form name = "add_phenotype" >
87                 <b>Trait name</b><input type="text" id="trait_ontology_name" name="trait_ontology_name" />
88                 <b>Value</b> <input type="text" id="phenotype_value" />
89                 <input type="hidden" id="stock_id" name="stock_id" value="<% $stock_id %>" />
90                 <input type="button" name="associate_phenotype_button" id="associate_phenotype_button" value="Submit" onclick="javascript:associate_phenotype()" />
91         </form>
92         </div>
93 </div>