add pdf download test
[sgn.git] / mason / breeders_toolbox / trialtreefolders.mas
blob466b7da6faf07a085e89648a4fd38e4f0fd9b69c
2 <%args>
3 @locations => ()
4 $breeding_programs
5 </%args>
7 <& /util/import_javascript.mas, classes => [ 'jquery.iframe-post-form','CXGN.BreedersToolbox.AddTrial','CXGN.BreedersToolbox.UploadTrial','CXGN.BreedersToolbox.Trial', 'jstree.dist.jstree', 'CXGN.Trial', 'CXGN.BreedersToolbox.HTMLSelect', 'CXGN.TrialTreeFolders','CXGN.BreedersToolbox.AddMultipleTrial' ] &>
9 <link rel="stylesheet" href="/static/documents/inc/jstree_theme/jstree-bstheme-min.css" />
11 <& /breeders_toolbox/folder/folder_set.mas &>
12 <& /breeders_toolbox/folder/folder_new.mas &>
13 <& /breeders_toolbox/folder/folder_move.mas &>
14 <& /breeders_toolbox/folder/folders_edit.mas, folder_tree_type => 'Trial', folder_tree_identifier => 'trial_list', folder_tree_refresh_name => 'refresh_jstree_html' &>
16 <& /breeders_toolbox/trial/trial_create_dialogs.mas, locations => \@locations, breeding_programs => $breeding_programs &>
17 <& /breeders_toolbox/trial/trial_upload_dialogs.mas, locations => \@locations, breeding_programs => $breeding_programs &>
18 <& /breeders_toolbox/trial/trial_create_multiloc_dialogs.mas, locations => \@locations, breeding_programs => $breeding_programs &>
20 <& /breeders_toolbox/trial/download_trials_phenotypes_dialog.mas &>
22 <table class="table table-bordered">
23   <thead>
24     <tr>
25       <th>Information</th>
26       <th>Breeding Programs -- Folders -- Trials&nbsp;&nbsp;&nbsp;&nbsp;<button class="btn btn-sm btn-default" id="refresh_jstree_html_trialtree_button" name="refresh_jstree_html">Refresh</button></th>
27     </tr>
28   </thead>
29   <tbody>
30   <tr>
31     <td>
32         <h4>Search</h4>
33         <input type="text" class="form-control input-sm" id="trial_tree_search" placeholder="Search" />
34         <hr>
35       <h4>Download Trial Phenotypes</h4>
36       <h5><i>Select multiple trials by holding 'Ctrl'.</i></h5>
37       <button class="btn btn-primary" id="trials_download_phenotypes_button" disabled="disabled" title="First Select Trial(s) to Download">Download Phenotypes</button>
38       <hr>
39       <h5><i>Double click<br />trial (&nbsp;<span class="glyphicon glyphicon-leaf text-success"></span>&nbsp;) or folder (&nbsp;<span class="glyphicon glyphicon-folder-open text-danger"></span>&nbsp;)<br/>to view detail page.</i></h5>
40       <h5><i>Breeding programs (&nbsp;<span class="glyphicon glyphicon-briefcase text-info"></span>&nbsp;)</i></h5>
41       <hr>
42       <h4>Folders</h4>
43       <button class="btn btn-sm btn-default" id="new_folder_dialog_link">Create new folder</button><br/><br/>
44       <button class="btn btn-sm btn-default" id="open_folder_dialog_link">Move trial to folder</button><br/><br/>
45       <button class="btn btn-sm btn-default" id="move_folder_dialog_link">Move folder</button>
46       
47       <div id="folder_edit_options" style="display:none">
48           <hr>
49           <h5><i>Select multiple folders by holding 'Ctrl'.</i></h5>
50           <button class="btn btn-primary" id="edit_folders_button" title="First Select Folder(s) to Edit">Edit Folder(s)</button>
51           <br/>
52       </div>
54       <!--<button id="delete" disabled="disabled" >Delete</button -->
55       <br />
56     </td>
57     <td>
58         <div id="trial_list" >[loading...]</div>
59     </td>
60   </tr>
61   </tbody>
62 </table>
65 <script>
67   jQuery.noConflict();
69   jQuery(document).ready(function($) {
71     jQuery.ajax( {
72       url: '/ajax/breeders/get_trials_with_folders_cached',
73       success: function(response) {
74         var html = '<ul>'+response.html+'</ul>';
76         jQuery('#trial_list').html(html);
77         //console.log(html);
78         jQuery('#trial_list').jstree( {
79             "core": { 'themes': { 'name': 'proton', 'responsive': true}},
80             "valid_children" : [ "folder", "trial", "breeding_program" ],
81             "types" : {
82                 "breeding_program" : {
83                     "icon": 'glyphicon glyphicon-briefcase text-info',
84                 },
85                 "folder" : {
86                     "icon": 'glyphicon glyphicon-folder-open text-danger',
87                 },
88                 "trial" : {
89                     "icon": 'glyphicon glyphicon-leaf text-success',
90                 }
91             },
92             "search" : {
93                  "case_insensitive" : true,
94              },
95           "plugins" : ["html_data","types","search"],
97         });
99       },
100       error: function(response) {
101         alert("An error occurred while loading the trial data.");
102       }
103   });
105     jQuery("#trial_tree_search").keyup(function() {
106         var v = jQuery("#trial_tree_search").val();
107         jQuery("#trial_list").jstree(true).search(v);
108     });
112   jQuery('#trial_list').on("changed.jstree", function (e, data) {
113     //console.log(data);
114        if ($('#trial_list').jstree('is_leaf', data.node) && data.node.data.jstree.type == 'trial') {
115          jQuery('#trials_download_phenotypes_button').removeAttr('disabled');
116          jQuery("#folder_edit_options").hide();
117        }
118        else if ($('#trial_list').jstree('is_leaf', data.node) && data.node.data.jstree.type == 'folder') {
119          jQuery('#trials_download_phenotypes_button').attr('disabled', 'disabled');
120          jQuery("#folder_edit_options").show();
121        }
122        else {
123          jQuery('#trials_download_phenotypes_button').attr('disabled', 'disabled');
124          jQuery("#folder_edit_options").hide();
125        }
126     });
129     $("#trial_list").delegate("li", "dblclick", function(event){
130       var node = $("#trial_list").jstree("get_node", this);
131       //console.log(node);
132       if (node.id.substr(0,1) !== 'j') {
133         if (node.type == 'folder') {
134             window.open('/folder/'+node.id);
135             event.stopPropagation();
136         } else if (node.type == 'trial') {
137             window.open('/breeders_toolbox/trial/'+node.id);
138             event.stopPropagation();
139         }
140       }
141     });
142   });
144 </script>