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