Merge pull request #5230 from solgenomics/topic/open_pollinated
[sgn.git] / mason / breeders_toolbox / trialtree.mas
blobf23cccfb93af5a8b3549b0d9cce71e09b48e8d1c
1 #DEPRECATED
3 <%args>
4 @locations => ()
5 @roles => ()
6 $breeding_programs
7 </%args>
9 <& /util/import_javascript.mas, classes => [ 'jquery.iframe-post-form','CXGN.BreedersToolbox.AddTrial','CXGN.BreedersToolbox.UploadTrial','CXGN.BreedersToolbox.Trial', 'jstree.dist.jstree' ] &>
11 <& /breeders_toolbox/trial/trial_create_dialogs.mas, locations => \@locations, breeding_programs => $breeding_programs &>
12 <& /breeders_toolbox/trial/trial_upload_dialogs.mas, locations => \@locations, breeding_programs => $breeding_programs &>
14 <table class="table table-bordered">
15   <thead>
16     <tr>
17       <th>Information</th>
18       <th>Breeding Programs -- -- Trials</th>
19     </tr>
20   </thead>
21   <tbody>
22   <tr>
23     <td>
24       <h4>Download Trial</h4>
25       <button class="btn btn-primary" id="download_button" disabled="disabled" title="First Select a Trial to Download">Excel</button>
26       <button class="btn btn-primary" id="download_button_csv" disabled="disabled" title="First Select a Trial to Download">CSV</button><br />
27       <hr>
28       <h5><i>Double click<br />trial to view</i></h5>
29       <!-- hr>
30       <button id="delete" disabled="disabled" >Delete</button -->
31       <br />
32     </td>
33     <td>
34       <div id="trial_list" >[loading...]</div>
35     </td>
36   </tr>
37   </tbody>
38 </table>
41 <script>
43   jQuery.noConflict(); 
45   jQuery(document).ready(function($) {  
46     
47     jQuery.ajax( { 
48       url: '/ajax/breeders/get_trials',
49       success: function(response) { 
50         var html = format(response);
51         jQuery('#trial_list').html(html);
52         jQuery('#trial_list').jstree();
54       },
55       error: function(response) { 
56         alert("An error occurred");
57       }
58   });
60   function format(s) { 
61     var html = "<ul>";
62     for (var k in s) { 
63       if(s.hasOwnProperty(k)) { 
64         html += "<li>"+ k;
65         if (s[k] !== null) { 
66           html += '<ul>';
67           for (var n=0; n<s[k].length; n++) { 
68        
69             html += '<li id="'+s[k][n][0]+'">'+s[k][n][1]+"</li>";
71           }
72           html += '</ul>';
73         }
75       }
76         html += '</li>';
77     }
78     html += "</ul>";
79      return html;
81    }
83      $('#trial_list').on("changed.jstree", function (e, data) {
84        if ($('#trial_list').jstree('is_leaf', data.node)) { 
85          $('#download_button').removeAttr('disabled');
86          $('#download_button_csv').removeAttr('disabled');
87        }
88        else { 
89          $('#download_button').attr('disabled', 'disabled');
90          $('#download_button_csv').attr('disabled', 'disabled');
91        }
92          
93        
94          // }
95     });                               
97     $('#download_button').on('click', function () {
98         var selected = $('#trial_list').jstree('get_bottom_selected');
99         if (selected.length !== 0) { 
100           window.open('/breeders/trials/phenotype/download/'+selected.join(","));
101         }
102         else { alert("No leaf nodes selected for download."); }
103        
104     });
106     $('#download_button_csv').on('click', function () {
107         var selected = $('#trial_list').jstree('get_bottom_selected');
108         if (selected.length !== 0) { 
109           window.open('/breeders/trials/phenotype/download/'+selected.join(",")+'?format=csv');
110         }
111         else { alert("No leaf nodes selected for download."); }
112        
113     });
115     $("#trial_list").delegate("li", "dblclick", function(){ 
116       var node = $("#trial_list").jstree("get_node", this); 
117       if ($('#trial_list').jstree('is_leaf', node) && node.id.substr(0,1) !== 'j') {                                   
118         window.open('/breeders_toolbox/trial/'+node.id);
119       }
120     }); 
121   });
122 </script>