refresh matview stockprop happens in ajax controller
[sgn.git] / js / CXGN / AJAX / Ontology.js
blob4fd8c116084c484f564d72f6ad8df7ab7e5e6e98
2 /**
3 * @class Ontology
4 * Function used for printing ontology annotations
5 * and helper functions for populating the menus of the associate_ontology tool
6 * @author Naama Menda <nm249@cornell.edu>
8 */
10 JSAN.use('jquery');
11 JSAN.use('jqueryui');
12 JSAN.use('popup');
13 JSAN.use('CXGN.Phenome.Tools');
15 var Ontology = {
16     submitCvtermForm: function(cvterm_add_uri, ontology_url) {
17         var onto_html = this.displayOntologies( "ontology" , ontology_url);
18         //make an AJAX request with the form params
19         var object_id = jQuery('#object_id').val();
20         var relationship = jQuery('#relationship_select').val();
21         var evidence_code = jQuery('#evidence_code_select').val();
22         var evidence_description = jQuery('#evidence_description_select').val();
23         var evidence_with = jQuery('#evidence_with_select').val();
24         var reference = jQuery('#reference_select').val();
25         var term_name =  jQuery('#term_name').val();
26         jQuery.ajax({
27                 url: "/ajax/locus/associate_ontology" ,
28                     type: 'POST',
29                     dataType: "json",
30                     async: false,
31             data: {
32                 'term_name': term_name,
33                 'object_id': object_id,
34                 'relationship': relationship,
35                 'evidence_code': evidence_code,
36                 'evidence_description': evidence_description,
37                 'evidence_with': evidence_with,
38                 'reference': reference ,
39             },
40             success: function(response) {
41                 var error = response.error;
42                 if (error) { alert(error) ; }
43             },
44             error: function () {
45                 alert('Error submitting ontology term');
46             }
48         } );
49         Tools.toggleContent('associate_cvterm_form', 'locus_ontology')
50         jQuery("#ontology").html( this.displayOntologies( "ontology" , ontology_url) );
51     },
53     displayOntologies: function(div_id, url) {
54         //alternate show the annotation and the detailed evidence
55         jQuery(function() {
56                 jQuery("#ontology_show_details").show()
57                 jQuery("#ontology_show_details input").click(function() {
58                         if( this.checked ) {
59                             jQuery("#ontology .evidence").show();
60                             jQuery(this).addClass('active');
61                         } else {
62                             jQuery("#ontology .evidence").hide();
63                             jQuery(this).removeClass('active');
64                         }
65                     });
66             });
67         jQuery.ajax( { url: url , dataType: "json",
68                     success: function(response) {
69                     var json = response;
70                     jQuery("#"+div_id).html(response.html);
71                     if ( response.error ) { alert(x.error) ; }
72                     if (response.html ) {
73                         jQuery("#ontology_show_details input").first()[0].disabled = false;
74                         jQuery("#ontology .evidence").hide();
75                     } else { jQuery('#ontology_show_details').hide(); }
76                 }
77             });
78     },
81     ////
82     //Make an ajax request for finding the available objects for ontology evidence
83     //(relationships, evidence codes, evidence description
84     populateEvidence: function(div_id, uri, dummy_option) {
85         jQuery.ajax({ url: uri , method:"GET" ,
86                     async: false,
87                     success: function(response) {
88                     var error = response.error;
89                     if (error) { alert(error) ; }
90                     var select = jQuery('#'+div_id);
91                     ////
92                     var arraykeys=[];
93                     for(var k in response) {arraykeys.push(k); }
94                     arraykeys.sort();
95                     var outputarray=[];
96                     for(var i=0; i<arraykeys.length; i++) {
97                         outputarray[arraykeys[i]]=response[arraykeys[i]];
98                     }
99                     ////
100                     var options = '';
101                     if (!dummy_option) dummy_option = '--Please select one--';
102                     options += '<option value="">' + dummy_option + '</option>';
103                     for ( var j in outputarray) {
104                         if ( !(isNaN(outputarray[j])) ) {
105                             options += '<option value="' + outputarray[j] + '">' + j + '</option>';
106                         }
107                     }
108                     jQuery("#"+div_id).html(options);
109                 }
110             });
111     },
112     getEvidenceWith: function() {
113     },
114     getReference: function() {
115     },